From e993bf9f47209632a59fb147b36d54f3ccc2999e Mon Sep 17 00:00:00 2001 From: kjayapra-amd Date: Mon, 6 Jul 2020 19:26:40 -0400 Subject: [PATCH] SWDEV-243423 - Avoid repeated metadata processing if the unbundled binary_ptr is same. Change-Id: I71e008021b728dec61187d9ff29483ad8c4cad5c --- rocclr/device/devprogram.cpp | 11 ++++++++--- rocclr/device/devprogram.hpp | 4 +++- rocclr/platform/program.cpp | 12 ++++++++++-- rocclr/platform/program.hpp | 3 ++- 4 files changed, 23 insertions(+), 7 deletions(-) mode change 100644 => 100755 rocclr/device/devprogram.hpp diff --git a/rocclr/device/devprogram.cpp b/rocclr/device/devprogram.cpp index aa986270f3..64387b3dd9 100755 --- a/rocclr/device/devprogram.cpp +++ b/rocclr/device/devprogram.cpp @@ -1978,7 +1978,7 @@ bool Program::initClBinary(const char* binaryIn, size_t size) { } // ================================================================================================ -bool Program::setBinary(const char* binaryIn, size_t size) { +bool Program::setBinary(const char* binaryIn, size_t size, const device::Program* same_dev_prog) { if (!initClBinary(binaryIn, size)) { DevLogError("Init CL Binary failed \n"); return false; @@ -2025,8 +2025,13 @@ bool Program::setBinary(const char* binaryIn, size_t size) { return false; } - clBinary()->loadCompileOptions(compileOptions_); - clBinary()->loadLinkOptions(linkOptions_); + if (same_dev_prog != nullptr) { + compileOptions_ = same_dev_prog->compileOptions(); + linkOptions_ = same_dev_prog->linkOptions(); + } else { + clBinary()->loadCompileOptions(compileOptions_); + clBinary()->loadLinkOptions(linkOptions_); + } clBinary()->resetElfIn(); return true; diff --git a/rocclr/device/devprogram.hpp b/rocclr/device/devprogram.hpp old mode 100644 new mode 100755 index 70b70e56bb..85731857a8 --- a/rocclr/device/devprogram.hpp +++ b/rocclr/device/devprogram.hpp @@ -166,6 +166,8 @@ class Program : public amd::HeapObject { //! Return the compiler options used to build the program. const std::string& compileOptions() const { return compileOptions_; } + const std::string& linkOptions() const { return linkOptions_; } + //! Return the option arg passed in to clCompileProgram(), clLinkProgram(), //! or clBuildProgram(), whichever is called last const std::string lastBuildOptionsArg() const { return lastBuildOptionsArg_; } @@ -191,7 +193,7 @@ class Program : public amd::HeapObject { ClBinary* clBinary() { return clBinary_; } const ClBinary* clBinary() const { return clBinary_; } - bool setBinary(const char* binaryIn, size_t size); + bool setBinary(const char* binaryIn, size_t size, const device::Program* same_dev_prog = nullptr); type_t type() const { return type_; } diff --git a/rocclr/platform/program.cpp b/rocclr/platform/program.cpp index eb96efc76e..a498d0fac7 100755 --- a/rocclr/platform/program.cpp +++ b/rocclr/platform/program.cpp @@ -86,7 +86,8 @@ const Symbol* Program::findSymbol(const char* kernelName) const { } int32_t Program::addDeviceProgram(Device& device, const void* image, size_t length, - bool make_copy, amd::option::Options* options) { + bool make_copy, amd::option::Options* options, + const amd::Program* same_prog) { if (image != NULL && !amd::isElfMagic((const char*)image)) { if (device.settings().useLightning_) { return CL_INVALID_BINARY; @@ -175,7 +176,14 @@ int32_t Program::addDeviceProgram(Device& device, const void* image, size_t leng binary_[&rootDev] = std::make_tuple(memory, length, make_copy); } - if (!program->setBinary(reinterpret_cast(memory), length)) { + const device::Program* same_dev_prog = nullptr; + if ((amd::IS_HIP) && (same_prog != nullptr)) { + auto same_dev_prog_map_ = same_prog->devicePrograms(); + guarantee(same_dev_prog_map_.size() == 1); + same_dev_prog = same_dev_prog_map_.begin()->second; + } + + if (!program->setBinary(reinterpret_cast(memory), length, same_dev_prog)) { delete program; return CL_INVALID_BINARY; } diff --git a/rocclr/platform/program.hpp b/rocclr/platform/program.hpp index 68bd72c2e3..ce6b6ba72e 100755 --- a/rocclr/platform/program.hpp +++ b/rocclr/platform/program.hpp @@ -175,7 +175,8 @@ class Program : public RuntimeObject { //! Add a new device program with or without binary image and options. int32_t addDeviceProgram(Device&, const void* image = NULL, size_t len = 0, - bool make_copy = true, amd::option::Options* options = NULL); + bool make_copy = true, amd::option::Options* options = NULL, + const amd::Program* same_prog = nullptr); //! Find the section for the given device. Return NULL if not found. device::Program* getDeviceProgram(const Device& device) const;