Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NPU] support npu config on aclinit #34500

Merged
merged 1 commit into from
Jul 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions paddle/fluid/platform/flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ DEFINE_string(selected_npus, "",
"This option is useful when doing multi process training and "
"each process have only one device (NPU). If you want to use "
"all visible devices, set this to empty string.");
DEFINE_string(
npu_config_path, "",
"The absolute path of configuration json file, like: /tmp/config.json. "
"If proveided, it will be passed to aclInit().");
#endif

#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
Expand Down
10 changes: 9 additions & 1 deletion paddle/fluid/platform/npu_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ DECLARE_uint64(reallocate_gpu_memory_in_mb);
DECLARE_bool(enable_cublas_tensor_op_math);
DECLARE_uint64(gpu_memory_limit_mb);
DECLARE_string(selected_npus);
DECLARE_string(npu_config_path);

constexpr static float fraction_reserve_gpu_memory = 0.05f;

Expand Down Expand Up @@ -385,7 +386,14 @@ AclInstance &AclInstance::Instance() {
}

AclInstance::AclInstance() {
PADDLE_ENFORCE_NPU_SUCCESS(aclInit(nullptr));
if (!FLAGS_npu_config_path.empty()) {
VLOG(4) << "Call aclInit(" << FLAGS_npu_config_path << ") ";
PADDLE_ENFORCE_NPU_SUCCESS(aclInit(FLAGS_npu_config_path.c_str()));
} else {
VLOG(4) << "Call aclInit(nullptr) ";
PADDLE_ENFORCE_NPU_SUCCESS(aclInit(nullptr));
}

VLOG(4) << "Call aclrtSetDevice ";
// NOTE(zhiqiu): why set devices here?
// Because ACL creates a default context which contains 2 streams
Expand Down
1 change: 1 addition & 0 deletions paddle/testing/paddle_gtest_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ int main(int argc, char** argv) {

#if defined(PADDLE_WITH_ASCEND_CL)
envs.push_back("selected_npus");
envs.push_back("npu_config_path");
#endif

char* env_str = nullptr;
Expand Down
1 change: 1 addition & 0 deletions python/paddle/fluid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ def __bootstrap__():
'initial_gpu_memory_in_mb',
'reallocate_gpu_memory_in_mb',
'gpu_memory_limit_mb',
'npu_config_path',
]

core.init_gflags(["--tryfromenv=" + ",".join(read_env_flags)])
Expand Down