CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
166 lines
4.6 KiB
C++
166 lines
4.6 KiB
C++
/*
|
|
* Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
|
|
#include <hip_test_common.hh>
|
|
|
|
/**
|
|
* @addtogroup hipDeviceGetByPCIBusId hipDeviceGetByPCIBusId
|
|
* @{
|
|
* @ingroup DriverTest
|
|
* `hipDeviceGetByPCIBusId(int* device, const char* pciBusId)` -
|
|
* Returns a handle to a compute device.
|
|
*/
|
|
|
|
#define SIZE 20
|
|
|
|
/**
|
|
* Test Description
|
|
* ------------------------
|
|
* - Check that PCI bus ID is the same as the one returned from attributes.
|
|
* - Perform for each device.
|
|
* Test source
|
|
* ------------------------
|
|
* - unit/device/hipDeviceGetByPCIBusId.cc
|
|
* Test requirements
|
|
* ------------------------
|
|
* - HIP_VERSION >= 5.2
|
|
*/
|
|
HIP_TEST_CASE(Unit_hipDeviceGetByPCIBusId_Functional) {
|
|
char pciBusId[SIZE]{};
|
|
int deviceCount = 0;
|
|
HIP_CHECK(hipGetDeviceCount(&deviceCount));
|
|
HIP_ASSERT(deviceCount != 0);
|
|
for (int i = 0; i < deviceCount; i++) {
|
|
int pciBusID = -1;
|
|
int pciDeviceID = -1;
|
|
int pciDomainID = -1;
|
|
int tempPciBusId = -1;
|
|
int tempDeviceId = -1;
|
|
int pciFunction = -1;
|
|
HIP_CHECK(hipDeviceGetPCIBusId(&pciBusId[0], SIZE, i));
|
|
REQUIRE(sscanf(pciBusId, "%x:%x:%x.%x", &pciDomainID, &pciBusID, &pciDeviceID, &pciFunction) ==
|
|
4);
|
|
HIP_CHECK(hipDeviceGetAttribute(&tempPciBusId, hipDeviceAttributePciBusId, i));
|
|
|
|
REQUIRE(pciBusID == tempPciBusId);
|
|
HIP_CHECK(hipDeviceGetByPCIBusId(&tempDeviceId, pciBusId));
|
|
REQUIRE(tempDeviceId == i);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Test Description
|
|
* ------------------------
|
|
* - Validates handling of `nullptr` arguments:
|
|
* -# When the output pointer to the device is `nullptr`
|
|
* - Expected output: do not return `hipSuccess`
|
|
* -# When the PCI bus ID pointer is `nullptr`
|
|
* - Expected output: do not return `hipSuccess`
|
|
* Test source
|
|
* ------------------------
|
|
* - unit/device/hipDeviceGetByPCIBusId.cc
|
|
* Test requirements
|
|
* ------------------------
|
|
* - HIP_VERSION >= 5.2
|
|
*/
|
|
HIP_TEST_CASE(Unit_hipDeviceGetByPCIBusId_NegativeNullChk) {
|
|
int device = -1;
|
|
hipError_t ret;
|
|
char pciBusIdstr[SIZE]{};
|
|
ret = hipDeviceGetByPCIBusId(nullptr, pciBusIdstr);
|
|
CHECK(ret != hipSuccess);
|
|
|
|
ret = hipDeviceGetByPCIBusId(&device, nullptr);
|
|
CHECK(ret != hipSuccess);
|
|
}
|
|
|
|
/**
|
|
* Test Description
|
|
* ------------------------
|
|
* - Validates handling of invalid PCI bus ID strings:
|
|
* -# When PCI bus ID is an empty string
|
|
* - Expected output: do not return `hipSuccess`
|
|
* -# When PCI bus ID is a short string
|
|
* - Expected output: do not return `hipSuccess`
|
|
* Test source
|
|
* ------------------------
|
|
* - unit/device/hipDeviceGetByPCIBusId.cc
|
|
* Test requirements
|
|
* ------------------------
|
|
* - HIP_VERSION >= 5.2
|
|
*/
|
|
HIP_TEST_CASE(Unit_hipDeviceGetByPCIBusId_NegativeInputString) {
|
|
int device = -1;
|
|
hipError_t ret;
|
|
ret = hipDeviceGetByPCIBusId(&device, "");
|
|
CHECK(ret != hipSuccess);
|
|
|
|
ret = hipDeviceGetByPCIBusId(&device, "0000:");
|
|
CHECK(ret != hipSuccess);
|
|
}
|
|
|
|
/**
|
|
* Test Description
|
|
* ------------------------
|
|
* - Validates handling of invalid PCI bus ID values:
|
|
* -# Passes non-existing PCI bus ID
|
|
* - Expected output: do not return `hipSuccess`
|
|
* Test source
|
|
* ------------------------
|
|
* - unit/device/hipDeviceGetByPCIBusId.cc
|
|
* Test requirements
|
|
* ------------------------
|
|
* - HIP_VERSION >= 5.2
|
|
*/
|
|
HIP_TEST_CASE(Unit_hipDeviceGetByPCIBusId_WrongBusID) {
|
|
int deviceCount = 0;
|
|
HIP_CHECK(hipGetDeviceCount(&deviceCount));
|
|
HIP_ASSERT(deviceCount != 0);
|
|
constexpr int MaxIter = 256;
|
|
constexpr int MaxBusIdLen = 12;
|
|
std::vector<int> pciBusId;
|
|
std::vector<int> pciDeviceID;
|
|
std::vector<int> pciDomainID;
|
|
|
|
// get bus id of all the devices
|
|
for (int i = 0; i < deviceCount; i++) {
|
|
hipDeviceProp_t prop;
|
|
HIP_CHECK(hipGetDeviceProperties(&prop, i));
|
|
pciBusId.push_back(prop.pciBusID);
|
|
pciDeviceID.push_back(prop.pciDeviceID);
|
|
pciDomainID.push_back(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 < MaxIter; 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[MaxBusIdLen];
|
|
int device = -1;
|
|
hipError_t ret;
|
|
snprintf(pciBusIdstr, sizeof(pciBusIdstr), "%04x:%02x:%02x", pciDomainID[0], id, pciDeviceID[0]);
|
|
ret = hipDeviceGetByPCIBusId(&device, pciBusIdstr);
|
|
REQUIRE(ret != hipSuccess);
|
|
}
|
|
|
|
|
|
/**
|
|
* End doxygen group DriverTest.
|
|
* @}
|
|
*/
|