From f670ae2f8d44d0cd95d1c2349c0499a771ee4c04 Mon Sep 17 00:00:00 2001
From: foreman
Date: Thu, 1 Oct 2015 08:37:19 -0400
Subject: [PATCH] P4 to Git Change 1196211 by nhaustov@nhaustov_hsa on
2015/10/01 08:27:23
SWDEV-76911 - Bug 11070: ViennaCL fails in amd::hsa::loader::Executable::Destroy
Destructors of global variables run in undefined order, so loader cannot
be global. Encapsulate loader functionality in Loader class and link its lifecycle
to Runtime.
In HSA Runtime, create Loader as part of Runtime singleton.
In ORCA Runtime, create Loader as part of HSAILProgram class.
Testing: smoke, pre-checkin
Affected files ...
... //depot/stg/opencl/drivers/opencl/compiler/sc/HSAIL/ext/amdhsacod/amdhsacod.cpp#10 integrate
... //depot/stg/opencl/drivers/opencl/compiler/sc/HSAIL/ext/loader/executable.cpp#12 integrate
... //depot/stg/opencl/drivers/opencl/compiler/sc/HSAIL/ext/loader/executable.hpp#8 integrate
... //depot/stg/opencl/drivers/opencl/compiler/sc/HSAIL/include/amd_hsa_loader.hpp#5 integrate
... //depot/stg/opencl/drivers/opencl/compiler/tools/aoc2/aoc2.cpp#78 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuprogram.cpp#210 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuprogram.hpp#61 edit
---
rocclr/runtime/device/gpu/gpuprogram.cpp | 8 ++++++--
rocclr/runtime/device/gpu/gpuprogram.hpp | 2 ++
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/rocclr/runtime/device/gpu/gpuprogram.cpp b/rocclr/runtime/device/gpu/gpuprogram.cpp
index 014de53f12..431cca6e3d 100644
--- a/rocclr/runtime/device/gpu/gpuprogram.cpp
+++ b/rocclr/runtime/device/gpu/gpuprogram.cpp
@@ -18,6 +18,7 @@
#include "utils/options.hpp"
#include "hsa.h"
#include "hsa_ext_image.h"
+#include "amd_hsa_loader.hpp"
namespace gpu {
@@ -1670,6 +1671,7 @@ HSAILProgram::HSAILProgram(Device& device)
binOpts_.bitness = ELFDATA2LSB;
binOpts_.alloc = &::malloc;
binOpts_.dealloc = &::free;
+ loader_ = amd::hsa::loader::Loader::Create(&loaderContext_);
}
HSAILProgram::HSAILProgram(NullDevice& device)
@@ -1689,6 +1691,7 @@ HSAILProgram::HSAILProgram(NullDevice& device)
binOpts_.bitness = ELFDATA2LSB;
binOpts_.alloc = &::malloc;
binOpts_.dealloc = &::free;
+ loader_ = amd::hsa::loader::Loader::Create(&loaderContext_);
}
HSAILProgram::~HSAILProgram()
@@ -1710,9 +1713,10 @@ HSAILProgram::~HSAILProgram()
}
releaseClBinary();
if (executable_ != NULL) {
- Executable::Destroy(executable_);
+ loader_->DestroyExecutable(executable_);
}
delete kernels_;
+ amd::hsa::loader::Loader::Destroy(loader_);
}
bool
@@ -2132,7 +2136,7 @@ HSAILProgram::linkImpl(amd::option::Options* options)
hsa_agent_t agent;
agent.handle = 1;
if (!isNull() && hsaLoad) {
- executable_ = Executable::Create(HSA_PROFILE_BASE, &loaderContext_, NULL);
+ executable_ = loader_->CreateExecutable(HSA_PROFILE_BASE, NULL);
if (executable_ == NULL) {
buildLog_ += "Error: Executable for AMD HSA Code Object isn't created.\n";
return false;
diff --git a/rocclr/runtime/device/gpu/gpuprogram.hpp b/rocclr/runtime/device/gpu/gpuprogram.hpp
index 01b61f1489..9f87328f35 100644
--- a/rocclr/runtime/device/gpu/gpuprogram.hpp
+++ b/rocclr/runtime/device/gpu/gpuprogram.hpp
@@ -15,6 +15,7 @@ class Options;
} // option
namespace hsa {
namespace loader {
+class Loader;
class Executable;
class Context;
} // loader
@@ -624,6 +625,7 @@ private:
uint maxScratchRegs_; //!< Maximum number of scratch regs used in the program by individual kernel
std::list staticSamplers_; //!< List od internal static samplers
bool isNull_; //!< Null program no memory allocations
+ amd::hsa::loader::Loader* loader_; //!< Loader object
amd::hsa::loader::Executable* executable_; //!< Executable for HSA Loader
ORCAHSALoaderContext loaderContext_; //!< Context for HSA Loader
};