From eb5bb292aef1fc8301bbb2386559ea1f6ed2b055 Mon Sep 17 00:00:00 2001 From: pensun Date: Tue, 27 Sep 2016 23:00:11 -0500 Subject: [PATCH] change hipEnvVarDriver to reduce communications to hipEnvVar Change-Id: I65a5f67dd51d53594fa51f88505e32321643d189 [ROCm/clr commit: e6d7ecc0f5370d0c0752c068cef98e1e1c382198] --- .../clr/hipamd/tests/src/hipEnvVarDriver.cpp | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/projects/clr/hipamd/tests/src/hipEnvVarDriver.cpp b/projects/clr/hipamd/tests/src/hipEnvVarDriver.cpp index 255cc72806..7046849525 100644 --- a/projects/clr/hipamd/tests/src/hipEnvVarDriver.cpp +++ b/projects/clr/hipamd/tests/src/hipEnvVarDriver.cpp @@ -27,13 +27,9 @@ THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include #include #include - +#include using namespace std; -//./hipEnvVar -c -d 0 -h - //putenv("SomeVariable=SomeValue"); - //putenv("export HIP_VISIBLE_DEVICES=0,1,2,3"); - int getDeviceNumber(){ FILE *in; char buff[512]; @@ -46,7 +42,8 @@ int getDeviceNumber(){ return atoi(buff); } -int getDevicePCIBusNum(int deviceID){ +// Query the current device ID remotely to hipEnvVar +int getDevicePCIBusNumRemote(int deviceID){ FILE *in; char buff[512]; string str = "./hipEnvVar -d "; @@ -59,6 +56,19 @@ int getDevicePCIBusNum(int deviceID){ return atoi(buff); } +// Query the current device ID locally +int getDevicePCIBusNum(int deviceID){ + hipSetDevice(deviceID); + hipDeviceProp_t devProp; + + hipGetDeviceProperties(&devProp, deviceID); + if (devProp.major < 1) { + printf("%d does not support HIP\n", deviceID); + return -1; + } + return devProp.pciBusID; +} + int main() { unsetenv("HIP_VISIBLE_DEVICES"); unsetenv("CUDA_VISIBLE_DEVICES"); @@ -78,11 +88,9 @@ int main() { for (int i = 0; i < totalDeviceNum ; i++) { setenv("HIP_VISIBLE_DEVICES",(char*)std::to_string(i).c_str(),1); setenv("CUDA_VISIBLE_DEVICES",(char*)std::to_string(i).c_str(),1); - //cout<<"HIP_VISIBLE_DEVICES is "<