2
0

Test cases for HIP_VISIBLE_DEVICES/CUDA_VISIBLE_DEVICES.

hipEnvVar is the base test case, to be called by hipEnvVarDriver
at the run time.
Test case includes tests for normal use case of the environment
variable, invalid value/sequence and use CUDA_VISIBLE_DEVICES as a
alternative.
Este cometimento está contido em:
pensun
2016-02-27 14:48:00 -06:00
ascendente 1f606261c1
cometimento 39b44cb484
4 ficheiros modificados com 125 adições e 37 eliminações
+78 -13
Ver ficheiro
@@ -13,26 +13,91 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
THE USE OR OTHER DEALINGS IN TcHE SOFTWARE. */
THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include <iostream>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;
int main() {
FILE *in;
char buff[512];
//./hipEnvVar -c -d 0 -h
//putenv("SomeVariable=SomeValue");
//putenv("export HIP_VISIBLE_DEVICES=0,1,2,3");
if(!(in = popen("ls -sail", "r"))){
int getDeviceNumber(){
FILE *in;
char buff[512];
string str;
if(!(in = popen("./hipEnvVar -c", "r"))){
return 1;
}
while(fgets(buff, sizeof(buff), in)!=NULL){
cout << buff;
}
fgets(buff, sizeof(buff), in);
pclose(in);
return 0;
return atoi(buff);
}
int getDevicePCIBusNum(int deviceID){
FILE *in;
char buff[512];
string str = "./hipEnvVar -d ";
str += std::to_string(deviceID);
if(!(in = popen(str.c_str(), "r"))){
return 1;
}
fgets(buff, sizeof(buff), in);
pclose(in);
return atoi(buff);
}
int main() {
unsetenv("HIP_VISIBLE_DEVICES");
//collect the device pci bus ID for all devices
int totalDeviceNum = getDeviceNumber();
std::cout << "The total number of available devices is " << totalDeviceNum<< std::endl
<<"Valid index range is 0 - "<<totalDeviceNum-1<<std::endl;
std::vector<int> devPCINum;
for (int i = 0; i < totalDeviceNum ; i++) {
devPCINum.push_back(getDevicePCIBusNum(i));
std::cout <<"The collected device PCI Bus ID of Device "<<i<<" is "
<< getDevicePCIBusNum(i) << std::endl;
}
//select each of the available devices to be the target device,
//query the returned device pci bus number, check if match the database
for (int i = 0; i < totalDeviceNum ; i++) {
setenv("HIP_VISIBLE_DEVICES",(char*)std::to_string(i).c_str(),1);
//cout<<"HIP_VISIBLE_DEVICES is "<<i<<" data in vector is "<<devPCINum[i]<<endl;
//std::cout <<"Returned pci number is"<< getDevicePCIBusNum(0) << std::endl;
if (devPCINum[i] != getDevicePCIBusNum(0)) {
std::cout << "The returned PciBusID is not correct"
<< std::endl;
exit(-1);
} else {
continue;
}
}
//check when set an invalid device number
setenv("HIP_VISIBLE_DEVICES","1000,0,1",1);
assert(getDeviceNumber() == 0);
if(totalDeviceNum > 2){
setenv("HIP_VISIBLE_DEVICES","0,1,1000,2",1);
assert(getDeviceNumber() == 2);
setenv("HIP_VISIBLE_DEVICES","0,1,2",1);
assert(getDeviceNumber() == 3);
// test if CUDA_VISIBLE_DEVICES will be accepted by the runtime
unsetenv("HIP_VISIBLE_DEVICES");
setenv("CUDA_VISIBLE_DEVICES","0,1,2",1);
assert(getDeviceNumber() == 3);
}
setenv("HIP_VISIBLE_DEVICES","-100,0,1",1);
assert(getDeviceNumber() == 0);
std::cout << "Passed!" << std::endl;
return 0;
}