diff --git a/projects/hip/src/hip_device.cpp b/projects/hip/src/hip_device.cpp index 407b8c2ae9..ef498acfcd 100644 --- a/projects/hip/src/hip_device.cpp +++ b/projects/hip/src/hip_device.cpp @@ -155,6 +155,8 @@ hipError_t hipDeviceGetAttribute(int* pi, hipDeviceAttribute_t attr, int device) hipError_t e = hipSuccess; + if(pi != nullptr) { + auto * hipDevice = ihipGetDevice(device); hipDeviceProp_t *prop = &hipDevice->_props; if (hipDevice) { @@ -215,6 +217,9 @@ hipError_t hipDeviceGetAttribute(int* pi, hipDeviceAttribute_t attr, int device) } else { e = hipErrorInvalidDevice; } + }else{ + e = hipErrorInvalidDevice; + } return ihipLogStatus(e); } diff --git a/projects/hip/tests/src/Functional/Negative/Device/hipDeviceGetAttribute.cpp b/projects/hip/tests/src/Functional/Negative/Device/hipDeviceGetAttribute.cpp new file mode 100644 index 0000000000..53aa812e06 --- /dev/null +++ b/projects/hip/tests/src/Functional/Negative/Device/hipDeviceGetAttribute.cpp @@ -0,0 +1,21 @@ +#include +#include +#include"hipDeviceUtil.h" + +int main() +{ + int pi; + int attr = 0; +// hipDeviceAttribute_t attr = hipDeviceAttributeMaxThreadsPerBlock; + HIP_CHECK(hipDeviceGetAttribute(nullptr, hipDeviceAttribute_t(attr), 0), hipDeviceGetAttribute); + HIP_CHECK(hipDeviceGetAttribute(&pi, hipDeviceAttribute_t(attr), 0), hipDeviceGetAttribute); + attr = -1; + HIP_CHECK(hipDeviceGetAttribute(nullptr, hipDeviceAttribute_t(attr), 0), hipDeviceGetAttribute); + HIP_CHECK(hipDeviceGetAttribute(&pi, hipDeviceAttribute_t(attr), 0), hipDeviceGetAttribute); + attr = 0; + HIP_CHECK(hipDeviceGetAttribute(nullptr, hipDeviceAttribute_t(attr), -1), hipDeviceGetAttribute); + HIP_CHECK(hipDeviceGetAttribute(&pi, hipDeviceAttribute_t(attr), -1), hipDeviceGetAttribute); + attr = -1; + HIP_CHECK(hipDeviceGetAttribute(nullptr, hipDeviceAttribute_t(attr), -1), hipDeviceGetAttribute); + HIP_CHECK(hipDeviceGetAttribute(&pi, hipDeviceAttribute_t(attr), -1), hipDeviceGetAttribute); +}