From b425e272301ec75b1f0cd741c83152e349e5b5c0 Mon Sep 17 00:00:00 2001 From: Satyanvesh Dittakavi Date: Wed, 21 Sep 2022 10:07:14 +0000 Subject: [PATCH] SWDEV-357250 - hiprtc support with AMD_LOG_LEVEL when linked as separate library Change-Id: Ieda83af85a9344b4e09d4fe85acc65386db79c39 --- hipamd/src/hiprtc/hiprtc.cpp | 11 +++++++++-- hipamd/src/hiprtc/hiprtcInternal.hpp | 5 +++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/hipamd/src/hiprtc/hiprtc.cpp b/hipamd/src/hiprtc/hiprtc.cpp index 6d433bd5eb..fb09d88434 100644 --- a/hipamd/src/hiprtc/hiprtc.cpp +++ b/hipamd/src/hiprtc/hiprtc.cpp @@ -164,11 +164,13 @@ hiprtcResult hiprtcGetLoweredName(hiprtcProgram prog, const char* name_expressio hiprtcResult hiprtcDestroyProgram(hiprtcProgram* prog) { HIPRTC_INIT_API(prog); + if (prog == nullptr) { HIPRTC_RETURN(HIPRTC_ERROR_INVALID_INPUT); } auto* rtcProgram = hiprtc::RTCCompileProgram::as_RTCCompileProgram(*prog); delete rtcProgram; + HIPRTC_RETURN(HIPRTC_SUCCESS); } @@ -237,6 +239,8 @@ hiprtcResult hiprtcVersion(int* major, int* minor) { } hiprtcResult hiprtcGetBitcode (hiprtcProgram prog, char* bitcode) { + HIPRTC_INIT_API(prog, bitcode); + if (bitcode == nullptr) { HIPRTC_RETURN(HIPRTC_ERROR_INVALID_INPUT); } @@ -245,10 +249,13 @@ hiprtcResult hiprtcGetBitcode (hiprtcProgram prog, char* bitcode) { if (!rtcProgram->GetBitcode(bitcode)) { HIPRTC_RETURN(HIPRTC_ERROR_INVALID_PROGRAM); } + HIPRTC_RETURN(HIPRTC_SUCCESS); } hiprtcResult hiprtcGetBitcodeSize(hiprtcProgram prog, size_t* bitcode_size) { + HIPRTC_INIT_API(prog, bitcode_size); + if (bitcode_size == nullptr) { HIPRTC_RETURN(HIPRTC_ERROR_INVALID_INPUT); } @@ -333,18 +340,18 @@ hiprtcResult hiprtcLinkAddData(hiprtcLinkState hip_link_state, hiprtcJITInputTyp } HIPRTC_RETURN(HIPRTC_SUCCESS); - } hiprtcResult hiprtcLinkComplete(hiprtcLinkState hip_link_state, void** bin_out, size_t* size_out) { HIPRTC_INIT_API(hip_link_state, bin_out, size_out); + hiprtc::RTCLinkProgram* rtc_link_prog_ptr = reinterpret_cast(hip_link_state); if (!rtc_link_prog_ptr->LinkComplete(bin_out, size_out)) { HIPRTC_RETURN(HIPRTC_ERROR_LINKING); } - HIPRTC_RETURN(HIPRTC_SUCCESS); + HIPRTC_RETURN(HIPRTC_SUCCESS); } hiprtcResult hiprtcLinkDestroy(hiprtcLinkState hip_link_state) { diff --git a/hipamd/src/hiprtc/hiprtcInternal.hpp b/hipamd/src/hiprtc/hiprtcInternal.hpp index 0ead8ff978..3a6d2f867a 100644 --- a/hipamd/src/hiprtc/hiprtcInternal.hpp +++ b/hipamd/src/hiprtc/hiprtcInternal.hpp @@ -62,7 +62,12 @@ template inline std::string ToString(T first, Arg } // namespace internal } // namespace hiprtc +static amd::Monitor g_hiprtcInitlock {"hiprtcInit lock"}; #define HIPRTC_INIT_API(...) \ + amd::ScopedLock lock(g_hiprtcInitlock); \ + if (!amd::Flag::init()) { \ + HIPRTC_RETURN(HIPRTC_ERROR_INTERNAL_ERROR); \ + } \ ClPrint(amd::LOG_INFO, amd::LOG_API, "%s ( %s )", __func__, \ hiprtc::internal::ToString(__VA_ARGS__).c_str());