From 05300c8fe3dce2cba98368b01e40f84d27202aaf Mon Sep 17 00:00:00 2001 From: Tao Sang Date: Sat, 11 Jul 2020 18:14:03 -0400 Subject: [PATCH] Implement HIP_ENABLE_DEFERRED_LOADING in right way Change-Id: Ia28dbdea5cde93b3ca69f44c6a3c18ec8a730d42 [ROCm/hip commit: 66fca8be231692b2b95878640eb22d71e789ba35] --- projects/hip/rocclr/hip_platform.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/projects/hip/rocclr/hip_platform.cpp b/projects/hip/rocclr/hip_platform.cpp index 6d9dd88065..4d8e28dce7 100755 --- a/projects/hip/rocclr/hip_platform.cpp +++ b/projects/hip/rocclr/hip_platform.cpp @@ -29,7 +29,6 @@ #include "elfio.hpp" constexpr unsigned __hipFatMAGIC2 = 0x48495046; // "HIPF" -int HIP_ENABLE_DEFERRED_LOADING = 1; // Will check later thread_local std::stack execStack_; PlatformState* PlatformState::platform_; // Initiaized as nullptr by default @@ -114,9 +113,15 @@ extern "C" void __hipRegisterFunction( dim3* blockDim, dim3* gridDim, int* wSize) { + static int enable_deferred_loading { []() { + char *var = getenv("HIP_ENABLE_DEFERRED_LOADING"); + return var ? atoi(var) : 1; + }() }; + hip::Function* func = new hip::Function(std::string(deviceName), modules); PlatformState::instance().registerStatFunction(hostFunction, func); - if (!HIP_ENABLE_DEFERRED_LOADING) { + + if (!enable_deferred_loading) { HIP_INIT(); hipFunction_t hfunc = nullptr; hipError_t hip_error = hipSuccess; @@ -876,9 +881,6 @@ void PlatformState::init() } initialized_ = true; - char *var = getenv("HIP_ENABLE_DEFERRED_LOADING"); - HIP_ENABLE_DEFERRED_LOADING = var ? atoi(var) : 1; - for (auto& it : statCO_.modules_) { digestFatBinary(it.first, it.second); }