diff --git a/projects/clr/hipamd/rocclr/hip_module.cpp b/projects/clr/hipamd/rocclr/hip_module.cpp index 383f7a77a9..70dbc02f3a 100755 --- a/projects/clr/hipamd/rocclr/hip_module.cpp +++ b/projects/clr/hipamd/rocclr/hip_module.cpp @@ -533,7 +533,7 @@ hipError_t hipModuleGetTexRef(textureReference** texRef, hipModule_t hmod, const } /* Get address and size for the global symbol */ - if (!PlatformState::instance().getDynTexRef(name, hmod, texRef)) { + if (hipSuccess != PlatformState::instance().getDynTexRef(name, hmod, texRef)) { DevLogPrintfError("Cannot get texRef for name: %s at module:0x%x \n", name, hmod); HIP_RETURN(hipErrorNotFound); @@ -543,5 +543,7 @@ hipError_t hipModuleGetTexRef(textureReference** texRef, hipModule_t hmod, const // have the default read mode set to normalized float. (*texRef)->readMode = hipReadModeNormalizedFloat; + PlatformState::instance().registerTexRef(*texRef, hmod, std::string(name)); + HIP_RETURN(hipSuccess); } diff --git a/projects/clr/hipamd/rocclr/hip_platform.cpp b/projects/clr/hipamd/rocclr/hip_platform.cpp index 23a1b3afc6..38dac4ad60 100755 --- a/projects/clr/hipamd/rocclr/hip_platform.cpp +++ b/projects/clr/hipamd/rocclr/hip_platform.cpp @@ -955,6 +955,15 @@ hipError_t PlatformState::unloadModule(hipModule_t hmod) { delete it->second; dynCO_map_.erase(hmod); + auto tex_it = texRef_map_.begin(); + while (tex_it != texRef_map_.end()) { + if (tex_it->second.first == hmod) { + tex_it = texRef_map_.erase(tex_it); + } else { + ++tex_it; + } + } + return hipSuccess; } @@ -989,6 +998,37 @@ hipError_t PlatformState::getDynGlobalVar(const char* hostVar, int deviceId, hip return hipSuccess; } +hipError_t PlatformState::registerTexRef(textureReference* texRef, hipModule_t hmod, + std::string name) { + amd::ScopedLock lock(lock_); + texRef_map_.insert(std::make_pair(texRef, std::make_pair(hmod, name))); + return hipSuccess; +} + +hipError_t PlatformState::getDynTexGlobalVar(textureReference* texRef, int deviceId, + hipDeviceptr_t* dev_ptr, size_t* size_ptr) { + amd::ScopedLock lock(lock_); + + auto tex_it = texRef_map_.find(texRef); + if (tex_it == texRef_map_.end()) { + DevLogPrintfError("Cannot find the texRef Entry: 0x%x", texRef); + return hipErrorNotFound; + } + + auto it = dynCO_map_.find(tex_it->second.first); + if (it == dynCO_map_.end()) { + DevLogPrintfError("Cannot find the module: 0x%x", tex_it->second.first); + return hipErrorNotFound; + } + + hip::DeviceVar* dvar = nullptr; + IHIP_RETURN_ONFAIL(it->second->getDeviceVar(&dvar, tex_it->second.second, deviceId)); + *dev_ptr = dvar->device_ptr(); + *size_ptr = dvar->size(); + + return hipSuccess; +} + hipError_t PlatformState::getDynTexRef(const char* hostVar, hipModule_t hmod, textureReference** texRef) { amd::ScopedLock lock(lock_); diff --git a/projects/clr/hipamd/rocclr/hip_platform.hpp b/projects/clr/hipamd/rocclr/hip_platform.hpp index b53a1a750d..620fb25ca7 100755 --- a/projects/clr/hipamd/rocclr/hip_platform.hpp +++ b/projects/clr/hipamd/rocclr/hip_platform.hpp @@ -52,6 +52,9 @@ public: hipDeviceptr_t* dev_ptr, size_t* size_ptr); hipError_t getDynTexRef(const char* hostVar, hipModule_t hmod, textureReference** texRef); + hipError_t registerTexRef(textureReference* texRef, hipModule_t hmod, std::string name); + hipError_t getDynTexGlobalVar(textureReference* texRef, int deviceId, hipDeviceptr_t* dev_ptr, size_t* size_ptr); + /* Singleton instance */ static PlatformState& instance() { if (platform_ == nullptr) { @@ -90,4 +93,5 @@ private: std::unordered_map dynCO_map_; hip::StatCO statCO_; //Static Code object var bool initialized_{false}; + std::unordered_map> texRef_map_; }; diff --git a/projects/clr/hipamd/rocclr/hip_texture.cpp b/projects/clr/hipamd/rocclr/hip_texture.cpp index fced181c5b..d56178e4ee 100755 --- a/projects/clr/hipamd/rocclr/hip_texture.cpp +++ b/projects/clr/hipamd/rocclr/hip_texture.cpp @@ -802,8 +802,9 @@ hipError_t hipTexRefSetArray(textureReference* texRef, hipDeviceptr_t refDevPtr = nullptr; size_t refDevSize = 0; - HIP_RETURN_ONFAIL(PlatformState::instance().getStatGlobalVar(texRef, ihipGetDevice(), &refDevPtr, - &refDevSize)); + + HIP_RETURN_ONFAIL(PlatformState::instance().getDynTexGlobalVar(texRef, ihipGetDevice(), + &refDevPtr, &refDevSize)); assert(refDevSize == sizeof(textureReference)); // Any previous address or HIP array state associated with the texture reference is superseded by this function. @@ -878,8 +879,8 @@ hipError_t hipTexRefSetAddress(size_t* ByteOffset, hipDeviceptr_t refDevPtr = nullptr; size_t refDevSize = 0; - HIP_RETURN_ONFAIL(PlatformState::instance().getStatGlobalVar(texRef, ihipGetDevice(), &refDevPtr, - &refDevSize)); + HIP_RETURN_ONFAIL(PlatformState::instance().getDynTexGlobalVar(texRef, ihipGetDevice(), + &refDevPtr, &refDevSize)); assert(refDevSize == sizeof(textureReference)); // Any previous address or HIP array state associated with the texture reference is superseded by this function. @@ -923,8 +924,8 @@ hipError_t hipTexRefSetAddress2D(textureReference* texRef, hipDeviceptr_t refDevPtr = nullptr; size_t refDevSize = 0; - HIP_RETURN_ONFAIL(PlatformState::instance().getStatGlobalVar(texRef, ihipGetDevice(), &refDevPtr, - &refDevSize)); + HIP_RETURN_ONFAIL(PlatformState::instance().getDynTexGlobalVar(texRef, ihipGetDevice(), + &refDevPtr, &refDevSize)); assert(refDevSize == sizeof(textureReference)); // Any previous address or HIP array state associated with the texture reference is superseded by this function. @@ -1201,8 +1202,8 @@ hipError_t hipTexRefSetMipmappedArray(textureReference* texRef, hipDeviceptr_t refDevPtr = nullptr; size_t refDevSize = 0; - HIP_RETURN_ONFAIL(PlatformState::instance().getStatGlobalVar(texRef, ihipGetDevice(), &refDevPtr, - &refDevSize)); + HIP_RETURN_ONFAIL(PlatformState::instance().getDynTexGlobalVar(texRef, ihipGetDevice(), + &refDevPtr, &refDevSize)); assert(refDevSize == sizeof(textureReference)); // Any previous address or HIP array state associated with the texture reference is superseded by this function.