diff --git a/CMakeLists.txt b/CMakeLists.txt index 4894168348..0cfa56ac9d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -259,7 +259,6 @@ if(HIP_PLATFORM STREQUAL "hcc") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${HIP_HCC_BUILD_FLAGS}") set(SOURCE_FILES_RUNTIME - src/code_object_bundle.cpp src/program_state.cpp src/hip_clang.cpp src/hip_hcc.cpp @@ -305,7 +304,7 @@ if(HIP_PLATFORM STREQUAL "hcc") target_link_libraries(hip_hcc PRIVATE hc_am) target_link_libraries(hip_hcc_static PRIVATE hc_am) - add_library(hiprtc SHARED src/hiprtc.cpp src/code_object_bundle.cpp) + add_library(hiprtc SHARED src/hiprtc.cpp) target_compile_options(hiprtc PRIVATE -DDISABLE_REDUCED_GPU_BLOB_COPY) set_property ( TARGET hiprtc PROPERTY VERSION "${HIP_LIB_VERSION_STRING}" ) set_property ( TARGET hiprtc PROPERTY SOVERSION "${HIP_LIB_VERSION_MAJOR}" ) @@ -315,6 +314,9 @@ if(HIP_PLATFORM STREQUAL "hcc") endif() set_target_properties(hip_hcc PROPERTIES CXX_VISIBILITY_PRESET hidden) set_target_properties(hip_hcc PROPERTIES VISIBILITY_INLINES_HIDDEN 1) + set_target_properties(hiprtc PROPERTIES CXX_VISIBILITY_PRESET hidden) + set_target_properties(hiprtc PROPERTIES VISIBILITY_INLINES_HIDDEN 1) + if(HIP_PLATFORM STREQUAL "hcc") find_package(amd_comgr REQUIRED CONFIG diff --git a/include/hip/hcc_detail/hiprtc.h b/include/hip/hcc_detail/hiprtc.h index 624f1ea157..ec9c85716a 100644 --- a/include/hip/hcc_detail/hiprtc.h +++ b/include/hip/hcc_detail/hiprtc.h @@ -28,6 +28,8 @@ extern "C" { #include +#pragma GCC visibility push (default) + enum hiprtcResult { HIPRTC_SUCCESS = 0, HIPRTC_ERROR_OUT_OF_MEMORY = 1, @@ -79,6 +81,8 @@ hiprtcResult hiprtcGetCode(hiprtcProgram prog, char* code); hiprtcResult hiprtcGetCodeSize(hiprtcProgram prog, size_t* codeSizeRet); +#pragma GCC visibility pop + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/lpl_ca/CMakeLists.txt b/lpl_ca/CMakeLists.txt index ac01a6a0ab..f626b88d89 100644 --- a/lpl_ca/CMakeLists.txt +++ b/lpl_ca/CMakeLists.txt @@ -14,7 +14,7 @@ install(TARGETS lpl RUNTIME DESTINATION bin) #-------------------------------------LPL--------------------------------------# #-------------------------------------CA---------------------------------------# -add_executable(ca ca.cpp ${PROJECT_SOURCE_DIR}/src/code_object_bundle.cpp) +add_executable(ca ca.cpp) set_target_properties( ca PROPERTIES CXX_STANDARD 11 diff --git a/lpl_ca/ca.hpp b/lpl_ca/ca.hpp index db63f02498..2d691cd38a 100644 --- a/lpl_ca/ca.hpp +++ b/lpl_ca/ca.hpp @@ -2,7 +2,7 @@ #include "common.hpp" -#include "../include/hip/hcc_detail/code_object_bundle.hpp" +#include "../src/code_object_bundle.inl" #include "clara/clara.hpp" diff --git a/src/code_object_bundle.cpp b/src/code_object_bundle.cpp deleted file mode 100644 index feef90a61a..0000000000 --- a/src/code_object_bundle.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include "../include/hip/hcc_detail/code_object_bundle.hpp" - -#include - -#include -#include -#include -#include -#include - -using namespace std; - -// CREATORS -hip_impl::Bundled_code_header::Bundled_code_header(const vector& x) - : Bundled_code_header{x.cbegin(), x.cend()} {} - -hip_impl::Bundled_code_header::Bundled_code_header( - const void* p) { // This is a pretty terrible interface, useful only because - // hipLoadModuleData is so poorly specified (for no fault of its own). - if (!p) return; - - if (!valid(*static_cast(p))) return; - auto ph = static_cast(p); - - size_t sz = sizeof(Header_) + ph->bundle_cnt_ * sizeof(Bundled_code::Header); - auto pb = static_cast(p) + sizeof(Header_); - auto n = ph->bundle_cnt_; - while (n--) { - sz += reinterpret_cast(pb)->bundle_sz; - pb += sizeof(Bundled_code::Header); - } - - read(static_cast(p), static_cast(p) + sz, *this); -} diff --git a/include/hip/hcc_detail/code_object_bundle.hpp b/src/code_object_bundle.inl similarity index 86% rename from include/hip/hcc_detail/code_object_bundle.hpp rename to src/code_object_bundle.inl index 77e0d706d6..596ac60661 100644 --- a/include/hip/hcc_detail/code_object_bundle.hpp +++ b/src/code_object_bundle.inl @@ -92,10 +92,6 @@ struct Bundled_code { #define magic_string_ "__CLANG_OFFLOAD_BUNDLE__" -#ifdef __GNUC__ -#pragma GCC visibility push (default) -#endif - class Bundled_code_header { // DATA - STATICS static constexpr auto magic_string_sz_ = sizeof(magic_string_) - 1; @@ -167,8 +163,26 @@ class Bundled_code_header { Bundled_code_header() = default; template Bundled_code_header(RandomAccessIterator f, RandomAccessIterator l); - explicit Bundled_code_header(const std::vector& blob); - explicit Bundled_code_header(const void* maybe_blob); + explicit Bundled_code_header(const std::vector& blob) + : Bundled_code_header{blob.cbegin(), blob.cend()} {} + explicit Bundled_code_header(const void* maybe_blob) { + // This is a pretty terrible interface, useful only because + // hipLoadModuleData is so poorly specified (for no fault of its own). + if (!maybe_blob) return; + + if (!valid(*static_cast(maybe_blob))) return; + auto ph = static_cast(maybe_blob); + + size_t sz = sizeof(Header_) + ph->bundle_cnt_ * sizeof(Bundled_code::Header); + auto pb = static_cast(maybe_blob) + sizeof(Header_); + auto n = ph->bundle_cnt_; + while (n--) { + sz += reinterpret_cast(pb)->bundle_sz; + pb += sizeof(Bundled_code::Header); + } + + read(static_cast(maybe_blob), static_cast(maybe_blob) + sz, *this); + } Bundled_code_header(const Bundled_code_header&) = default; Bundled_code_header(Bundled_code_header&&) = default; ~Bundled_code_header() = default; @@ -180,10 +194,6 @@ class Bundled_code_header { size_t bundled_code_size = 0; }; -#ifdef __GNUC__ -#pragma GCC visibility pop -#endif - // CREATORS template Bundled_code_header::Bundled_code_header(RandomAccessIterator f, RandomAccessIterator l) diff --git a/src/hip_module.cpp b/src/hip_module.cpp index 116c4ff94c..2d4fde7c26 100644 --- a/src/hip_module.cpp +++ b/src/hip_module.cpp @@ -50,7 +50,7 @@ THE SOFTWARE. #include #include #include -#include "../include/hip/hcc_detail/code_object_bundle.hpp" +#include "code_object_bundle.inl" #include "hip_fatbin.h" // TODO Use Pool APIs from HCC to get memory regions. diff --git a/src/hiprtc.cpp b/src/hiprtc.cpp index 3c7fe6e78c..4efdbad653 100644 --- a/src/hiprtc.cpp +++ b/src/hiprtc.cpp @@ -21,7 +21,7 @@ THE SOFTWARE. */ #include "../include/hip/hiprtc.h" -#include "../include/hip/hcc_detail/code_object_bundle.hpp" +#include "code_object_bundle.inl" #include "../include/hip/hcc_detail/elfio/elfio.hpp" #include "../include/hip/hcc_detail/program_state.hpp" diff --git a/src/program_state.inl b/src/program_state.inl index bdf127c9c5..c62b8f4061 100644 --- a/src/program_state.inl +++ b/src/program_state.inl @@ -1,6 +1,6 @@ #include "../include/hip/hcc_detail/program_state.hpp" -#include "../include/hip/hcc_detail/code_object_bundle.hpp" +#include "code_object_bundle.inl" #include "../include/hip/hcc_detail/hsa_helpers.hpp" #if !defined(__cpp_exceptions)