From 45fb4ac8f609e8dec777025f5ee19485efd222b6 Mon Sep 17 00:00:00 2001 From: foreman Date: Thu, 13 Sep 2018 19:25:30 -0400 Subject: [PATCH] P4 to Git Change 1605680 by gandryey@gera-ocl-lc on 2018/09/13 19:07:27 SWDEV-79445 - OCL generic changes and code clean-up - Fix test_basic progvar_prog_scope_uninit with LC. Detect global variables usage in the program and add the code object allocation to the memory dependency tracking Affected files ... ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palprogram.cpp#70 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palprogram.hpp#27 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palvirtual.cpp#123 edit --- rocclr/runtime/device/pal/palprogram.cpp | 42 ++++++++++++++++++++++-- rocclr/runtime/device/pal/palprogram.hpp | 8 +++-- rocclr/runtime/device/pal/palvirtual.cpp | 9 +++-- 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/rocclr/runtime/device/pal/palprogram.cpp b/rocclr/runtime/device/pal/palprogram.cpp index 0417ba3279..f1b920c257 100644 --- a/rocclr/runtime/device/pal/palprogram.cpp +++ b/rocclr/runtime/device/pal/palprogram.cpp @@ -999,7 +999,36 @@ static hsa_status_t GetKernelNamesCallback(hsa_executable_t hExec, hsa_executabl return HSA_STATUS_ERROR; } - char* name = (char*)alloca(length + 1); + char* name = reinterpret_cast(alloca(length + 1)); + if (!symbol->GetInfo(HSA_EXECUTABLE_SYMBOL_INFO_NAME, name)) { + return HSA_STATUS_ERROR; + } + name[length] = '\0'; + + symbolNameList->push_back(std::string(name)); + } + return HSA_STATUS_SUCCESS; +} + +static hsa_status_t GetGlobalVarNamesCallback( + hsa_executable_t hExec, hsa_executable_symbol_t hSymbol, + void* data) { + auto symbol = Symbol::Object(hSymbol); + auto symbolNameList = reinterpret_cast*>(data); + + hsa_symbol_kind_t type; + if (!symbol->GetInfo(HSA_CODE_SYMBOL_INFO_TYPE, &type)) { + return HSA_STATUS_ERROR; + } + + if (type == HSA_SYMBOL_KIND_VARIABLE) { + // VariableSymbol* vsym = symbol; // Casting to the variable structure + uint32_t length; + if (!symbol->GetInfo(HSA_EXECUTABLE_SYMBOL_INFO_NAME_LENGTH, &length)) { + return HSA_STATUS_ERROR; + } + + char* name = reinterpret_cast(alloca(length + 1)); if (!symbol->GetInfo(HSA_EXECUTABLE_SYMBOL_INFO_NAME, name)) { return HSA_STATUS_ERROR; } @@ -1530,7 +1559,7 @@ bool LightningProgram::setKernels(amd::option::Options* options, void* binary, s // Get the list of kernels std::vector kernelNameList; - status = executable_->IterateSymbols(GetKernelNamesCallback, (void*)&kernelNameList); + status = executable_->IterateSymbols(GetKernelNamesCallback, &kernelNameList); if (status != HSA_STATUS_SUCCESS) { buildLog_ += "Error: Failed to get kernel names\n"; return false; @@ -1568,6 +1597,15 @@ bool LightningProgram::setKernels(amd::option::Options* options, void* binary, s return false; } + // Get the list of global variables + std::vector glbVarNames; + status = executable_->IterateSymbols(GetGlobalVarNamesCallback, &glbVarNames); + if (status != HSA_STATUS_SUCCESS) { + buildLog_ += "Error: Failed to get kernel names\n"; + return false; + } + globalVars_ = (glbVarNames.size() != 0) ? true : false; + DestroySegmentCpuAccess(); // Save the binary and type diff --git a/rocclr/runtime/device/pal/palprogram.hpp b/rocclr/runtime/device/pal/palprogram.hpp index a6e718c807..e7046e285c 100644 --- a/rocclr/runtime/device/pal/palprogram.hpp +++ b/rocclr/runtime/device/pal/palprogram.hpp @@ -178,6 +178,9 @@ class HSAILProgram : public device::Program { return loader_->FindHostAddress(devAddr); } + //! Global variables are a part of the code segment + bool GlobalVariables() const { return globalVars_; } + protected: //! pre-compile setup for GPU virtual bool initBuild(amd::option::Options* options); @@ -252,8 +255,9 @@ class HSAILProgram : public device::Program { std::list staticSamplers_; //!< List od internal static samplers union { struct { - uint32_t isNull_ : 1; //!< Null program no memory allocations - uint32_t internal_ : 1; //!< Internal blit program + uint32_t isNull_ : 1; //!< Null program no memory allocations + uint32_t internal_ : 1; //!< Internal blit program + uint32_t globalVars_ : 1; //!< Code object contains global variables }; uint32_t flags_; //!< Program flags }; diff --git a/rocclr/runtime/device/pal/palvirtual.cpp b/rocclr/runtime/device/pal/palvirtual.cpp index d757c2b877..2a40468b6c 100644 --- a/rocclr/runtime/device/pal/palvirtual.cpp +++ b/rocclr/runtime/device/pal/palvirtual.cpp @@ -3227,14 +3227,17 @@ bool VirtualGPU::processMemObjectsHSA(const amd::Kernel& kernel, const_address p dev().srds().fillResourceList(*this); } - addVmMemory(&hsaKernel.prog().codeSegGpu()); - + const static bool IsReadOnly = false; for (const pal::Memory* mem : hsaKernel.prog().globalStores()) { - const static bool IsReadOnly = false; // Validate global store for a dependency in the queue memoryDependency().validate(*this, mem, IsReadOnly); addVmMemory(mem); } + if (hsaKernel.prog().GlobalVariables()) { + // Validate code object for a dependency in the queue + memoryDependency().validate(*this, &hsaKernel.prog().codeSegGpu(), IsReadOnly); + } + addVmMemory(&hsaKernel.prog().codeSegGpu()); return true; }