From b705f7416671f14f7ee058de53d1941dbf070002 Mon Sep 17 00:00:00 2001
From: foreman
Date: Fri, 2 Dec 2016 18:40:16 -0500
Subject: [PATCH] P4 to Git Change 1349031 by lmoriche@lmoriche_opencl_dev on
2016/12/02 18:33:20
SWDEV-107568 - [ROCm CQE][OCL][CZ] Basic 2.0 conformance test giving Segmentation fault (core dumped) at "progvar_prog_scope_uninit"
- Detect if writable program scope variables are present in the program, and if so, insert barrier each dispatch of a kernel from this program.
Affected files ...
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rockernel.hpp#11 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocprogram.cpp#48 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocprogram.hpp#16 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocvirtual.cpp#21 edit
---
rocclr/runtime/device/rocm/rockernel.hpp | 2 +-
rocclr/runtime/device/rocm/rocprogram.cpp | 26 ++++++++++++++++++++---
rocclr/runtime/device/rocm/rocprogram.hpp | 3 +++
rocclr/runtime/device/rocm/rocvirtual.cpp | 8 +++++++
4 files changed, 35 insertions(+), 4 deletions(-)
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;
}