From 069e4c5244afcef9092dc63b8f18c82ce0b85998 Mon Sep 17 00:00:00 2001 From: yongqiangma Date: Mon, 14 Sep 2020 12:26:17 +0800 Subject: [PATCH] use BM_VISIBLE_DEVICES to set running card. test=develop (#4284) --- lite/api/cxx_api_impl.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lite/api/cxx_api_impl.cc b/lite/api/cxx_api_impl.cc index 3b3337139b..a41c1d0a30 100644 --- a/lite/api/cxx_api_impl.cc +++ b/lite/api/cxx_api_impl.cc @@ -58,6 +58,16 @@ void CxxPaddleApiImpl::Init(const lite_api::CxxConfig &config) { config.mlu_input_layout(), config.mlu_firstconv_param()); #endif // LITE_WITH_MLU + +#ifdef LITE_WITH_BM + Env::Init(); + int device_id = 0; + if (const char *c_id = getenv("BM_VISIBLE_DEVICES")) { + device_id = static_cast(*c_id) - 48; + } + TargetWrapper::SetDevice(device_id); +#endif // LITE_WITH_BM + auto use_layout_preprocess_pass = config.model_dir().find("OPENCL_PRE_PRECESS"); VLOG(1) << "use_layout_preprocess_pass:" << use_layout_preprocess_pass; -- GitLab