From fb8690f812a5eeea5f8cd09231eefd059c35aacf Mon Sep 17 00:00:00 2001 From: Ammar ELWazir Date: Fri, 8 Jul 2022 18:44:49 -0500 Subject: [PATCH] SWDEV-345650 - Solving hipKernelNameRefByPtr Stream Issue Stream is not important to get the kernel name from Function that can be found in the functions_ map. Change-Id: I164bc3ebcc5552359856e76204d8b124ba0d2f34 --- hipamd/src/hip_code_object.cpp | 8 ++++++++ hipamd/src/hip_code_object.hpp | 1 + hipamd/src/hip_global.hpp | 3 ++- hipamd/src/hip_intercept.cpp | 14 ++------------ hipamd/src/hip_platform.cpp | 4 ++++ hipamd/src/hip_platform.hpp | 2 +- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/hipamd/src/hip_code_object.cpp b/hipamd/src/hip_code_object.cpp index be3fac910e..896b1e640b 100644 --- a/hipamd/src/hip_code_object.cpp +++ b/hipamd/src/hip_code_object.cpp @@ -766,6 +766,14 @@ hipError_t StatCO::registerStatFunction(const void* hostFunction, Function* func return hipSuccess; } +const char* StatCO::getStatFuncName(const void* hostFunction) const { + const auto it = functions_.find(hostFunction); + if (it == functions_.end()) { + return nullptr; + } + return it->second->name().c_str(); +} + hipError_t StatCO::getStatFunc(hipFunction_t* hfunc, const void* hostFunction, int deviceId) { amd::ScopedLock lock(sclock_); diff --git a/hipamd/src/hip_code_object.hpp b/hipamd/src/hip_code_object.hpp index 112bce8dd9..13c9a48c2c 100644 --- a/hipamd/src/hip_code_object.hpp +++ b/hipamd/src/hip_code_object.hpp @@ -139,6 +139,7 @@ public: hipError_t registerStatManagedVar(Var *var); //Retrive Vars/Funcs for a given hostSidePtr(const void*), unless stated otherwise. + const char* getStatFuncName(const void* hostFunction) const; hipError_t getStatFunc(hipFunction_t* hfunc, const void* hostFunction, int deviceId); hipError_t getStatFuncAttr(hipFuncAttributes* func_attr, const void* hostFunction, int deviceId); hipError_t getStatGlobalVar(const void* hostVar, int deviceId, hipDeviceptr_t* dev_ptr, diff --git a/hipamd/src/hip_global.hpp b/hipamd/src/hip_global.hpp index 6c964b625d..00fffd6a1d 100644 --- a/hipamd/src/hip_global.hpp +++ b/hipamd/src/hip_global.hpp @@ -67,7 +67,8 @@ public: hipError_t getStatFunc(hipFunction_t *hfunc, int deviceId); hipError_t getStatFuncAttr(hipFuncAttributes* func_attr, int deviceId); void resize_dFunc(size_t size) { dFunc_.resize(size); } - FatBinaryInfo** moduleInfo() { return modules_; }; + FatBinaryInfo** moduleInfo() { return modules_; } + const std::string& name() const { return name_; } private: std::vector dFunc_; //DeviceFuncObj per Device diff --git a/hipamd/src/hip_intercept.cpp b/hipamd/src/hip_intercept.cpp index 162b32714f..4048c645f0 100644 --- a/hipamd/src/hip_intercept.cpp +++ b/hipamd/src/hip_intercept.cpp @@ -39,21 +39,11 @@ int hipGetStreamDeviceId(hipStream_t stream) { return (s != nullptr)? s->DeviceId() : ihipGetDevice(); } -const char* hipKernelNameRefByPtr(const void* hostFunction, hipStream_t stream) { +const char* hipKernelNameRefByPtr(const void* hostFunction, hipStream_t) { if (hostFunction == NULL) { return NULL; } - int deviceId = hipGetStreamDeviceId(stream); - if (deviceId == -1) { - LogPrintfError("Wrong Device Id: %d \n", deviceId); - return NULL; - } - hipFunction_t func = nullptr; - hipError_t hip_error = PlatformState::instance().getStatFunc(&func, hostFunction, deviceId); - if (hip_error != hipSuccess) { - return NULL; - } - return hipKernelNameRef(func); + return PlatformState::instance().getStatFuncName(hostFunction); } hipError_t hipRegisterApiCallback(uint32_t id, void* fun, void* arg) { diff --git a/hipamd/src/hip_platform.cpp b/hipamd/src/hip_platform.cpp index 6e65c1d7d8..edc14f2146 100644 --- a/hipamd/src/hip_platform.cpp +++ b/hipamd/src/hip_platform.cpp @@ -889,6 +889,10 @@ hipError_t PlatformState::registerStatManagedVar(hip::Var* var) { return statCO_.registerStatManagedVar(var); } +const char* PlatformState::getStatFuncName(const void* hostFunction) const { + return statCO_.getStatFuncName(hostFunction); +} + hipError_t PlatformState::getStatFunc(hipFunction_t* hfunc, const void* hostFunction, int deviceId) { return statCO_.getStatFunc(hfunc, hostFunction, deviceId); diff --git a/hipamd/src/hip_platform.hpp b/hipamd/src/hip_platform.hpp index b85bbbf5c7..2a3e40e604 100644 --- a/hipamd/src/hip_platform.hpp +++ b/hipamd/src/hip_platform.hpp @@ -74,7 +74,7 @@ class PlatformState { hipError_t registerStatGlobalVar(const void* hostVar, hip::Var* var); hipError_t registerStatManagedVar(hip::Var* var); - + const char* getStatFuncName(const void* hostFunction) const; hipError_t getStatFunc(hipFunction_t* hfunc, const void* hostFunction, int deviceId); hipError_t getStatFuncAttr(hipFuncAttributes* func_attr, const void* hostFunction, int deviceId); hipError_t getStatGlobalVar(const void* hostVar, int deviceId, hipDeviceptr_t* dev_ptr,