From 7e78ed7190c4d7db115e365a76cd59686571abc2 Mon Sep 17 00:00:00 2001 From: Rahul Garg Date: Thu, 8 Sep 2016 22:37:24 +0530 Subject: [PATCH] Initial support for hipChooseDevice function Change-Id: Iedbf5f98c96673ab701dd7539d80a77b994d296f [ROCm/hip commit: 9e05375acf3a5a4859f70de377b87c78b8db8249] --- .../hip/include/hcc_detail/hip_runtime_api.h | 8 ++++ projects/hip/src/hip_device.cpp | 37 +++++++++++++++++++ projects/hip/tests/src/hipChooseDevice.cpp | 17 +++++++++ 3 files changed, 62 insertions(+) create mode 100644 projects/hip/tests/src/hipChooseDevice.cpp diff --git a/projects/hip/include/hcc_detail/hip_runtime_api.h b/projects/hip/include/hcc_detail/hip_runtime_api.h index 1f4a1fb8a9..bcb2053a70 100644 --- a/projects/hip/include/hcc_detail/hip_runtime_api.h +++ b/projects/hip/include/hcc_detail/hip_runtime_api.h @@ -345,6 +345,14 @@ hipError_t hipSetDeviceFlags ( unsigned flags); * @} */ +/** + * @brief Select compute-device which best matches criteria. + * + * @param [out] device ID + * @param [in] device properties pointer + * + */ +hipError_t hipChooseDevice(int *device,hipDeviceProp_t* prop); /** *------------------------------------------------------------------------------------------------- diff --git a/projects/hip/src/hip_device.cpp b/projects/hip/src/hip_device.cpp index 61221e64eb..5abafe6748 100644 --- a/projects/hip/src/hip_device.cpp +++ b/projects/hip/src/hip_device.cpp @@ -361,3 +361,40 @@ hipError_t hipDeviceTotalMem (size_t *bytes,hipDevice_t device) *bytes= device->_props.totalGlobalMem; return ihipLogStatus(e); } + +hipError_t hipChooseDevice( int* device, const hipDeviceProp_t* prop ) +{ + hipDeviceProp_t tempProp; + int deviceCount; + int inPropCount=0; + int matchedPropCount=0; + hipError_t e = hipSuccess; + hipGetDeviceCount( &deviceCount ); + *device = 0; + for (int i=0; i< deviceCount; i++) { + hipGetDeviceProperties( &tempProp, i ); + if(prop->major !=0) { + inPropCount++; + if(tempProp.major >= prop->major) { + matchedPropCount++; + } + if(prop->minor !=0) { + inPropCount++; + if(tempProp.minor >= prop->minor) { + matchedPropCount++; + } + } + } + + if(inPropCount == matchedPropCount) { + *device = i; + } +#if 0 + else{ + e= hipErrorInvalidValue; + } +#endif + } + return ihipLogStatus(e); +} + diff --git a/projects/hip/tests/src/hipChooseDevice.cpp b/projects/hip/tests/src/hipChooseDevice.cpp new file mode 100644 index 0000000000..b1cd73ee87 --- /dev/null +++ b/projects/hip/tests/src/hipChooseDevice.cpp @@ -0,0 +1,17 @@ +#include +#include +int main( void ) { + hipDeviceProp_t prop; + int dev; + + hipGetDevice( &dev ) ; + printf( "ID of current HIP device: %d\n", dev ); + + memset( &prop, 0, sizeof( hipDeviceProp_t ) ); + prop.major = 1; + prop.minor = 3; + hipChooseDevice( &dev, &prop ); + printf( "ID of hip device closest to revision 1.3: %d\n", dev ); + + hipSetDevice( dev ); +}