@@ -177,7 +177,7 @@ Session::Session(const std::map<string, string> &options) { | |||
// check init status | |||
sessionId_ = 0; | |||
if (!g_ge_initialized) { | |||
GELOGE(GE_CLI_GE_NOT_INITIALIZED); | |||
GELOGE(GE_CLI_GE_NOT_INITIALIZED, "GE is not initialized."); | |||
return; | |||
} | |||
// call Initialize | |||
@@ -16,9 +16,7 @@ | |||
#include "common/auth/file_saver.h" | |||
#include <fcntl.h> | |||
#include <securec.h> | |||
#include <unistd.h> | |||
#include <cstdlib> | |||
#include <fstream> | |||
#include <vector> | |||
@@ -39,12 +37,12 @@ Status FileSaver::OpenFile(int32_t &fd, const std::string &file_path) { | |||
return FAILED; | |||
} | |||
char real_path[PATH_MAX] = {0}; | |||
GE_IF_BOOL_EXEC(realpath(file_path.c_str(), real_path) == nullptr, | |||
char real_path[MMPA_MAX_PATH] = {0}; | |||
GE_IF_BOOL_EXEC(mmRealPath(file_path.c_str(), real_path, MMPA_MAX_PATH) != EN_OK, | |||
GELOGI("File %s is not exist, it will be created.", file_path.c_str())); | |||
// Open file | |||
mode_t mode = S_IRUSR | S_IWUSR; | |||
fd = mmOpen2(real_path, O_RDWR | O_CREAT | O_TRUNC, mode); | |||
mmMode_t mode = M_IRUSR | M_IWUSR; | |||
fd = mmOpen2(real_path, M_RDWR | M_CREAT | O_TRUNC, mode); | |||
if (fd == EN_INVALID_PARAM || fd == EN_ERROR) { | |||
// -1: Failed to open file; - 2: Illegal parameter | |||
GELOGE(FAILED, "Open file failed. mmpa_errno = %d, %s", fd, strerror(errno)); | |||
@@ -194,7 +192,7 @@ Status FileSaver::SaveToBuffWithFileHeader(const ModelFileHeader &file_header, | |||
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status FileSaver::CheckPath(const std::string &file_path) { | |||
// Determine file path length | |||
if (file_path.size() >= PATH_MAX) { | |||
if (file_path.size() >= MMPA_MAX_PATH) { | |||
GELOGE(FAILED, "Path is too long:%zu", file_path.size()); | |||
return FAILED; | |||
} | |||
@@ -16,9 +16,6 @@ | |||
#include "common/debug/memory_dumper.h" | |||
#include <fcntl.h> | |||
#include <unistd.h> | |||
#include <string> | |||
#include "framework/common/debug/log.h" | |||
@@ -138,26 +135,26 @@ int MemoryDumper::OpenFile(const char *filename) { | |||
} | |||
// Get the absolute path | |||
string real_path; | |||
char tmp_path[PATH_MAX] = {0}; | |||
char tmp_path[MMPA_MAX_PATH] = {0}; | |||
GE_IF_BOOL_EXEC( | |||
-1 != path_split_pos, string prefix_path = std::string(filename).substr(0, path_split_pos); | |||
string last_path = std::string(filename).substr(path_split_pos, strlen(filename) - 1); | |||
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(prefix_path.length() >= PATH_MAX, return kInvalidFd, "Prefix path is too long!"); | |||
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(realpath(prefix_path.c_str(), tmp_path) == nullptr, return kInvalidFd, | |||
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(prefix_path.length() >= MMPA_MAX_PATH, return kInvalidFd, "Prefix path is too long!"); | |||
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(mmRealPath(prefix_path.c_str(), tmp_path, MMPA_MAX_PATH) != EN_OK, return kInvalidFd, | |||
"Dir %s does not exit.", prefix_path.c_str()); | |||
real_path = std::string(tmp_path) + last_path;) | |||
GE_IF_BOOL_EXEC( | |||
path_split_pos == -1 || path_split_pos == 0, | |||
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(strlen(filename) >= PATH_MAX, return kInvalidFd, "Prefix path is too long!"); | |||
GE_IF_BOOL_EXEC(realpath(filename, tmp_path) == nullptr, | |||
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(strlen(filename) >= MMPA_MAX_PATH, return kInvalidFd, "Prefix path is too long!"); | |||
GE_IF_BOOL_EXEC(mmRealPath(filename, tmp_path, MMPA_MAX_PATH) != EN_OK, | |||
GELOGI("File %s does not exit, it will be created.", filename)); | |||
real_path = std::string(tmp_path);) | |||
// Open file, only the current user can read and write, to avoid malicious application access | |||
// Using the O_EXCL, if the file already exists,return failed to avoid privilege escalation vulnerability. | |||
mode_t mode = S_IRUSR | S_IWUSR; | |||
mmMode_t mode = M_IRUSR | M_IWUSR; | |||
int32_t fd = mmOpen2(real_path.c_str(), O_RDWR | O_CREAT | O_APPEND, mode); | |||
int32_t fd = mmOpen2(real_path.c_str(), M_WRONLY | M_CREAT | O_TRUNC, mode); | |||
if (fd == EN_ERROR || fd == EN_INVALID_PARAM) { | |||
GELOGE(kInvalidFd, "open file failed. errno = %d, %s", fd, strerror(errno)); | |||
return kInvalidFd; | |||
@@ -118,19 +118,19 @@ Status TransFormatFromNchwToFzC04(const TransArgs &args, TransResult &result) { | |||
// data overflow check totally | |||
GE_IF_BOOL_EXEC(!CheckInt64MulOverflow(h_o, w_o), | |||
GELOGE(INTERNAL_ERROR, "int64 mul overflow.A[%lld], B[%lld]", h_o, w_o); | |||
GELOGE(INTERNAL_ERROR, "int64 mul overflow.A[%ld], B[%ld]", h_o, w_o); | |||
return INTERNAL_ERROR); | |||
GE_IF_BOOL_EXEC(!CheckInt64MulOverflow(n_o, c_o), | |||
GELOGE(INTERNAL_ERROR, "int64 mul overflow.A[%lld], B[%lld]", n_o, c_o); | |||
GELOGE(INTERNAL_ERROR, "int64 mul overflow.A[%ld], B[%ld]", n_o, c_o); | |||
return INTERNAL_ERROR); | |||
auto t1 = h_o * w_o; | |||
auto t2 = n_o * c_o; | |||
GE_IF_BOOL_EXEC(!CheckInt64MulOverflow(t1, t2), GELOGE(INTERNAL_ERROR, "int64 mul overflow.A[%lld], B[%lld]", t1, t2); | |||
GE_IF_BOOL_EXEC(!CheckInt64MulOverflow(t1, t2), GELOGE(INTERNAL_ERROR, "int64 mul overflow.A[%ld], B[%ld]", t1, t2); | |||
return INTERNAL_ERROR); | |||
int64_t total_ele_cnt = n_o * c_o * h_o * w_o; | |||
GE_IF_BOOL_EXEC(!CheckInt64MulOverflow(total_ele_cnt, size), | |||
GELOGE(INTERNAL_ERROR, "int64 mul overflow.A[%lld], B[%lld]", total_ele_cnt, size); | |||
GELOGE(INTERNAL_ERROR, "int64 mul overflow.A[%ld], B[%d]", total_ele_cnt, size); | |||
return INTERNAL_ERROR); | |||
int64_t dst_size = total_ele_cnt * size; | |||
if (dst_size == 0) { | |||
@@ -205,20 +205,20 @@ Status PaddingNC(const TransArgs &args, TransArgs &args_tmp, std::shared_ptr<uin | |||
// data overflow check | |||
GE_IF_BOOL_EXEC(!CheckInt64MulOverflow(h_o, w_o), | |||
GELOGE(INTERNAL_ERROR, "int64 mul overflow.A[%lld], B[%lld]", h_o, w_o); | |||
GELOGE(INTERNAL_ERROR, "int64 mul overflow.A[%ld], B[%ld]", h_o, w_o); | |||
return INTERNAL_ERROR); | |||
GE_IF_BOOL_EXEC(!CheckInt64MulOverflow(n_o, c_o), | |||
GELOGE(INTERNAL_ERROR, "int64 mul overflow.A[%lld], B[%lld]", n_o, c_o); | |||
GELOGE(INTERNAL_ERROR, "int64 mul overflow.A[%ld], B[%ld]", n_o, c_o); | |||
return INTERNAL_ERROR); | |||
auto t1 = h_o * w_o; | |||
auto t2 = n_o * c_o; | |||
GE_IF_BOOL_EXEC(!CheckInt64MulOverflow(t1, t2), GELOGE(INTERNAL_ERROR, "int64 mul overflow.A[%lld], B[%lld]", t1, t2); | |||
GE_IF_BOOL_EXEC(!CheckInt64MulOverflow(t1, t2), GELOGE(INTERNAL_ERROR, "int64 mul overflow.A[%ld], B[%ld]", t1, t2); | |||
return INTERNAL_ERROR); | |||
int64_t total_ele_cnt = n_o * c_o * h_o * w_o; | |||
int size = GetSizeByDataType(args.src_data_type); | |||
GE_IF_BOOL_EXEC(!CheckInt64MulOverflow(total_ele_cnt, size), | |||
GELOGE(INTERNAL_ERROR, "int64 mul overflow.A[%lld], B[%lld]", total_ele_cnt, size); | |||
GELOGE(INTERNAL_ERROR, "int64 mul overflow.A[%ld], B[%d]", total_ele_cnt, size); | |||
return INTERNAL_ERROR); | |||
int64_t dst_size = total_ele_cnt * size; | |||
@@ -30,8 +30,10 @@ const uint8_t kPrefixIndex = 9; | |||
namespace ge { | |||
void OpTilingManager::ClearHandles() noexcept { | |||
for (const auto &handle : handles_) { | |||
if (dlclose(handle.second) != 0) { | |||
GELOGE(FAILED, "Failed to close handle of %s: %s", handle.first.c_str(), dlerror()); | |||
if (mmDlclose(handle.second) != 0) { | |||
const char *error = mmDlerror(); | |||
GE_IF_BOOL_EXEC(error == nullptr, error = ""); | |||
GELOGE(FAILED, "Failed to close handle of %s: %s", handle.first.c_str(), error); | |||
} | |||
} | |||
handles_.clear(); | |||
@@ -40,11 +42,12 @@ void OpTilingManager::ClearHandles() noexcept { | |||
OpTilingManager::~OpTilingManager() { ClearHandles(); } | |||
std::string OpTilingManager::GetPath() { | |||
const char *opp_path_env = std::getenv(kEnvName); | |||
char opp_path_env[MMPA_MAX_PATH] = { 0x00 }; | |||
INT32 res = mmGetEnv(kEnvName, opp_path_env, MMPA_MAX_PATH); | |||
std::string opp_path = kDefaultPath; | |||
if (opp_path_env != nullptr) { | |||
char resolved_path[PATH_MAX]; | |||
if (realpath(opp_path_env, resolved_path) == NULL) { | |||
if (res == EN_OK) { | |||
char resolved_path[MMPA_MAX_PATH]; | |||
if (mmRealPath(opp_path_env, resolved_path, MMPA_MAX_PATH) != EN_OK) { | |||
ErrorManager::GetInstance().ATCReportErrMessage( | |||
"E19024", {"env", "value", "situation"}, {"ASCEND_OPP_PATH", opp_path_env, "loading the tiling lib"}); | |||
GELOGE(PARAM_INVALID, "Failed load tiling lib as env 'ASCEND_OPP_PATH'[%s] is invalid path.", opp_path_env); | |||
@@ -66,16 +69,20 @@ void OpTilingManager::LoadSo() { | |||
std::string built_in_name = kDefaultBuiltInTilingPath.substr(kPrefixIndex); | |||
std::string custom_name = kDefaultCustomTilingPath.substr(kPrefixIndex); | |||
void *handle_bi = dlopen(built_in_tiling_lib.c_str(), RTLD_NOW | RTLD_GLOBAL); | |||
void *handle_bi = mmDlopen(built_in_tiling_lib.c_str(), MMPA_RTLD_NOW | MMPA_RTLD_GLOBAL); | |||
if (handle_bi == nullptr) { | |||
GELOGW("Failed to dlopen %s!", dlerror()); | |||
const char *error = mmDlerror(); | |||
GE_IF_BOOL_EXEC(error == nullptr, error = ""); | |||
GELOGW("Failed to dlopen %s!", error); | |||
} else { | |||
handles_[built_in_name] = handle_bi; | |||
} | |||
void *handle_ct = dlopen(custom_tiling_lib.c_str(), RTLD_NOW | RTLD_GLOBAL); | |||
void *handle_ct = mmDlopen(custom_tiling_lib.c_str(), MMPA_RTLD_NOW | MMPA_RTLD_GLOBAL); | |||
if (handle_ct == nullptr) { | |||
GELOGW("Failed to dlopen %s!", dlerror()); | |||
const char *error = mmDlerror(); | |||
GE_IF_BOOL_EXEC(error == nullptr, error = ""); | |||
GELOGW("Failed to dlopen %s!", error); | |||
} else { | |||
handles_[custom_name] = handle_ct; | |||
} | |||
@@ -16,9 +16,7 @@ | |||
#include "common/ge/plugin_manager.h" | |||
#include <dirent.h> | |||
#include <sys/stat.h> | |||
#include <unistd.h> | |||
#include <algorithm> | |||
#include <cstring> | |||
#include <fstream> | |||
@@ -38,8 +36,10 @@ const char *const kExt = ".so"; // supported extension of shared obje | |||
namespace ge { | |||
void PluginManager::ClearHandles_() noexcept { | |||
for (const auto &handle : handles_) { | |||
if (dlclose(handle.second) != 0) { | |||
GELOGW("Failed to close handle of %s: %s", handle.first.c_str(), dlerror()); | |||
if (mmDlclose(handle.second) != 0) { | |||
const char *error = mmDlerror(); | |||
GE_IF_BOOL_EXEC(error == nullptr, error = ""); | |||
GELOGW("Failed to close handle of %s: %s", handle.first.c_str(), error); | |||
} | |||
} | |||
handles_.clear(); | |||
@@ -48,18 +48,18 @@ void PluginManager::ClearHandles_() noexcept { | |||
PluginManager::~PluginManager() { ClearHandles_(); } | |||
string PluginManager::GetPath() { | |||
Dl_info dl_info; | |||
if (dladdr(reinterpret_cast<void *>(&PluginManager::GetPath), &dl_info) == 0) { | |||
mmDlInfo dl_info; | |||
if (mmDladdr(reinterpret_cast<void *>(&PluginManager::GetPath), &dl_info) != EN_OK) { | |||
GELOGW("Failed to read the shared library file path!"); | |||
return string(); | |||
} else { | |||
std::string so_path = dl_info.dli_fname; | |||
char path[PATH_MAX] = {0}; | |||
if (so_path.length() >= PATH_MAX) { | |||
char path[MMPA_MAX_PATH] = {0}; | |||
if (so_path.length() >= MMPA_MAX_PATH) { | |||
GELOGW("The shared library file path is too long!"); | |||
return string(); | |||
} | |||
if (realpath(so_path.c_str(), path) == nullptr) { | |||
if (mmRealPath(so_path.c_str(), path, MMPA_MAX_PATH) != EN_OK) { | |||
GELOGW("Failed to get realpath of %s", so_path.c_str()); | |||
return string(); | |||
} | |||
@@ -93,7 +93,7 @@ Status PluginManager::LoadSo(const string &path, const vector<string> &func_chec | |||
std::vector<std::string> path_vec; | |||
SplitPath(path, path_vec); | |||
for (const auto &single_path : path_vec) { | |||
GE_IF_BOOL_EXEC(single_path.length() >= PATH_MAX, GELOGE(GE_PLGMGR_PATH_INVALID, | |||
GE_IF_BOOL_EXEC(single_path.length() >= MMPA_MAX_PATH, GELOGE(GE_PLGMGR_PATH_INVALID, | |||
"The shared library file path is too long!"); | |||
continue); | |||
// load break when number of loaded so reach maximum | |||
@@ -119,16 +119,18 @@ Status PluginManager::LoadSo(const string &path, const vector<string> &func_chec | |||
GELOGI("dlopen the shared library path name: %s.", file_path_dlopen.c_str()); | |||
// load continue when dlopen is failed | |||
auto handle = dlopen(file_path_dlopen.c_str(), RTLD_NOW | RTLD_GLOBAL); | |||
auto handle = mmDlopen(file_path_dlopen.c_str(), MMPA_RTLD_NOW | MMPA_RTLD_GLOBAL); | |||
if (handle == nullptr) { | |||
GELOGE(GE_PLGMGR_PATH_INVALID, "Failed to dlopen %s!", dlerror()); | |||
const char *error = mmDlerror(); | |||
GE_IF_BOOL_EXEC(error == nullptr, error = ""); | |||
GELOGE(GE_PLGMGR_PATH_INVALID, "Failed to dlopen %s!", error); | |||
continue; | |||
} | |||
// load continue when so is invalid | |||
bool is_valid = true; | |||
for (const auto &func_name : func_check_list) { | |||
auto real_fn = (void (*)())dlsym(handle, func_name.c_str()); | |||
auto real_fn = (void (*)())mmDlsym(handle, const_cast<char *>(func_name.c_str())); | |||
if (real_fn == nullptr) { | |||
GELOGE(GE_PLGMGR_PATH_INVALID, "%s is skipped since function %s is not existed!", func_name.c_str(), | |||
func_name.c_str()); | |||
@@ -137,7 +139,7 @@ Status PluginManager::LoadSo(const string &path, const vector<string> &func_chec | |||
} | |||
} | |||
if (!is_valid) { | |||
GE_LOGE_IF(dlclose(handle), "Failed to dlclose."); | |||
GE_LOGE_IF(mmDlclose(handle), "Failed to dlclose."); | |||
continue; | |||
} | |||
@@ -197,22 +199,29 @@ Status PluginManager::Load(const string &path, const vector<string> &func_check_ | |||
so_list_.clear(); | |||
ClearHandles_(); | |||
char canonical_path[PATH_MAX] = {0}; | |||
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(path.length() >= PATH_MAX, GELOGW("File path is too long!"); | |||
char canonical_path[MMPA_MAX_PATH] = {0}; | |||
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(path.length() >= MMPA_MAX_PATH, GELOGW("File path is too long!"); | |||
return FAILED, "File path is too long!"); | |||
if (realpath(path.c_str(), canonical_path) == nullptr) { | |||
if (mmRealPath(path.c_str(), canonical_path, MMPA_MAX_PATH) != EN_OK) { | |||
GELOGW("Failed to get realpath of %s", path.c_str()); | |||
return SUCCESS; | |||
} | |||
DIR *dir = opendir(canonical_path); | |||
if (dir == nullptr) { | |||
GELOGW("Invalid path for load: %s", path.c_str()); | |||
return SUCCESS; | |||
INT32 is_dir = mmIsDir(canonical_path); | |||
// Lib plugin path not exist | |||
if (is_dir != EN_OK) { | |||
GELOGW("Invalid path for load: %s", path.c_str()); | |||
return SUCCESS; | |||
} | |||
struct dirent *entry = nullptr; | |||
while ((entry = readdir(dir)) != nullptr) { | |||
mmDirent **entries = nullptr; | |||
auto ret = mmScandir(canonical_path, &entries, nullptr, nullptr); | |||
if (ret < EN_OK) { | |||
GELOGW("scan dir failed. path = %s, ret = %d", canonical_path, ret); | |||
return FAILED; | |||
} | |||
for (int i = 0; i < ret; ++i) { | |||
mmDirent *entry = entries[i]; | |||
// read fileName and fileType | |||
std::string file_name = entry->d_name; | |||
unsigned char file_type = entry->d_type; | |||
@@ -250,9 +259,11 @@ Status PluginManager::Load(const string &path, const vector<string> &func_check_ | |||
GELOGI("Dlopen so path name: %s. ", file_path_dlopen.c_str()); | |||
// load continue when dlopen is failed | |||
auto handle = dlopen(file_path_dlopen.c_str(), RTLD_NOW | RTLD_GLOBAL); | |||
auto handle = mmDlopen(file_path_dlopen.c_str(), MMPA_RTLD_NOW | MMPA_RTLD_GLOBAL); | |||
if (handle == nullptr) { | |||
GELOGW("Failed in dlopen %s!", dlerror()); | |||
const char *error = mmDlerror(); | |||
GE_IF_BOOL_EXEC(error == nullptr, error = ""); | |||
GELOGW("Failed in dlopen %s!", error); | |||
continue; | |||
} | |||
@@ -261,7 +272,7 @@ Status PluginManager::Load(const string &path, const vector<string> &func_check_ | |||
// load continue when so is invalid | |||
bool is_valid = true; | |||
for (const auto &func_name : func_check_list) { | |||
auto real_fn = (void (*)())dlsym(handle, func_name.c_str()); | |||
auto real_fn = (void (*)())mmDlsym(handle, const_cast<char *>(func_name.c_str())); | |||
if (real_fn == nullptr) { | |||
GELOGW("The %s is skipped since function %s is not existed!", file_name.c_str(), func_name.c_str()); | |||
is_valid = false; | |||
@@ -269,7 +280,7 @@ Status PluginManager::Load(const string &path, const vector<string> &func_check_ | |||
} | |||
} | |||
if (!is_valid) { | |||
GE_LOGE_IF(dlclose(handle), "Failed to dlclose."); | |||
GE_LOGE_IF(mmDlclose(handle), "Failed to dlclose."); | |||
continue; | |||
} | |||
@@ -279,7 +290,7 @@ Status PluginManager::Load(const string &path, const vector<string> &func_check_ | |||
handles_[string(file_name)] = handle; | |||
num_of_loaded_so++; | |||
} | |||
closedir(dir); | |||
mmScandirFree(entries, ret); | |||
if (num_of_loaded_so == 0) { | |||
GELOGW("No loadable shared library found in the path: %s", path.c_str()); | |||
return SUCCESS; | |||
@@ -17,7 +17,6 @@ | |||
#ifndef GE_COMMON_GE_PLUGIN_MANAGER_H_ | |||
#define GE_COMMON_GE_PLUGIN_MANAGER_H_ | |||
#include <dlfcn.h> | |||
#include <functional> | |||
#include <iostream> | |||
#include <map> | |||
@@ -30,6 +29,7 @@ | |||
#include "common/ge_inner_error_codes.h" | |||
#include "engine/dnnengine.h" | |||
#include "framework/common/debug/ge_log.h" | |||
#include "mmpa/mmpa_api.h" | |||
namespace ge { | |||
using SoToHandleMap = std::map<std::string, void *>; | |||
@@ -57,7 +57,7 @@ class PluginManager { | |||
template <typename R, typename... Types> | |||
Status GetAllFunctions(const string &func_name, map<string, function<R(Types... args)>> &funcs) { | |||
for (const auto &handle : handles_) { | |||
auto real_fn = (R(*)(Types...))dlsym(handle.second, func_name.c_str()); | |||
auto real_fn = (R(*)(Types...))mmDlsym(handle.second, const_cast<char *>(func_name.c_str())); | |||
if (real_fn == nullptr) { | |||
GELOGW("Failed to get function %s in %s!", func_name.c_str(), handle.first.c_str()); | |||
return GE_PLGMGR_FUNC_NOT_EXIST; | |||
@@ -72,7 +72,7 @@ class PluginManager { | |||
Status InvokeAll(const string &func_name, Types... args) { | |||
for (const auto &handle : handles_) { | |||
// If the funcName is existed, signature of realFn can be casted to any type | |||
auto real_fn = (void (*)(Types...))dlsym(handle.second, func_name.c_str()); | |||
auto real_fn = (void (*)(Types...))mmDlsym(handle.second, const_cast<char *>(func_name.c_str())); | |||
if (real_fn == nullptr) { | |||
GELOGW("Failed to invoke function %s in %s!", func_name.c_str(), handle.first.c_str()); | |||
return GE_PLGMGR_INVOKE_FAILED; | |||
@@ -87,7 +87,7 @@ class PluginManager { | |||
Status InvokeAll(const string &func_name, T arg) { | |||
for (const auto &handle : handles_) { | |||
// If the funcName is existed, signature of realFn can be casted to any type | |||
auto real_fn = (void (*)(T))dlsym(handle.second, func_name.c_str()); | |||
auto real_fn = (void (*)(T))mmDlsym(handle.second, const_cast<char *>(func_name.c_str())); | |||
if (real_fn == nullptr) { | |||
GELOGW("Failed to invoke function %s in %s!", func_name.c_str(), handle.first.c_str()); | |||
return GE_PLGMGR_INVOKE_FAILED; | |||
@@ -112,7 +112,7 @@ class PluginManager { | |||
Status InvokeAll(const string &func_name, T1 arg) { | |||
for (const auto &handle : handles_) { | |||
// If the funcName is existed, signature of realFn can be casted to any type | |||
auto real_fn = (T2(*)(T1))dlsym(handle.second, func_name.c_str()); | |||
auto real_fn = (T2(*)(T1))mmDlsym(handle.second, const_cast<char *>(func_name.c_str())); | |||
if (real_fn == nullptr) { | |||
GELOGW("Failed to invoke function %s in %s!", func_name.c_str(), handle.first.c_str()); | |||
return GE_PLGMGR_INVOKE_FAILED; | |||
@@ -130,7 +130,7 @@ class PluginManager { | |||
Status InvokeAll(const string &func_name) { | |||
for (const auto &handle : handles_) { | |||
// If the funcName is existed, signature of realFn can be casted to any type | |||
auto real_fn = (T(*)())dlsym(handle.second, func_name.c_str()); | |||
auto real_fn = (T(*)())mmDlsym(handle.second, const_cast<char *>(func_name.c_str())); | |||
if (real_fn == nullptr) { | |||
GELOGW("Failed to invoke function %s in %s!", func_name.c_str(), handle.first.c_str()); | |||
return GE_PLGMGR_INVOKE_FAILED; | |||
@@ -16,8 +16,6 @@ | |||
#include "common/ge/tbe_plugin_manager.h" | |||
#include <dirent.h> | |||
#include <unistd.h> | |||
#include <algorithm> | |||
#include <cstring> | |||
#include <fstream> | |||
@@ -50,9 +48,11 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY TBEPluginManager &TBEPluginMana | |||
Status TBEPluginManager::ClearHandles_() { | |||
Status ret = SUCCESS; | |||
for (const auto &handle : handles_vec_) { | |||
if (dlclose(handle) != 0) { | |||
if (mmDlclose(handle) != 0) { | |||
ret = FAILED; | |||
GELOGW("Failed to close handle: %s", dlerror()); | |||
const char *error = mmDlerror(); | |||
GE_IF_BOOL_EXEC(error == nullptr, error = ""); | |||
GELOGW("Failed to close handle: %s", error); | |||
} | |||
} | |||
handles_vec_.clear(); | |||
@@ -65,18 +65,18 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status TBEPluginManager::Finali | |||
} | |||
string TBEPluginManager::GetPath() { | |||
Dl_info dl_info; | |||
if (dladdr(reinterpret_cast<void *>(&TBEPluginManager::GetPath), &dl_info) == 0) { | |||
mmDlInfo dl_info; | |||
if (mmDladdr(reinterpret_cast<void *>(&TBEPluginManager::GetPath), &dl_info) != EN_OK) { | |||
GELOGW("Failed to read so path!"); | |||
return string(); | |||
} else { | |||
string so_path = dl_info.dli_fname; | |||
char path[PATH_MAX] = {0}; | |||
if (so_path.length() >= PATH_MAX) { | |||
char path[MMPA_MAX_PATH] = {0}; | |||
if (so_path.length() >= MMPA_MAX_PATH) { | |||
GELOGW("File path is too long!"); | |||
return string(); | |||
} | |||
if (realpath(so_path.c_str(), path) == nullptr) { | |||
if (mmRealPath(so_path.c_str(), path, MMPA_MAX_PATH) != EN_OK) { | |||
GELOGW("Failed to get realpath of %s", so_path.c_str()); | |||
return string(); | |||
} | |||
@@ -108,35 +108,36 @@ void TBEPluginManager::FindParserSo(const string &path, vector<string> &file_lis | |||
GELOGW("RealPath is empty."); | |||
return; | |||
} | |||
struct stat stat_buf; | |||
if ((stat(real_path.c_str(), &stat_buf) != 0) || (!S_ISDIR(stat_buf.st_mode))) { | |||
GELOGW("%s is not a dir.", real_path.c_str()); | |||
return; | |||
} | |||
struct dirent *dent(0); | |||
DIR *dir = opendir(real_path.c_str()); | |||
// Plugin path does not exist | |||
if (dir == nullptr) { | |||
GELOGW("Open directory %s failed.", real_path.c_str()); | |||
return; | |||
INT32 is_dir = mmIsDir(real_path.c_str()); | |||
// Lib plugin path not exist | |||
if (is_dir != EN_OK) { | |||
GELOGW("%s is not a dir.", real_path.c_str()); | |||
return; | |||
} | |||
while ((dent = readdir(dir)) != nullptr) { | |||
if (strcmp(dent->d_name, ".") == 0 || strcmp(dent->d_name, "..") == 0) continue; | |||
string name = dent->d_name; | |||
string full_name = real_path + "/" + name; | |||
const string so_suff = ".so"; | |||
const string caffe_parser_so_suff = "lib_caffe_parser.so"; | |||
const string aicpu_so_suff = "_aicpu.so"; | |||
const string aicpu_host_so_suff = "_online.so"; | |||
if (name.size() >= so_suff.size() && name.compare(name.size() - so_suff.size(), so_suff.size(), so_suff) == 0) { | |||
ProcessSoFullName(file_list, caffe_parser_path, full_name, caffe_parser_so_suff, aicpu_so_suff, | |||
aicpu_host_so_suff); | |||
} else { | |||
FindParserSo(full_name, file_list, caffe_parser_path); | |||
} | |||
mmDirent **entries = nullptr; | |||
auto ret = mmScandir(real_path.c_str(), &entries, nullptr, nullptr); | |||
if (ret < EN_OK) { | |||
GELOGW("scan dir failed. path = %s, ret = %d", real_path.c_str(), ret); | |||
return; | |||
} | |||
for (int i = 0; i < ret; ++i) { | |||
mmDirent *dent = entries[i]; | |||
if (strcmp(dent->d_name, ".") == 0 || strcmp(dent->d_name, "..") == 0) continue; | |||
string name = dent->d_name; | |||
string full_name = real_path + "/" + name; | |||
const string so_suff = ".so"; | |||
const string caffe_parser_so_suff = "lib_caffe_parser.so"; | |||
const string aicpu_so_suff = "_aicpu.so"; | |||
const string aicpu_host_so_suff = "_online.so"; | |||
if (name.size() >= so_suff.size() && name.compare(name.size() - so_suff.size(), so_suff.size(), so_suff) == 0) { | |||
ProcessSoFullName(file_list, caffe_parser_path, full_name, caffe_parser_so_suff, aicpu_so_suff, | |||
aicpu_host_so_suff); | |||
} else { | |||
FindParserSo(full_name, file_list, caffe_parser_path); | |||
} | |||
} | |||
closedir(dir); | |||
mmScandirFree(entries, ret); | |||
} | |||
void TBEPluginManager::GetPluginSoFileList(const string &path, vector<string> &file_list, string &caffe_parser_path) { | |||
@@ -159,8 +160,9 @@ void TBEPluginManager::GetCustomOpPath(std::string &customop_path) { | |||
fmk_type = ge::TypeUtils::FmkTypeToSerialString(type); | |||
GELOGI("Framework type is %s.", fmk_type.c_str()); | |||
const char *path_env = std::getenv("ASCEND_OPP_PATH"); | |||
if (path_env != nullptr) { | |||
char path_env[MMPA_MAX_PATH] = { 0x00 }; | |||
INT32 res = mmGetEnv("ASCEND_OPP_PATH", path_env, MMPA_MAX_PATH); | |||
if (res == EN_OK) { | |||
std::string path = path_env; | |||
customop_path = (path + "/framework/custom" + "/:") + (path + "/framework/built-in/" + fmk_type); | |||
GELOGI("Get custom so path from env : %s", path_env); | |||
@@ -210,9 +212,11 @@ void TBEPluginManager::LoadPluginSo(const std::map<string, string> &options) { | |||
for (auto elem : file_list) { | |||
StringUtils::Trim(elem); | |||
void *handle = dlopen(elem.c_str(), RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE); | |||
void *handle = mmDlopen(elem.c_str(), MMPA_RTLD_NOW | MMPA_RTLD_GLOBAL | MMPA_RTLD_NODELETE); | |||
if (handle == nullptr) { | |||
GELOGW("dlopen failed, plugin name:%s. Message(%s).", elem.c_str(), dlerror()); | |||
const char *error = mmDlerror(); | |||
GE_IF_BOOL_EXEC(error == nullptr, error = ""); | |||
GELOGW("dlopen failed, plugin name:%s. Message(%s).", elem.c_str(), error); | |||
} else if (find(handles_vec_.begin(), handles_vec_.end(), handle) == handles_vec_.end()) { | |||
// Close dl when the program exist, not close here | |||
GELOGI("Plugin load %s success.", elem.c_str()); | |||
@@ -17,7 +17,6 @@ | |||
#ifndef GE_COMMON_GE_TBE_PLUGIN_MANAGER_H_ | |||
#define GE_COMMON_GE_TBE_PLUGIN_MANAGER_H_ | |||
#include <dlfcn.h> | |||
#include <functional> | |||
#include <iostream> | |||
#include <map> | |||
@@ -14,8 +14,6 @@ | |||
* limitations under the License. | |||
*/ | |||
#include <fcntl.h> | |||
#include <unistd.h> | |||
#include <climits> | |||
#include <cstdio> | |||
#include <fstream> | |||
@@ -448,12 +446,12 @@ Status ModelCacheHelper::SaveJsonToFile(const string &file_name, const Json &jso | |||
} | |||
const string path = cache_path_ + file_name; | |||
const int FILE_AUTHORITY = 0600; | |||
int fd = open(path.c_str(), O_WRONLY | O_CREAT | O_TRUNC, FILE_AUTHORITY); | |||
int fd = mmOpen2(path.c_str(), M_WRONLY | M_CREAT | O_TRUNC, FILE_AUTHORITY); | |||
if (fd < 0) { | |||
GELOGW("Fail to open the file: %s.", path.c_str()); | |||
return INTERNAL_ERROR; | |||
} | |||
if (close(fd) != 0) { | |||
if (mmClose(fd) != 0) { | |||
GELOGW("Fail to close the file: %s.", path.c_str()); | |||
return INTERNAL_ERROR; | |||
} | |||
@@ -393,7 +393,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelHelper::LoadTask(Om | |||
GELOGE(INTERNAL_ERROR, "ReadProtoFromArray failed."); | |||
return INTERNAL_ERROR; | |||
} | |||
GELOGI("TASK_INFO op_size:%zu, stream_num:%u", task->op().size(), task->stream_num()); | |||
GELOGI("TASK_INFO op_size:%d, stream_num:%u", task->op().size(), task->stream_num()); | |||
} | |||
model_->SetModelTaskDef(task); | |||
return SUCCESS; | |||
@@ -17,7 +17,6 @@ | |||
#include "common/model_parser/base.h" | |||
#include "common/helper/model_helper.h" | |||
#include <securec.h> | |||
#include <sys/sysinfo.h> | |||
#include <fstream> | |||
#include <memory> | |||
#include <string> | |||
@@ -16,9 +16,7 @@ | |||
#include "common/model_saver.h" | |||
#include <fcntl.h> | |||
#include <securec.h> | |||
#include <unistd.h> | |||
#include <cstdlib> | |||
#include <fstream> | |||
#include <string> | |||
@@ -51,14 +49,14 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelSaver::SaveJsonToFi | |||
return FAILED; | |||
} | |||
char real_path[PATH_MAX] = {0}; | |||
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(strlen(file_path) >= PATH_MAX, return FAILED, "file path is too long!"); | |||
GE_IF_BOOL_EXEC(realpath(file_path, real_path) == nullptr, | |||
char real_path[MMPA_MAX_PATH] = {0}; | |||
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(strlen(file_path) >= MMPA_MAX_PATH, return FAILED, "file path is too long!"); | |||
GE_IF_BOOL_EXEC(mmRealPath(file_path, real_path, MMPA_MAX_PATH) != EN_OK, | |||
GELOGI("File %s does not exit, it will be created.", file_path)); | |||
// Open file | |||
mode_t mode = S_IRUSR | S_IWUSR; | |||
int32_t fd = mmOpen2(real_path, O_RDWR | O_CREAT | O_TRUNC, mode); | |||
mmMode_t mode = M_IRUSR | M_IWUSR; | |||
int32_t fd = mmOpen2(real_path, M_RDWR | M_CREAT | O_TRUNC, mode); | |||
if (fd == EN_ERROR || fd == EN_INVALID_PARAM) { | |||
ErrorManager::GetInstance().ATCReportErrMessage("E19001", {"file", "errmsg"}, {file_path, strerror(errno)}); | |||
GELOGE(FAILED, "Open file[%s] failed. %s", file_path, strerror(errno)); | |||
@@ -72,7 +70,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelSaver::SaveJsonToFi | |||
ErrorManager::GetInstance().ATCReportErrMessage( | |||
"E19004", {"file", "errmsg"}, {file_path, strerror(errno)}); | |||
// Need to both print the error info of mmWrite and mmClose, so return ret after mmClose | |||
GELOGE(FAILED, "Write to file failed. errno = %d, %s", mmpa_ret, strerror(errno)); | |||
GELOGE(FAILED, "Write to file failed. errno = %ld, %s", mmpa_ret, strerror(errno)); | |||
ret = FAILED; | |||
} | |||
// Close file | |||
@@ -214,8 +214,12 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ge::Status ProfilingManager::Pa | |||
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ge::Status ProfilingManager::InitFromOptions(const Options &options) { | |||
#ifdef DAVINCI_SUPPORT_PROFILING | |||
// enable profiling support two ways: env and front end | |||
const char *profiling_mode = std::getenv("PROFILING_MODE"); | |||
const char *prof_options = std::getenv("PROFILING_OPTIONS"); | |||
char profiling_mode_temp[MMPA_MAX_PATH] = { 0x00 }; | |||
char prof_options_temp[MMPA_MAX_PATH] = { 0x00 }; | |||
(void)mmGetEnv("PROFILING_MODE", profiling_mode_temp, MMPA_MAX_PATH); | |||
(void)mmGetEnv("PROFILING_OPTIONS", prof_options_temp, MMPA_MAX_PATH ); | |||
const char *profiling_mode = profiling_mode_temp; | |||
const char *prof_options = prof_options_temp; | |||
if ((profiling_mode == nullptr) || (strcmp("true", profiling_mode) != 0) || (prof_options == nullptr)) { | |||
is_load_profiling_ = false; | |||
is_execute_profiling_ = false; | |||
@@ -25,13 +25,14 @@ | |||
#include "common/dump/dump_properties.h" | |||
#include "graph/op_desc.h" | |||
#include "common/ge_compiler_options.h" | |||
namespace ge { | |||
// Configuration property management | |||
static const char *SYSMODE __attribute__((unused)) = "FMK_SYSMODE"; | |||
static const char *USE_FUSION __attribute__((unused)) = "FMK_USE_FUSION"; | |||
static const char *TIMESTAT_ENABLE __attribute__((unused)) = "DAVINCI_TIMESTAT_ENABLE"; | |||
static const char *ANNDROID_DEBUG __attribute__((unused)) = "ANNDROID_DEBUG"; | |||
static const char *SYSMODE GE_ATTRIBUTE_UNUSED = "FMK_SYSMODE"; | |||
static const char *USE_FUSION GE_ATTRIBUTE_UNUSED = "FMK_USE_FUSION"; | |||
static const char *TIMESTAT_ENABLE GE_ATTRIBUTE_UNUSED = "DAVINCI_TIMESTAT_ENABLE"; | |||
static const char *ANNDROID_DEBUG GE_ATTRIBUTE_UNUSED = "ANNDROID_DEBUG"; | |||
class PropertiesManager { | |||
public: | |||
@@ -16,11 +16,12 @@ | |||
#include "framework/common/util.h" | |||
#include <fcntl.h> | |||
#include <sys/stat.h> | |||
#ifdef __GNUC__ | |||
#include <regex.h> | |||
#include <unistd.h> | |||
#else | |||
#include <regex> | |||
#endif | |||
#include <algorithm> | |||
#include <climits> | |||
#include <cstdlib> | |||
@@ -208,29 +209,30 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool ReadBytesFromBinaryFile(co | |||
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY int CreateDirectory(const std::string &directory_path) { | |||
GE_CHK_BOOL_EXEC(!directory_path.empty(), return -1, "directory path is empty."); | |||
auto dir_path_len = directory_path.length(); | |||
if (dir_path_len >= PATH_MAX) { | |||
ErrorManager::GetInstance().ATCReportErrMessage("E19002", {"filepath", "size"}, | |||
{directory_path, std::to_string(PATH_MAX)}); | |||
GELOGW("Path[%s] len is too long, it must be less than %d", directory_path.c_str(), PATH_MAX); | |||
if (dir_path_len >= MMPA_MAX_PATH) { | |||
ErrorManager::GetInstance().ATCReportErrMessage( | |||
"E19002", {"filepath", "size"}, {directory_path, std::to_string(MMPA_MAX_PATH)}); | |||
GELOGW("Path[%s] len is too long, it must be less than %d", directory_path.c_str(), MMPA_MAX_PATH); | |||
return -1; | |||
} | |||
char tmp_dir_path[PATH_MAX] = {0}; | |||
char tmp_dir_path[MMPA_MAX_PATH] = {0}; | |||
for (size_t i = 0; i < dir_path_len; i++) { | |||
tmp_dir_path[i] = directory_path[i]; | |||
if ((tmp_dir_path[i] == '\\') || (tmp_dir_path[i] == '/')) { | |||
if (access(tmp_dir_path, F_OK) != 0) { | |||
int32_t ret = mmMkdir(tmp_dir_path, S_IRUSR | S_IWUSR | S_IXUSR); // 700 | |||
if (mmAccess2(tmp_dir_path, M_F_OK) != EN_OK) { | |||
int32_t ret = mmMkdir(tmp_dir_path, M_IRUSR | M_IWUSR | M_IXUSR); // 700 | |||
if (ret != 0) { | |||
if (errno != EEXIST) { | |||
ErrorManager::GetInstance().ATCReportErrMessage("E19006", {"path"}, {directory_path}); | |||
GELOGW("Can not create directory %s. Make sure the directory exists and writable.", directory_path.c_str()); | |||
GELOGW("Can not create directory %s. Make sure the directory exists and writable.", | |||
directory_path.c_str()); | |||
return ret; | |||
} | |||
} | |||
} | |||
} | |||
} | |||
int32_t ret = mmMkdir(const_cast<char *>(directory_path.c_str()), S_IRUSR | S_IWUSR | S_IXUSR); // 700 | |||
int32_t ret = mmMkdir(const_cast<char *>(directory_path.c_str()), M_IRUSR | M_IWUSR | M_IXUSR); // 700 | |||
if (ret != 0) { | |||
if (errno != EEXIST) { | |||
ErrorManager::GetInstance().ATCReportErrMessage("E19006", {"path"}, {directory_path}); | |||
@@ -305,9 +307,9 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool ReadProtoFromMem(const cha | |||
} | |||
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY uint64_t GetCurrentTimestamp() { | |||
struct timeval tv {}; | |||
int ret = gettimeofday(&tv, nullptr); | |||
GE_LOGE_IF(ret != 0, "Func gettimeofday may failed: ret=%d", ret); | |||
mmTimeval tv {}; | |||
int ret = mmGetTimeOfDay(&tv, nullptr); | |||
GE_LOGE_IF(ret != EN_OK, "Func gettimeofday may failed: ret=%d", ret); | |||
auto total_use_time = tv.tv_usec + tv.tv_sec * 1000000; // 1000000: seconds to microseconds | |||
return static_cast<uint64_t>(total_use_time); | |||
} | |||
@@ -347,16 +349,15 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool CheckInt64MulOverflow(int6 | |||
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY std::string RealPath(const char *path) { | |||
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(path == nullptr, return "", "path pointer is NULL."); | |||
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG( | |||
strlen(path) >= PATH_MAX, | |||
ErrorManager::GetInstance().ATCReportErrMessage("E19002", {"filepath", "size"}, {path, std::to_string(PATH_MAX)}); | |||
return "", "Path[%s] len is too long, it must be less than %d", path, PATH_MAX); | |||
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(strlen(path) >= MMPA_MAX_PATH, | |||
ErrorManager::GetInstance().ATCReportErrMessage("E19002", {"filepath", "size"}, {path, std::to_string(MMPA_MAX_PATH)}); | |||
return "", "Path[%s] len is too long, it must be less than %d", path, MMPA_MAX_PATH); | |||
// Nullptr is returned when the path does not exist or there is no permission | |||
// Return absolute path when path is accessible | |||
std::string res; | |||
char resolved_path[PATH_MAX] = {0}; | |||
if (realpath(path, resolved_path) != nullptr) { | |||
char resolved_path[MMPA_MAX_PATH] = {0}; | |||
if (mmRealPath(path, resolved_path, MMPA_MAX_PATH) == EN_OK) { | |||
res = resolved_path; | |||
} | |||
@@ -383,7 +384,11 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool CheckInputPathValid(const | |||
// A regular matching expression to verify the validity of the input file path | |||
// Path section: Support upper and lower case letters, numbers dots(.) chinese and underscores | |||
// File name section: Support upper and lower case letters, numbers, underscores chinese and dots(.) | |||
std::string mode = "^[\u4e00-\u9fa5A-Za-z0-9./_-]+$"; | |||
#ifdef __GNUC__ | |||
std::string mode = "^[\u4e00-\u9fa5A-Za-z0-9./_-]+$"; | |||
#else | |||
std::string mode = "^[a-zA-Z]:([\\\\/][^\\s\\\\/:*?<>\"|][^\\\\/:*?<>\"|]*)*([/\\\\][^\\s\\\\/:*?<>\"|])?$"; | |||
#endif | |||
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG( | |||
!ValidateStr(real_path, mode), | |||
@@ -392,7 +397,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool CheckInputPathValid(const | |||
return false, "Invalid value for %s[%s], %s.", atc_param.c_str(), real_path.c_str(), kPathValidReason); | |||
// The absolute path points to a file that is not readable | |||
if (access(real_path.c_str(), R_OK) != 0) { | |||
if (mmAccess2(real_path.c_str(), M_R_OK) != EN_OK) { | |||
ErrorManager::GetInstance().ATCReportErrMessage("E19003", {"file", "errmsg"}, {file_path.c_str(), strerror(errno)}); | |||
GELOGW("Read file[%s] failed, errmsg[%s]", file_path.c_str(), strerror(errno)); | |||
return false; | |||
@@ -410,15 +415,19 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool CheckOutputPathValid(const | |||
return false; | |||
} | |||
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG( | |||
strlen(file_path.c_str()) >= PATH_MAX, ErrorManager::GetInstance().ATCReportErrMessage( | |||
"E19002", {"filepath", "size"}, {file_path, std::to_string(PATH_MAX)}); | |||
return "", "Path[%s] len is too long, it must be less than %d", file_path.c_str(), PATH_MAX); | |||
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(strlen(file_path.c_str()) >= MMPA_MAX_PATH, | |||
ErrorManager::GetInstance().ATCReportErrMessage( | |||
"E19002", {"filepath", "size"}, {file_path, std::to_string(MMPA_MAX_PATH)}); | |||
return "", "Path[%s] len is too long, it must be less than %d", file_path.c_str(), MMPA_MAX_PATH); | |||
// A regular matching expression to verify the validity of the input file path | |||
// Path section: Support upper and lower case letters, numbers dots(.) chinese and underscores | |||
// File name section: Support upper and lower case letters, numbers, underscores chinese and dots(.) | |||
std::string mode = "^[\u4e00-\u9fa5A-Za-z0-9./_-]+$"; | |||
#ifdef __GNUC__ | |||
std::string mode = "^[\u4e00-\u9fa5A-Za-z0-9./_-]+$"; | |||
#else | |||
std::string mode = "^[a-zA-Z]:([\\\\/][^\\s\\\\/:*?<>\"|][^\\\\/:*?<>\"|]*)*([/\\\\][^\\s\\\\/:*?<>\"|])?$"; | |||
#endif | |||
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG( | |||
!ValidateStr(file_path, mode), | |||
@@ -430,7 +439,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool CheckOutputPathValid(const | |||
// Can get absolute path (file exists) | |||
if (!real_path.empty()) { | |||
// File is not readable or writable | |||
if (access(real_path.c_str(), W_OK | F_OK) != 0) { | |||
if (mmAccess2(real_path.c_str(), M_W_OK | M_F_OK) != EN_OK) { | |||
ErrorManager::GetInstance().ATCReportErrMessage("E19004", {"file", "errmsg"}, {real_path, strerror(errno)}); | |||
GELOGW("Write file[%s] failed, errmsg[%s]", real_path.c_str(), strerror(errno)); | |||
return false; | |||
@@ -461,6 +470,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool CheckOutputPathValid(const | |||
} | |||
FMK_FUNC_HOST_VISIBILITY bool ValidateStr(const std::string &str, const std::string &mode) { | |||
#ifdef __GNUC__ | |||
char ebuff[kMaxBuffSize]; | |||
regex_t reg; | |||
int cflags = REG_EXTENDED | REG_NOSUB; | |||
@@ -482,6 +492,23 @@ FMK_FUNC_HOST_VISIBILITY bool ValidateStr(const std::string &str, const std::str | |||
regfree(®); | |||
return true; | |||
#else | |||
std::wstring wstr(str.begin(), str.end()); | |||
std::wstring wmode(mode.begin(), mode.end()); | |||
std::wsmatch match; | |||
bool res = false; | |||
try { | |||
std::wregex reg(wmode, std::regex::icase); | |||
// Matching string part | |||
res = regex_match(wstr, match, reg); | |||
res = regex_search(str, std::regex("[`!@#$%^&*()|{}';',<>?]")); | |||
} catch (std::exception &ex) { | |||
GELOGW("The directory %s is invalid, error: %s.", str.c_str(), ex.what()); | |||
return false; | |||
} | |||
return !(res) && (str.size() == match.str().size()); | |||
#endif | |||
} | |||
FMK_FUNC_HOST_VISIBILITY bool IsValidFile(const char *file_path) { | |||
@@ -433,7 +433,7 @@ Status DNNEngineManager::ReadJsonFile(const std::string &file_path, JsonHandle h | |||
return FAILED; | |||
} | |||
const char *file = file_path.data(); | |||
if ((access(file, F_OK)) == -1) { | |||
if ((mmAccess2(file, M_F_OK)) != EN_OK) { | |||
if (engines_map_.size() != 0) { | |||
GELOGE(FAILED, "The json file %s is not exist, %s", file_path.c_str(), strerror(errno)); | |||
return FAILED; | |||
@@ -1102,7 +1102,7 @@ bool IsAtomicOutputMemory(const ge::NodePtr &node, uint32_t output_index, bool i | |||
if (static_cast<uint32_t>(index) == output_index) { | |||
if (node->GetOwnerComputeGraph() != nullptr) { | |||
string graph_name = node->GetOwnerComputeGraph()->GetName(); | |||
GELOGD("[IMAS]Atomic no assign %s name[%s] output[%d] streamid[%ld].", graph_name.c_str(), | |||
GELOGD("[IMAS]Atomic no assign %s name[%s] output[%ld] streamid[%ld].", graph_name.c_str(), | |||
op_desc->GetName().c_str(), index, op_desc->GetStreamId()); | |||
} | |||
return true; | |||
@@ -1219,7 +1219,7 @@ Status BlockMemAssigner::AssignOutputMemoryWithReuse(const NodePtr &node, vector | |||
int64_t stream_id = op_desc->GetStreamId(); | |||
vector<int64_t> memorys_type; | |||
bool has_mem_type_attr = ge::AttrUtils::GetListInt(op_desc, ATTR_NAME_OUTPUT_MEM_TYPE_LIST, memorys_type); | |||
GELOGI("Assign memory node[%s], output size[%d], output memory type size[%d]", op_desc->GetName().c_str(), | |||
GELOGI("Assign memory node[%s], output size[%zu], output memory type size[%zu]", op_desc->GetName().c_str(), | |||
op_desc->GetOutputsSize(), memorys_type.size()); | |||
if (has_mem_type_attr && (memorys_type.size() != op_desc->GetOutputsSize())) { | |||
GELOGE(INTERNAL_ERROR, "fusion: node[%s], output memory size err[outputsize:%zu, memorysize:%zu]", | |||
@@ -1257,7 +1257,7 @@ Status BlockMemAssigner::AssignOutputMemoryWithReuse(const NodePtr &node, vector | |||
// fusion: other type's size not means malloc HBM memory | |||
bool l1_flag = has_mem_type_attr && memorys_type[i] == RT_MEMORY_L1; | |||
if (l1_flag) { | |||
GELOGI("fusion: node[%s], output[%s], output memory type [%d]", | |||
GELOGI("fusion: node[%s], output[%s], output memory type [%ld]", | |||
op_desc->GetName().c_str(), op_desc->GetOutputNameByIndex(i).c_str(), memorys_type[i]); | |||
size = 0; | |||
} | |||
@@ -1350,7 +1350,7 @@ void BlockMemAssigner::AssignMemoryWithReuse(vector<int64_t> &ranges) { | |||
bool workspace_skip_flag = false; | |||
if (has_tvm_workspace_mem_type_attr && tvm_workspace_memory_type[i] == RT_MEMORY_L1) { | |||
GELOGI( | |||
"fusion: node[%s]workspace index[%d] is not hbm type, add to zero_memory_list, workspace memory type [%ld]", | |||
"fusion: node[%s]workspace index[%zu] is not hbm type, add to zero_memory_list, workspace memory type [%ld]", | |||
node_op_desc->GetName().c_str(), i, tvm_workspace_memory_type[i]); | |||
workspace_skip_flag = true; | |||
} | |||
@@ -456,7 +456,7 @@ Status GraphMemoryAssigner::AssignContinuousInputMemory(const ge::NodePtr &node, | |||
output_list.at(peer_out_data_anchor->GetIdx()) - continuous_mem_start + tensor_desc_size + MEM_ALIGN_SIZE; | |||
} | |||
GELOGI( | |||
"[IMAS]Check Continuous input : Set %s name[%s] output[%d] offset to [%zu] stream_id[%ld] size[%zu] " | |||
"[IMAS]Check Continuous input : Set %s name[%s] output[%d] offset to [%ld] stream_id[%ld] size[%u] " | |||
"real_size[%u].", | |||
node->GetOwnerComputeGraph()->GetName().c_str(), peer_op_desc->GetName().c_str(), | |||
peer_out_data_anchor->GetIdx(), output_list.at(peer_out_data_anchor->GetIdx()), peer_op_desc->GetStreamId(), | |||
@@ -131,7 +131,7 @@ Status CpuTaskZeroCopy::Init(std::vector<uintptr_t> &mbuf_list, std::map<const v | |||
for (const auto &virtual_args_addr : virtual_args_addrs) { | |||
for (size_t i = 0; i < virtual_args_addr.second.size(); ++i) { | |||
src_addrs.push_back(mbuf_list.at(index)); | |||
dst_addrs.push_back(reinterpret_cast<uint64_t>(reinterpret_cast<uintptr_t>(virtual_args_addr.second.at(i)))); | |||
dst_addrs.push_back(static_cast<uint64_t>(reinterpret_cast<uintptr_t>(virtual_args_addr.second.at(i)))); | |||
} | |||
} | |||
index++; | |||
@@ -17,11 +17,7 @@ | |||
#include "graph/load/new_model_manager/davinci_model.h" | |||
#include <cce/dnn.h> | |||
#include <dlfcn.h> | |||
#include <graph/utils/node_utils.h> | |||
#include <pthread.h> | |||
#include <sched.h> | |||
#include <sys/prctl.h> | |||
#include <algorithm> | |||
#include <map> | |||
#include <utility> | |||
@@ -1459,7 +1455,7 @@ Status DavinciModel::InitLabelSet(const OpDescPtr &op_desc) { | |||
return INTERNAL_ERROR; | |||
} | |||
if (label_index >= LabelNum()) { | |||
GELOGE(INTERNAL_ERROR, "InitLabelSet: label index: %u >= label size: %zu.", label_index, LabelNum()); | |||
GELOGE(INTERNAL_ERROR, "InitLabelSet: label index: %u >= label size: %u.", label_index, LabelNum()); | |||
return INTERNAL_ERROR; | |||
} | |||
if (label_id_indication_.count(label_index) > 0) { | |||
@@ -2187,7 +2183,7 @@ Status DavinciModel::CopyInputData(const InputData &input_data, bool device_data | |||
void *mem_addr = data.second.GetBasicAddr(); | |||
void *data_buf_addr = reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(data_buf.data)); | |||
uint64_t data_buf_length = data_buf.length; | |||
GELOGI("[IMAS]CopyPlainData memcpy graph_%lu type[F] input[%lu] dst[%p] src[%p] mem_size[%lu] datasize[%lu]", | |||
GELOGI("[IMAS]CopyPlainData memcpy graph_%u type[F] input[%u] dst[%p] src[%p] mem_size[%lu] datasize[%lu]", | |||
runtime_param_.graph_id, data.first, mem_addr, data_buf_addr, data_size, data_buf_length); | |||
GE_CHK_RT_RET(rtMemcpy(mem_addr, data_size, data_buf_addr, data_buf_length, kind)); | |||
} | |||
@@ -2552,10 +2548,10 @@ Status DavinciModel::CopyOutputData(uint32_t data_id, OutputData &output_data, r | |||
if (is_dynamic_) { | |||
GELOGI("No need to check output data size."); | |||
} else if (buffer.length < mem_size) { | |||
GELOGE(FAILED, "Tensor data size=%lu, buffer size=%u", mem_size, buffer.length); | |||
GELOGE(FAILED, "Tensor data size=%lu, buffer size=%lu", mem_size, buffer.length); | |||
return FAILED; | |||
} else if (buffer.length > mem_size) { | |||
GELOGW("Tensor data size=%lu, buffer size=%u", mem_size, buffer.length); | |||
GELOGW("Tensor data size=%lu, buffer size=%lu", mem_size, buffer.length); | |||
} | |||
int64_t data_size = output.second.GetDataSize(); | |||
@@ -2566,7 +2562,7 @@ Status DavinciModel::CopyOutputData(uint32_t data_id, OutputData &output_data, r | |||
uint64_t buffer_length = buffer.length; | |||
void *buffer_addr = reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(buffer.data)); | |||
GELOGI("[IMAS]CopyPlainData memcpy graph_%u type[F] output[%u] memaddr[%p] mem_size[%ld] datasize[%u]", | |||
GELOGI("[IMAS]CopyPlainData memcpy graph_%u type[F] output[%u] memaddr[%p] mem_size[%lu] datasize[%lu]", | |||
runtime_param_.graph_id, output.first, output.second.GetBasicAddr(), data_size, buffer_length); | |||
GE_CHK_RT_RET(rtMemcpy(buffer_addr, buffer_length, output.second.GetBasicAddr(), data_size, kind)); | |||
idx++; | |||
@@ -2982,7 +2978,7 @@ void DavinciModel::UnbindTaskSinkStream() { | |||
Status DavinciModel::CreateKnownZeroCopyMap(const vector<void *> &inputs, const vector<void *> &outputs) { | |||
GELOGI("DavinciModel::CreateKnownZeroCopyMap in."); | |||
if (inputs.size() > data_op_list_.size()) { | |||
GELOGE(FAILED, "input data addr %u should less than input op number %u.", inputs.size(), data_op_list_.size()); | |||
GELOGE(FAILED, "input data addr %zu should less than input op number %zu.", inputs.size(), data_op_list_.size()); | |||
return FAILED; | |||
} | |||
// remove zero copy addr in last iteration | |||
@@ -2991,16 +2987,16 @@ Status DavinciModel::CreateKnownZeroCopyMap(const vector<void *> &inputs, const | |||
for (size_t i = 0; i < inputs.size(); ++i) { | |||
const vector<void *> addr_list = ModelUtils::GetOutputDataAddrs(runtime_param_, data_op_list_[i]); | |||
knonw_input_data_info_[addr_list[kDataIndex]] = inputs[i]; | |||
GELOGI("DavinciModel::CreateKnownZeroCopyMap input %d,v addr %p,p addr %p .", i, addr_list[kDataIndex], inputs[i]); | |||
GELOGI("DavinciModel::CreateKnownZeroCopyMap input %zu,v addr %p,p addr %p .", i, addr_list[kDataIndex], inputs[i]); | |||
} | |||
if (output_op_list_.size() < kOutputNum) { | |||
GELOGW("output op num in graph is %u.", output_op_list_.size()); | |||
GELOGW("output op num in graph is %zu.", output_op_list_.size()); | |||
return SUCCESS; | |||
} | |||
const vector<void *> addr_list = ModelUtils::GetInputDataAddrs(runtime_param_, output_op_list_[kDataIndex]); | |||
for (size_t i = 0; i < addr_list.size() && i < outputs.size(); ++i) { | |||
knonw_output_data_info_[addr_list[i]] = outputs[i]; | |||
GELOGI("DavinciModel::CreateKnownZeroCopyMap output %d,v addr %p,p addr %p .", i, addr_list[i], outputs[i]); | |||
GELOGI("DavinciModel::CreateKnownZeroCopyMap output %zu,v addr %p,p addr %p .", i, addr_list[i], outputs[i]); | |||
} | |||
GELOGI("DavinciModel::CreateKnownZeroCopyMap success."); | |||
return SUCCESS; | |||
@@ -3010,13 +3006,13 @@ Status DavinciModel::UpdateKnownZeroCopyAddr() { | |||
for (size_t i = 0; i < total_io_addrs_.size(); ++i) { | |||
auto it_in = knonw_input_data_info_.find(total_io_addrs_[i]); | |||
if (it_in != knonw_input_data_info_.end()) { | |||
GELOGI("DavinciModel::UpdateKnownZeroCopyAddr input %d,v addr %p,p addr %p .", i, total_io_addrs_[i], | |||
GELOGI("DavinciModel::UpdateKnownZeroCopyAddr input %zu,v addr %p,p addr %p .", i, total_io_addrs_[i], | |||
knonw_input_data_info_.at(total_io_addrs_[i])); | |||
total_io_addrs_[i] = knonw_input_data_info_.at(total_io_addrs_[i]); | |||
} | |||
auto it_out = knonw_output_data_info_.find(total_io_addrs_[i]); | |||
if (it_out != knonw_output_data_info_.end()) { | |||
GELOGI("DavinciModel::UpdateKnownZeroCopyAddr output %d,v addr %p,p addr %p .", i, total_io_addrs_[i], | |||
GELOGI("DavinciModel::UpdateKnownZeroCopyAddr output %zu,v addr %p,p addr %p .", i, total_io_addrs_[i], | |||
knonw_output_data_info_.at(total_io_addrs_[i])); | |||
total_io_addrs_[i] = knonw_output_data_info_.at(total_io_addrs_[i]); | |||
} | |||
@@ -3037,7 +3033,7 @@ Status DavinciModel::UpdateKnownNodeArgs(const vector<void *> &inputs, const vec | |||
if (task != nullptr) { | |||
Status ret = task->UpdateArgs(); | |||
if (ret != SUCCESS) { | |||
GELOGE(FAILED, "task %d created by davinci model is nullptr.", task_index); | |||
GELOGE(FAILED, "task %zu created by davinci model is nullptr.", task_index); | |||
return FAILED; | |||
} | |||
} | |||
@@ -3066,7 +3062,7 @@ Status DavinciModel::UpdateKnownNodeArgs(const vector<void *> &inputs, const vec | |||
} | |||
Status DavinciModel::InitTaskInfo(domi::ModelTaskDef &model_task_def) { | |||
GELOGI("InitTaskInfo in, task size %zu", model_task_def.task().size()); | |||
GELOGI("InitTaskInfo in, task size %d", model_task_def.task().size()); | |||
task_list_.resize(model_task_def.task_size()); | |||
for (int i = 0; i < model_task_def.task_size(); ++i) { | |||
// dynamic shape will create task_list_ before | |||
@@ -3142,8 +3138,9 @@ Status DavinciModel::DistributeTask() { | |||
task_desc_info_.clear(); | |||
bool flag = GetL1FusionEnableOption(); | |||
char *skt_enable_env = std::getenv("SKT_ENABLE"); | |||
int64_t env_flag = (skt_enable_env != nullptr) ? std::strtol(skt_enable_env, nullptr, kDecimal) : 0; | |||
char skt_enable_env[MMPA_MAX_PATH] = { 0x00 }; | |||
INT32 res = mmGetEnv("SKT_ENABLE", skt_enable_env, MMPA_MAX_PATH); | |||
int64_t env_flag = (res == EN_OK) ? std::strtol(skt_enable_env, nullptr, kDecimal) : 0; | |||
if (env_flag != 0) { | |||
flag = true; | |||
} | |||
@@ -3331,7 +3328,7 @@ bool DavinciModel::CheckInputAndModelSize(const int64_t &input_size, const int64 | |||
if (input_size > op_size) { | |||
GELOGW( | |||
"Input size [%u] is bigger than om size need [%u], " | |||
"Input size [%ld] is bigger than om size need [%ld], " | |||
"MAY cause inference result ERROR, please check model input", | |||
input_size, op_size); | |||
} | |||
@@ -3413,7 +3410,7 @@ Status DavinciModel::UpdateIoTaskArgs(const std::map<uint32_t, ZeroCopyOffset> & | |||
for (const auto &data : data_info) { | |||
if (data.first >= blobs.size()) { // check data index. | |||
GELOGE(FAILED, "Verify %s data num failed: can not find No.%zu data, because user only feeds %zu", | |||
GELOGE(FAILED, "Verify %s data num failed: can not find No.%u data, because user only feeds %zu", | |||
input_or_output.c_str(), data.first, blobs.size()); | |||
return FAILED; | |||
} | |||
@@ -3522,7 +3519,7 @@ Status DavinciModel::InitConstant(const OpDescPtr &op_desc) { | |||
GeTensor *tensor = const_cast<GeTensor *>(v_weights[0].get()); | |||
GE_IF_BOOL_EXEC(static_cast<size_t>(v_output_size[0]) < tensor->GetData().size(), | |||
GELOGE(PARAM_INVALID, "output size:%u less than weight data size:%zu", v_output_size[0], | |||
GELOGE(PARAM_INVALID, "output size:%ld less than weight data size:%zu", v_output_size[0], | |||
tensor->GetData().size()); | |||
return PARAM_INVALID;); | |||
@@ -3546,12 +3543,12 @@ Status DavinciModel::InitConstant(const OpDescPtr &op_desc) { | |||
uint64_t offset = static_cast<uint64_t>(elem_num * kBytes); | |||
uint64_t hbm_raw_data_base_addr = | |||
reinterpret_cast<uint64_t>(reinterpret_cast<uintptr_t>(v_output_addr[0])) + offset; | |||
static_cast<uint64_t>(reinterpret_cast<uintptr_t>(v_output_addr[0])) + offset; | |||
for (int64_t i = elem_num - 1; i >= 0; --i) { | |||
buff[i] = hbm_raw_data_base_addr + (buff[i] - buff[0]); | |||
} | |||
} | |||
GELOGI("[IMAS]InitConstant memcpy graph_%u type[V] name[%s] output[%d] memaddr[%p] mem_size[%u] datasize[%zu]", | |||
GELOGI("[IMAS]InitConstant memcpy graph_%u type[V] name[%s] output[%d] memaddr[%p] mem_size[%lu] datasize[%zu]", | |||
runtime_param_.graph_id, op_desc->GetName().c_str(), 0, v_output_addr[0], v_output_size[0], | |||
tensor->GetData().size()); | |||
GE_CHK_RT_RET(rtMemcpy(v_output_addr[0], v_output_size[0], tensor->GetData().data(), tensor->GetData().size(), | |||
@@ -3906,7 +3903,9 @@ Status DavinciModel::InitEntryTask() { | |||
uint8_t *DavinciModel::MallocFeatureMapMem(size_t data_size) { | |||
uint8_t *mem_base = nullptr; | |||
const string purpose("feature map,used for op input and output."); | |||
if (std::getenv(kEnvGeuseStaticMemory) != nullptr) { | |||
char ge_static_mem_env[MMPA_MAX_PATH] = { 0x00 }; | |||
INT32 res = mmGetEnv(kEnvGeuseStaticMemory, ge_static_mem_env, MMPA_MAX_PATH); | |||
if (res == EN_OK) { | |||
data_size = static_cast<size_t>(VarManager::Instance(session_id_)->GetGraphMemoryMaxSize()); | |||
string memory_key = std::to_string(0) + "_f"; | |||
mem_base = MemManager::Instance(RT_MEMORY_HBM)->MallocMemory(purpose, memory_key, data_size, GetDeviceId()); | |||
@@ -3936,7 +3935,9 @@ uint8_t *DavinciModel::MallocP2PMem(size_t p2p_data_size) { | |||
uint8_t *DavinciModel::MallocWeightsMem(size_t weights_size) { | |||
uint8_t *weights_mem_base = nullptr; | |||
const string purpose("weights memory in inference network."); | |||
if (std::getenv(kEnvGeuseStaticMemory) != nullptr) { | |||
char ge_static_mem_env[MMPA_MAX_PATH] = { 0x00 }; | |||
INT32 res = mmGetEnv(kEnvGeuseStaticMemory, ge_static_mem_env, MMPA_MAX_PATH); | |||
if (res == EN_OK) { | |||
string weight_memory_key = std::to_string(0) + "_w"; | |||
weights_mem_base = | |||
MemManager::Instance(RT_MEMORY_HBM)->MallocMemory(purpose, weight_memory_key, weights_size, GetDeviceId()); | |||
@@ -3947,7 +3948,9 @@ uint8_t *DavinciModel::MallocWeightsMem(size_t weights_size) { | |||
} | |||
void DavinciModel::FreeFeatureMapMem() { | |||
if (std::getenv(kEnvGeuseStaticMemory) != nullptr && is_inner_mem_base_) { | |||
char ge_static_mem_env[MMPA_MAX_PATH] = { 0x00 }; | |||
INT32 res = mmGetEnv(kEnvGeuseStaticMemory, ge_static_mem_env, MMPA_MAX_PATH); | |||
if (res == EN_OK && is_inner_mem_base_) { | |||
string weight_memory_key = std::to_string(0) + "_f"; | |||
if (MemManager::Instance(RT_MEMORY_HBM)->GetMemoryAddr(weight_memory_key) != nullptr) { | |||
GE_CHK_STATUS(MemManager::Instance(RT_MEMORY_HBM)->FreeMemory(weight_memory_key, GetDeviceId()), | |||
@@ -3979,7 +3982,9 @@ void DavinciModel::FreeP2PMem() { | |||
} | |||
void DavinciModel::FreeWeightsMem() { | |||
if (std::getenv(kEnvGeuseStaticMemory) != nullptr) { | |||
char ge_static_mem_env[MMPA_MAX_PATH] = { 0x00 }; | |||
INT32 res = mmGetEnv(kEnvGeuseStaticMemory, ge_static_mem_env, MMPA_MAX_PATH); | |||
if (res == EN_OK) { | |||
string memory_key = std::to_string(0) + "_w"; | |||
if (MemManager::Instance(RT_MEMORY_HBM)->GetMemoryAddr(memory_key) != nullptr) { | |||
GE_CHK_STATUS(MemManager::Instance(RT_MEMORY_HBM)->FreeMemory(memory_key, GetDeviceId()), | |||
@@ -4160,7 +4165,7 @@ Status DavinciModel::GetAllAippInputOutputDims(uint32_t index, std::vector<Input | |||
vector<std::string> inputs; | |||
if (AttrUtils::GetListStr(data_op, ATTR_NAME_AIPP_INPUTS, inputs) && !inputs.empty()) { | |||
GELOGI("GetAllAippInputOutputDims: Data: %s has %u related aippInfo.", data_op->GetName().c_str(), inputs.size()); | |||
GELOGI("GetAllAippInputOutputDims: Data: %s has %zu related aippInfo.", data_op->GetName().c_str(), inputs.size()); | |||
for (auto it : inputs) { | |||
InputOutputDims input_info; | |||
ParseAIPPInfo(it, input_info); | |||
@@ -4171,7 +4176,7 @@ Status DavinciModel::GetAllAippInputOutputDims(uint32_t index, std::vector<Input | |||
int64_t data_input_size; | |||
(void)TensorUtils::GetSize(*(data_op->GetInputDescPtr(kDataIndex)), data_input_size); | |||
GELOGD( | |||
"GetAllAippInputOutputDims related Data[%d]: tensor_name is %s, dim_num is %u, tensor_size: %zu, format: " | |||
"GetAllAippInputOutputDims related Data[%d]: tensor_name is %s, dim_num is %zu, tensor_size: %zu, format: " | |||
"%s, data_type: %s, shape: %s .", | |||
index, data_op->GetName().c_str(), data_input_desc->GetShape().GetDimNum(), data_input_size, | |||
TypeUtils::FormatToSerialString(data_input_desc->GetFormat()).c_str(), | |||
@@ -1019,8 +1019,8 @@ Status ModelManager::GetAippType(uint32_t model_id, uint32_t index, InputAippTyp | |||
Status ModelManager::GenSessionId(uint64_t &session_id) { | |||
std::lock_guard<std::mutex> lock(session_id_create_mutex_); | |||
struct timeval tv; | |||
if (gettimeofday(&tv, nullptr) != 0) { | |||
mmTimeval tv; | |||
if (mmGetTimeOfDay(&tv, nullptr) != 0) { | |||
GELOGE(INTERNAL_ERROR, "Failed to get current time."); | |||
return INTERNAL_ERROR; | |||
} | |||
@@ -1037,8 +1037,8 @@ Status ModelManager::GenSessionId(uint64_t &session_id) { | |||
Status ModelManager::LoadModelOffline(uint32_t &model_id, const ModelData &model, shared_ptr<ModelListener> listener, | |||
void *dev_ptr, size_t mem_size, void *weight_ptr, size_t weight_size) { | |||
GE_CHK_BOOL_RET_STATUS(model.key.empty() || access(model.key.c_str(), F_OK) == 0, | |||
ACL_ERROR_GE_EXEC_MODEL_KEY_PATH_INVALID, | |||
GE_CHK_BOOL_RET_STATUS(model.key.empty() || mmAccess2(model.key.c_str(), M_F_OK) == EN_OK, | |||
ACL_ERROR_GE_EXEC_MODEL_KEY_PATH_INVALID, | |||
"input key file path %s is invalid, %s", model.key.c_str(), strerror(errno)); | |||
GenModelId(&model_id); | |||
@@ -1123,7 +1123,7 @@ Status ModelManager::LoadModelOffline(uint32_t &model_id, const ModelData &model | |||
Status ModelManager::LoadModelWithQ(uint32_t &model_id, const ModelData &model_data, | |||
const std::vector<uint32_t> &input_queue_ids, | |||
const std::vector<uint32_t> &output_queue_ids) { | |||
GE_CHK_BOOL_RET_STATUS(model_data.key.empty() || access(model_data.key.c_str(), F_OK) == 0, | |||
GE_CHK_BOOL_RET_STATUS(model_data.key.empty() || mmAccess2(model_data.key.c_str(), M_F_OK) == EN_OK, | |||
ACL_ERROR_GE_EXEC_MODEL_KEY_PATH_INVALID, "input key file path %s is not valid, %s", | |||
model_data.key.c_str(), strerror(errno)); | |||
@@ -18,7 +18,6 @@ | |||
#define GE_GRAPH_LOAD_NEW_MODEL_MANAGER_MODEL_MANAGER_H_ | |||
#include <model/ge_root_model.h> | |||
#include <pthread.h> | |||
#include <stdint.h> | |||
#include <algorithm> | |||
#include <map> | |||
@@ -356,7 +356,7 @@ vector<void *> ModelUtils::GetInputDataAddrs(const RuntimeParam &model_param, Co | |||
// feature maps | |||
void *mem_addr = nullptr; | |||
if (has_mem_type_attr && v_memory_type[i] == RT_MEMORY_L1) { // fusion | |||
mem_addr = reinterpret_cast<uint8_t *>(reinterpret_cast<intptr_t>(input_offset)); | |||
mem_addr = reinterpret_cast<uint8_t *>(static_cast<intptr_t>(input_offset)); | |||
v_input_data_addr.push_back(mem_addr); | |||
} else if (has_mem_type_attr && v_memory_type[i] == RT_MEMORY_TS_4G) { | |||
int64_t tensor_size = 0; | |||
@@ -424,7 +424,7 @@ vector<void *> ModelUtils::GetOutputDataAddrs(const RuntimeParam &model_param, C | |||
// feature maps | |||
void *mem_addr = nullptr; | |||
if (has_mem_type_attr && v_memory_type[i] == RT_MEMORY_L1) { // fusion | |||
mem_addr = reinterpret_cast<uint8_t *>(reinterpret_cast<intptr_t>(v_output_offset[i])); | |||
mem_addr = reinterpret_cast<uint8_t *>(static_cast<intptr_t>(v_output_offset[i])); | |||
v_output_data_addr.push_back(mem_addr); | |||
} else if (has_mem_type_attr && v_memory_type[i] == RT_MEMORY_TS_4G) { | |||
const GeTensorDescPtr tensor_desc = op_desc->MutableOutputDesc(i); | |||
@@ -500,7 +500,7 @@ vector<void *> ModelUtils::GetWorkspaceDataAddrs(const RuntimeParam &model_param | |||
continue; | |||
} | |||
if (has_mem_type_attr && v_memory_type[i] == RT_MEMORY_L1) { | |||
v_workspace_data_addr.push_back(reinterpret_cast<uint8_t *>(reinterpret_cast<intptr_t>(v_workspace_offset[i]))); | |||
v_workspace_data_addr.push_back(reinterpret_cast<uint8_t *>(static_cast<intptr_t>(v_workspace_offset[i]))); | |||
GELOGI("[IMAS]GetWorkspaceDataAddrs graph_%u type[L1] name[%s], mem_addr[workspace index %zu]:0x%lx", | |||
model_param.graph_id, op_desc->GetName().c_str(), i, v_workspace_offset[i]); | |||
} else if (v_workspace_bytes[i] == 0) { | |||
@@ -149,7 +149,7 @@ Status KernelExTaskInfo::Init(const domi::TaskDef &task_def, DavinciModel *davin | |||
return FAILED; | |||
} | |||
uint64_t workspace_base_addr = reinterpret_cast<uint64_t>(reinterpret_cast<uintptr_t>(workspace_data_addrs[0])); | |||
uint64_t workspace_base_addr = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(workspace_data_addrs[0])); | |||
const vector<void *> input_addrs = ModelUtils::GetInputDataAddrs(rts_param, op_desc); | |||
const vector<void *> output_addrs = ModelUtils::GetOutputDataAddrs(rts_param, op_desc); | |||
vector<void *> io_addrs; | |||
@@ -287,7 +287,7 @@ Status KernelExTaskInfo::CopyTaskInfo(const domi::KernelExDef &kernel_def, const | |||
} | |||
if (workspace_data_sizes[0] < static_cast<int64_t>(kernel_def.task_info_size())) { | |||
GELOGE(FAILED, "Node:%s workspace size is %zu, task info size is %zu.", op_desc->GetName().c_str(), | |||
GELOGE(FAILED, "Node:%s workspace size is %ld, task info size is %d.", op_desc->GetName().c_str(), | |||
workspace_data_sizes[0], kernel_def.task_info_size()); | |||
return FAILED; | |||
} | |||
@@ -73,7 +73,8 @@ Status KernelTaskInfo::Init(const domi::TaskDef &task_def, DavinciModel *davinci | |||
GELOGD("node[%s] is_n_batch_spilt %d", op_desc_->GetName().c_str(), is_n_batch_spilt_); | |||
(void)AttrUtils::GetInt(*op_desc_, ATTR_NAME_FUSION_GROUP_KEY, group_key_); | |||
has_group_key_ = (group_key_ != kInvalidGroupKey); | |||
GELOGD("node[%s] has_group_key_ %ld, group key is [%ld]", op_desc_->GetName().c_str(), has_group_key_, group_key_); | |||
GELOGD("node[%s] has_group_key_ %d, group key is [%ld]", op_desc_->GetName().c_str(), has_group_key_, group_key_); | |||
// fusion_op_info | |||
vector<std::string> original_op_names; | |||
bool result = AttrUtils::GetListStr(op_desc_, ge::ATTR_NAME_DATA_DUMP_ORIGIN_OP_NAMES, original_op_names); | |||
@@ -216,7 +217,7 @@ Status KernelTaskInfo::SuperKernelLaunch() { | |||
rtError_t rt_ret; | |||
auto &skt_kernel_list = skt_info_.kernel_list; | |||
auto &skt_arg_list = skt_info_.arg_list; | |||
GELOGI("SuperKernelLaunch: Skt_kernel_list size[%d] skt_arg_list[%d]", skt_kernel_list.size(), skt_arg_list.size()); | |||
GELOGI("SuperKernelLaunch: Skt_kernel_list size[%zu] skt_arg_list[%zu]", skt_kernel_list.size(), skt_arg_list.size()); | |||
if (skt_kernel_list.size() == kSKTSingleSize && skt_arg_list.size() == kSKTSingleSize) { | |||
rt_ret = rtKernelLaunchWithFlag(skt_info_.kernel_list[0], static_cast<uint32_t>(skt_info_.last_block_dim), | |||
skt_info_.arg_list[0], skt_info_.last_args_size, | |||
@@ -367,8 +368,9 @@ Status KernelTaskInfo::Distribute() { | |||
GELOGI("Known node %s args addr %p, offset %u.", op_desc_->GetName().c_str(), args_, args_offset_); | |||
} | |||
rtError_t rt_ret = RT_ERROR_NONE; | |||
char *skt_enable_env = getenv("SKT_ENABLE"); | |||
int64_t env_flag = (skt_enable_env != nullptr) ? strtol(skt_enable_env, nullptr, 10) : 0; | |||
char skt_enable_env[MMPA_MAX_PATH] = { 0x00 }; | |||
INT32 res = mmGetEnv("SKT_ENABLE", skt_enable_env, MMPA_MAX_PATH); | |||
int64_t env_flag = (res == EN_OK) ? strtol(skt_enable_env, nullptr, 10) : 0; | |||
bool call_skt = ((env_flag != 0) || is_l1_fusion_enable_); | |||
if (kernel_type_ == cce::ccKernelType::AI_CPU || kernel_type_ == cce::ccKernelType::CUST_AI_CPU) { | |||
GELOGI("distribute task info kernel_type %d, flag %d", kernel_type_, dump_flag_); | |||
@@ -747,15 +749,15 @@ Status KernelTaskInfo::InitAICPUCustomTask(uint32_t op_index, const domi::Kernel | |||
} | |||
} | |||
*(reinterpret_cast<uint64_t *>(args + ctx_.argsOffset[0])) = | |||
reinterpret_cast<uint64_t>(reinterpret_cast<uintptr_t>(custom_info_.input_descs)); // arg 0 | |||
static_cast<uint64_t>(reinterpret_cast<uintptr_t>(custom_info_.input_descs)); // arg 0 | |||
*(reinterpret_cast<uint64_t *>(args + ctx_.argsOffset[1])) = | |||
reinterpret_cast<uint64_t>(reinterpret_cast<uintptr_t>(custom_info_.input_addrs)); // arg 1 | |||
static_cast<uint64_t>(reinterpret_cast<uintptr_t>(custom_info_.input_addrs)); // arg 1 | |||
*(reinterpret_cast<uint64_t *>(args + ctx_.argsOffset[2])) = | |||
reinterpret_cast<uint64_t>(reinterpret_cast<uintptr_t>(custom_info_.output_descs)); // arg 2 | |||
static_cast<uint64_t>(reinterpret_cast<uintptr_t>(custom_info_.output_descs)); // arg 2 | |||
*(reinterpret_cast<uint64_t *>(args + ctx_.argsOffset[3])) = | |||
reinterpret_cast<uint64_t>(reinterpret_cast<uintptr_t>(custom_info_.output_addrs)); // arg 3 | |||
static_cast<uint64_t>(reinterpret_cast<uintptr_t>(custom_info_.output_addrs)); // arg 3 | |||
*(reinterpret_cast<uint64_t *>(args + ctx_.argsOffset[4])) = | |||
reinterpret_cast<uint64_t>(reinterpret_cast<uintptr_t>(custom_info_.attr_handle)); // arg 4 | |||
static_cast<uint64_t>(reinterpret_cast<uintptr_t>(custom_info_.attr_handle)); // arg 4 | |||
rt_ret = rtMalloc(&args_, args_size_, RT_MEMORY_HBM); | |||
if (rt_ret != RT_ERROR_NONE) { | |||
@@ -913,7 +915,7 @@ Status KernelTaskInfo::InitAicpuTask(uint32_t op_index, const domi::KernelDef &k | |||
op_desc_->GetType().c_str(), ext_info.size(), aicpu_ext_info_addr_); | |||
aicpu_param_head->extInfoAddr = reinterpret_cast<uintptr_t>(aicpu_ext_info_addr_); | |||
aicpu_param_head->extInfoLength = reinterpret_cast<uintptr_t>(ext_info.size()); | |||
aicpu_param_head->extInfoLength = static_cast<uintptr_t>(ext_info.size()); | |||
// malloc device memory for args | |||
rtError_t rt_ret = rtMalloc(static_cast<void **>(&args_), args_size_, RT_MEMORY_HBM); | |||
@@ -1122,18 +1124,24 @@ Status KernelTaskInfo::CceUpdateKernelArgs(const domi::KernelContext &context, u | |||
} | |||
GELOGI("FileName:%s, Path:%s.", file_name.c_str(), canonicalPath.c_str()); | |||
auto handle = dlopen(canonicalPath.c_str(), RTLD_NOW | RTLD_GLOBAL); | |||
auto handle = mmDlopen(canonicalPath.c_str(), MMPA_RTLD_NOW | MMPA_RTLD_GLOBAL); | |||
const char *error = ""; | |||
if (handle == nullptr) { | |||
GELOGE(GE_PLGMGR_SO_NOT_EXIST, "Failed in dlopen %s! ", dlerror()); | |||
error = mmDlerror(); | |||
GE_IF_BOOL_EXEC(error == nullptr, error = ""); | |||
GELOGE(GE_PLGMGR_SO_NOT_EXIST, "Failed in dlopen %s! ", error); | |||
return FAILED; | |||
} | |||
cce::ccStatus_t cc_ret; | |||
std::string update_kernel_args = "ccUpdateKernelArgs"; | |||
auto cceUpdateKernelArgs = (cce::ccStatus_t(*)(cce::ccOpContext &, uint64_t, uint64_t, uint64_t, void *, uint64_t, | |||
void *))dlsym(handle, "ccUpdateKernelArgs"); | |||
void *))mmDlsym(handle, const_cast<char *>(update_kernel_args.c_str())); | |||
if (cceUpdateKernelArgs == nullptr) { | |||
GELOGE(FAILED, "Failed to invoke function ccUpdateKernelArgs"); | |||
if (dlclose(handle) != 0) { | |||
GELOGW("Failed to close handle %s", dlerror()); | |||
if (mmDlclose(handle) != 0) { | |||
error = mmDlerror(); | |||
GE_IF_BOOL_EXEC(error == nullptr, error = ""); | |||
GELOGW("Failed to close handle %s", error); | |||
} | |||
return FAILED; | |||
} else { | |||
@@ -1146,8 +1154,10 @@ Status KernelTaskInfo::CceUpdateKernelArgs(const domi::KernelContext &context, u | |||
const_cast<char *>(kernel_def.args().data()), args_size_, sm_contrl); | |||
} | |||
} | |||
if (dlclose(handle) != 0) { | |||
GELOGW("Failed to close handle %s", dlerror()); | |||
if (mmDlclose(handle) != 0) { | |||
error = mmDlerror(); | |||
GE_IF_BOOL_EXEC(error == nullptr, error = ""); | |||
GELOGW("Failed to close handle %s", error); | |||
return FAILED; | |||
} | |||
if (cc_ret != cce::CC_STATUS_SUCCESS) { | |||
@@ -1188,7 +1198,7 @@ Status KernelTaskInfo::SetFlowtable(std::string &flowtable, const domi::KernelDe | |||
*(reinterpret_cast<uint64_t *>( | |||
args + (reinterpret_cast<uint16_t *>(const_cast<char *>(context.args_offset().data())))[0])) = | |||
reinterpret_cast<uint64_t>(reinterpret_cast<uintptr_t>(flowtable_)); | |||
static_cast<uint64_t>(reinterpret_cast<uintptr_t>(flowtable_)); | |||
} | |||
return SUCCESS; | |||
} | |||
@@ -23,7 +23,7 @@ Status SuperKernel::Launch(rtStream_t stream, uint32_t dump_flag) { | |||
const void *func_stub_ = this->GetFuncStub(); | |||
const void *args[] = {this->GetNavTablePtr(), | |||
reinterpret_cast<const void *>(reinterpret_cast<uintptr_t>(this->GetNavTableSize()))}; | |||
reinterpret_cast<const void *>(static_cast<uintptr_t>(this->GetNavTableSize()))}; | |||
rtError_t rt_ret = rtMalloc((void **)&(device_args_addr_), sizeof(args), RT_MEMORY_HBM); | |||
GE_IF_BOOL_EXEC(rt_ret != RT_ERROR_NONE, GELOGE(RT_FAILED, "rtMalloc failied. error: 0x%X", rt_ret); return | |||
@@ -27,7 +27,7 @@ SuperKernelFactory &SuperKernelFactory::GetInstance() { | |||
Status SuperKernelFactory::Init() { | |||
if (!is_init_) { | |||
std::string skt_bin = "libcce_aicore.so"; | |||
handle_ = dlopen(skt_bin.c_str(), RTLD_NOW | RTLD_GLOBAL); | |||
handle_ = mmDlopen(skt_bin.c_str(), MMPA_RTLD_NOW | MMPA_RTLD_GLOBAL); | |||
if (handle_ == nullptr) { | |||
GELOGE(FAILED, "SKT: open skt lib failed, please check LD_LIBRARY_PATH."); | |||
} | |||
@@ -85,8 +85,10 @@ Status SuperKernelFactory::FuseKernels(const std::vector<void *> &stub_func_list | |||
"equal to 2"); | |||
return FAILED; | |||
} | |||
GELOGI("SKT: superkernel start fuse, superkernel size %d.", stub_func_list.size()); | |||
uint64_t nav_table[2 * stub_func_list.size()]; | |||
GELOGI("SKT: superkernel start fuse, superkernel size %zu.", stub_func_list.size()); | |||
const size_t nav_table_len = 2 * stub_func_list.size(); | |||
std::unique_ptr<uint64_t[]> nav_table(new(std::nothrow) uint64_t[nav_table_len]); | |||
GE_CHECK_NOTNULL(nav_table); | |||
uint64_t nav_table_size = 2 * stub_func_list.size() * sizeof(int64_t); | |||
rtError_t rt_ret; | |||
@@ -99,16 +101,16 @@ Status SuperKernelFactory::FuseKernels(const std::vector<void *> &stub_func_list | |||
GELOGD("SKT: fuseKernels subFunc %p, device func address %p", stub_func_list[i], sub_device_func); | |||
// store two uint64_t address | |||
// address divided by 4 because of 32bits encoding, call offset will *4 when calculating | |||
nav_table[i * 2] = reinterpret_cast<uint64_t>(reinterpret_cast<uintptr_t>(sub_device_func)) / 4; | |||
nav_table[i * 2] = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(sub_device_func)) / 4; | |||
GELOGD("SKT: CALL offet %lu", nav_table[i * 2]); | |||
nav_table[i * 2 + 1] = reinterpret_cast<uint64_t>(reinterpret_cast<uintptr_t>(args_addr_list[i])); | |||
nav_table[i * 2 + 1] = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(args_addr_list[i])); | |||
GELOGD("SKT: fuseKernels args base address %lu", nav_table[i * 2 + 1]); | |||
} | |||
rt_ret = rtMalloc((void **)&hbm_nav_table_addr, nav_table_size, RT_MEMORY_HBM); | |||
GE_IF_BOOL_EXEC(rt_ret != RT_ERROR_NONE, GELOGE(RT_FAILED, "rtMalloc failed. error: 0x%X", rt_ret); | |||
return RT_ERROR_TO_GE_STATUS(rt_ret);) | |||
rt_ret = | |||
rtMemcpy((void *)hbm_nav_table_addr, nav_table_size, (void *)nav_table, nav_table_size, RT_MEMCPY_HOST_TO_DEVICE); | |||
rtMemcpy((void *)hbm_nav_table_addr, nav_table_size, (void *)nav_table.get(), nav_table_size, RT_MEMCPY_HOST_TO_DEVICE); | |||
GE_IF_BOOL_EXEC(rt_ret != RT_ERROR_NONE, GELOGE(RT_FAILED, "rtMemcpy failed. error: 0x%X", rt_ret); | |||
GE_CHK_RT(rtFree(hbm_nav_table_addr)); return RT_ERROR_TO_GE_STATUS(rt_ret);) | |||
// Create the necessary metadata for the super kernel | |||
@@ -34,8 +34,10 @@ class SuperKernelFactory { | |||
~SuperKernelFactory() { | |||
if (handle_ != nullptr) { | |||
GELOGI("SKT: SKT LIB PATH release."); | |||
if (dlclose(handle_) != 0) { | |||
GELOGW("failed to close handle, message: %s", dlerror()); | |||
if (mmDlclose(handle_) != 0) { | |||
const char *error = mmDlerror(); | |||
GE_IF_BOOL_EXEC(error == nullptr, error = ""); | |||
GELOGW("failed to close handle, message: %s", error); | |||
} | |||
} | |||
}; | |||
@@ -69,7 +69,7 @@ Status ZeroCopyOffset::InitInputDataInfo(const vector<int64_t> &output_size_list | |||
uint64_t out_offset = | |||
reinterpret_cast<uint64_t>(virtual_addr_list[kDataIndex]) + zero_copy_relative_offset_.at(index); | |||
int64_t real_data_size = ModelUtils::GetOutputSize(op_desc).at(kDataIndex); | |||
data_info_.emplace_back(real_data_size, reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(out_offset))); | |||
data_info_.emplace_back(real_data_size, reinterpret_cast<void *>(static_cast<uintptr_t>(out_offset))); | |||
relative_offset_.emplace_back(zero_copy_relative_offset_.at(index)); | |||
GELOGI("[ZCPY] virtual_addr: %p has been l2-fusion to %lu, need copy data_size is %ld.", basic_addr_, | |||
out_offset, real_data_size); | |||
@@ -119,7 +119,7 @@ Status ZeroCopyOffset::InitOutputDataInfo(const vector<int64_t> &input_size_list | |||
in_count++; | |||
uint64_t in_offset = reinterpret_cast<uint64_t>(virtual_addr_list[idx]) + zero_copy_relative_offset_.at(index); | |||
int64_t real_data_size = ModelUtils::GetInputSize(op_desc).at(idx); | |||
data_info_.emplace_back(real_data_size, reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(in_offset))); | |||
data_info_.emplace_back(real_data_size, reinterpret_cast<void *>(static_cast<uintptr_t>(in_offset))); | |||
relative_offset_.emplace_back(zero_copy_relative_offset_.at(index)); | |||
GELOGI("[ZCPY] virtual_addr: %p has been l2-fusion from %lu, need copy data_size is %ld.", basic_addr_, | |||
in_offset, real_data_size); | |||
@@ -19,6 +19,7 @@ | |||
#include "framework/common/debug/ge_log.h" | |||
#include "framework/common/util.h" | |||
#include "graph/load/new_model_manager/model_utils.h" | |||
#inlcude "common/ge_compiler_options.h" | |||
namespace ge { | |||
const char *const kDefaultBatchLable = "Batch_default"; | |||
@@ -157,7 +158,7 @@ Status ZeroCopyTask::DistributeParam(bool async_mode, rtStream_t stream) { | |||
rt_err = rtMemcpyAsync(args_addr_, args_size_, args_info_.data(), args_info_.size(), RT_MEMCPY_HOST_TO_DEVICE_EX, | |||
stream); | |||
} else { | |||
__builtin_prefetch(args_addr_); | |||
GE_BUILTIN_PREFETCH(args_addr_); | |||
rt_err = rtMemcpy(args_addr_, args_size_, args_info_.data(), args_info_.size(), RT_MEMCPY_HOST_TO_DEVICE); | |||
} | |||
@@ -92,13 +92,13 @@ ge::Status VarResource::SaveVarAddr(const std::string &var_name, const ge::GeTen | |||
GELOGD("VarResource::SaveVarAddr, var_key = %s", var_key.c_str()); | |||
if (var_addr_mgr_map_.count(var_key) == 0) { | |||
uint64_t logic_address = VarManager::Instance(session_id_)->GetVarMemLogicBase() + | |||
reinterpret_cast<uint64_t>(reinterpret_cast<std::uintptr_t>(address)); | |||
static_cast<uint64_t>(reinterpret_cast<std::uintptr_t>(address)); | |||
GELOGI("SaveVarAddr node_name %s, tensor_desc format %s, type %s.", var_name.c_str(), | |||
TypeUtils::FormatToSerialString(tensor_desc.GetFormat()).c_str(), | |||
TypeUtils::DataTypeToSerialString(tensor_desc.GetDataType()).c_str()); | |||
VarAddrMgr var_addr_mgr; | |||
var_addr_mgr.address = reinterpret_cast<uint8_t *>(reinterpret_cast<std::uintptr_t>(logic_address)); | |||
var_addr_mgr.offset = reinterpret_cast<uint64_t>(reinterpret_cast<std::uintptr_t>(address)); | |||
var_addr_mgr.address = reinterpret_cast<uint8_t *>(static_cast<std::uintptr_t>(logic_address)); | |||
var_addr_mgr.offset = static_cast<uint64_t>(reinterpret_cast<std::uintptr_t>(address)); | |||
var_addr_mgr.tensor_desc = tensor_desc; | |||
var_addr_mgr.memory_type = memory_type; | |||
var_addr_mgr_map_[var_key] = var_addr_mgr; | |||
@@ -510,7 +510,7 @@ ge::Status VarManager::AssignVarMem(const std::string &var_name, const ge::GeTen | |||
} | |||
result = var_resource_->SaveVarAddr( | |||
var_name, tensor_desc, reinterpret_cast<uint8_t *>(reinterpret_cast<uintptr_t>(mem_offset)), memory_type); | |||
var_name, tensor_desc, reinterpret_cast<uint8_t *>(static_cast<uintptr_t>(mem_offset)), memory_type); | |||
if (result != SUCCESS) { | |||
GELOGE(ge::INTERNAL_ERROR, "AssignVarMem by offset failed."); | |||
return ge::INTERNAL_ERROR; | |||
@@ -527,7 +527,7 @@ ge::Status VarManager::AssignVarMem(const std::string &var_name, const ge::GeTen | |||
result = var_resource_->GetCurVarDesc(var_name, cur_tensor_desc); | |||
if (result != SUCCESS) { | |||
var_resource_->SetVarAddr(var_name, tensor_desc, | |||
reinterpret_cast<uint8_t *>(reinterpret_cast<uintptr_t>(mem_offset)), memory_type); | |||
reinterpret_cast<uint8_t *>(static_cast<uintptr_t>(mem_offset)), memory_type); | |||
return SUCCESS; | |||
} | |||
@@ -542,7 +542,7 @@ ge::Status VarManager::AssignVarMem(const std::string &var_name, const ge::GeTen | |||
ge::TypeUtils::FormatToSerialString(cur_tensor_desc.GetFormat()).c_str(), | |||
cur_tensor_desc.GetShape().GetDims().size()); | |||
var_resource_->SetVarAddr(var_name, tensor_desc, | |||
reinterpret_cast<uint8_t *>(reinterpret_cast<uintptr_t>(mem_offset)), memory_type); | |||
reinterpret_cast<uint8_t *>(static_cast<uintptr_t>(mem_offset)), memory_type); | |||
} | |||
return SUCCESS; | |||
@@ -374,7 +374,7 @@ Status TransVarDataUtils::SyncVarData2BroadCast(const string &var_name, const ge | |||
GE_MAKE_GUARD_RTMEM(src_host_addr); | |||
GE_CHK_STATUS_RET(SyncTensorToHost(var_name, src_tensor_desc, &src_host_addr, src_addr_size, session_id)); | |||
GELOGI("src_addr_size: %u, dst_addr_size: %u", src_addr_size, dst_addr_size); | |||
GELOGI("src_addr_size: %ld, dst_addr_size: %ld", src_addr_size, dst_addr_size); | |||
GE_CHK_BOOL_RET_STATUS(src_addr_size == dst_addr_size, FAILED, "var data size is not equal broadcast "); | |||
GE_CHK_RT_RET(rtMemcpy(dst_addr, dst_addr_size, src_host_addr, src_addr_size, RT_MEMCPY_HOST_TO_DEVICE)); | |||
@@ -403,7 +403,7 @@ Status TransVarDataUtils::SyncTensorToHost(const string &var_name, const ge::GeT | |||
GE_CHK_STATUS_RET(VarManager::Instance(session_id)->GetVarAddr(var_name, src_tensor_desc, &src_addr)); | |||
uint8_t *mem_addr = | |||
src_addr - | |||
static_cast<int64_t>(reinterpret_cast<uintptr_t>(VarManager::Instance(session_id)->GetVarMemLogicBase())) + | |||
static_cast<int64_t>(static_cast<uintptr_t>(VarManager::Instance(session_id)->GetVarMemLogicBase())) + | |||
static_cast<int64_t>( | |||
reinterpret_cast<uintptr_t>(VarManager::Instance(session_id)->GetVarMemoryBase(RT_MEMORY_HBM))); | |||
GE_CHK_RT_RET(rtMallocHost(reinterpret_cast<void **>(host_addr), src_tensor_size)); | |||
@@ -420,7 +420,7 @@ Status TransVarDataUtils::SyncTensorToDevice(const string &var_name, const uint8 | |||
GE_CHK_STATUS_RET(VarManager::Instance(session_id)->GetVarAddr(var_name, dst_tensor_desc, &dst_addr)); | |||
uint8_t *mem_addr = | |||
dst_addr - | |||
static_cast<int64_t>(reinterpret_cast<uintptr_t>(VarManager::Instance(session_id)->GetVarMemLogicBase())) + | |||
static_cast<int64_t>(static_cast<uintptr_t>(VarManager::Instance(session_id)->GetVarMemLogicBase())) + | |||
static_cast<int64_t>( | |||
reinterpret_cast<uintptr_t>(VarManager::Instance(session_id)->GetVarMemoryBase(RT_MEMORY_HBM))); | |||
GE_CHK_RT_RET(rtMemcpy(mem_addr, addr_size, host_addr, addr_size, RT_MEMCPY_HOST_TO_DEVICE)); | |||
@@ -32,7 +32,7 @@ Debug::~Debug() = default; | |||
void Debug::DumpProto(const Message &proto, const char *file) { | |||
std::string file_path = RealPath(file); | |||
int fd = open(file_path.c_str(), O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); | |||
int fd = mmOpen2(file_path.c_str(), M_WRONLY | M_CREAT | O_TRUNC, M_IRUSR | M_IWUSR | M_UMASK_GRPREAD | M_UMASK_OTHREAD); | |||
if (fd == -1) { | |||
GELOGW("Write %s failed", file_path.c_str()); | |||
return; | |||
@@ -40,7 +40,7 @@ void Debug::DumpProto(const Message &proto, const char *file) { | |||
auto output = ge::MakeShared<FileOutputStream>(fd); | |||
if (output == nullptr) { | |||
GELOGW("create output failed."); | |||
if (close(fd) != 0) { | |||
if (mmClose(fd) != 0) { | |||
GELOGW("close fd failed."); | |||
} | |||
return; | |||
@@ -49,7 +49,7 @@ void Debug::DumpProto(const Message &proto, const char *file) { | |||
if (!ret) { | |||
GELOGW("dump proto failed."); | |||
} | |||
if (close(fd) != 0) { | |||
if (mmClose(fd) != 0) { | |||
GELOGW("close fd failed."); | |||
} | |||
} | |||
@@ -17,7 +17,6 @@ | |||
#ifndef GE_GRAPH_MANAGER_UTIL_DEBUG_H_ | |||
#define GE_GRAPH_MANAGER_UTIL_DEBUG_H_ | |||
#include <fcntl.h> | |||
#include <sys/stat.h> | |||
#include <sys/types.h> | |||
#include <time.h> | |||
@@ -25,7 +24,6 @@ | |||
#include <google/protobuf/io/coded_stream.h> | |||
#include <google/protobuf/io/zero_copy_stream_impl.h> | |||
#include <google/protobuf/text_format.h> | |||
#include <unistd.h> | |||
#include <algorithm> | |||
#include <fstream> | |||
#include <iosfwd> | |||
@@ -57,9 +57,9 @@ struct GraphExecutionContext { | |||
do { \ | |||
if ((context != nullptr) && (context)->profiler != nullptr) { \ | |||
if (node_name != nullptr) { \ | |||
context->profiler->RecordEvent(evt_type, "tid:%lu [%s] [%s] " fmt, GetTid(), node_name, category, ##__VA_ARGS__);\ | |||
context->profiler->RecordEvent(evt_type, "tid:%lu [%s] [%s] " fmt, GeLog::GetTid(), node_name, category, ##__VA_ARGS__);\ | |||
} else { \ | |||
context->profiler->RecordEvent(evt_type, "tid:%lu [%s] " fmt, GetTid(), category, ##__VA_ARGS__); \ | |||
context->profiler->RecordEvent(evt_type, "tid:%lu [%s] " fmt, GeLog::GetTid(), category, ##__VA_ARGS__); \ | |||
}\ | |||
} \ | |||
} while (0) | |||
@@ -110,7 +110,7 @@ Status GELib::InnerInitialize(const map<string, string> &options) { | |||
Status initSystemStatus = SystemInitialize(options); | |||
GE_TIMESTAMP_END(SystemInitialize, "InnerInitialize::SystemInitialize"); | |||
if (initSystemStatus != SUCCESS) { | |||
GELOGE(initSystemStatus); | |||
GELOGE(initSystemStatus, "GE system initial failed."); | |||
RollbackInit(); | |||
return initSystemStatus; | |||
} | |||
@@ -120,7 +120,7 @@ Status GELib::InnerInitialize(const map<string, string> &options) { | |||
Status initEmStatus = engineManager_.Initialize(options); | |||
GE_TIMESTAMP_END(EngineInitialize, "InnerInitialize::EngineInitialize"); | |||
if (initEmStatus != SUCCESS) { | |||
GELOGE(initEmStatus); | |||
GELOGE(initEmStatus, "GE engine manager initial failed."); | |||
RollbackInit(); | |||
return initEmStatus; | |||
} | |||
@@ -130,7 +130,7 @@ Status GELib::InnerInitialize(const map<string, string> &options) { | |||
Status initOpsStatus = opsManager_.Initialize(options); | |||
GE_TIMESTAMP_END(OpsManagerInitialize, "InnerInitialize::OpsManagerInitialize"); | |||
if (initOpsStatus != SUCCESS) { | |||
GELOGE(initOpsStatus); | |||
GELOGE(initOpsStatus, "GE ops manager initial failed."); | |||
RollbackInit(); | |||
return initOpsStatus; | |||
} | |||
@@ -140,7 +140,7 @@ Status GELib::InnerInitialize(const map<string, string> &options) { | |||
Status initOpsBuilderStatus = OpsKernelBuilderManager::Instance().Initialize(options); | |||
GE_TIMESTAMP_END(OpsKernelBuilderManagerInitialize, "InnerInitialize::OpsKernelBuilderManager"); | |||
if (initOpsBuilderStatus != SUCCESS) { | |||
GELOGE(initOpsBuilderStatus); | |||
GELOGE(initOpsBuilderStatus, "GE ops builder manager initial failed."); | |||
RollbackInit(); | |||
return initOpsBuilderStatus; | |||
} | |||
@@ -150,7 +150,7 @@ Status GELib::InnerInitialize(const map<string, string> &options) { | |||
Status initSmStatus = sessionManager_.Initialize(options); | |||
GE_TIMESTAMP_END(SessionManagerInitialize, "InnerInitialize::SessionManagerInitialize"); | |||
if (initSmStatus != SUCCESS) { | |||
GELOGE(initSmStatus); | |||
GELOGE(initSmStatus, "GE session manager initial failed."); | |||
RollbackInit(); | |||
return initSmStatus; | |||
} | |||
@@ -52,9 +52,11 @@ void CsaInteract::Init(int32_t dev_index, int64_t job_id) { | |||
if (!is_init_) { | |||
dev_index_ = dev_index; | |||
job_id_ = job_id; | |||
char *file_dir_env = std::getenv(FMK_STATUS_FILE_DIR_ENV); | |||
char file_dir_env[MMPA_MAX_PATH] = { 0x00 }; | |||
INT32 res = mmGetEnv(FMK_STATUS_FILE_DIR_ENV, file_dir_env, MMPA_MAX_PATH); | |||
string csa_path_prefix; | |||
if (file_dir_env != nullptr) { | |||
if (res == EN_OK) { | |||
csa_path_prefix = file_dir_env; | |||
} | |||
if (!csa_path_prefix.empty()) { | |||
@@ -186,21 +188,21 @@ Status CsaInteract::WriteHcomDetection(const std::string &content) { | |||
/// | |||
Status CsaInteract::WriteFile(const std::string &file_name, const std::string &content) { | |||
// if file path is not exist, then make path | |||
INT32 flags = O_WRONLY | O_TRUNC | O_CREAT; | |||
int32_t fd = mmOpen2(file_name.c_str(), flags, M_IRUSR | M_IWUSR | S_IRGRP); | |||
INT32 flags = M_WRONLY | O_TRUNC | M_CREAT; | |||
int32_t fd = mmOpen2(file_name.c_str(), flags, M_IRUSR | M_IWUSR | M_UMASK_GRPREAD); | |||
if (fd == EN_ERROR) { | |||
if (MakePath(file_name) != SUCCESS) { | |||
GELOGE(INTERNAL_ERROR, "csainteract create file path fail, errno is %d", errno); | |||
return INTERNAL_ERROR; | |||
} | |||
fd = mmOpen2(file_name.c_str(), flags, M_IRUSR | M_IWUSR | S_IRGRP); | |||
fd = mmOpen2(file_name.c_str(), flags, M_IRUSR | M_IWUSR | M_UMASK_GRPREAD); | |||
if (fd == EN_ERROR) { | |||
GELOGE(INTERNAL_ERROR, "open file fail, errno is %d", errno); | |||
return INTERNAL_ERROR; | |||
} | |||
} | |||
ssize_t ret = write(fd, content.c_str(), content.length()); | |||
mmSsize_t ret = mmWrite(fd, (void *)content.c_str(), content.length()); | |||
if (ret == EN_ERROR) { | |||
GELOGE(INTERNAL_ERROR, "write file fail, errno is %d", errno); | |||
ret = mmClose(fd); | |||
@@ -239,7 +241,7 @@ Status CsaInteract::MakePath(const std::string &file_name) { | |||
while (found != std::string::npos) { | |||
std::string pre_path = file_path.substr(0, found + 1); | |||
if (mmAccess(pre_path.c_str()) != EN_OK) { | |||
if (mmMkdir(pre_path.c_str(), S_IRWXU) != EN_OK) { | |||
if (mmMkdir(pre_path.c_str(), M_IRWXU) != EN_OK) { | |||
GELOGE(INTERNAL_ERROR, "csainteract mkdir fail, errno is %d", errno); | |||
return INTERNAL_ERROR; | |||
} | |||
@@ -85,7 +85,7 @@ Status OpsKernelManager::Initialize(const map<string, string> &options_const) { | |||
initialize_ = options; | |||
Status rst0 = plugin_manager_.InvokeAll<map<string, string> &, Status>(kInitialize, initialize_); | |||
if (rst0 == FAILED) { | |||
GELOGE(GE_OPS_GET_NO_VALID_SO); | |||
GELOGE(GE_OPS_GET_NO_VALID_SO, "There is invalid so about OpsKernelInfoStore."); | |||
return GE_OPS_GET_NO_VALID_SO; | |||
} | |||
Status rst1 = | |||
@@ -61,7 +61,7 @@ Status SessionManager::SetRtContext(SessionId session_id, rtContext_t rt_context | |||
Status SessionManager::CreateSession(const std::map<std::string, std::string> &options, SessionId &session_id) { | |||
if (!init_flag_) { | |||
GELOGE(GE_SESSION_MANAGER_NOT_INIT); | |||
GELOGE(GE_SESSION_MANAGER_NOT_INIT, "Session manager is not initialized."); | |||
return GE_SESSION_MANAGER_NOT_INIT; | |||
} | |||
SessionId next_session_id = 0; | |||
@@ -92,7 +92,7 @@ Status SessionManager::CreateSession(const std::map<std::string, std::string> &o | |||
Status SessionManager::DestroySession(SessionId session_id) { | |||
if (!init_flag_) { | |||
GELOGE(GE_SESSION_MANAGER_NOT_INIT); | |||
GELOGE(GE_SESSION_MANAGER_NOT_INIT, "Session manager is not initialized."); | |||
return GE_SESSION_MANAGER_NOT_INIT; | |||
} | |||
std::lock_guard<std::mutex> lock(mutex_); | |||
@@ -119,7 +119,7 @@ Status SessionManager::DestroySession(SessionId session_id) { | |||
Status SessionManager::GetVariable(SessionId session_id, const std::string &name, Tensor &val) { | |||
if (!init_flag_) { | |||
GELOGE(GE_SESSION_MANAGER_NOT_INIT); | |||
GELOGE(GE_SESSION_MANAGER_NOT_INIT, "Session manager is not initialized."); | |||
return GE_SESSION_MANAGER_NOT_INIT; | |||
} | |||
SessionPtr innerSession = nullptr; | |||
@@ -143,7 +143,7 @@ Status SessionManager::AddGraph(SessionId session_id, uint32_t graph_id, const G | |||
Status SessionManager::AddGraph(SessionId session_id, uint32_t graph_id, const Graph &graph, | |||
const std::map<std::string, std::string> &options) { | |||
if (!init_flag_) { | |||
GELOGE(GE_SESSION_MANAGER_NOT_INIT); | |||
GELOGE(GE_SESSION_MANAGER_NOT_INIT, "Session manager is not initialized."); | |||
return GE_SESSION_MANAGER_NOT_INIT; | |||
} | |||
SessionPtr innerSession = nullptr; | |||
@@ -203,7 +203,7 @@ Status SessionManager::AddGraphWithCopy(SessionId session_id, uint32_t graph_id, | |||
Status SessionManager::RunGraph(SessionId session_id, uint32_t graph_id, const std::vector<Tensor> &inputs, | |||
std::vector<Tensor> &outputs) { | |||
if (!init_flag_) { | |||
GELOGE(GE_SESSION_MANAGER_NOT_INIT); | |||
GELOGE(GE_SESSION_MANAGER_NOT_INIT, "Session manager is not initialized."); | |||
return GE_SESSION_MANAGER_NOT_INIT; | |||
} | |||
SessionPtr innerSession = nullptr; | |||
@@ -221,7 +221,7 @@ Status SessionManager::RunGraph(SessionId session_id, uint32_t graph_id, const s | |||
Status SessionManager::RemoveGraph(SessionId session_id, uint32_t graph_id) { | |||
if (!init_flag_) { | |||
GELOGE(GE_SESSION_MANAGER_NOT_INIT); | |||
GELOGE(GE_SESSION_MANAGER_NOT_INIT, "Session manager is not initialized."); | |||
return GE_SESSION_MANAGER_NOT_INIT; | |||
} | |||
SessionPtr innerSession = nullptr; | |||
@@ -239,7 +239,7 @@ Status SessionManager::RemoveGraph(SessionId session_id, uint32_t graph_id) { | |||
bool SessionManager::HasSession(SessionId session_id) { | |||
if (!init_flag_) { | |||
GELOGE(GE_SESSION_MANAGER_NOT_INIT); | |||
GELOGE(GE_SESSION_MANAGER_NOT_INIT, "Session manager is not initialized."); | |||
return false; | |||
} | |||
return session_manager_map_.find(session_id) != session_manager_map_.end(); | |||
@@ -247,7 +247,7 @@ bool SessionManager::HasSession(SessionId session_id) { | |||
Status SessionManager::GetNextSessionId(SessionId &next_session_id) { | |||
if (!init_flag_) { | |||
GELOGE(GE_SESSION_MANAGER_NOT_INIT); | |||
GELOGE(GE_SESSION_MANAGER_NOT_INIT, "Session manager is not initialized."); | |||
return GE_SESSION_MANAGER_NOT_INIT; | |||
} | |||
static SessionId session_id = 0; | |||
@@ -260,7 +260,7 @@ Status SessionManager::RegisterCallBackFunc( | |||
SessionId session_id, const std::string &key, | |||
const std::function<Status(uint32_t, const std::map<std::string, ge::Tensor> &)> &callback) { | |||
if (!init_flag_) { | |||
GELOGE(GE_SESSION_MANAGER_NOT_INIT); | |||
GELOGE(GE_SESSION_MANAGER_NOT_INIT, "Session manager is not initialized."); | |||
return GE_SESSION_MANAGER_NOT_INIT; | |||
} | |||
SessionPtr innerSession = nullptr; | |||
@@ -278,7 +278,7 @@ Status SessionManager::RegisterCallBackFunc( | |||
Status SessionManager::BuildGraph(SessionId session_id, uint32_t graph_id, const std::vector<InputTensorInfo> &inputs) { | |||
if (!init_flag_) { | |||
GELOGE(GE_SESSION_MANAGER_NOT_INIT); | |||
GELOGE(GE_SESSION_MANAGER_NOT_INIT, "Session manager is not initialized."); | |||
return GE_SESSION_MANAGER_NOT_INIT; | |||
} | |||
SessionPtr innerSession = nullptr; | |||
@@ -297,7 +297,7 @@ Status SessionManager::BuildGraph(SessionId session_id, uint32_t graph_id, const | |||
Status SessionManager::RunGraphAsync(SessionId session_id, uint32_t graph_id, | |||
const std::vector<InputTensorInfo> &inputs, RunAsyncCallback callback) { | |||
if (!init_flag_) { | |||
GELOGE(GE_SESSION_MANAGER_NOT_INIT); | |||
GELOGE(GE_SESSION_MANAGER_NOT_INIT, "Session manager is not initialized."); | |||
return GE_SESSION_MANAGER_NOT_INIT; | |||
} | |||
SessionPtr innerSession = nullptr; | |||
@@ -317,7 +317,7 @@ Status SessionManager::GetVariables(SessionId session_id, const std::vector<std: | |||
std::vector<Tensor> &var_values) { | |||
// step 0: init session manager | |||
if (!init_flag_) { | |||
GELOGE(GE_SESSION_MANAGER_NOT_INIT); | |||
GELOGE(GE_SESSION_MANAGER_NOT_INIT, "Session manager is not initialized."); | |||
return GE_SESSION_MANAGER_NOT_INIT; | |||
} | |||
SessionPtr innerSession = nullptr; | |||
@@ -383,7 +383,7 @@ Status SessionManager::GetVariables(SessionId session_id, const std::vector<std: | |||
bool SessionManager::IsGraphNeedRebuild(SessionId session_id, uint32_t graph_id) { | |||
if (!init_flag_) { | |||
GELOGE(GE_SESSION_MANAGER_NOT_INIT); | |||
GELOGE(GE_SESSION_MANAGER_NOT_INIT, "Session manager is not initialized."); | |||
return true; | |||
} | |||
SessionPtr innerSession = nullptr; | |||
@@ -59,7 +59,7 @@ Status SingleOp::ValidateArgs(const std::vector<DataBuffer> &inputs, const std:: | |||
for (size_t i = 0; i < num_inputs; ++i) { | |||
// preventing from read out of bound | |||
size_t aligned_size = GetAlignedSize(inputs[i].length); | |||
GELOGI("Input [%zu], aligned_size:%zu, inputs.length:%lu, input_sizes_:%lu", | |||
GELOGI("Input [%zu], aligned_size:%zu, inputs.length:%lu, input_sizes_:%zu", | |||
i, aligned_size, inputs[i].length, input_sizes_[i]); | |||
if (aligned_size < input_sizes_[i]) { | |||
GELOGE(ACL_ERROR_GE_PARAM_INVALID, "Input size mismatch. index = %zu, model expect %zu," | |||
@@ -77,7 +77,7 @@ Status SingleOp::ValidateArgs(const std::vector<DataBuffer> &inputs, const std:: | |||
for (size_t i = 0; i < num_outputs; ++i) { | |||
// preventing from write out of bound | |||
size_t aligned_size = GetAlignedSize(outputs[i].length); | |||
GELOGI("Output [%zu], aligned_size:%zu, outputs.length:%lu, output_sizes_:%lu", | |||
GELOGI("Output [%zu], aligned_size:%zu, outputs.length:%lu, output_sizes_:%zu", | |||
i, aligned_size, outputs[i].length, output_sizes_[i]); | |||
if (aligned_size < output_sizes_[i]) { | |||
GELOGE(ACL_ERROR_GE_PARAM_INVALID, "Output size mismatch. index = %zu, model expect %zu," | |||
@@ -143,7 +143,7 @@ Status SingleOp::UpdateArgs(const std::vector<DataBuffer> &inputs, const std::ve | |||
GE_CHECK_NOTNULL(task_io_addr); | |||
auto io_addr = reinterpret_cast<uint64_t *>(const_cast<uintptr_t *>(task_io_addr)); | |||
for (size_t i = 0; i < io_addr_num; ++i) { | |||
io_addr[i] = reinterpret_cast<uintptr_t>(args_[i]); | |||
io_addr[i] = static_cast<uintptr_t>(args_[i]); | |||
} | |||
} else { | |||
GELOGW("Only TF_kernel aicpu and aicpu_CC are supported, but got %u", task->GetOpTaskType()); | |||
@@ -18,11 +18,19 @@ | |||
#define INC_FRAMEWORK_COMMON_DEBUG_GE_LOG_H_ | |||
#include <cstdint> | |||
#include <unistd.h> | |||
#include <sys/syscall.h> | |||
#include "framework/common/ge_inner_error_codes.h" | |||
#include "toolchain/slog.h" | |||
#ifdef __GNUC__ | |||
#include <unistd.h> | |||
#include <sys/syscall.h> | |||
#else | |||
#include "mmpa/mmpa_api.h" | |||
#endif | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
#define GE_MODULE_NAME static_cast<int>(GE) | |||
@@ -37,6 +45,21 @@ enum TraceStatus { TRACE_INIT = 0, TRACE_RUNNING, TRACE_WAITING, TRACE_STOP }; | |||
#define GELOGO(...) GE_LOG_OPLOG(GE_MODULE_NAME, __VA_ARGS__) | |||
#define GELOGT(VALUE, ...) GE_LOG_TRACE(GE_MODULE_NAME, VALUE, __VA_ARGS__) | |||
class GeLog { | |||
public: | |||
#ifdef __GNUC__ | |||
static pid_t GetTid() { | |||
thread_local static pid_t tid = syscall(__NR_gettid); | |||
return tid; | |||
} | |||
#else | |||
static int GetTid() { | |||
thread_local static int tid = static_cast<int>(GetCurrentThreadId()); | |||
return tid; | |||
} | |||
#endif | |||
}; | |||
inline bool IsLogEnable(int module_name, int log_level) { | |||
int32_t enable = CheckLogLevel(module_name, log_level); | |||
// 1:enable, 0:disable | |||
@@ -46,23 +69,41 @@ inline bool IsLogEnable(int module_name, int log_level) { | |||
return false; | |||
} | |||
inline pid_t GetTid() { | |||
thread_local static pid_t tid = syscall(__NR_gettid); | |||
return tid; | |||
} | |||
#define GELOGE(ERROR_CODE, fmt, ...) \ | |||
dlog_error(GE_MODULE_NAME, "%lu %s: ErrorNo: %d(%s) " fmt, GeLog::GetTid(), __FUNCTION__, ERROR_CODE, \ | |||
((GE_GET_ERRORNO_STR(ERROR_CODE)).c_str()), ##__VA_ARGS__) | |||
#define GELOGW(fmt, ...) \ | |||
if (IsLogEnable(GE_MODULE_NAME, DLOG_WARN)) dlog_warn(GE_MODULE_NAME, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, ##__VA_ARGS__) | |||
#define GELOGI(fmt, ...) \ | |||
if (IsLogEnable(GE_MODULE_NAME, DLOG_INFO)) dlog_info(GE_MODULE_NAME, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, ##__VA_ARGS__) | |||
#define GELOGD(fmt, ...) \ | |||
if (IsLogEnable(GE_MODULE_NAME, DLOG_DEBUG)) dlog_debug(GE_MODULE_NAME, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, ##__VA_ARGS__) | |||
#define GEEVENT(fmt, ...) dlog_event(GE_MODULE_NAME, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, ##__VA_ARGS__) | |||
#define GELOGO(fmt, ...) \ | |||
Dlog(GE_MODULE_NAME, DLOG_OPLOG, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, ##__VA_ARGS__) | |||
#define GELOGT(VALUE, fmt, ...) \ | |||
do { \ | |||
TraceStatus stat = VALUE; \ | |||
const char *const TraceStatStr[] = {"INIT", "RUNNING", "WAITING", "STOP"}; \ | |||
int idx = static_cast<int>(stat); \ | |||
char *k = const_cast<char *>("status"); \ | |||
char *v = const_cast<char *>(TraceStatStr[idx]); \ | |||
KeyValue kv = {k, v}; \ | |||
DlogWithKV(static_cast<int>(GE_MODULE_NAME), DLOG_TRACE, &kv, 1, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, ##__VA_ARGS__); \ | |||
} while (0) | |||
#define GE_LOG_ERROR(MOD_NAME, ERROR_CODE, fmt, ...) \ | |||
dlog_error(MOD_NAME, "%lu %s: ErrorNo: %d(%s) " fmt, GetTid(), __FUNCTION__, ERROR_CODE, \ | |||
dlog_error(MOD_NAME, "%lu %s: ErrorNo: %d(%s) " fmt, GeLog::GetTid(), __FUNCTION__, ERROR_CODE, \ | |||
((GE_GET_ERRORNO_STR(ERROR_CODE)).c_str()), ##__VA_ARGS__) | |||
#define GE_LOG_WARN(MOD_NAME, fmt, ...) \ | |||
if (IsLogEnable(MOD_NAME, DLOG_WARN)) dlog_warn(MOD_NAME, "%lu %s:" fmt, GetTid(), __FUNCTION__, ##__VA_ARGS__) | |||
if (IsLogEnable(MOD_NAME, DLOG_WARN)) dlog_warn(MOD_NAME, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, ##__VA_ARGS__) | |||
#define GE_LOG_INFO(MOD_NAME, fmt, ...) \ | |||
if (IsLogEnable(MOD_NAME, DLOG_INFO)) dlog_info(MOD_NAME, "%lu %s:" fmt, GetTid(), __FUNCTION__, ##__VA_ARGS__) | |||
if (IsLogEnable(MOD_NAME, DLOG_INFO)) dlog_info(MOD_NAME, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, ##__VA_ARGS__) | |||
#define GE_LOG_DEBUG(MOD_NAME, fmt, ...) \ | |||
if (IsLogEnable(MOD_NAME, DLOG_DEBUG)) dlog_debug(MOD_NAME, "%lu %s:" fmt, GetTid(), __FUNCTION__, ##__VA_ARGS__) | |||
#define GE_LOG_EVENT(MOD_NAME, fmt, ...) dlog_event(MOD_NAME, "%lu %s:" fmt, GetTid(), __FUNCTION__, ##__VA_ARGS__) | |||
if (IsLogEnable(MOD_NAME, DLOG_DEBUG)) dlog_debug(MOD_NAME, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, ##__VA_ARGS__) | |||
#define GE_LOG_EVENT(MOD_NAME, fmt, ...) dlog_event(MOD_NAME, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, ##__VA_ARGS__) | |||
#define GE_LOG_OPLOG(MOD_NAME, fmt, ...) \ | |||
Dlog(MOD_NAME, DLOG_OPLOG, "%lu %s:" fmt, GetTid(), __FUNCTION__, ##__VA_ARGS__) | |||
Dlog(MOD_NAME, DLOG_OPLOG, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, ##__VA_ARGS__) | |||
#define GE_LOG_TRACE(MOD_NAME, value, fmt, ...) \ | |||
do { \ | |||
@@ -72,7 +113,7 @@ inline pid_t GetTid() { | |||
char *k = const_cast<char *>("status"); \ | |||
char *v = const_cast<char *>(TraceStatStr[idx]); \ | |||
KeyValue kv = {k, v}; \ | |||
DlogWithKV(static_cast<int>(MOD_NAME), DLOG_TRACE, &kv, 1, "%lu %s:" fmt, GetTid(), __FUNCTION__, ##__VA_ARGS__); \ | |||
DlogWithKV(static_cast<int>(MOD_NAME), DLOG_TRACE, &kv, 1, "%lu %s:" fmt, GeLog::GetTid(), __FUNCTION__, ##__VA_ARGS__); \ | |||
} while (0) | |||
// print memory when it is greater than 1KB. | |||
@@ -82,4 +123,7 @@ inline pid_t GetTid() { | |||
GELOGI("MallocMemory, func=%s, size=%zu, purpose=%s", (#FUNC), static_cast<size_t>(SIZE), (PURPOSE)); \ | |||
} \ | |||
} while (0); | |||
#ifdef __cplusplus | |||
} | |||
#endif | |||
#endif // INC_FRAMEWORK_COMMON_DEBUG_GE_LOG_H_ |
@@ -0,0 +1,32 @@ | |||
/** | |||
* Copyright 2020 Huawei Technologies Co., Ltd | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
#ifndef INC_FRAMEWORK_COMMON_GE_COMPILER_OPTIONS_H_ | |||
#define INC_FRAMEWORK_COMMON_GE_COMPILER_OPTIONS_H_ | |||
namespace ge { | |||
#ifdef __GNUC__ | |||
#define GE_ATTRIBUTE_UNUSED __attribute__((unused)) | |||
#define GE_FUNCTION_IDENTIFIER __PRETTY_FUNCTION__ | |||
#define GE_BUILTIN_PREFETCH(args_addr) __builtin_prefetch(args_addr) | |||
#else | |||
#define GE_ATTRIBUTE_UNUSED | |||
#define GE_FUNCTION_IDENTIFIER __FUNCSIG__ | |||
#define GE_BUILTIN_PREFETCH(args_addr) | |||
#endif | |||
} // namespace ge | |||
#endif // INC_FRAMEWORK_COMMON_GE_COMPILER_OPTIONS_H_ |
@@ -17,6 +17,7 @@ | |||
#ifndef INC_FRAMEWORK_COMMON_STRING_UTIL_H_ | |||
#define INC_FRAMEWORK_COMMON_STRING_UTIL_H_ | |||
#include <cctype> | |||
#include <securec.h> | |||
#include <algorithm> | |||
@@ -18,7 +18,6 @@ | |||
#define INC_FRAMEWORK_COMMON_TYPES_H_ | |||
#include <limits.h> | |||
#include <linux/limits.h> | |||
#include <stdint.h> | |||
#include <algorithm> | |||
#include <map> | |||
@@ -529,7 +528,7 @@ REGISTER_OPTYPE_DECLARE(HVDWAIT, "HorovodWait"); | |||
// aicpu op for online_infer dynamic_dims | |||
REGISTER_OPTYPE_DECLARE(GETDYNAMICDIMS, "GetDynamicDims"); | |||
enum InputMode { INPUT = 0, CONST }; | |||
enum InputMode { INPUT = 0, CONST_INPUT}; | |||
// Definition of the processing status enum of the process module | |||
enum ModelProcessState { | |||