From ac37a1a3ca0c2c2a474eadcd81bb52ce6aafee32 Mon Sep 17 00:00:00 2001 From: Jatin Chaudhary Date: Thu, 15 Jul 2021 01:38:39 -0700 Subject: [PATCH] SWDEV-283267 - Deprecate -use-pch option and add hiprtc builtin header for all hiprtc programs Change-Id: I2ed98c65fb310d89a787510c6a362ee0929b83d9 [ROCm/clr commit: 7b8b7a9ba1827011299023621d5706b7f7b4b916] --- projects/clr/hipamd/src/hip_rtc.cpp | 60 +++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/projects/clr/hipamd/src/hip_rtc.cpp b/projects/clr/hipamd/src/hip_rtc.cpp index f03cb996c0..ca609a5a52 100755 --- a/projects/clr/hipamd/src/hip_rtc.cpp +++ b/projects/clr/hipamd/src/hip_rtc.cpp @@ -23,12 +23,14 @@ #include #include "platform/program.hpp" -#ifdef __HIP_ENABLE_PCH -extern const char __hip_pch[]; -extern unsigned __hip_pch_size; -void __hipGetPCH(const char** pch, unsigned int *size) { - *pch = __hip_pch; - *size = __hip_pch_size; +#ifdef __HIP_ENABLE_RTC +extern "C" { +extern const char __hipRTC_header[]; +extern unsigned __hipRTC_header_size; +} +void __hipGetRTC(const char** rtc, unsigned int* size) { + *rtc = __hipRTC_header; + *size = __hipRTC_header_size; } #endif @@ -160,17 +162,12 @@ static std::string getValueOf(const std::string& option) { static void transformOptions(std::vector& options, amd::Program* program) { std::vector t_option; for (auto& i : options) { -#ifdef __HIP_ENABLE_PCH - // Use precompiled header for hip + // This functionality is no longer supported - just consume at the moment and remove this in + // couple of releases if (i == "-hip-pch") { - const char* pch = nullptr; - unsigned int pch_size = 0; - __hipGetPCH(&pch, &pch_size); - program->addPreCompiledHeader(std::string(pch, pch_size)); - i = "-nogpuinc"; + i.clear(); continue; } -#endif // Some rtc samples use --gpu-architecture if (i.rfind("--gpu-architecture=", 0) == 0) { auto val = getValueOf(i); @@ -230,8 +227,33 @@ hiprtcResult hiprtcCreateProgram(hiprtcProgram* prog, const char* src, const cha HIPRTC_RETURN(HIPRTC_ERROR_INVALID_INPUT); } - amd::Program* program = new amd::Program(*hip::getCurrentDevice()->asContext(), src, amd::Program::HIP, - numHeaders, headers, headerNames); + // Add header from hiprtc_header.o + std::vector header_sources; + std::vector header_names; + + header_sources.reserve(numHeaders + 1); + header_names.reserve(numHeaders + 1); + +#ifdef __HIP_ENABLE_RTC + const char* rtc_pch = nullptr; + unsigned rtc_size = 0; + __hipGetRTC(&rtc_pch, &rtc_size); + if (rtc_pch == nullptr || rtc_size == 0) { + HIPRTC_RETURN(HIPRTC_ERROR_BUILTIN_OPERATION_FAILURE); + } + std::string rtc_pch_str(rtc_pch, rtc_size); + header_sources.push_back(rtc_pch_str.data()); + header_names.push_back("hiprtc_runtime.h"); +#endif + + for (int i = 0; i < numHeaders; i++) { + header_sources.push_back(headers[i]); + header_names.push_back(headerNames[i]); + } + + amd::Program* program = + new amd::Program(*hip::getCurrentDevice()->asContext(), src, amd::Program::HIP, + header_sources.size(), header_sources.data(), header_names.data()); if (program == NULL) { HIPRTC_RETURN(HIPRTC_ERROR_INVALID_INPUT); } @@ -268,6 +290,12 @@ hiprtcResult hiprtcCompileProgram(hiprtcProgram prog, int numOptions, const char oarr.push_back(hipVerMajor); oarr.push_back(hipVerMinor); oarr.push_back(hipVerPatch); +#ifdef __HIP_ENABLE_RTC + oarr.push_back("-D__HIPCC_RTC__"); + oarr.push_back("-include hiprtc_runtime.h"); + oarr.push_back("-std=c++14"); + oarr.push_back("-nogpuinc"); +#endif transformOptions(oarr, program); std::copy(oarr.begin(), oarr.end(), std::ostream_iterator(ostrstr, " "));