From 824ee1aa72c8fcd5d13a66d88668d56ca8316cf1 Mon Sep 17 00:00:00 2001 From: Siu Chi Chan Date: Sat, 9 Mar 2019 14:21:11 -0500 Subject: [PATCH] move triple_to_hsa_isa into the header --- include/hip/hcc_detail/code_object_bundle.hpp | 60 ++++++++++++++++++- src/code_object_bundle.cpp | 54 ----------------- 2 files changed, 59 insertions(+), 55 deletions(-) diff --git a/include/hip/hcc_detail/code_object_bundle.hpp b/include/hip/hcc_detail/code_object_bundle.hpp index 7b97503c16..67154026ef 100644 --- a/include/hip/hcc_detail/code_object_bundle.hpp +++ b/include/hip/hcc_detail/code_object_bundle.hpp @@ -33,7 +33,65 @@ THE SOFTWARE. #include namespace hip_impl { -hsa_isa_t triple_to_hsa_isa(const std::string& triple); + +inline +__attribute__((visibility("hidden"))) +std::string transmogrify_triple(const std::string& triple) +{ + static constexpr const char old_prefix[]{"hcc-amdgcn--amdhsa-gfx"}; + static constexpr const char new_prefix[]{"hcc-amdgcn-amd-amdhsa--gfx"}; + + if (triple.find(old_prefix) == 0) { + return new_prefix + triple.substr(sizeof(old_prefix) - 1); + } + + return (triple.find(new_prefix) == 0) ? triple : ""; +} + +inline +__attribute__((visibility("hidden"))) +std::string isa_name(std::string triple) +{ + static constexpr const char offload_prefix[]{"hcc-"}; + + triple = transmogrify_triple(triple); + if (triple.empty()) return {}; + + triple.erase(0, sizeof(offload_prefix) - 1); + + static hsa_isa_t tmp{}; + static const bool is_old_rocr{ + hsa_isa_from_name(triple.c_str(), &tmp) != HSA_STATUS_SUCCESS}; + + if (is_old_rocr) { + std::string tmp{triple.substr(triple.rfind('x') + 1)}; + triple.replace(0, std::string::npos, "AMD:AMDGPU"); + + for (auto&& x : tmp) { + triple.push_back(':'); + triple.push_back(x); + } + } + + return triple; +} + +inline +__attribute__((visibility("hidden"))) +hsa_isa_t triple_to_hsa_isa(const std::string& triple) { + const std::string isa{isa_name(std::move(triple))}; + + if (isa.empty()) return hsa_isa_t({}); + + hsa_isa_t r{}; + + if(HSA_STATUS_SUCCESS != hsa_isa_from_name(isa.c_str(), &r)) { + r.handle = 0; + } + + return r; +} + struct Bundled_code { union Header { diff --git a/src/code_object_bundle.cpp b/src/code_object_bundle.cpp index 91258f0c75..6285cb3828 100644 --- a/src/code_object_bundle.cpp +++ b/src/code_object_bundle.cpp @@ -10,60 +10,6 @@ using namespace std; -inline -std::string transmogrify_triple(const std::string& triple) -{ - static constexpr const char old_prefix[]{"hcc-amdgcn--amdhsa-gfx"}; - static constexpr const char new_prefix[]{"hcc-amdgcn-amd-amdhsa--gfx"}; - - if (triple.find(old_prefix) == 0) { - return new_prefix + triple.substr(sizeof(old_prefix) - 1); - } - - return (triple.find(new_prefix) == 0) ? triple : ""; -} - -inline -std::string isa_name(std::string triple) -{ - static constexpr const char offload_prefix[]{"hcc-"}; - - triple = transmogrify_triple(triple); - if (triple.empty()) return {}; - - triple.erase(0, sizeof(offload_prefix) - 1); - - static hsa_isa_t tmp{}; - static const bool is_old_rocr{ - hsa_isa_from_name(triple.c_str(), &tmp) != HSA_STATUS_SUCCESS}; - - if (is_old_rocr) { - std::string tmp{triple.substr(triple.rfind('x') + 1)}; - triple.replace(0, std::string::npos, "AMD:AMDGPU"); - - for (auto&& x : tmp) { - triple.push_back(':'); - triple.push_back(x); - } - } - - return triple; -} - -hsa_isa_t hip_impl::triple_to_hsa_isa(const std::string& triple) { - const std::string isa{isa_name(std::move(triple))}; - - if (isa.empty()) return hsa_isa_t({}); - - hsa_isa_t r{}; - - if(HSA_STATUS_SUCCESS != hsa_isa_from_name(isa.c_str(), &r)) { - r.handle = 0; - } - - return r; -} - // DATA - STATICS constexpr const char hip_impl::Bundled_code_header::magic_string_[];