[dtest] Additional tests for hipDevice APIs
APIs: hipDeviceGetAttribute(), hipGetDeviceProperties(),
hipDeviceGetByPCIBusId() and hipDeviceGetPCIBusId()
1. New negative test cases for each API.
2. Additional attributes for testing with hipDeviceGetAttribute()
SWDEV-238517 Enhancing hip unit tests
Change-Id: I3c24462426ffaf3a9317b7de9cd33f7c65791a4b
이 커밋은 다음에 포함됨:
@@ -1,56 +1,182 @@
|
||||
/*
|
||||
Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../../test_common.cpp
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "test_common.h"
|
||||
|
||||
int main(void) {
|
||||
char pciBusId[13];
|
||||
int deviceCount = 0;
|
||||
HIPCHECK(hipGetDeviceCount(&deviceCount));
|
||||
HIPASSERT(deviceCount != 0);
|
||||
for (int i = 0; i < deviceCount; i++) {
|
||||
int pciBusID = -1;
|
||||
int pciDeviceID = -1;
|
||||
int pciDomainID = -1;
|
||||
int tempPciBusId = -1;
|
||||
int tempDeviceId = -1;
|
||||
HIPCHECK(hipDeviceGetPCIBusId(&pciBusId[0], 13, i));
|
||||
sscanf(pciBusId, "%04x:%02x:%02x", &pciDomainID, &pciBusID, &pciDeviceID);
|
||||
HIPCHECK(hipDeviceGetAttribute(&tempPciBusId, hipDeviceAttributePciBusId, i));
|
||||
if (pciBusID != tempPciBusId) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
HIPCHECK(hipDeviceGetByPCIBusId(&tempDeviceId, pciBusId));
|
||||
if (tempDeviceId != i) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
passed();
|
||||
}
|
||||
/*
|
||||
Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../../test_common.cpp NVCC_OPTIONS -std=c++11
|
||||
* TEST: %t --tests 0x1
|
||||
* TEST: %t --tests 0x2
|
||||
* TEST: %t --tests 0x3
|
||||
* TEST: %t --tests 0x4
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "test_common.h"
|
||||
/**
|
||||
* Validates negative scenarios for hipDeviceGetByPCIBusId
|
||||
* scenario: Validates device number from pciBusIdstr string
|
||||
*/
|
||||
bool testPciBusId(void) {
|
||||
bool testResult = true;
|
||||
char pciBusId[13];
|
||||
int deviceCount = 0;
|
||||
HIPCHECK(hipGetDeviceCount(&deviceCount));
|
||||
HIPASSERT(deviceCount != 0);
|
||||
for (int i = 0; i < deviceCount; i++) {
|
||||
int pciBusID = -1;
|
||||
int pciDeviceID = -1;
|
||||
int pciDomainID = -1;
|
||||
int tempPciBusId = -1;
|
||||
int tempDeviceId = -1;
|
||||
HIPCHECK(hipDeviceGetPCIBusId(&pciBusId[0], 13, i));
|
||||
sscanf(pciBusId, "%04x:%02x:%02x", &pciDomainID,
|
||||
&pciBusID, &pciDeviceID);
|
||||
HIPCHECK(hipDeviceGetAttribute(&tempPciBusId,
|
||||
hipDeviceAttributePciBusId, i));
|
||||
if (pciBusID != tempPciBusId) {
|
||||
testResult = false;
|
||||
break;
|
||||
}
|
||||
HIPCHECK(hipDeviceGetByPCIBusId(&tempDeviceId, pciBusId));
|
||||
if (tempDeviceId != i) {
|
||||
testResult = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return testResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates negative scenarios for hipDeviceGetByPCIBusId
|
||||
* scenario: device = nullptr and pciBusIdstr = nullptr
|
||||
*/
|
||||
bool testNullPtr() {
|
||||
bool TestPassed = true;
|
||||
int device = -1;
|
||||
hipError_t ret;
|
||||
char pciBusIdstr[13];
|
||||
ret = hipDeviceGetByPCIBusId(nullptr, pciBusIdstr);
|
||||
if (ret == hipSuccess) {
|
||||
TestPassed &= false;
|
||||
printf("Test {device = nullptr} Failed \n");
|
||||
}
|
||||
ret = hipDeviceGetByPCIBusId(&device, nullptr);
|
||||
if (ret == hipSuccess) {
|
||||
TestPassed &= false;
|
||||
printf("Test {pciBusIdstr = nullptr} Failed \n");
|
||||
}
|
||||
return TestPassed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates negative scenarios for hipDeviceGetByPCIBusId
|
||||
* scenario1: Pass an empty like ""
|
||||
* scenario1: Pass an shorter string "0000:"
|
||||
*/
|
||||
bool testInputString() {
|
||||
bool TestPassed = true;
|
||||
int device = -1;
|
||||
hipError_t ret;
|
||||
ret = hipDeviceGetByPCIBusId(&device, "");
|
||||
if (ret == hipSuccess) {
|
||||
TestPassed &= false;
|
||||
printf("Test {empty input string:\"\"} Failed \n");
|
||||
}
|
||||
ret = hipDeviceGetByPCIBusId(&device, "0000:");
|
||||
if (ret == hipSuccess) {
|
||||
TestPassed &= false;
|
||||
printf("Test {shorter input string: \"0000:\"} Failed \n");
|
||||
}
|
||||
return TestPassed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates negative scenarios for hipDeviceGetByPCIBusId
|
||||
* scenario: Pass wrong bus id in pciBusIdstr
|
||||
*/
|
||||
bool testWrongBusID() {
|
||||
bool TestPassed = true;
|
||||
int deviceCount = 0;
|
||||
HIPCHECK(hipGetDeviceCount(&deviceCount));
|
||||
HIPASSERT(deviceCount != 0);
|
||||
int pciBusId[deviceCount], pciDeviceID[deviceCount],
|
||||
pciDomainID[deviceCount];
|
||||
// get bus id of all the devices
|
||||
for (int i = 0; i < deviceCount; i++) {
|
||||
hipDeviceProp_t prop;
|
||||
HIPCHECK(hipGetDeviceProperties(&prop, i));
|
||||
pciBusId[i] = prop.pciBusID;
|
||||
pciDeviceID[i] = prop.pciDeviceID;
|
||||
pciDomainID[i] = prop.pciDomainID;
|
||||
printf("device %d: pciDomainID=%x, pciBusID=%x, pciDeviceID=%x \n",
|
||||
i, prop.pciDomainID, prop.pciBusID, prop.pciDomainID);
|
||||
}
|
||||
// get a non existing bus id
|
||||
int id = 0;
|
||||
for (; id < 256; id++) {
|
||||
bool bFound = false;
|
||||
// check if id is the pci busid of any existing device
|
||||
for (int j = 0; j < deviceCount; j++) {
|
||||
if (id == pciBusId[j]) {
|
||||
bFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!bFound)
|
||||
break;
|
||||
}
|
||||
// now pass the non existing bus id as string
|
||||
char pciBusIdstr[12];
|
||||
int device = -1;
|
||||
hipError_t ret;
|
||||
snprintf(pciBusIdstr, sizeof(pciBusIdstr), "%04x:%02x:%02x", pciDomainID[0],
|
||||
id, pciDeviceID[0]);
|
||||
ret = hipDeviceGetByPCIBusId(&device, pciBusIdstr);
|
||||
if (ret == hipSuccess) {
|
||||
TestPassed = false;
|
||||
printf("Test: hipDeviceGetByPCIBusId(&device,%s) Failed \n", pciBusIdstr);
|
||||
}
|
||||
return TestPassed;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
bool TestPassed = true;
|
||||
HipTest::parseStandardArguments(argc, argv, true);
|
||||
|
||||
if (p_tests == 0x1) {
|
||||
TestPassed = testPciBusId();
|
||||
} else if (p_tests == 0x2) {
|
||||
TestPassed = testNullPtr();
|
||||
} else if (p_tests == 0x3) {
|
||||
TestPassed = testInputString();
|
||||
} else if (p_tests == 0x4) {
|
||||
TestPassed = testWrongBusID();
|
||||
} else {
|
||||
printf("Invalid Test Case \n");
|
||||
exit(1);
|
||||
}
|
||||
if (TestPassed) {
|
||||
passed();
|
||||
} else {
|
||||
failed("Test Case %x Failed!", p_tests);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,16 +24,18 @@
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../../test_common.cpp NVCC_OPTIONS -std=c++11 EXCLUDE_HIP_PLATFORM nvidia
|
||||
* BUILD: %t %s ../../test_common.cpp NVCC_OPTIONS -std=c++11
|
||||
* TEST_NAMED: %t hipDeviceGetPCIBusId-vs-hipDeviceGetAttribute --tests 0x1
|
||||
* TEST_NAMED: %t hipDeviceGetPCIBusId-vs-lspci --tests 0x2 EXCLUDE_HIP_PLATFORM nvidia
|
||||
* TEST_NAMED: %t hipDeviceGetPCIBusId-vs-lspci --tests 0x2
|
||||
* TEST_NAMED: %t hipDeviceGetPCIBusId-negative --tests 0x3
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include "test_common.h"
|
||||
#define MAX_DEVICE_LENGTH 20
|
||||
|
||||
static bool getPciBusId(int deviceCount, char hipDeviceList[][MAX_DEVICE_LENGTH]) {
|
||||
static bool getPciBusId(int deviceCount,
|
||||
char hipDeviceList[][MAX_DEVICE_LENGTH]) {
|
||||
for (int i = 0; i < deviceCount; i++) {
|
||||
HIPCHECK(hipDeviceGetPCIBusId(hipDeviceList[i], MAX_DEVICE_LENGTH, i));
|
||||
}
|
||||
@@ -47,7 +49,6 @@ bool comparePciBusIDWithHipDeviceGetAttribute() {
|
||||
HIPASSERT(deviceCount != 0);
|
||||
printf("No.of gpus in the system: %d\n", deviceCount);
|
||||
char hipDeviceList[deviceCount][MAX_DEVICE_LENGTH];
|
||||
char pciDeviceList[deviceCount][MAX_DEVICE_LENGTH];
|
||||
|
||||
getPciBusId(deviceCount, hipDeviceList);
|
||||
|
||||
@@ -58,7 +59,8 @@ bool comparePciBusIDWithHipDeviceGetAttribute() {
|
||||
int tempPciBusId = -1;
|
||||
sscanf(hipDeviceList[i], "%04x:%02x:%02x", &pciDomainID, &pciBusID,
|
||||
&pciDeviceID);
|
||||
HIPCHECK(hipDeviceGetAttribute(&tempPciBusId, hipDeviceAttributePciBusId, i));
|
||||
HIPCHECK(hipDeviceGetAttribute(&tempPciBusId,
|
||||
hipDeviceAttributePciBusId, i));
|
||||
if (pciBusID != tempPciBusId) {
|
||||
testResult = false;
|
||||
printf("pciBusID from hipDeviceGetPCIBusId mismatched to that from "
|
||||
@@ -106,7 +108,7 @@ bool compareHipDeviceGetPCIBusIdWithLspci() {
|
||||
getPciBusId(deviceCount, hipDeviceList);
|
||||
|
||||
// Get lspci device list and compare with hip device list
|
||||
#if defined(__CUDA_ARCH__)
|
||||
#ifdef __HIP_PLATFORM_NVCC__
|
||||
char const *command = "lspci -D | grep controller | grep NVIDIA | "
|
||||
"cut -d ' ' -f 1";
|
||||
#else
|
||||
@@ -132,7 +134,8 @@ bool compareHipDeviceGetPCIBusIdWithLspci() {
|
||||
}
|
||||
}
|
||||
if (bMatchFound == false) {
|
||||
printf("PCI device: %s is not reported by HIP\n", pciDeviceList[index]);
|
||||
printf("PCI device: %s is not reported by HIP\n",
|
||||
pciDeviceList[index]);
|
||||
}
|
||||
index++;
|
||||
}
|
||||
@@ -149,15 +152,66 @@ bool compareHipDeviceGetPCIBusIdWithLspci() {
|
||||
return testResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates negative scenarios for hipDeviceGetPCIBusId
|
||||
* scenario1: pciBusId = nullptr
|
||||
* scenario2: device = -1 (Invalid Device)
|
||||
* scenario3: device = Non Existing Device
|
||||
* scenario4: len = 0
|
||||
* scenario5: len < 0
|
||||
*/
|
||||
bool testInvalidParameters() {
|
||||
bool TestPassed = true;
|
||||
hipError_t ret;
|
||||
int deviceCount = 0;
|
||||
HIPCHECK(hipGetDeviceCount(&deviceCount));
|
||||
HIPASSERT(deviceCount != 0);
|
||||
printf("No.of gpus in the system: %d\n", deviceCount);
|
||||
char pciBusId[MAX_DEVICE_LENGTH];
|
||||
// pciBusId = nullptr
|
||||
int device;
|
||||
HIPCHECK(hipGetDevice(&device));
|
||||
ret = hipDeviceGetPCIBusId(nullptr, MAX_DEVICE_LENGTH, device);
|
||||
if (ret == hipSuccess) {
|
||||
TestPassed &= false;
|
||||
printf("Test {pciBusId = nullptr} Failed \n");
|
||||
}
|
||||
// len = 0
|
||||
ret = hipDeviceGetPCIBusId(pciBusId, 0, device);
|
||||
if (ret == hipSuccess) {
|
||||
TestPassed &= false;
|
||||
printf("Test {len = 0} Failed \n");
|
||||
}
|
||||
// len < 0
|
||||
ret = hipDeviceGetPCIBusId(pciBusId, -1, device);
|
||||
if (ret == hipSuccess) {
|
||||
TestPassed &= false;
|
||||
printf("Test {len < 0} Failed \n");
|
||||
}
|
||||
// device = -1
|
||||
ret = hipDeviceGetPCIBusId(pciBusId, MAX_DEVICE_LENGTH, -1);
|
||||
if (ret == hipSuccess) {
|
||||
TestPassed &= false;
|
||||
printf("Test {device = -1} Failed \n");
|
||||
}
|
||||
// device = Non Existing Device
|
||||
ret = hipDeviceGetPCIBusId(pciBusId, MAX_DEVICE_LENGTH, deviceCount);
|
||||
if (ret == hipSuccess) {
|
||||
TestPassed &= false;
|
||||
printf("Test {device = Non Existing Device} Failed \n");
|
||||
}
|
||||
return TestPassed;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
bool testResult = true;
|
||||
HipTest::parseStandardArguments(argc, argv, true);
|
||||
|
||||
if (p_tests & 0x1) {
|
||||
if (p_tests == 0x1) {
|
||||
testResult &= comparePciBusIDWithHipDeviceGetAttribute();
|
||||
}
|
||||
|
||||
if (p_tests & 0x2) {
|
||||
if (p_tests == 0x2) {
|
||||
#ifdef __unix__
|
||||
testResult &= compareHipDeviceGetPCIBusIdWithLspci();
|
||||
#else
|
||||
@@ -165,6 +219,10 @@ int main(int argc, char* argv[]) {
|
||||
#endif
|
||||
}
|
||||
|
||||
if (p_tests == 0x3) {
|
||||
testResult &= testInvalidParameters();
|
||||
}
|
||||
|
||||
if (testResult) {
|
||||
passed();
|
||||
} else {
|
||||
|
||||
@@ -22,129 +22,282 @@ THE SOFTWARE.
|
||||
// Test the device info API extensions for HIP:
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../../test_common.cpp
|
||||
* TEST: %t
|
||||
* BUILD: %t %s ../../test_common.cpp NVCC_OPTIONS -std=c++11
|
||||
* TEST: %t --tests 0x1
|
||||
* TEST: %t --tests 0x2
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include "hip/hip_runtime.h"
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
#define CHECK(error) \
|
||||
if (error != hipSuccess) { \
|
||||
fprintf(stderr, "error: '%s'(%d) at %s:%d\n", hipGetErrorString(error), error, __FILE__, \
|
||||
__LINE__); \
|
||||
exit(EXIT_FAILURE); \
|
||||
}
|
||||
|
||||
hipError_t test_hipDeviceGetAttribute(int deviceId, hipDeviceAttribute_t attr,
|
||||
hipError_t test_hipDeviceGetAttribute(int deviceId,
|
||||
hipDeviceAttribute_t attr,
|
||||
int expectedValue = -1) {
|
||||
int value = 0;
|
||||
std::cout << "Test hipDeviceGetAttribute attribute " << attr;
|
||||
if (expectedValue != -1) {
|
||||
std::cout << " expected value " << expectedValue;
|
||||
}
|
||||
hipError_t e = hipDeviceGetAttribute(&value, attr, deviceId);
|
||||
std::cout << " actual value " << value << std::endl;
|
||||
if ((expectedValue != -1) && value != expectedValue) {
|
||||
std::cout << "fail" << std::endl;
|
||||
return hipErrorInvalidValue;
|
||||
}
|
||||
return hipSuccess;
|
||||
int value = 0;
|
||||
std::cout << "Test hipDeviceGetAttribute attribute " << attr;
|
||||
if (expectedValue != -1) {
|
||||
std::cout << " expected value " << expectedValue;
|
||||
}
|
||||
hipError_t e = hipDeviceGetAttribute(&value, attr, deviceId);
|
||||
std::cout << " actual value " << value << std::endl;
|
||||
if ((expectedValue != -1) && value != expectedValue) {
|
||||
std::cout << "fail" << std::endl;
|
||||
return hipErrorInvalidValue;
|
||||
}
|
||||
return hipSuccess;
|
||||
}
|
||||
|
||||
hipError_t test_hipDeviceGetHdpAddress(int deviceId, hipDeviceAttribute_t attr,
|
||||
uint32_t* expectedValue = (uint32_t*)0xdeadbeef) {
|
||||
uint32_t* value = 0;
|
||||
std::cout << "Test hipDeviceGetHdpAddress attribute " << attr;
|
||||
if (expectedValue != (uint32_t*)0xdeadbeef) {
|
||||
std::cout << " expected value " << expectedValue;
|
||||
}
|
||||
hipError_t e = hipDeviceGetAttribute((int*) &value, attr, deviceId);
|
||||
std::cout << " actual value " << value << std::endl;
|
||||
if ((expectedValue != (uint32_t*)0xdeadbeef) && value != expectedValue) {
|
||||
std::cout << "fail" << std::endl;
|
||||
return hipErrorInvalidValue;
|
||||
}
|
||||
return hipSuccess;
|
||||
hipError_t test_hipDeviceGetHdpAddress(int deviceId,
|
||||
hipDeviceAttribute_t attr,
|
||||
uint32_t* expectedValue) {
|
||||
uint32_t* value = 0;
|
||||
std::cout << "Test hipDeviceGetHdpAddress attribute " << attr;
|
||||
if (expectedValue != reinterpret_cast<uint32_t*>(0xdeadbeef)) {
|
||||
std::cout << " expected value " << expectedValue;
|
||||
}
|
||||
hipError_t e = hipDeviceGetAttribute(reinterpret_cast<int*>(&value),
|
||||
attr, deviceId);
|
||||
std::cout << " actual value " << value << std::endl;
|
||||
if ((expectedValue != reinterpret_cast<uint32_t*>(0xdeadbeef)) &&
|
||||
value != expectedValue) {
|
||||
std::cout << "fail" << std::endl;
|
||||
return hipErrorInvalidValue;
|
||||
}
|
||||
return hipSuccess;
|
||||
}
|
||||
|
||||
bool testAttributeValues() {
|
||||
int deviceId;
|
||||
HIPCHECK(hipGetDevice(&deviceId));
|
||||
hipDeviceProp_t props;
|
||||
HIPCHECK(hipGetDeviceProperties(&props, deviceId));
|
||||
printf("info: running on device #%d %s\n", deviceId, props.name);
|
||||
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeMaxThreadsPerBlock,
|
||||
props.maxThreadsPerBlock));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeMaxBlockDimX,
|
||||
props.maxThreadsDim[0]));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeMaxBlockDimY,
|
||||
props.maxThreadsDim[1]));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeMaxBlockDimZ,
|
||||
props.maxThreadsDim[2]));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeMaxGridDimX,
|
||||
props.maxGridSize[0]));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeMaxGridDimY,
|
||||
props.maxGridSize[1]));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeMaxGridDimZ,
|
||||
props.maxGridSize[2]));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeMaxSharedMemoryPerBlock,
|
||||
props.sharedMemPerBlock));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeTotalConstantMemory,
|
||||
props.totalConstMem));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeWarpSize,
|
||||
props.warpSize));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeMaxRegistersPerBlock,
|
||||
props.regsPerBlock));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeClockRate,
|
||||
props.clockRate));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeMemoryClockRate,
|
||||
props.memoryClockRate));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeMemoryBusWidth,
|
||||
props.memoryBusWidth));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeMultiprocessorCount,
|
||||
props.multiProcessorCount));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeIsMultiGpuBoard,
|
||||
props.isMultiGpuBoard));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeComputeMode,
|
||||
props.computeMode));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeL2CacheSize,
|
||||
props.l2CacheSize));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeMaxThreadsPerMultiProcessor,
|
||||
props.maxThreadsPerMultiProcessor));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeComputeCapabilityMajor,
|
||||
props.major));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeComputeCapabilityMinor,
|
||||
props.minor));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeConcurrentKernels,
|
||||
props.concurrentKernels));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributePciBusId,
|
||||
props.pciBusID));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributePciDeviceId,
|
||||
props.pciDeviceID));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeMaxSharedMemoryPerMultiprocessor,
|
||||
props.maxSharedMemoryPerMultiProcessor));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeIntegrated,
|
||||
props.integrated));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeMaxTexture1DWidth,
|
||||
props.maxTexture1D));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeMaxTexture2DWidth,
|
||||
props.maxTexture2D[0]));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeMaxTexture2DHeight,
|
||||
props.maxTexture2D[1]));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeMaxTexture3DWidth,
|
||||
props.maxTexture3D[0]));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeMaxTexture3DHeight,
|
||||
props.maxTexture3D[1]));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeMaxTexture3DDepth,
|
||||
props.maxTexture3D[2]));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeCooperativeLaunch,
|
||||
props.cooperativeLaunch));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeCooperativeMultiDeviceLaunch,
|
||||
props.cooperativeMultiDeviceLaunch));
|
||||
|
||||
#ifndef __HIP_PLATFORM_NVCC__
|
||||
HIPCHECK(test_hipDeviceGetHdpAddress(deviceId,
|
||||
hipDeviceAttributeHdpMemFlushCntl,
|
||||
props.hdpMemFlushCntl));
|
||||
HIPCHECK(test_hipDeviceGetHdpAddress(deviceId,
|
||||
hipDeviceAttributeHdpRegFlushCntl,
|
||||
props.hdpRegFlushCntl));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeDirectManagedMemAccessFromHost,
|
||||
props.directManagedMemAccessFromHost));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeConcurrentManagedAccess,
|
||||
props.concurrentManagedAccess));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributePageableMemoryAccess,
|
||||
props.pageableMemoryAccess));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributePageableMemoryAccessUsesHostPageTables,
|
||||
props.pageableMemoryAccessUsesHostPageTables));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeCooperativeMultiDeviceUnmatchedFunc,
|
||||
props.cooperativeMultiDeviceUnmatchedFunc));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeCooperativeMultiDeviceUnmatchedGridDim,
|
||||
props.cooperativeMultiDeviceUnmatchedGridDim));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeCooperativeMultiDeviceUnmatchedBlockDim,
|
||||
props.cooperativeMultiDeviceUnmatchedBlockDim));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeCooperativeMultiDeviceUnmatchedSharedMem,
|
||||
props.cooperativeMultiDeviceUnmatchedSharedMem));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeAsicRevision,
|
||||
props.asicRevision));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeManagedMemory,
|
||||
props.managedMemory));
|
||||
#endif
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeMaxPitch,
|
||||
props.memPitch));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeTextureAlignment,
|
||||
props.textureAlignment));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeKernelExecTimeout,
|
||||
props.kernelExecTimeoutEnabled));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeCanMapHostMemory,
|
||||
props.canMapHostMemory));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeEccEnabled,
|
||||
props.ECCEnabled));
|
||||
HIPCHECK(test_hipDeviceGetAttribute(deviceId,
|
||||
hipDeviceAttributeTexturePitchAlignment,
|
||||
props.texturePitchAlignment));
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* Validates negative scenarios for hipDeviceGetAttribute
|
||||
* scenario1: pi = nullptr
|
||||
* scenario2: device = -1 (Invalid Device)
|
||||
* scenario3: device = Non Existing Device
|
||||
* scenario4: attr = Invalid Attribute
|
||||
*/
|
||||
bool testInvalidParameters() {
|
||||
bool TestPassed = true;
|
||||
hipError_t ret;
|
||||
int deviceCount = 0;
|
||||
HIPCHECK(hipGetDeviceCount(&deviceCount));
|
||||
HIPASSERT(deviceCount != 0);
|
||||
printf("No.of gpus in the system: %d\n", deviceCount);
|
||||
// pi = nullptr
|
||||
int device;
|
||||
HIPCHECK(hipGetDevice(&device));
|
||||
ret = hipDeviceGetAttribute(nullptr, hipDeviceAttributePciBusId, device);
|
||||
if (ret == hipSuccess) {
|
||||
TestPassed &= false;
|
||||
printf("Test {pi = nullptr} Failed \n");
|
||||
}
|
||||
// device = -1
|
||||
int pi = -1;
|
||||
ret = hipDeviceGetAttribute(&pi, hipDeviceAttributePciBusId, -1);
|
||||
if (ret == hipSuccess) {
|
||||
TestPassed &= false;
|
||||
printf("Test {device = -1} Failed \n");
|
||||
}
|
||||
// device = Non Existing Device
|
||||
pi = -1;
|
||||
ret = hipDeviceGetAttribute(&pi, hipDeviceAttributePciBusId, deviceCount);
|
||||
if (ret == hipSuccess) {
|
||||
TestPassed &= false;
|
||||
printf("Test {device = Non Existing Device} Failed \n");
|
||||
}
|
||||
// attr = Invalid Attribute
|
||||
pi = -1;
|
||||
ret = hipDeviceGetAttribute(&pi, static_cast<hipDeviceAttribute_t>(-1),
|
||||
device);
|
||||
if (ret == hipSuccess) {
|
||||
TestPassed &= false;
|
||||
printf("Test {attr = Invalid Attribute} Failed \n");
|
||||
}
|
||||
return TestPassed;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
int deviceId;
|
||||
CHECK(hipGetDevice(&deviceId));
|
||||
hipDeviceProp_t props;
|
||||
CHECK(hipGetDeviceProperties(&props, deviceId));
|
||||
printf("info: running on device #%d %s\n", deviceId, props.name);
|
||||
bool TestPassed = true;
|
||||
HipTest::parseStandardArguments(argc, argv, true);
|
||||
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxThreadsPerBlock,
|
||||
props.maxThreadsPerBlock));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxBlockDimX,
|
||||
props.maxThreadsDim[0]));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxBlockDimY,
|
||||
props.maxThreadsDim[1]));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxBlockDimZ,
|
||||
props.maxThreadsDim[2]));
|
||||
CHECK(
|
||||
test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxGridDimX, props.maxGridSize[0]));
|
||||
CHECK(
|
||||
test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxGridDimY, props.maxGridSize[1]));
|
||||
CHECK(
|
||||
test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxGridDimZ, props.maxGridSize[2]));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxSharedMemoryPerBlock,
|
||||
props.sharedMemPerBlock));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeTotalConstantMemory,
|
||||
props.totalConstMem));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeWarpSize, props.warpSize));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxRegistersPerBlock,
|
||||
props.regsPerBlock));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeClockRate, props.clockRate));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMemoryClockRate,
|
||||
props.memoryClockRate));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMemoryBusWidth,
|
||||
props.memoryBusWidth));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMultiprocessorCount,
|
||||
props.multiProcessorCount));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeIsMultiGpuBoard,
|
||||
props.isMultiGpuBoard)); //
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeComputeMode, props.computeMode));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeL2CacheSize, props.l2CacheSize));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxThreadsPerMultiProcessor,
|
||||
props.maxThreadsPerMultiProcessor));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeComputeCapabilityMajor,
|
||||
props.major));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeComputeCapabilityMinor,
|
||||
props.minor)); //
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeConcurrentKernels,
|
||||
props.concurrentKernels));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributePciBusId, props.pciBusID));
|
||||
CHECK(
|
||||
test_hipDeviceGetAttribute(deviceId, hipDeviceAttributePciDeviceId, props.pciDeviceID)); //
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxSharedMemoryPerMultiprocessor,
|
||||
props.maxSharedMemoryPerMultiProcessor));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeIntegrated, props.integrated));
|
||||
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxTexture1DWidth, props.maxTexture1D));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxTexture2DWidth, props.maxTexture2D[0]));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxTexture2DHeight, props.maxTexture2D[1]));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxTexture3DWidth, props.maxTexture3D[0]));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxTexture3DHeight, props.maxTexture3D[1]));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxTexture3DDepth, props.maxTexture3D[2]));
|
||||
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeCooperativeLaunch, props.cooperativeLaunch));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeCooperativeMultiDeviceLaunch, props.cooperativeMultiDeviceLaunch));
|
||||
|
||||
#ifndef __HIP_PLATFORM_NVIDIA__
|
||||
CHECK(test_hipDeviceGetHdpAddress(deviceId, hipDeviceAttributeHdpMemFlushCntl, props.hdpMemFlushCntl));
|
||||
CHECK(test_hipDeviceGetHdpAddress(deviceId, hipDeviceAttributeHdpRegFlushCntl, props.hdpRegFlushCntl));
|
||||
#endif
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeMaxPitch, props.memPitch));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeTextureAlignment, props.textureAlignment));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeKernelExecTimeout, props.kernelExecTimeoutEnabled));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeCanMapHostMemory, props.canMapHostMemory));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeEccEnabled, props.ECCEnabled));
|
||||
CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributeAsicRevision, props.asicRevision));
|
||||
if (p_tests == 0x1) {
|
||||
TestPassed = testAttributeValues();
|
||||
} else if (p_tests == 0x2) {
|
||||
TestPassed = testInvalidParameters();
|
||||
} else {
|
||||
printf("Invalid Test Case \n");
|
||||
exit(1);
|
||||
}
|
||||
if (TestPassed) {
|
||||
passed();
|
||||
};
|
||||
} else {
|
||||
failed("Test Case %x Failed!", p_tests);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
Copyright (c) 2020-Present Advanced Micro Devices, Inc. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../../test_common.cpp NVCC_OPTIONS -std=c++11
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include "test_common.h"
|
||||
|
||||
/**
|
||||
* Validates negative scenarios for hipGetDeviceProperties
|
||||
* scenario1: props = nullptr
|
||||
* scenario2: device = -1 (Invalid Device)
|
||||
* scenario3: device = Non Existing Device
|
||||
*/
|
||||
bool testInvalidParameters() {
|
||||
bool TestPassed = true;
|
||||
hipError_t ret;
|
||||
// props = nullptr
|
||||
#ifndef __HIP_PLATFORM_NVCC__
|
||||
int device;
|
||||
HIPCHECK(hipGetDevice(&device));
|
||||
// this test case results in segmentation fault on NVCC
|
||||
ret = hipGetDeviceProperties(nullptr, device);
|
||||
if (ret == hipSuccess) {
|
||||
TestPassed &= false;
|
||||
printf("Test {props = nullptr} Failed \n");
|
||||
}
|
||||
#endif
|
||||
hipDeviceProp_t prop;
|
||||
ret = hipGetDeviceProperties(&prop, -1);
|
||||
if (ret == hipSuccess) {
|
||||
TestPassed &= false;
|
||||
printf("Test {device = -1} Failed \n");
|
||||
}
|
||||
// device = Non Existing Device
|
||||
int deviceCount = 0;
|
||||
HIPCHECK(hipGetDeviceCount(&deviceCount));
|
||||
HIPASSERT(deviceCount != 0);
|
||||
ret = hipGetDeviceProperties(&prop, deviceCount);
|
||||
if (ret == hipSuccess) {
|
||||
TestPassed &= false;
|
||||
printf("Test {device = Non Existing Device} Failed \n");
|
||||
}
|
||||
return TestPassed;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
HipTest::parseStandardArguments(argc, argv, true);
|
||||
bool TestPassed = testInvalidParameters();
|
||||
if (TestPassed) {
|
||||
passed();
|
||||
} else {
|
||||
failed("Test Case %x Failed!", p_tests);
|
||||
}
|
||||
}
|
||||
새 이슈에서 참조
사용자 차단