Input args NULL check in hipChooseDevice

Change-Id: I1a7b8cded2f81d739645bbf3dab2f04bb9c3c796


[ROCm/hip commit: a833b9a704]
This commit is contained in:
Rahul Garg
2017-06-13 13:35:50 +05:30
parent aaa09cbf1c
commit 0e4dbe0b2f
+58 -52
View File
@@ -415,72 +415,78 @@ hipError_t hipChooseDevice( int* device, const hipDeviceProp_t* prop )
int inPropCount = 0; int inPropCount = 0;
int matchedPropCount = 0; int matchedPropCount = 0;
hipError_t e = hipSuccess; hipError_t e = hipSuccess;
ihipGetDeviceCount( &deviceCount ); if((device == NULL) || (prop == NULL)) {
*device = 0; e = hipErrorInvalidValue;
for (int i = 0; i < deviceCount; i++) { }
ihipGetDeviceProperties( &tempProp, i ); if(e == hipSuccess) {
if(prop->major != 0) { ihipGetDeviceCount( &deviceCount );
inPropCount++; *device = 0;
if(tempProp.major >= prop->major) { for (int i = 0; i < deviceCount; i++) {
matchedPropCount++; ihipGetDeviceProperties( &tempProp, i );
} if(prop->major != 0) {
if(prop->minor != 0) {
inPropCount++; inPropCount++;
if(tempProp.minor >= prop->minor) { if(tempProp.major >= prop->major) {
matchedPropCount++; matchedPropCount++;
} }
if(prop->minor != 0) {
inPropCount++;
if(tempProp.minor >= prop->minor) {
matchedPropCount++;
}
}
} }
} if(prop->totalGlobalMem != 0) {
if(prop->totalGlobalMem != 0) { inPropCount++;
inPropCount++; if(tempProp.totalGlobalMem >= prop->totalGlobalMem) {
if(tempProp.totalGlobalMem >= prop->totalGlobalMem) { matchedPropCount++;
matchedPropCount++; }
} }
} if(prop->sharedMemPerBlock != 0) {
if(prop->sharedMemPerBlock != 0) { inPropCount++;
inPropCount++; if(tempProp.sharedMemPerBlock >= prop->sharedMemPerBlock) {
if(tempProp.sharedMemPerBlock >= prop->sharedMemPerBlock) { matchedPropCount++;
matchedPropCount++; }
} }
} if(prop->maxThreadsPerBlock != 0) {
if(prop->maxThreadsPerBlock != 0) { inPropCount++;
inPropCount++; if(tempProp.maxThreadsPerBlock >= prop->maxThreadsPerBlock ) {
if(tempProp.maxThreadsPerBlock >= prop->maxThreadsPerBlock ) { matchedPropCount++;
matchedPropCount++; }
} }
} if(prop->totalConstMem != 0) {
if(prop->totalConstMem != 0) { inPropCount++;
inPropCount++; if(tempProp.totalConstMem >= prop->totalConstMem ) {
if(tempProp.totalConstMem >= prop->totalConstMem ) { matchedPropCount++;
matchedPropCount++; }
} }
} if(prop->multiProcessorCount != 0) {
if(prop->multiProcessorCount != 0) { inPropCount++;
inPropCount++; if(tempProp.multiProcessorCount >= prop->multiProcessorCount ) {
if(tempProp.multiProcessorCount >= prop->multiProcessorCount ) { matchedPropCount++;
matchedPropCount++; }
} }
} if(prop->maxThreadsPerMultiProcessor != 0) {
if(prop->maxThreadsPerMultiProcessor != 0) { inPropCount++;
inPropCount++; if(tempProp.maxThreadsPerMultiProcessor >= prop->maxThreadsPerMultiProcessor ) {
if(tempProp.maxThreadsPerMultiProcessor >= prop->maxThreadsPerMultiProcessor ) { matchedPropCount++;
matchedPropCount++; }
} }
} if(prop->memoryClockRate != 0) {
if(prop->memoryClockRate != 0) { inPropCount++;
inPropCount++; if(tempProp.memoryClockRate >= prop->memoryClockRate ) {
if(tempProp.memoryClockRate >= prop->memoryClockRate ) { matchedPropCount++;
matchedPropCount++; }
}
if(inPropCount == matchedPropCount) {
*device = i;
} }
}
if(inPropCount == matchedPropCount) {
*device = i;
}
#if 0 #if 0
else{ else{
e= hipErrorInvalidValue; e= hipErrorInvalidValue;
} }
#endif #endif
}
} }
return ihipLogStatus(e); return ihipLogStatus(e);
} }