From 7309e9ea6a4a45a1ea1f3ba828e667e80340f8df Mon Sep 17 00:00:00 2001 From: pensun Date: Tue, 16 Feb 2016 10:00:05 -0600 Subject: [PATCH] modify to add remove invalid devices numbers --- hipamd/src/hip_hcc.cpp | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/hipamd/src/hip_hcc.cpp b/hipamd/src/hip_hcc.cpp index 24d6c20dfd..c955629ed6 100644 --- a/hipamd/src/hip_hcc.cpp +++ b/hipamd/src/hip_hcc.cpp @@ -32,6 +32,7 @@ THE SOFTWARE. #include #include #include +#include #include #include @@ -64,7 +65,7 @@ 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 HIP_VISIBLE_DEVICES_IDS; +std::vector g_hip_visible_devices; #define TRACE_API 0x1 /* trace API calls and return values */ #define TRACE_SYNC 0x2 /* trace synchronization pieces */ @@ -484,20 +485,23 @@ void ihipReadEnv_I(int *var_ptr, const char *var_name1, const char *var_name2, c // Check if the environment variable is either HIP_VISIBLE_DEVICES or CUDA_LAUNCH_BLOCKING, which // contains a sequence of comma-separated device IDs if (!(strcmp(var_name1,"HIP_VISIBLE_DEVICES") && strcmp(var_name2, "CUDA_VISIBLE_DEVICES")) && env){ - // Parse the string stream of env and store the device ids to HIP_VISIBLE_DEVICES_IDS global variable + // Parse the string stream of env and store the device ids to g_hip_visible_devices global variable std::string str = env; std::istringstream ss(str); std::string device_id; - while (std::getline(ss, device_id, ',')) { - HIP_VISIBLE_DEVICES_IDS.push_back(atoi(device_id.c_str())); + 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 for debugging + + // Print out the number of ids if (HIP_PRINT_ENV) { - std::cout << "HIP visible device id is set to be: "; - for(int i=0;i= g_deviceCnt){ + // Make sure any DeviceID after invalid DeviceID will be erased. + g_hip_visible_devices.resize(i); + break; + } + } tprintf(TRACE_API, "pid=%u %-30s\n", getpid(), "");