diff --git a/rocclr/hip_rtc.cpp b/rocclr/hip_rtc.cpp index 3724e375e8..d80a845ec6 100755 --- a/rocclr/hip_rtc.cpp +++ b/rocclr/hip_rtc.cpp @@ -148,20 +148,26 @@ static std::string getValueOf(const std::string& option) { return res; } -static void transformOptions(std::vector& options, amd::Program* program) { +static void transformOptions(std::vector& options, amd::Program* program) { std::vector t_option; for (auto& i : options) { - std::string t_str(i); #ifdef __HIP_ENABLE_PCH // Use precompiled header for hip - if (t_str == "-hip-pch") { + 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"; + continue; } #endif + // Some rtc samples use --gpu-architecture + if (i.rfind("--gpu-architecture=", 0) == 0) { + auto val = getValueOf(i); + i = "--offload-arch=" + val; + continue; + } } } @@ -240,13 +246,23 @@ hiprtcResult hiprtcCompileProgram(hiprtcProgram prog, int numOptions, const char amd::Program* program = as_amd(reinterpret_cast(prog)); std::ostringstream ostrstr; - std::vector oarr(&options[0], &options[numOptions]); + std::vector oarr(&options[0], &options[numOptions]); + + const std::string hipVerOpt{"--hip-version=" + std::to_string(HIP_VERSION_MAJOR) + '.' + + std::to_string(HIP_VERSION_MINOR) + '.' + + std::to_string(HIP_VERSION_PATCH)}; + const std::string hipVerMajor{"-DHIP_VERSION_MAJOR=" + std::to_string(HIP_VERSION_MAJOR)}; + const std::string hipVerMinor{"-DHIP_VERSION_MINOR=" + std::to_string(HIP_VERSION_MINOR)}; + const std::string hipVerPatch{"-DHIP_VERSION_PATCH=" + std::to_string(HIP_VERSION_PATCH)}; + + oarr.push_back(hipVerOpt); + oarr.push_back(hipVerMajor); + oarr.push_back(hipVerMinor); + oarr.push_back(hipVerPatch); + transformOptions(oarr, program); std::copy(oarr.begin(), oarr.end(), std::ostream_iterator(ostrstr, " ")); - ostrstr.str().append(" -DHIP_VERSION_MAJOR=9"); - ostrstr.str().append(" -DHIP_VERSION_MINOR=0"); - std::vector devices{hip::getCurrentDevice()->devices()[0]}; if (CL_SUCCESS != program->build(devices, ostrstr.str().c_str(), nullptr, nullptr)) { HIPRTC_RETURN(HIPRTC_ERROR_COMPILATION);