feat: change jit_compile default value from ACL

This commit is contained in:
yangxiaorun
2023-04-06 20:03:16 +08:00
parent fe8f45afd4
commit 2d4c60d2f1
5 changed files with 96 additions and 3 deletions
+23
View File
@@ -138,6 +138,29 @@ ACL_FUNC_VISIBILITY aclError aclopCompileAndExecuteV2(const char *opType,
*/
ACL_FUNC_VISIBILITY aclError aclSetCompileopt(aclCompileOpt opt, const char *value);
/**
* @ingroup AscendCL
* @brief get compile option value size
*
* @param aclCompileOpt [IN] compile option
*
* @retval size of compile option value
*/
ACL_FUNC_VISIBILITY size_t aclGetCompileoptSize(aclCompileOpt opt);
/**
* @ingroup AscendCL
* @brief get compile option
*
* @param aclCompileOpt [IN] compile option
* @param value [OUT] pointer for the option value
* @param length [IN] length of value
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError aclGetCompileopt(aclCompileOpt opt, char *value, size_t length);
/**
* @ingroup AscendCL
* @brief set compile flag
@@ -67,6 +67,22 @@ void MakeCompileCacheDirAndSetOption() {
c10_npu::option::register_options::OptionRegister::GetInstance()->Set("ACL_OP_COMPILER_CACHE_MODE", "enable");
c10_npu::option::register_options::OptionRegister::GetInstance()->Set("ACL_OP_COMPILER_CACHE_DIR", compile_cache_dir);
}
void GetAndSetDefaultJitCompileByAcl() {
auto opt_size = at_npu::native::AclGetCompileoptSize(ACL_OP_JIT_COMPILE);
if (!opt_size.has_value()) {
ASCEND_LOGW("Get ACL JitCompile default value size failed, use PTA default value: True");
return;
}
TORCH_CHECK(opt_size.value() != 0, "AclGetCompileoptSize opt_size.value() = 0 !");
char value_name[opt_size.value()];
auto ret = at_npu::native::AclGetCompileopt(ACL_OP_JIT_COMPILE, value_name, opt_size.value());
// Get func success but get value failed, throw error
TORCH_CHECK(ret == ACL_SUCCESS, "Get ACL JitCompile default value failed.");
std::string value_str(value_name);
c10_npu::option::SetOption("jitCompile", value_str);
ASCEND_LOGI("Get ACL JitCompile default value %s and set", value_str.c_str());
}
} // namespace
namespace c10_npu {
@@ -167,6 +183,8 @@ NpuSysCtrl::NpuSysCtrl() : init_flag_(false), device_id_(0) {}
// set default compile cache mode and dir for users to improve op compile time
MakeCompileCacheDirAndSetOption();
// set default jit_Compile value from Get acl defalut value
GetAndSetDefaultJitCompileByAcl();
return INIT_SUCC;
}
@@ -14,15 +14,15 @@
// limitations under the License.
#include <c10/util/Exception.h>
#include <c10/util/Optional.h>
#include "torch_npu/csrc/core/npu/register/FunctionLoader.h"
#include "torch_npu/csrc/framework/interface/AclOpCompileInterface.h"
#include "third_party/acl/inc/acl/acl_base.h"
namespace at_npu
{
namespace native
{
#undef LOAD_FUNCTION
#define LOAD_FUNCTION(funcName) \
REGISTER_FUNCTION(libacl_op_compiler, funcName)
@@ -32,6 +32,8 @@ namespace at_npu
REGISTER_LIBRARY(libacl_op_compiler)
LOAD_FUNCTION(aclSetCompileopt)
LOAD_FUNCTION(aclGetCompileoptSize)
LOAD_FUNCTION(aclGetCompileopt)
LOAD_FUNCTION(aclGenGraphAndDumpForOp)
LOAD_FUNCTION(aclCreateGraphDumpOpt)
LOAD_FUNCTION(aclDestroyGraphDumpOpt)
@@ -49,6 +51,32 @@ aclError AclSetCompileopt(aclCompileOpt opt, const char *value) {
return ret;
}
c10::optional<size_t> AclGetCompileoptSize(aclCompileOpt opt) {
typedef aclError (*aclGetCompileoptSizeFunc)(aclCompileOpt opt);
static aclGetCompileoptSizeFunc func = nullptr;
if (func == nullptr) {
func = (aclGetCompileoptSizeFunc)GET_FUNC(aclGetCompileoptSize);
}
if (func == nullptr) {
return c10::nullopt;
} else {
return func(opt);
}
}
aclError AclGetCompileopt(aclCompileOpt opt, char *value, size_t length) {
typedef aclError (*aclGetCompileoptFunc)(aclCompileOpt opt, char *value, size_t length);
static aclGetCompileoptFunc func = nullptr;
if (func == nullptr) {
func = (aclGetCompileoptFunc)GET_FUNC(aclGetCompileopt);
}
if (func == nullptr) {
return ACL_ERROR_GE_FAILURE;
} else {
return func(opt, value, length);
}
}
aclError AclGenGraphAndDumpForOp(const char *opType,
int numInputs, const aclTensorDesc *const inputDesc[], const aclDataBuffer *const inputs[],
int numOutputs, const aclTensorDesc *const outputDesc[], aclDataBuffer *const outputs[],
@@ -15,7 +15,7 @@
#ifndef __PLUGIN_NATIVE_NPU_INTERFACE_ACLOPCOMPILE__
#define __PLUGIN_NATIVE_NPU_INTERFACE_ACLOPCOMPILE__
#include <c10/util/Optional.h>
#include "third_party/acl/inc/acl/acl_op_compiler.h"
namespace at_npu {
@@ -44,6 +44,29 @@ aclError AclopSetCompileFlag(aclOpCompileFlag flag);
*/
ACL_FUNC_VISIBILITY aclError AclSetCompileopt(aclCompileOpt opt, const char *value);
/**
* @ingroup AscendCL
* @brief get compile option value size
*
* @param aclCompileOpt [IN] compile option
*
* @retval size of compile option value
*/
ACL_FUNC_VISIBILITY c10::optional<size_t> AclGetCompileoptSize(aclCompileOpt opt);
/**
* @ingroup AscendCL
* @brief get compile option
*
* @param aclCompileOpt [IN] compile option
* @param value [OUT] pointer for the option value
* @param length [IN] length of value
*
* @retval ACL_SUCCESS The function is successfully executed.
* @retval OtherValues Failure
*/
ACL_FUNC_VISIBILITY aclError AclGetCompileopt(aclCompileOpt opt, char *value, size_t length);
/**
* @ingroup AscendCL
* @brief dump op graph for AOE
+1
View File
@@ -89,6 +89,7 @@ def get_mm_bmm_format_nd():
return _MM_BMM_ND_ENABLE
def is_jit_compile_false() -> bool:
torch_npu.npu._lazy_init()
return torch_npu._C._npu_is_jit_compile_false()
class npuConfig: