diff --git a/projects/hip/src/hip_hcc.cpp b/projects/hip/src/hip_hcc.cpp index c955629ed6..ae0f00320f 100644 --- a/projects/hip/src/hip_hcc.cpp +++ b/projects/hip/src/hip_hcc.cpp @@ -64,8 +64,7 @@ int HIP_LAUNCH_BLOCKING = 0; int HIP_STAGING_SIZE = 64; /* size of staging buffers, in KB */ int HIP_STAGING_BUFFERS = 2; int HIP_VISIBLE_DEVICES = 0; /* Contains a comma-separated sequence of GPU identifiers */ -// vector of integers that contains the visible device IDs -std::vector g_hip_visible_devices; +std::vector g_hip_visible_devices; /* vector of integers that contains the visible device IDs */ #define TRACE_API 0x1 /* trace API calls and return values */ #define TRACE_SYNC 0x2 /* trace synchronization pieces */ @@ -489,14 +488,16 @@ void ihipReadEnv_I(int *var_ptr, const char *var_name1, const char *var_name2, c std::string str = env; std::istringstream ss(str); std::string device_id; + // Clean up the defult value + g_hip_visible_devices.clear(); + // Read the visible device numbers while (std::getline(ss, device_id, ',')) { if (atoi(device_id.c_str()) >= 0) { g_hip_visible_devices.push_back(atoi(device_id.c_str())); }else// Any device number after invalid number will not present break; } - - // Print out the number of ids + // Print out the number of ids if (HIP_PRINT_ENV) { printf ("%-30s = ", var_name1); for(int i=0;i= g_deviceCnt){ + if(g_hip_visible_devices[i] >= deviceCnt){ // Make sure any DeviceID after invalid DeviceID will be erased. g_hip_visible_devices.resize(i); break; } } + g_devices = new ihipDevice_t[deviceCnt]; + g_deviceCnt = 0; + for (int i=0; i"); } @@ -596,6 +608,12 @@ INLINE bool ihipIsValidDevice(unsigned deviceIndex) return (deviceIndex < g_deviceCnt); } +// check if the device ID is set as visible +INLINE bool ihipIsVisibleDevice(unsigned deviceIndex) +{ + return std::find(g_hip_visible_devices.begin(), g_hip_visible_devices.end(), + (int)deviceIndex) != g_hip_visible_devices.end(); +} //--- INLINE ihipDevice_t *ihipGetTlsDefaultDevice()