From 7ce37f3a085808aaf43713f98d423f397ba11805 Mon Sep 17 00:00:00 2001 From: Siu Chi Chan Date: Thu, 18 Oct 2018 16:53:03 -0400 Subject: [PATCH] Support more than one bundles in a single .kernel section When compiling with Early Finalization enabled in HCC, the resulting .kernel section of the host object now may contain more than one device code bundles. This is to teach the HIP runtime to correctly extract all the bundles from the .kernel section. [ROCm/hip commit: 30ce25e62796c8defaa456e5e7f9b4649537f5db] --- .../include/hip/hcc_detail/code_object_bundle.hpp | 5 +++++ projects/hip/src/program_state.cpp | 14 ++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/projects/hip/include/hip/hcc_detail/code_object_bundle.hpp b/projects/hip/include/hip/hcc_detail/code_object_bundle.hpp index c36dd91813..7b97503c16 100644 --- a/projects/hip/include/hip/hcc_detail/code_object_bundle.hpp +++ b/projects/hip/include/hip/hcc_detail/code_object_bundle.hpp @@ -84,6 +84,9 @@ class Bundled_code_header { std::copy_n(f + y.header.offset, y.header.bundle_sz, std::back_inserter(y.blob)); it += y.header.triple_sz; + + x.bundled_code_size = std::max(x.bundled_code_size, + y.header.offset + y.header.bundle_sz); } return true; @@ -123,6 +126,8 @@ class Bundled_code_header { // MANIPULATORS Bundled_code_header& operator=(const Bundled_code_header&) = default; Bundled_code_header& operator=(Bundled_code_header&&) = default; + + size_t bundled_code_size = 0; }; // CREATORS diff --git a/projects/hip/src/program_state.cpp b/projects/hip/src/program_state.cpp index 8766134582..88cdeeb404 100644 --- a/projects/hip/src/program_state.cpp +++ b/projects/hip/src/program_state.cpp @@ -209,10 +209,16 @@ const unordered_map>>& code_object_blobs(bool reb nullptr); for (auto&& blob : blobs) { - Bundled_code_header tmp{blob}; - if (valid(tmp)) { - for (auto&& bundle : bundles(tmp)) { - r[triple_to_hsa_isa(bundle.triple)].push_back(bundle.blob); + for (auto sub_blob = blob.begin(); sub_blob != blob.end(); ) { + Bundled_code_header tmp(sub_blob, blob.end()); + if (valid(tmp)) { + for (auto&& bundle : bundles(tmp)) { + r[triple_to_hsa_isa(bundle.triple)].push_back(bundle.blob); + } + sub_blob+=tmp.bundled_code_size; + } + else { + break; } } }