diff --git a/projects/clr/hipamd/CMakeLists.txt b/projects/clr/hipamd/CMakeLists.txt index 3eedf35b09..3a77735865 100644 --- a/projects/clr/hipamd/CMakeLists.txt +++ b/projects/clr/hipamd/CMakeLists.txt @@ -336,9 +336,9 @@ if(HIP_PLATFORM STREQUAL "hcc") target_link_libraries(hip_hcc_static PRIVATE hc_am) add_library(hiprtc SHARED src/hiprtc.cpp src/code_object_bundle.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}" ) - target_include_directories( hiprtc SYSTEM PRIVATE ${PROJECT_SOURCE_DIR}/include ${HSA_PATH}/include) diff --git a/projects/clr/hipamd/include/hip/hcc_detail/code_object_bundle.hpp b/projects/clr/hipamd/include/hip/hcc_detail/code_object_bundle.hpp index f312d2e79b..77e0d706d6 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/code_object_bundle.hpp +++ b/projects/clr/hipamd/include/hip/hcc_detail/code_object_bundle.hpp @@ -31,9 +31,11 @@ THE SOFTWARE. #include #include #include - +#include namespace hip_impl { - +#if !defined(DISABLE_REDUCED_GPU_BLOB_COPY) +std::unordered_set& get_all_gpuarch(); +#endif inline std::string transmogrify_triple(const std::string& triple) { @@ -43,7 +45,6 @@ std::string transmogrify_triple(const std::string& triple) if (triple.find(old_prefix) == 0) { return new_prefix + triple.substr(sizeof(old_prefix) - 1); } - return (triple.find(new_prefix) == 0) ? triple : ""; } @@ -114,9 +115,7 @@ class Bundled_code_header { friend inline bool read(RandomAccessIterator f, RandomAccessIterator l, Bundled_code_header& x) { if (f == l) return false; - std::copy_n(f, sizeof(x.header_.cbuf_), x.header_.cbuf_); - if (valid(x)) { x.bundles_.resize(x.header_.bundle_cnt_); @@ -126,11 +125,16 @@ class Bundled_code_header { it += sizeof(y.header.cbuf); y.triple.assign(it, it + y.header.triple_sz); - + #ifdef DISABLE_REDUCED_GPU_BLOB_COPY std::copy_n(f + y.header.offset, y.header.bundle_sz, std::back_inserter(y.blob)); - + #else + auto& gpuArch = get_all_gpuarch(); + auto itgpuArch = std::find(gpuArch.begin(),gpuArch.end(),y.triple); + if (itgpuArch != gpuArch.end()){ + std::copy_n(f + y.header.offset, y.header.bundle_sz, std::back_inserter(y.blob)); + } + #endif it += y.header.triple_sz; - x.bundled_code_size = std::max(x.bundled_code_size, y.header.offset + y.header.bundle_sz); } diff --git a/projects/clr/hipamd/lpl_ca/CMakeLists.txt b/projects/clr/hipamd/lpl_ca/CMakeLists.txt index b36d73bbcb..ac01a6a0ab 100644 --- a/projects/clr/hipamd/lpl_ca/CMakeLists.txt +++ b/projects/clr/hipamd/lpl_ca/CMakeLists.txt @@ -26,7 +26,7 @@ target_include_directories(ca PUBLIC ${PROJECT_SOURCE_DIR}/src) find_library( hsart NAMES libhsa-runtime64.so libhsa-runtime64.so.1 HINTS ${HSA_PATH}/lib) target_link_libraries(ca PUBLIC ${hsart}) -target_compile_options(ca PUBLIC -Wall) +target_compile_options(ca PUBLIC -DDISABLE_REDUCED_GPU_BLOB_COPY -Wall) install(TARGETS ca RUNTIME DESTINATION bin) -#-------------------------------------CA---------------------------------------# \ No newline at end of file +#-------------------------------------CA---------------------------------------# diff --git a/projects/clr/hipamd/src/hip_hcc.cpp b/projects/clr/hipamd/src/hip_hcc.cpp index 85c08943bf..af40b29ea9 100644 --- a/projects/clr/hipamd/src/hip_hcc.cpp +++ b/projects/clr/hipamd/src/hip_hcc.cpp @@ -39,6 +39,7 @@ THE SOFTWARE. #include #include #include +#include #include #include @@ -2542,6 +2543,16 @@ hipError_t hipHccGetAcceleratorView(hipStream_t stream, hc::accelerator_view** a // TODO - add a contect sequence number for debug. Print operator<< ctx:0.1 (device.ctx) namespace hip_impl { + std::unordered_set& get_all_gpuarch() { + static std::unordered_set r{}; + static std::once_flag init; + std::call_once(init, []() { + for (int i=0; i < g_deviceCnt; i++){ + r.insert("hcc-amdgcn-amd-amdhsa--gfx"+std::to_string(g_deviceArray[i]->_props.gcnArch)); + }}); + return r; + } + std::vector all_hsa_agents() { std::vector r{}; std::vector visible_accelerators; diff --git a/projects/clr/hipamd/src/program_state.inl b/projects/clr/hipamd/src/program_state.inl index 272addd053..3581dea229 100644 --- a/projects/clr/hipamd/src/program_state.inl +++ b/projects/clr/hipamd/src/program_state.inl @@ -244,7 +244,8 @@ public: if (!valid(tmp)) break; for (auto&& bundle : bundles(tmp)) { - impl.code_object_blobs.second[elf][triple_to_hsa_isa(bundle.triple)].push_back(bundle.blob); + if(bundle.blob.size()) + impl.code_object_blobs.second[elf][triple_to_hsa_isa(bundle.triple)].push_back(bundle.blob); } blob_it += tmp.bundled_code_size;