From 4eade0ce83845ffe97515fb453608a8ef9876f09 Mon Sep 17 00:00:00 2001 From: Evgeny Mankov Date: Thu, 11 Feb 2016 22:26:01 +0300 Subject: [PATCH] BDFID (BusID/DeviceID/FunctionID) support. Except FunctionID (or DomainID in CUDA) support, because cudaDeviceProp::pciDomainID is not reported by CUDA. [ROCm/hip commit: 33f60c300d19ac05be030d6141e85de4fd300d69] --- projects/hip/include/hip_runtime_api.h | 4 ++++ projects/hip/include/nvcc_detail/hip_runtime_api.h | 6 ++++-- projects/hip/src/hip_hcc.cpp | 13 +++++++++++++ projects/hip/tests/src/hipGetDeviceAttribute.cpp | 3 ++- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/projects/hip/include/hip_runtime_api.h b/projects/hip/include/hip_runtime_api.h index 9e86bfc034..ca02197ac1 100644 --- a/projects/hip/include/hip_runtime_api.h +++ b/projects/hip/include/hip_runtime_api.h @@ -91,6 +91,8 @@ typedef struct hipDeviceProp_t { int clockInstructionRate; ///< Frequency in khz of the timer used by the device-side "clock*" instructions. New for HIP. hipDeviceArch_t arch; ///< Architectural feature flags. New for HIP. int concurrentKernels; ///< Device can possibly execute multiple kernels concurrently. + int pciBusID; ///< PCI Bus ID. + int pciDeviceID; ///< PCI Device ID. } hipDeviceProp_t; @@ -146,6 +148,8 @@ typedef enum hipDeviceAttribute_t { hipDeviceAttributeMaxThreadsPerMultiProcessor, ///< Maximum resident threads per multiprocessor. hipDeviceAttributeComputeCapabilityMajor, ///< Major compute capability version number. hipDeviceAttributeComputeCapabilityMinor, ///< Minor compute capability version number. + hipDeviceAttributePciBusId, ///< PCI Bus ID. + hipDeviceAttributePciDeviceId, ///< PCI Device ID. } hipDeviceAttribute_t; /** diff --git a/projects/hip/include/nvcc_detail/hip_runtime_api.h b/projects/hip/include/nvcc_detail/hip_runtime_api.h index 4c9b35cab8..63e3c9983b 100644 --- a/projects/hip/include/nvcc_detail/hip_runtime_api.h +++ b/projects/hip/include/nvcc_detail/hip_runtime_api.h @@ -252,8 +252,10 @@ inline static hipError_t hipDeviceGetAttribute(int* pi, hipDeviceAttribute_t att cdattr = cudaDevAttrMaxThreadsPerMultiProcessor; break; case hipDeviceAttributeComputeCapabilityMajor: cdattr = cudaDevAttrComputeCapabilityMajor; break; - case hipDeviceAttributeComputeCapabilityMinor: - cdattr = cudaDevAttrComputeCapabilityMinor; break; + case hipDeviceAttributePciBusId: + cdattr = cudaDevAttrPciBusId; break; + case hipDeviceAttributePciDeviceId: + cdattr = cudaDevAttrPciDeviceId; break; default: cerror = cudaErrorInvalidValue; break; } diff --git a/projects/hip/src/hip_hcc.cpp b/projects/hip/src/hip_hcc.cpp index 4b7b53550d..e367fe308b 100644 --- a/projects/hip/src/hip_hcc.cpp +++ b/projects/hip/src/hip_hcc.cpp @@ -310,7 +310,16 @@ hipError_t ihipDevice_t::getProperties(hipDeviceProp_t* prop) //prop->clockInstructionRate = counterHz / 1000; prop->clockInstructionRate = 100*1000; /* TODO-RT - hard-code until HSART has function to properly report clock */ + // Get Agent BDFID (bus/device/function ID) + uint16_t bdf_id = 1; + err = hsa_agent_get_info(_hsa_agent, (hsa_agent_info_t)HSA_AMD_AGENT_INFO_BDFID, &bdf_id); + DeviceErrorCheck(err); + // BDFID is 16bit uint: [8bit - BusID | 5bit - Device ID | 3bit - Function/DomainID] + // TODO/Clarify: cudaDeviceProp::pciDomainID how to report? + // prop->pciDomainID = bdf_id & 0x7; + prop->pciDeviceID = (bdf_id>>3) & 0x1F; + prop->pciBusID = (bdf_id>>8) & 0xFF; // Masquerade as a 3.0-level device. This will change as more HW functions are properly supported. // Application code should use the arch.has* to do detailed feature detection. @@ -839,6 +848,10 @@ hipError_t hipDeviceGetAttribute(int* pi, hipDeviceAttribute_t attr, int device) *pi = prop->major; break; case hipDeviceAttributeComputeCapabilityMinor: *pi = prop->minor; break; + case hipDeviceAttributePciBusId: + *pi = prop->pciBusID; break; + case hipDeviceAttributePciDeviceId: + *pi = prop->pciDeviceID; break; default: e = hipErrorInvalidValue; break; } diff --git a/projects/hip/tests/src/hipGetDeviceAttribute.cpp b/projects/hip/tests/src/hipGetDeviceAttribute.cpp index 62b6d432a0..6dc8861159 100644 --- a/projects/hip/tests/src/hipGetDeviceAttribute.cpp +++ b/projects/hip/tests/src/hipGetDeviceAttribute.cpp @@ -73,7 +73,8 @@ int main(int argc, char *argv[]) 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, hipDeviceAttributePciBusId, props.pciBusID)); + CHECK(test_hipDeviceGetAttribute(deviceId, hipDeviceAttributePciDeviceId, props.pciDeviceID)); passed(); };