Reduce GPU copying based on arch it runs on (#1751)

Implements SWDEV-213230.

[ROCm/clr commit: 888a7f2a90]
このコミットが含まれているのは:
ansurya
2020-02-13 14:21:51 +05:30
committed by GitHub
コミット 708af7e6ac
5個のファイルの変更28行の追加12行の削除
+1 -1
ファイルの表示
@@ -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)
+12 -8
ファイルの表示
@@ -31,9 +31,11 @@ THE SOFTWARE.
#include <string>
#include <utility>
#include <vector>
#include <unordered_set>
namespace hip_impl {
#if !defined(DISABLE_REDUCED_GPU_BLOB_COPY)
std::unordered_set<std::string>& 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);
}
+2 -2
ファイルの表示
@@ -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---------------------------------------#
#-------------------------------------CA---------------------------------------#
+11
ファイルの表示
@@ -39,6 +39,7 @@ THE SOFTWARE.
#include <algorithm>
#include <atomic>
#include <mutex>
#include <unordered_set>
#include <hc.hpp>
#include <hc_am.hpp>
@@ -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<std::string>& get_all_gpuarch() {
static std::unordered_set<std::string> 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<hsa_agent_t> all_hsa_agents() {
std::vector<hsa_agent_t> r{};
std::vector<hc::accelerator> visible_accelerators;
+2 -1
ファイルの表示
@@ -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;