diff --git a/paddle/fluid/platform/flags.cc b/paddle/fluid/platform/flags.cc index 1d76c2ea584b7e393da2bee6e0dd41731463eb81..ae4a7b8b67263e90f174b022ad1d7cb153a39e64 100644 --- a/paddle/fluid/platform/flags.cc +++ b/paddle/fluid/platform/flags.cc @@ -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) diff --git a/paddle/fluid/platform/npu_info.cc b/paddle/fluid/platform/npu_info.cc index 11795f1611f7e6ba7092196d91bb09967cc7b81c..64a602b0b3b798c23ca778942766652d1663157d 100644 --- a/paddle/fluid/platform/npu_info.cc +++ b/paddle/fluid/platform/npu_info.cc @@ -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; @@ -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 diff --git a/paddle/testing/paddle_gtest_main.cc b/paddle/testing/paddle_gtest_main.cc index 1f11be7e3c7260fb3878eb98284851097560dfd8..6feef11a366d976f1ba931c997a70293370c6b4c 100644 --- a/paddle/testing/paddle_gtest_main.cc +++ b/paddle/testing/paddle_gtest_main.cc @@ -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; diff --git a/python/paddle/fluid/__init__.py b/python/paddle/fluid/__init__.py index c761057ff8b2fa90f5595bef87296f6e99c72edd..2986ffc1116508e25e43c1fe89e4b6efce14dd89 100644 --- a/python/paddle/fluid/__init__.py +++ b/python/paddle/fluid/__init__.py @@ -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)])