change hipEnvVarDriver to reduce communications to hipEnvVar

Change-Id: I65a5f67dd51d53594fa51f88505e32321643d189


[ROCm/clr commit: e6d7ecc0f5]
This commit is contained in:
pensun
2016-09-27 23:00:11 -05:00
szülő d5d764a4d4
commit eb5bb292ae
@@ -27,13 +27,9 @@ THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#include <stdlib.h>
#include <assert.h>
#include <string>
#include <hip_runtime.h>
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 "<<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;
if (devPCINum[i] != getDevicePCIBusNumRemote(0)) {
std::cout << "The returned PciBusID is not correct"<< std::endl;
std::cout << "Expected "<< devPCINum[i] << ", but get " << getDevicePCIBusNum << endl;
exit(-1);
} else {
continue;