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 ); +}