From 522ae8ead423255f786586afaf5aeff80ffc528d Mon Sep 17 00:00:00 2001 From: Satyanvesh Dittakavi Date: Thu, 19 Sep 2024 19:19:14 +0000 Subject: [PATCH] SWDEV-483241 - Add a compile option to avoid including default hiprtc header Change-Id: Ic23b41395588e6183abac36cb7543da02b0aba29 --- hipamd/src/hiprtc/hiprtc.cpp | 25 ++++++++++++++++++++++--- hipamd/src/hiprtc/hiprtcInternal.cpp | 4 ---- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/hipamd/src/hiprtc/hiprtc.cpp b/hipamd/src/hiprtc/hiprtc.cpp index 78e3490e52..7ef2aff23a 100644 --- a/hipamd/src/hiprtc/hiprtc.cpp +++ b/hipamd/src/hiprtc/hiprtc.cpp @@ -116,16 +116,35 @@ hiprtcResult hiprtcCompileProgram(hiprtcProgram prog, int numOptions, const char auto* rtcProgram = hiprtc::RTCCompileProgram::as_RTCCompileProgram(prog); bool fgpu_rdc = false; - std::vector opt; + bool no_builtin_header = false; + std::vector opt, compile_options; opt.reserve(numOptions); + compile_options.reserve(numOptions + 4); for (int i = 0; i < numOptions; i++) { if (std::string(options[i]) == std::string("-fgpu-rdc")) { fgpu_rdc = true; } - opt.push_back(std::string(options[i])); + + if (std::string(options[i]) != std::string("--hiprtc-no-builtin-header")) { + opt.push_back(std::string(options[i])); + } else { + no_builtin_header = true; + } } - if (!rtcProgram->compile(opt, fgpu_rdc)) { + // Do not include the default hiprtc header if the app passes --hiprtc-no-builtin-header option. + // This is to avoid conflicts with std type traits defined in hiprtc header. Once the actual fix + // to move type traits to __hip_internal namespace is made in 7.0, this option can be removed. + if (!no_builtin_header) { + compile_options.push_back("-D__HIPCC_RTC__"); + compile_options.push_back("-nogpuinc"); + compile_options.push_back("-include"); + compile_options.push_back("hiprtc_runtime.h"); + } + + compile_options.insert(std::end(compile_options), std::begin(opt), std::end(opt)); + + if (!rtcProgram->compile(compile_options, fgpu_rdc)) { HIPRTC_RETURN(HIPRTC_ERROR_COMPILATION); } diff --git a/hipamd/src/hiprtc/hiprtcInternal.cpp b/hipamd/src/hiprtc/hiprtcInternal.cpp index f2a8e4ea18..b799b98774 100644 --- a/hipamd/src/hiprtc/hiprtcInternal.cpp +++ b/hipamd/src/hiprtc/hiprtcInternal.cpp @@ -184,11 +184,7 @@ RTCCompileProgram::RTCCompileProgram(std::string name_) : RTCProgram(name_), fgp compile_options_.push_back(hipVerMajor); compile_options_.push_back(hipVerMinor); compile_options_.push_back(hipVerPatch); - compile_options_.push_back("-D__HIPCC_RTC__"); - compile_options_.push_back("-include"); - compile_options_.push_back("hiprtc_runtime.h"); compile_options_.push_back("-std=c++14"); - compile_options_.push_back("-nogpuinc"); compile_options_.push_back("-Wno-gnu-line-marker"); compile_options_.push_back("-Wno-missing-prototypes"); #ifdef _WIN32