From 7aa68bc3cb56dad53a62cb0f1b2f59d4767bb699 Mon Sep 17 00:00:00 2001 From: kjayapra-amd Date: Fri, 17 Jul 2020 17:29:32 -0400 Subject: [PATCH] SWDEV-240800 - Adding initial support for hipDeviceGetP2PAttribute. Some attr support still pending. Change-Id: I0611aed136270db497dfa374144f6f5e35352a8f [ROCm/clr commit: 311fc8c513f0274a7e6f93bfd94a7382cb177956] --- .../include/hip/hcc_detail/hip_runtime_api.h | 20 +++++++++ .../include/hip/nvcc_detail/hip_runtime_api.h | 6 +++ .../clr/hipamd/rocclr/hip_device_runtime.cpp | 7 --- projects/clr/hipamd/rocclr/hip_hcc.def.in | 1 + projects/clr/hipamd/rocclr/hip_hcc.map.in | 1 + projects/clr/hipamd/rocclr/hip_peer.cpp | 45 +++++++++++++++++-- 6 files changed, 69 insertions(+), 11 deletions(-) mode change 100644 => 100755 projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h mode change 100644 => 100755 projects/clr/hipamd/include/hip/nvcc_detail/hip_runtime_api.h mode change 100644 => 100755 projects/clr/hipamd/rocclr/hip_device_runtime.cpp diff --git a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h old mode 100644 new mode 100755 index e8a7a9e623..3c8a775289 --- a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h @@ -95,6 +95,13 @@ typedef struct ihipCtx_t* hipCtx_t; // Note many APIs also use integer deviceIds as an alternative to the device pointer: typedef int hipDevice_t; +typedef enum hipDeviceP2PAttr { + hipDevP2PAttrPerformanceRank = 0, + hipDevP2PAttrAccessSupported, + hipDevP2PAttrNativeAtomicSupported, + hipDevP2PAttrHipArrayAccessSupported +} hipDeviceP2PAttr; + typedef struct ihipStream_t* hipStream_t; #define hipIpcMemLazyEnablePeerAccess 0 @@ -2799,6 +2806,19 @@ hipError_t hipDeviceComputeCapability(int* major, int* minor, hipDevice_t device */ hipError_t hipDeviceGetName(char* name, int len, hipDevice_t device); + +/** + * @brief Returns a value for attr of link between two devices + * @param [out] value + * @param [in] attr + * @param [in] srcDevice + * @param [in] dstDevice + * + * @returns #hipSuccess, #hipErrorInavlidDevice + */ +hipError_t hipDeviceGetP2PAttribute(int* value, hipDeviceP2PAttr attr, + int srcDevice, int dstDevice); + /** * @brief Returns a PCI Bus Id string for the device, overloaded to take int device ID. * @param [out] pciBusId diff --git a/projects/clr/hipamd/include/hip/nvcc_detail/hip_runtime_api.h b/projects/clr/hipamd/include/hip/nvcc_detail/hip_runtime_api.h old mode 100644 new mode 100755 index fe72f33d65..3744c6740c --- a/projects/clr/hipamd/include/hip/nvcc_detail/hip_runtime_api.h +++ b/projects/clr/hipamd/include/hip/nvcc_detail/hip_runtime_api.h @@ -179,6 +179,7 @@ typedef enum cudaSharedMemConfig hipSharedMemConfig; typedef CUfunc_cache hipFuncCache; typedef CUjit_option hipJitOption; typedef CUdevice hipDevice_t; +typedef enum cudaDeviceP2PAttr hipDeviceP2PAttr; typedef CUmodule hipModule_t; typedef CUfunction hipFunction_t; typedef CUdeviceptr hipDeviceptr_t; @@ -1606,6 +1607,11 @@ inline static hipError_t hipDeviceGetName(char* name, int len, hipDevice_t devic return hipCUResultTohipError(cuDeviceGetName(name, len, device)); } +inline static hipError_t hipDeviceGetP2PAttribute(int* value, hipDeviceP2PAttr attr, + int srcDevice, int dstDevice) { + return hipCUDAErrorTohipError(cudaDeviceGetP2PAttribute(value, attr, srcDevice, dstDevice)); +} + inline static hipError_t hipDeviceGetPCIBusId(char* pciBusId, int len, hipDevice_t device) { return hipCUDAErrorTohipError(cudaDeviceGetPCIBusId(pciBusId, len, device)); } diff --git a/projects/clr/hipamd/rocclr/hip_device_runtime.cpp b/projects/clr/hipamd/rocclr/hip_device_runtime.cpp old mode 100644 new mode 100755 index be979dab9e..470b088f02 --- a/projects/clr/hipamd/rocclr/hip_device_runtime.cpp +++ b/projects/clr/hipamd/rocclr/hip_device_runtime.cpp @@ -367,13 +367,6 @@ hipError_t hipDeviceGetLimit ( size_t* pValue, hipLimit_t limit ) { } } -/** -hipError_t hipDeviceGetP2PAttribute ( int* value, hipDeviceP2PAttr attr, int srcDevice, int dstDevice ) { - assert(0); - HIP_RETURN(hipSuccess); -} -**/ - hipError_t hipDeviceGetPCIBusId ( char* pciBusId, int len, int device ) { HIP_INIT_API(hipDeviceGetPCIBusId, (void*)pciBusId, len, device); diff --git a/projects/clr/hipamd/rocclr/hip_hcc.def.in b/projects/clr/hipamd/rocclr/hip_hcc.def.in index da43f5f51d..5e45689c1a 100755 --- a/projects/clr/hipamd/rocclr/hip_hcc.def.in +++ b/projects/clr/hipamd/rocclr/hip_hcc.def.in @@ -29,6 +29,7 @@ hipDeviceGetLimit hipDeviceGetName hipDeviceGetPCIBusId hipDeviceGetSharedMemConfig +hipDeviceGetP2PAttribute hipDevicePrimaryCtxGetState hipDevicePrimaryCtxRelease hipDevicePrimaryCtxReset diff --git a/projects/clr/hipamd/rocclr/hip_hcc.map.in b/projects/clr/hipamd/rocclr/hip_hcc.map.in index e66d4be92d..f355a4e14a 100755 --- a/projects/clr/hipamd/rocclr/hip_hcc.map.in +++ b/projects/clr/hipamd/rocclr/hip_hcc.map.in @@ -30,6 +30,7 @@ global: hipDeviceGetName; hipDeviceGetPCIBusId; hipDeviceGetSharedMemConfig; + hipDeviceGetP2PAttribute; hipDevicePrimaryCtxGetState; hipDevicePrimaryCtxRelease; hipDevicePrimaryCtxReset; diff --git a/projects/clr/hipamd/rocclr/hip_peer.cpp b/projects/clr/hipamd/rocclr/hip_peer.cpp index 225361d525..24207b52c6 100755 --- a/projects/clr/hipamd/rocclr/hip_peer.cpp +++ b/projects/clr/hipamd/rocclr/hip_peer.cpp @@ -52,24 +52,61 @@ hipError_t canAccessPeer(int* canAccessPeer, int deviceId, int peerDeviceId){ amd::Device* device = nullptr; amd::Device* peer_device = nullptr; if (canAccessPeer == nullptr) { - HIP_RETURN(hipErrorInvalidValue); + return hipErrorInvalidValue; } /* Peer cannot be self */ if (deviceId == peerDeviceId) { *canAccessPeer = 0; - HIP_RETURN(hipSuccess); + return hipSuccess; } /* Cannot exceed the max number of devices */ if (static_cast(deviceId) >= g_devices.size() || static_cast(peerDeviceId) >= g_devices.size()) { - HIP_RETURN(hipErrorInvalidDevice); + return hipErrorInvalidDevice; } device = g_devices[deviceId]->devices()[0]; peer_device = g_devices[peerDeviceId]->devices()[0]; *canAccessPeer = static_cast(std::find(device->p2pDevices_.begin(), device->p2pDevices_.end(), as_cl(peer_device)) != device->p2pDevices_.end()); - HIP_RETURN(hipSuccess); + return hipSuccess; +} + +hipError_t hipDeviceGetP2PAttribute(int* value, hipDeviceP2PAttr attr, + int srcDevice, int dstDevice) { + HIP_INIT_API(hipDeviceGetP2PAttribute, value, attr, srcDevice, dstDevice); + + hipError_t hip_error = hipSuccess; + + if (value == nullptr) { + HIP_RETURN(hipErrorInvalidValue); + } + + if (srcDevice >= static_cast(g_devices.size()) + || dstDevice >= static_cast(g_devices.size())) { + HIP_RETURN(hipErrorInvalidDevice); + } + + switch (attr) { + case hipDevP2PAttrPerformanceRank : + assert(0 && "Unimplemented"); + break; + case hipDevP2PAttrAccessSupported : + hip_error = canAccessPeer(value, srcDevice, dstDevice); + break; + case hipDevP2PAttrNativeAtomicSupported : + assert(0 && "Unimplemented"); + break; + case hipDevP2PAttrHipArrayAccessSupported : + assert(0 && "Unimplemented"); + break; + default : + DevLogPrintfError("Invalid attribute attr: %d ", attr); + hip_error = hipErrorInvalidValue; + break; + } + + HIP_RETURN(hip_error); } hipError_t hipDeviceCanAccessPeer(int* canAccess, int deviceId, int peerDeviceId) {