Initial support for hipChooseDevice function
Change-Id: Iedbf5f98c96673ab701dd7539d80a77b994d296f
[ROCm/hip commit: 9e05375acf]
Этот коммит содержится в:
@@ -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);
|
||||
|
||||
/**
|
||||
*-------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
#include <stdio.h>
|
||||
#include <hip_runtime.h>
|
||||
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 );
|
||||
}
|
||||
Ссылка в новой задаче
Block a user