Updated hipEnvVarDriver to work with Windows (#1614)
* Updated hipEnvVarDriver to work with Windows * Cleaned up a bit of code * Fixed a part where putenv was used for both win and linux * Defines moved to test_common.h and cleaned up code * Cleaned up some macro defines and used const char instead * Got rid of some excess commenting * directory paths are unconditional * Cleaned some duplicate code, and variables are now declared and defined together
Этот коммит содержится в:
коммит произвёл
Maneesh Gupta
родитель
0a68be8b5b
Коммит
e73927caee
@@ -34,41 +34,43 @@ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWA
|
||||
|
||||
using namespace std;
|
||||
|
||||
const string directed_dir = "directed_tests" + string(PATH_SEPERATOR_STR) + "hipEnvVar";
|
||||
const string dir = "." + string(PATH_SEPERATOR_STR) + "hipEnvVar";
|
||||
|
||||
int getDeviceNumber() {
|
||||
FILE* in;
|
||||
char buff[512];
|
||||
string str;
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
if (!(in = popen("./directed_tests/hipEnvVar -c", "r"))) {
|
||||
// Check at same level
|
||||
if (!(in = popen("./hipEnvVar -c", "r"))) {
|
||||
FILE* in = popen((directed_dir + " -c").c_str(), "r");
|
||||
if(fgets(buff, 512, in) == NULL){
|
||||
pclose(in);
|
||||
//Check at same level
|
||||
in = popen((dir + " -c").c_str(), "r");
|
||||
if(fgets(buff, 512, in) == NULL){
|
||||
pclose(in);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
while (fgets(buff, 512, in) != NULL) {
|
||||
cout << buff;
|
||||
}
|
||||
cout << buff;
|
||||
pclose(in);
|
||||
return atoi(buff);
|
||||
}
|
||||
|
||||
// Query the current device ID remotely to hipEnvVar
|
||||
void getDevicePCIBusNumRemote(int deviceID, char* pciBusID) {
|
||||
FILE* in;
|
||||
string str = "./directed_tests/hipEnvVar -d ";
|
||||
str += std::to_string(deviceID);
|
||||
void getDevicePCIBusNumRemote(int deviceID, char* pciBusID) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
if (!(in = popen(str.c_str(), "r"))) {
|
||||
// Check at same level
|
||||
if (!(in = popen("./hipEnvVar -d ", "r"))) {
|
||||
exit(1);
|
||||
FILE* in = popen((directed_dir + " -d " + std::to_string(deviceID)).c_str(), "r");
|
||||
if(fgets(pciBusID, 100, in) == NULL){
|
||||
pclose(in);
|
||||
//Check at same level
|
||||
in = popen((dir + " -d").c_str(), "r");
|
||||
if(fgets(pciBusID, 100, in) == NULL){
|
||||
pclose(in);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
while (fgets(pciBusID, 100, in) != NULL) {
|
||||
cout << pciBusID;
|
||||
}
|
||||
cout << pciBusID;
|
||||
pclose(in);
|
||||
return;
|
||||
}
|
||||
|
||||
// Query the current device ID locally on AMD path
|
||||
@@ -81,9 +83,8 @@ void getDevicePCIBusNum(int deviceID, char* pciBusID) {
|
||||
}
|
||||
|
||||
int main() {
|
||||
unsetenv("HIP_VISIBLE_DEVICES");
|
||||
unsetenv("CUDA_VISIBLE_DEVICES");
|
||||
|
||||
unsetenv(HIP_VISIBLE_DEVICES_STR);
|
||||
unsetenv(CUDA_VISIBLE_DEVICES_STR);
|
||||
std::vector<std::string> devPCINum;
|
||||
char pciBusID[100];
|
||||
// collect the device pci bus ID for all devices
|
||||
@@ -126,8 +127,8 @@ int main() {
|
||||
setenv("CUDA_VISIBLE_DEVICES", "0,1,2", 1);
|
||||
assert(getDeviceNumber() == 3);
|
||||
// test if CUDA_VISIBLE_DEVICES will be accepted by the runtime
|
||||
unsetenv("HIP_VISIBLE_DEVICES");
|
||||
unsetenv("CUDA_VISIBLE_DEVICES");
|
||||
unsetenv(HIP_VISIBLE_DEVICES_STR);
|
||||
unsetenv(CUDA_VISIBLE_DEVICES_STR);
|
||||
setenv("CUDA_VISIBLE_DEVICES", "0,1,2", 1);
|
||||
assert(getDeviceNumber() == 3);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,15 @@ unsigned threadsPerBlock = 256;
|
||||
int p_gpuDevice = 0;
|
||||
unsigned p_verbose = 0;
|
||||
int p_tests = -1; /*which tests to run. Interpretation is left to each test. default:all*/
|
||||
|
||||
#ifdef _WIN64
|
||||
const char* HIP_VISIBLE_DEVICES_STR = "HIP_VISIBLE_DEVICES=";
|
||||
const char* CUDA_VISIBLE_DEVICES_STR = "CUDA_VISIBLE_DEVICES=";
|
||||
const char* PATH_SEPERATOR_STR = "\\";
|
||||
#else
|
||||
const char* HIP_VISIBLE_DEVICES_STR = "HIP_VISIBLE_DEVICES";
|
||||
const char* CUDA_VISIBLE_DEVICES_STR = "CUDA_VISIBLE_DEVICES";
|
||||
const char* PATH_SEPERATOR_STR = "/";
|
||||
#endif
|
||||
|
||||
namespace HipTest {
|
||||
|
||||
|
||||
@@ -104,6 +104,7 @@ THE SOFTWARE.
|
||||
#define popen(x,y) _popen(x,y)
|
||||
#define pclose(x) _pclose(x)
|
||||
#define setenv(x,y,z) _putenv_s(x,y)
|
||||
#define unsetenv _putenv
|
||||
#else
|
||||
#define aligned_free(x) free(x)
|
||||
#endif
|
||||
@@ -120,6 +121,9 @@ extern unsigned threadsPerBlock;
|
||||
extern int p_gpuDevice;
|
||||
extern unsigned p_verbose;
|
||||
extern int p_tests;
|
||||
extern const char* HIP_VISIBLE_DEVICES_STR;
|
||||
extern const char* CUDA_VISIBLE_DEVICES_STR;
|
||||
extern const char* PATH_SEPERATOR_STR;
|
||||
|
||||
// ********************* CPP section *********************
|
||||
#ifdef __cplusplus
|
||||
|
||||
Ссылка в новой задаче
Block a user