From 36f69cbf7613e971d454190e9bbbc505a30fd702 Mon Sep 17 00:00:00 2001 From: foreman Date: Tue, 23 Jul 2019 20:09:59 -0400 Subject: [PATCH] P4 to Git Change 1972494 by kjayapra@0_HIPWS_P2P1_ROCM on 2019/07/23 20:01:13 SWDEV-144570 - Handling variable register during hipModuleLoad. Affected files ... ... //depot/stg/opencl/drivers/opencl/api/hip/hip_internal.hpp#31 edit ... //depot/stg/opencl/drivers/opencl/api/hip/hip_module.cpp#30 edit ... //depot/stg/opencl/drivers/opencl/api/hip/hip_platform.cpp#34 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/devprogram.cpp#51 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/devprogram.hpp#30 edit --- rocclr/runtime/device/devprogram.cpp | 63 ++++++++++++++++++++++++++++ rocclr/runtime/device/devprogram.hpp | 2 + 2 files changed, 65 insertions(+) diff --git a/rocclr/runtime/device/devprogram.cpp b/rocclr/runtime/device/devprogram.cpp index 60ce4282fc..52237835d4 100644 --- a/rocclr/runtime/device/devprogram.cpp +++ b/rocclr/runtime/device/devprogram.cpp @@ -3097,4 +3097,67 @@ bool Program::FindGlobalVarSize(void* binary, size_t binSize) { #endif // defined(WITH_LIGHTNING_COMPILER) || defined(USE_COMGR_LIBRARY) return true; } + +amd_comgr_status_t getSymbolFromModule(amd_comgr_symbol_t symbol, void* userData) { + size_t nlen; + amd_comgr_status_t status; + amd_comgr_symbol_type_t type; + std::vector* var_names = reinterpret_cast*>(userData); + + /* Retrieve the symbol info */ + status = amd::Comgr::symbol_get_info(symbol, AMD_COMGR_SYMBOL_INFO_NAME_LENGTH, &nlen); + if (status != AMD_COMGR_STATUS_SUCCESS) { + return status; + } + + /* Retrieve the symbol name */ + char* name = new char[nlen + 1]; + status = amd::Comgr::symbol_get_info(symbol, AMD_COMGR_SYMBOL_INFO_NAME, name); + if (status != AMD_COMGR_STATUS_SUCCESS) { + return status; + } + + /* Retrieve the symbol type*/ + status = amd::Comgr::symbol_get_info(symbol, AMD_COMGR_SYMBOL_INFO_TYPE, &type); + if (status != AMD_COMGR_STATUS_SUCCESS) { + return status; + } + + /* If symbol type is object(Variable) add it to vector */ + if (type == AMD_COMGR_SYMBOL_TYPE_OBJECT) { + var_names->push_back(std::string(name)); + } + + delete[] name; + return status; +} + +bool Program::getGlobalSymbolsFromCodeObj(std::vector* var_names) const { + amd_comgr_status_t status = AMD_COMGR_STATUS_SUCCESS; + amd_comgr_data_t dataObject; + + /* Create comgr data */ + status = amd::Comgr::create_data(AMD_COMGR_DATA_KIND_EXECUTABLE, &dataObject); + if (status != AMD_COMGR_STATUS_SUCCESS) { + buildLog_ += "COMGR: Cannot create comgr data \n"; + return false; + } + + /* Set the binary as a dataObject */ + status = amd::Comgr::set_data(dataObject,static_cast(clBinary_->data().second), + reinterpret_cast(clBinary_->data().first)); + if (status != AMD_COMGR_STATUS_SUCCESS) { + buildLog_ += "COMGR: Cannot set comgr data \n"; + return false; + } + + /* Iterate through list of symbols */ + status = amd::Comgr::iterate_symbols(dataObject, getSymbolFromModule, var_names); + if (status != AMD_COMGR_STATUS_SUCCESS) { + buildLog_ += "COMGR: Cannot iterate comgr symbols \n"; + return false; + } + + return true; +} } diff --git a/rocclr/runtime/device/devprogram.hpp b/rocclr/runtime/device/devprogram.hpp index 68de7babb1..31b6086621 100644 --- a/rocclr/runtime/device/devprogram.hpp +++ b/rocclr/runtime/device/devprogram.hpp @@ -228,6 +228,8 @@ class Program : public amd::HeapObject { //! Check if SRAM ECC is enable const bool sramEccEnable() const { return (sramEccEnabled_ == 1); } + virtual bool getGlobalSymbolsFromCodeObj(std::vector* var_names) const; + virtual bool createGlobalVarObj(amd::Memory** amd_mem_obj, void** dptr, size_t* bytes, const char* globalName) const { ShouldNotReachHere();