diff --git a/rocclr/runtime/device/rocm/rockernel.hpp b/rocclr/runtime/device/rocm/rockernel.hpp index 96455a2f0f..7ca68edb98 100644 --- a/rocclr/runtime/device/rocm/rockernel.hpp +++ b/rocclr/runtime/device/rocm/rockernel.hpp @@ -128,7 +128,7 @@ public: bool init_LC(); #endif // defined(WITH_LIGHTNING_COMPILER) - const HSAILProgram* program() { + const HSAILProgram* program() const { return static_cast(program_); } diff --git a/rocclr/runtime/device/rocm/rocprogram.cpp b/rocclr/runtime/device/rocm/rocprogram.cpp index bf66c20e82..c09c5faa80 100644 --- a/rocclr/runtime/device/rocm/rocprogram.cpp +++ b/rocclr/runtime/device/rocm/rocprogram.cpp @@ -109,6 +109,8 @@ HSAILProgram::HSAILProgram(roc::NullDevice& device) hsaProgramHandle_.handle = 0; hsaExecutable_.handle = 0; + hasGlobalStores_ = false; + #if defined(WITH_LIGHTNING_COMPILER) metadata_ = NULL; #endif // defined(WITH_LIGHTNING_COMPILER) @@ -886,6 +888,8 @@ HSAILProgram::setKernels_LC(amd::option::Options *options, void* binary, size_t } size_t progvarsTotalSize = 0; + size_t dynamicSize = 0; + size_t progvarsWriteSize = 0; // Begin the Elf image from memory Elf* e = elf_memory((char*) binary, binSize, NULL); @@ -936,9 +940,16 @@ HSAILProgram::setKernels_LC(amd::option::Options *options, void* binary, size_t } } // Accumulate the size of R & !X loadable segments - else if (pHdr.p_type == PT_LOAD - && (pHdr.p_flags & PF_R) && !(pHdr.p_flags & PF_X)) { - progvarsTotalSize += pHdr.p_memsz; + else if (pHdr.p_type == PT_LOAD && !(pHdr.p_flags & PF_X)) { + if (pHdr.p_flags & PF_R) { + progvarsTotalSize += pHdr.p_memsz; + } + if (pHdr.p_flags & PF_W) { + progvarsWriteSize += pHdr.p_memsz; + } + } + else if (pHdr.p_type == PT_DYNAMIC) { + dynamicSize += pHdr.p_memsz; } } @@ -950,6 +961,10 @@ HSAILProgram::setKernels_LC(amd::option::Options *options, void* binary, size_t return false; } + if (progvarsWriteSize != dynamicSize) { + hasGlobalStores_ = true; + } + progvarsTotalSize -= dynamicSize; setGlobalVariableTotalSize(progvarsTotalSize); saveBinaryAndSetType(TYPE_EXECUTABLE, binary, binSize); @@ -1037,6 +1052,11 @@ HSAILProgram::setKernels_LC(amd::option::Options *options, void* binary, size_t return false; } + // FIME_lmoriche: the compiler should set the kernarg alignment based + // on the alignment requirement of the parameters. For now, bump it to + // the worse case: 128byte aligned. + kernargSegmentAlignment = std::max(kernargSegmentAlignment, 128u); + Kernel *aKernel = new roc::Kernel( kernelName, this, diff --git a/rocclr/runtime/device/rocm/rocprogram.hpp b/rocclr/runtime/device/rocm/rocprogram.hpp index 02cc1193bb..d273a982cc 100644 --- a/rocclr/runtime/device/rocm/rocprogram.hpp +++ b/rocclr/runtime/device/rocm/rocprogram.hpp @@ -58,6 +58,8 @@ public: return dev().getBackendDevice(); } + bool hasGlobalStores() const { return hasGlobalStores_; } + protected: //! pre-compile setup for GPU virtual bool initBuild(amd::option::Options* options); @@ -160,6 +162,7 @@ private: // aclBinary and aclCompiler - for the compiler library aclBinary* binaryElf_; //!< Binary for the new compiler library aclBinaryOptions binOpts_; //!< Binary options to create aclBinary + bool hasGlobalStores_; //!< program has writable program scope variables /* HSA executable */ hsa_ext_program_t hsaProgramHandle_; //!< Handle to HSA runtime program diff --git a/rocclr/runtime/device/rocm/rocvirtual.cpp b/rocclr/runtime/device/rocm/rocvirtual.cpp index 431cdf53f3..0b48c25af7 100644 --- a/rocclr/runtime/device/rocm/rocvirtual.cpp +++ b/rocclr/runtime/device/rocm/rocvirtual.cpp @@ -315,6 +315,14 @@ VirtualGPU::processMemObjects( } } + if (hsaKernel.program()->hasGlobalStores()) { + // Sync AQL packets + setAqlHeader(kDispatchPacketHeader); + // Clear memory dependency state + const static bool All = true; + memoryDependency().clear(!All); + } + return true; }