From a87f517873e12d497e3c0d60286957d573397e89 Mon Sep 17 00:00:00 2001 From: kjayapra-amd Date: Mon, 13 Apr 2020 19:18:07 -0400 Subject: [PATCH] SWDEV-227602 - Adding support for hipFuncGetAttribute Change-Id: I16511274653c8c5521447eb2ed0fc5331dae8cba --- vdi/hip_hcc.def.in | 1 + vdi/hip_hcc.map.in | 1 + vdi/hip_module.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) mode change 100644 => 100755 vdi/hip_hcc.def.in mode change 100644 => 100755 vdi/hip_hcc.map.in diff --git a/vdi/hip_hcc.def.in b/vdi/hip_hcc.def.in old mode 100644 new mode 100755 index ef511ee43a..5eaedf6851 --- a/vdi/hip_hcc.def.in +++ b/vdi/hip_hcc.def.in @@ -138,6 +138,7 @@ hipModuleUnload hipOccupancyMaxPotentialBlockSize hipOccupancyMaxActiveBlocksPerMultiprocessor hipOccupancyMaxActiveBlocksPerMultiprocessorWithFlags +hipFuncGetAttribute hipFuncGetAttributes hipPeekAtLastError hipPointerGetAttributes diff --git a/vdi/hip_hcc.map.in b/vdi/hip_hcc.map.in old mode 100644 new mode 100755 index 2139f45ab8..98a3479f40 --- a/vdi/hip_hcc.map.in +++ b/vdi/hip_hcc.map.in @@ -138,6 +138,7 @@ global: hipOccupancyMaxPotentialBlockSize; hipOccupancyMaxActiveBlocksPerMultiprocessor; hipOccupancyMaxActiveBlocksPerMultiprocessorWithFlags; + hipFuncGetAttribute; hipFuncGetAttributes; hipPeekAtLastError; hipPointerGetAttributes; diff --git a/vdi/hip_module.cpp b/vdi/hip_module.cpp index 1e5f7d8b31..3d40d8c967 100755 --- a/vdi/hip_module.cpp +++ b/vdi/hip_module.cpp @@ -262,6 +262,69 @@ hipError_t hipModuleGetGlobal(hipDeviceptr_t* dptr, size_t* bytes, hipModule_t h HIP_RETURN(hipSuccess); } +hipError_t hipFuncGetAttribute(int* value, hipFunction_attribute attrib, hipFunction_t hfunc) { + HIP_INIT_API(hipFuncGetAttribute, value, attrib, hfunc); + + if ((value == nullptr) || (hfunc == nullptr)) { + HIP_RETURN(hipErrorInvalidValue); + } + + hip::Function* function = hip::Function::asFunction(hfunc); + if (function == nullptr) { + HIP_RETURN(hipErrorInvalidHandle); + } + + amd::Kernel* kernel = function->function_; + if (kernel == nullptr) { + HIP_RETURN(hipErrorInvalidDeviceFunction); + } + + const device::Kernel::WorkGroupInfo* wrkGrpInfo + = kernel->getDeviceKernel(*(hip::getCurrentDevice()->devices()[0]))->workGroupInfo(); + if (wrkGrpInfo == nullptr) { + HIP_RETURN(hipErrorMissingConfiguration); + } + + switch(attrib) { + case HIP_FUNC_ATTRIBUTE_SHARED_SIZE_BYTES: + *value = static_cast(wrkGrpInfo->localMemSize_ + - wrkGrpInfo->privateMemSize_); + break; + case HIP_FUNC_ATTRIBUTE_MAX_THREADS_PER_BLOCK: + *value = static_cast(wrkGrpInfo->wavefrontPerSIMD_ + * wrkGrpInfo->wavefrontSize_); + break; + case HIP_FUNC_ATTRIBUTE_CONST_SIZE_BYTES: + *value = 0; + break; + case HIP_FUNC_ATTRIBUTE_LOCAL_SIZE_BYTES: + *value = static_cast(wrkGrpInfo->localMemSize_); + break; + case HIP_FUNC_ATTRIBUTE_NUM_REGS: + *value = static_cast(wrkGrpInfo->availableGPRs_); + break; + case HIP_FUNC_ATTRIBUTE_PTX_VERSION: + *value = 30; // Defaults to 3.0 as HCC + break; + case HIP_FUNC_ATTRIBUTE_BINARY_VERSION: + *value = static_cast(kernel->signature().version()); + break; + case HIP_FUNC_ATTRIBUTE_CACHE_MODE_CA: + *value = 0; + break; + case HIP_FUNC_ATTRIBUTE_MAX_DYNAMIC_SHARED_SIZE_BYTES: + *value = static_cast(wrkGrpInfo->availableLDSSize_); + break; + case HIP_FUNC_ATTRIBUTE_PREFERRED_SHARED_MEMORY_CARVEOUT: + *value = 0; + break; + default: + HIP_RETURN(hipErrorInvalidValue); + } + + HIP_RETURN(hipSuccess); +} + hipError_t hipFuncGetAttributes(hipFuncAttributes* attr, const void* func) { HIP_INIT_API(hipFuncGetAttributes, attr, func);