From 92dff2234f2bd33e03b47865124ba4c74ca5f954 Mon Sep 17 00:00:00 2001 From: Aditya Atluri Date: Tue, 27 Sep 2016 13:33:42 -0500 Subject: [PATCH] Fixed hipDeviceGetAttribute 1. Added negative test for hipDeviceGetAttribute 2. Fixed hipDeviceGetAttribute if int ptr input is null Change-Id: I0e31f50fa407701fddf96e4eb64a87a371ff5d95 [ROCm/hip commit: 5b45c97a30d621f6a3d02b48179658dae80d9be8] --- projects/hip/src/hip_device.cpp | 5 +++++ .../Negative/Device/hipDeviceGetAttribute.cpp | 21 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 projects/hip/tests/src/Functional/Negative/Device/hipDeviceGetAttribute.cpp 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); +}