From f899b79163e2a9416c7ef7f5bfbe4d831417caf9 Mon Sep 17 00:00:00 2001
From: foreman
Date: Thu, 12 Jan 2017 11:03:31 -0500
Subject: [PATCH] P4 to Git Change 1361170 by wchau@wchau_WIN_OCL_LC on
2017/01/12 10:55:25
SWDEV-102698 - [OCL-LC-ROCm] Add code caching support to OpenCL program manager - resubmission of CL#1358063 with addition of PAL/LC support
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/build/Makefile.api#149 edit
... //depot/stg/opencl/drivers/opencl/compiler/tools/Makefile#22 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/device.cpp#207 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/device.hpp#282 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/build/Makefile.pal#8 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palcompiler.cpp#12 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/paldevice.cpp#42 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/paldevice.hpp#15 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palprogram.cpp#28 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/build/Makefile.oclrocm#12 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/roccompiler.cpp#27 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocdevice.cpp#34 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocdevice.hpp#12 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocprogram.cpp#51 edit
... //depot/stg/opencl/drivers/opencl/runtime/utils/flags.hpp#264 edit
[ROCm/clr commit: c9781ce180c9de620c381322c4d9101a299b017e]
---
projects/clr/rocclr/runtime/device/device.cpp | 180 ++++++++++++++++++
projects/clr/rocclr/runtime/device/device.hpp | 56 +++++-
.../rocclr/runtime/device/pal/palcompiler.cpp | 2 +-
.../rocclr/runtime/device/pal/paldevice.cpp | 23 +++
.../rocclr/runtime/device/pal/paldevice.hpp | 8 +
.../rocclr/runtime/device/pal/palprogram.cpp | 15 +-
.../runtime/device/rocm/roccompiler.cpp | 2 +-
.../rocclr/runtime/device/rocm/rocdevice.cpp | 27 ++-
.../rocclr/runtime/device/rocm/rocdevice.hpp | 12 +-
.../rocclr/runtime/device/rocm/rocprogram.cpp | 15 +-
projects/clr/rocclr/runtime/utils/flags.hpp | 7 +-
11 files changed, 330 insertions(+), 17 deletions(-)
diff --git a/projects/clr/rocclr/runtime/device/device.cpp b/projects/clr/rocclr/runtime/device/device.cpp
index b05b09691c..8e3463834d 100644
--- a/projects/clr/rocclr/runtime/device/device.cpp
+++ b/projects/clr/rocclr/runtime/device/device.cpp
@@ -50,6 +50,7 @@ extern void DeviceUnload();
#include
#include
#include
+#include
@@ -614,6 +615,185 @@ Device::allocMapTarget(
return devMem->allocMapTarget(origin, region, mapFlags, rowPitch, slicePitch);
}
+
+#if defined(WITH_LIGHTNING_COMPILER)
+CacheCompilation::CacheCompilation(std::string targetStr, std::string postfix, bool enableCache, bool resetCache)
+ : codeCache_ ( targetStr, 0, AMD_PLATFORM_BUILD_NUMBER, postfix )
+ , isCodeCacheEnabled_ (enableCache)
+{
+ if (resetCache) {
+ // clean up the cached data of the target device
+ StringCache emptyCache(targetStr, 0, 0, postfix);
+ }
+}
+
+bool
+CacheCompilation::linkLLVMBitcode(amd::opencl_driver::Compiler* C,
+ std::vector& inputs,
+ amd::opencl_driver::Buffer* output,
+ std::vector& options,
+ std::string& buildLog)
+{
+ std::string cacheOpt;
+ cacheOpt = std::accumulate(begin(options), end(options), cacheOpt);
+
+ bool ret = false;
+ bool cachedCodeExist = false;
+ std::vector bcSet;
+ if (isCodeCacheEnabled_) {
+ using namespace amd::opencl_driver;
+
+ for (auto &input : inputs) {
+ assert(input->Type() == DT_LLVM_BC);
+
+ BufferReference* bc = reinterpret_cast(input);
+ StringCache::CachedData cachedData = { bc->Ptr(), bc->Size() };
+ bcSet.push_back(cachedData);
+ }
+
+ std::string dstData = "";
+ if (codeCache_.getCacheEntry(isCodeCacheEnabled_, bcSet.data(), bcSet.size(),
+ cacheOpt, dstData, "Link LLVM Bitcodes")) {
+ std::copy(dstData.begin(), dstData.end(), std::back_inserter(output->Buf()));
+ cachedCodeExist = true;
+ }
+ }
+
+ if (!cachedCodeExist) {
+ if (!C->LinkLLVMBitcode(inputs, output, options)) {
+ return false;
+ }
+
+ if (isCodeCacheEnabled_) {
+ std::string dstData(output->Buf().data(), output->Buf().size());
+ if (!codeCache_.makeCacheEntry(bcSet.data(), bcSet.size(), cacheOpt, dstData)) {
+ buildLog += "Warning: Failed to caching codes.\n";
+ LogWarning("Caching codes failed!");
+ }
+ }
+ }
+
+ return true;
+}
+
+bool
+CacheCompilation::compileToLLVMBitcode(amd::opencl_driver::Compiler* C,
+ std::vector& inputs,
+ amd::opencl_driver::Buffer* output,
+ std::vector& options,
+ std::string& buildLog)
+{
+ std::string cacheOpt;
+ for (uint i=0; i < options.size(); i++) {
+ // skip the header file option, which is associated with the -cl-std= option
+ if (options[i].compare("-include-pch") == 0) {
+ i++;
+ continue;
+ }
+ cacheOpt += options[i];
+ }
+
+ bool ret = false;
+ bool cachedCodeExist = false;
+ std::vector bcSet;
+ if (isCodeCacheEnabled_) {
+ using namespace amd::opencl_driver;
+
+ bool checkCache = true;
+ for (auto &input : inputs) {
+ if (input->Type() == DT_CL) {
+ BufferReference* bc = reinterpret_cast(input);
+ StringCache::CachedData cachedData = { bc->Ptr(), bc->Size() };
+ bcSet.push_back(cachedData);
+ }
+ else if (input->Type() == DT_CL_HEADER) {
+ FileReference* bcFile = reinterpret_cast(input);
+ std::string bc;
+ bcFile->ReadToString(bc);
+ StringCache::CachedData cachedData = { bc.c_str(), bc.size() };
+ bcSet.push_back(cachedData);
+ }
+ else {
+ buildLog += "Error: unsupported bitcode type for checking cache.\n";
+ checkCache = false;
+ break;
+ }
+ }
+
+ std::string dstData = "";
+ if (checkCache &&
+ codeCache_.getCacheEntry(isCodeCacheEnabled_, bcSet.data(), bcSet.size(),
+ cacheOpt, dstData, "Compile to LLVM Bitcodes")) {
+ std::copy(dstData.begin(), dstData.end(), std::back_inserter(output->Buf()));
+ cachedCodeExist = true;
+ }
+ }
+
+ if (!cachedCodeExist) {
+ if (!C->CompileToLLVMBitcode(inputs, output, options)) {
+ return false;
+ }
+
+ if (isCodeCacheEnabled_) {
+ std::string dstData(output->Buf().data(), output->Buf().size());
+ if (!codeCache_.makeCacheEntry(bcSet.data(), bcSet.size(), cacheOpt, dstData)) {
+ buildLog += "Warning: Failed to caching codes.\n";
+ LogWarning("Caching codes failed!");
+ }
+ }
+ }
+
+ return true;
+}
+
+bool
+CacheCompilation::compileAndLinkExecutable(amd::opencl_driver::Compiler* C,
+ std::vector& inputs,
+ amd::opencl_driver::Buffer* output,
+ std::vector& options,
+ std::string& buildLog)
+{
+ std::string cacheOpt;
+ cacheOpt = std::accumulate(begin(options), end(options), cacheOpt);
+
+ bool ret = false;
+ bool cachedCodeExist = false;
+ std::vector bcSet;
+ if (isCodeCacheEnabled_) {
+ for (auto &input : inputs) {
+ assert(input->Type() == amd::opencl_driver::DT_LLVM_BC);
+
+ amd::opencl_driver::Buffer* bc = (amd::opencl_driver::Buffer*) input;
+ StringCache::CachedData cachedData = { bc->Buf().data(), bc->Size() };
+ bcSet.push_back(cachedData);
+ }
+
+ std::string dstData = "";
+ if (codeCache_.getCacheEntry(isCodeCacheEnabled_, bcSet.data(), bcSet.size(),
+ cacheOpt, dstData, "Compile and Link Executable")) {
+ std::copy(dstData.begin(), dstData.end(), std::back_inserter(output->Buf()));
+ cachedCodeExist = true;
+ }
+ }
+
+ if (!cachedCodeExist) {
+ if (!C->CompileAndLinkExecutable(inputs, output, options)) {
+ return false;
+ }
+
+ if (isCodeCacheEnabled_) {
+ std::string dstData(output->Buf().data(), output->Buf().size());
+ if (!codeCache_.makeCacheEntry(bcSet.data(), bcSet.size(), cacheOpt, dstData)) {
+ buildLog += "Warning: Failed to caching codes.\n";
+ LogWarning("Caching codes failed!");
+ }
+ }
+ }
+
+ return true;
+}
+#endif
+
} // namespace amd
namespace device {
diff --git a/projects/clr/rocclr/runtime/device/device.hpp b/projects/clr/rocclr/runtime/device/device.hpp
index a31d7672b7..91d1bfee7a 100644
--- a/projects/clr/rocclr/runtime/device/device.hpp
+++ b/projects/clr/rocclr/runtime/device/device.hpp
@@ -17,6 +17,7 @@
#include "appprofile.hpp"
#if defined(WITH_LIGHTNING_COMPILER)
+#include "caching/cache.hpp"
#include "driver/AmdCompiler.h"
#endif // defined(WITH_LIGHTNING_COMPILER)
#include "acl.h"
@@ -1632,7 +1633,7 @@ public:
inline bool isFineGrainedSystem(bool FGSOPT = false) const {
return FGSOPT && (info().svmCapabilities_ & CL_DEVICE_SVM_FINE_GRAIN_SYSTEM) != 0 ? true : false;
}
-
+
//! Return this device's type.
cl_device_type type() const {
return info().type_ & ~(CL_DEVICE_TYPE_DEFAULT | CL_HSA_ENABLED_AMD
@@ -1843,6 +1844,59 @@ struct KernelParameterDescriptor
const char* typeName_; //!< Argument's type name
};
+#if defined(WITH_LIGHTNING_COMPILER)
+
+//! Compilation process with cache support.
+class CacheCompilation : public amd::HeapObject
+{
+public:
+
+ enum COMPILER_OPERATION {
+ LINK_LLVM_BITCODES = 0,
+ COMPILE_TO_LLVM,
+ COMPILE_AND_LINK_EXEC
+ };
+
+ //! Constructor
+ CacheCompilation(std::string targetStr,
+ std::string postfix,
+ bool enableCache,
+ bool resetCache);
+
+ //! NB, the cacheOpt argument is used for specifying the operation
+ //! condition, normally would be the same as the options argument.
+ //! However, the cacheOpt argument should not include any option
+ //! that would be modified each time but not affect the operation,
+ //! e.g. output file name.
+
+ //! Link LLVM bitcode
+ bool linkLLVMBitcode(amd::opencl_driver::Compiler* C,
+ std::vector& inputs,
+ amd::opencl_driver::Buffer* output,
+ std::vector& options,
+ std::string& buildLog);
+
+ //! Compile to LLVM bitcode
+ bool compileToLLVMBitcode(amd::opencl_driver::Compiler* C,
+ std::vector& inputs,
+ amd::opencl_driver::Buffer* output,
+ std::vector& options,
+ std::string& buildLog);
+
+ //! Compile and link executable
+ bool compileAndLinkExecutable(amd::opencl_driver::Compiler* C,
+ std::vector& inputs,
+ amd::opencl_driver::Buffer* output,
+ std::vector& options,
+ std::string& buildLog);
+
+private:
+ StringCache codeCache_; //! Cached codes
+ const bool isCodeCacheEnabled_; //! Code cache enable
+};
+
+#endif
+
/*! @}
* @}
*/
diff --git a/projects/clr/rocclr/runtime/device/pal/palcompiler.cpp b/projects/clr/rocclr/runtime/device/pal/palcompiler.cpp
index 9e2a20dbb3..83e3405df3 100644
--- a/projects/clr/rocclr/runtime/device/pal/palcompiler.cpp
+++ b/projects/clr/rocclr/runtime/device/pal/palcompiler.cpp
@@ -376,7 +376,7 @@ LightningProgram::compileImpl(
std::vector params(sit, end);
// Compile source to IR
- bool ret = C->CompileToLLVMBitcode(inputs, output, params);
+ bool ret = dev().cacheCompilation()->compileToLLVMBitcode(C.get(), inputs, output, params, buildLog_);
buildLog_ += C->Output();
if (!ret) {
buildLog_ += "Error: Failed to compile opencl source (from CL to LLVM IR).\n";
diff --git a/projects/clr/rocclr/runtime/device/pal/paldevice.cpp b/projects/clr/rocclr/runtime/device/pal/paldevice.cpp
index c016d97833..c80e8e54b5 100644
--- a/projects/clr/rocclr/runtime/device/pal/paldevice.cpp
+++ b/projects/clr/rocclr/runtime/device/pal/paldevice.cpp
@@ -870,6 +870,29 @@ Device::create(Pal::IDevice* device)
hwDebugMgr_ = new GpuDebugManager(this);
}
+#if defined(WITH_LIGHTNING_COMPILER)
+ // create compilation object with cache support
+ int gfxipMajor = hwInfo()->gfxipVersion_ / 100;
+ int gfxipMinor = hwInfo()->gfxipVersion_ / 10 % 10;
+ int gfxipStepping = hwInfo()->gfxipVersion_ % 10;
+
+ // Use compute capability as target (AMD:AMDGPU:major:minor:stepping)
+ // with dash as delimiter to be compatible with Windows directory name
+ std::ostringstream cacheTarget;
+ cacheTarget << "AMD-AMDGPU-" << gfxipMajor << "-" << gfxipMinor << "-" << gfxipStepping;
+
+ amd::CacheCompilation* compObj = new amd::CacheCompilation(cacheTarget.str(),
+ "_pal",
+ OCL_CODE_CACHE_ENABLE,
+ OCL_CODE_CACHE_RESET);
+ if (!compObj) {
+ LogError("Unable to create cache compilation object!");
+ return false;
+ }
+
+ cacheCompilation_.reset(compObj);
+#endif
+
return true;
}
diff --git a/projects/clr/rocclr/runtime/device/pal/paldevice.hpp b/projects/clr/rocclr/runtime/device/pal/paldevice.hpp
index c205ca9b04..a5f4fd1543 100644
--- a/projects/clr/rocclr/runtime/device/pal/paldevice.hpp
+++ b/projects/clr/rocclr/runtime/device/pal/paldevice.hpp
@@ -112,11 +112,19 @@ public:
virtual void* svmAlloc(amd::Context& context, size_t size, size_t alignment, cl_svm_mem_flags flags, void* svmPtr) const { return NULL; }
virtual void svmFree(void* ptr) const {return;}
+#if defined(WITH_LIGHTNING_COMPILER)
+ amd::CacheCompilation* cacheCompilation() const { return cacheCompilation_.get(); }
+#endif
+
protected:
Pal::AsicRevision asicRevision_; //!< ASIC revision
Pal::GfxIpLevel ipLevel_; //!< Device IP level
const AMDDeviceInfo* hwInfo_; //!< Device HW info structure
+#if defined(WITH_LIGHTNING_COMPILER)
+ std::unique_ptr cacheCompilation_; //! Compilation with cache support
+#endif
+
//! Fills OpenCL device info structure
void fillDeviceInfo(
const Pal::DeviceProperties& palProp,//!< PAL device properties
diff --git a/projects/clr/rocclr/runtime/device/pal/palprogram.cpp b/projects/clr/rocclr/runtime/device/pal/palprogram.cpp
index 57f022b0f4..432a8b26ef 100644
--- a/projects/clr/rocclr/runtime/device/pal/palprogram.cpp
+++ b/projects/clr/rocclr/runtime/device/pal/palprogram.cpp
@@ -1300,7 +1300,10 @@ LightningProgram::linkImpl(
}
std::vector linkOptions;
- bool ret = C->LinkLLVMBitcode(inputs, output, linkOptions);
+
+ // NOTE: The params is also used to identy cached code object. This parameter
+ // should not contain any dyanamically generated filename.
+ bool ret = dev().cacheCompilation()->linkLLVMBitcode(C.get(), inputs, output, linkOptions, buildLog_);
buildLog_ += C->Output();
if (!ret) {
buildLog_ += "Error: Linking bitcode failed: linking source & IR libraries.\n";
@@ -1459,7 +1462,9 @@ LightningProgram::linkImpl(amd::option::Options *options)
return false;
}
- bool ret = C->LinkLLVMBitcode(inputs, linked_bc, linkOptions);
+ // NOTE: The linkOptions parameter is also used to identy cached code object. This parameter
+ // should not contain any dyanamically generated filename.
+ bool ret = dev().cacheCompilation()->linkLLVMBitcode(C.get(), inputs, linked_bc, linkOptions, buildLog_);
buildLog_ += C->Output();
if (!ret) {
buildLog_ += "Error: Linking bitcode failed: linking source & IR libraries.\n";
@@ -1504,10 +1509,12 @@ LightningProgram::linkImpl(amd::option::Options *options)
std::istream_iterator sit(strstr), end;
std::vector params(sit, end);
- ret = C->CompileAndLinkExecutable(inputs, out_exec, params);
+ // NOTE: The params is also used to identy cached code object. This parameter
+ // should not contain any dyanamically generated filename.
+ ret = dev().cacheCompilation()->compileAndLinkExecutable(C.get(), inputs, out_exec, params, buildLog_);
buildLog_ += C->Output();
if (!ret) {
- buildLog_ += "Error: Creating the executable failed: Compiling LLVM IRs to exe.\n";
+ buildLog_ += "Error: Creating the executable failed: Compiling LLVM IRs to exeutable\n";
return false;
}
diff --git a/projects/clr/rocclr/runtime/device/rocm/roccompiler.cpp b/projects/clr/rocclr/runtime/device/rocm/roccompiler.cpp
index 87ab556a24..d21d80c4d5 100644
--- a/projects/clr/rocclr/runtime/device/rocm/roccompiler.cpp
+++ b/projects/clr/rocclr/runtime/device/rocm/roccompiler.cpp
@@ -204,7 +204,7 @@ HSAILProgram::compileImpl_LC(
std::vector params(sit, end);
// Compile source to IR
- bool ret = C->CompileToLLVMBitcode(inputs, output, params);
+ bool ret = dev().cacheCompilation()->compileToLLVMBitcode(C.get(), inputs, output, params, buildLog_);
buildLog_ += C->Output();
if (!ret) {
buildLog_ += "Error: Failed to compile opencl source (from CL to LLVM IR).\n";
diff --git a/projects/clr/rocclr/runtime/device/rocm/rocdevice.cpp b/projects/clr/rocclr/runtime/device/rocm/rocdevice.cpp
index 0d5deb8788..c2a17180d4 100644
--- a/projects/clr/rocclr/runtime/device/rocm/rocdevice.cpp
+++ b/projects/clr/rocclr/runtime/device/rocm/rocdevice.cpp
@@ -300,7 +300,7 @@ bool NullDevice::init() {
bool isOnline = false;
//Check if the particular device is online
for (unsigned int i=0; i< devices.size(); i++) {
- if (static_cast(devices[i])->deviceInfo_.hsaDeviceId_ ==
+ if (static_cast(devices[i])->deviceInfo_.hsaDeviceId_ ==
DeviceInfo[id].hsaDeviceId_){
isOnline = true;
}
@@ -592,6 +592,29 @@ Device::mapHSADeviceToOpenCLDevice(hsa_agent_t dev)
}
}
+#if defined(WITH_LIGHTNING_COMPILER)
+ // create compilation object with cache support
+ int gfxipMajor = deviceInfo_.gfxipVersion_ / 100;
+ int gfxipMinor = deviceInfo_.gfxipVersion_ / 10 % 10;
+ int gfxipStepping = deviceInfo_.gfxipVersion_ % 10;
+
+ // Use compute capability as target (AMD:AMDGPU:major:minor:stepping)
+ // with dash as delimiter to be compatible with Windows directory name
+ std::ostringstream cacheTarget;
+ cacheTarget << "AMD-AMDGPU-" << gfxipMajor << "-" << gfxipMinor << "-" << gfxipStepping;
+
+ amd::CacheCompilation* compObj = new amd::CacheCompilation(cacheTarget.str(),
+ "_rocm",
+ OCL_CODE_CACHE_ENABLE,
+ OCL_CODE_CACHE_RESET);
+ if (!compObj) {
+ LogError("Unable to create cache compilation object!");
+ return false;
+ }
+
+ cacheCompilation_.reset(compObj);
+#endif
+
return true;
}
@@ -1080,7 +1103,7 @@ Device::bindExternalDevice(
#else
if((flags&amd::Context::GLDeviceKhr)==0)
return false;
-
+
MesaInterop::MESA_INTEROP_KIND kind=MesaInterop::MESA_INTEROP_NONE;
MesaInterop::DisplayHandle display;
MesaInterop::ContextHandle context;
diff --git a/projects/clr/rocclr/runtime/device/rocm/rocdevice.hpp b/projects/clr/rocclr/runtime/device/rocm/rocdevice.hpp
index 32213f1fb5..cd6b4505dd 100644
--- a/projects/clr/rocclr/runtime/device/rocm/rocdevice.hpp
+++ b/projects/clr/rocclr/runtime/device/rocm/rocdevice.hpp
@@ -80,6 +80,8 @@ public:
Compiler* compiler() const { return compilerHandle_; }
+ const Settings &settings() const { return reinterpret_cast(*settings_); }
+
//! Construct an HSAIL program object from the ELF assuming it is valid
virtual device::Program *createProgram(amd::option::Options* options = NULL);
const AMDDeviceInfo& deviceInfo() const {
@@ -193,6 +195,10 @@ public:
return false;
}
+#if defined(WITH_LIGHTNING_COMPILER)
+ amd::CacheCompilation* cacheCompilation() const { return cacheCompilation_.get(); }
+#endif
+
protected:
//! Initialize compiler instance and handle
static bool initCompiler(bool isOffline);
@@ -202,6 +208,10 @@ protected:
static Compiler* compilerHandle_;
//! Device Id for an HsaDevice
AMDDeviceInfo deviceInfo_;
+#if defined(WITH_LIGHTNING_COMPILER)
+ //! Compilation with cache support
+ std::unique_ptr cacheCompilation_;
+#endif
private:
static const bool offlineDevice_;
};
@@ -329,8 +339,6 @@ public:
virtual void svmFree(void* ptr) const;
- const Settings &settings() const { return reinterpret_cast(*settings_); }
-
//! Returns transfer engine object
const device::BlitManager& xferMgr() const { return xferQueue()->blitMgr(); }
diff --git a/projects/clr/rocclr/runtime/device/rocm/rocprogram.cpp b/projects/clr/rocclr/runtime/device/rocm/rocprogram.cpp
index c09c5faa80..0ae5965944 100644
--- a/projects/clr/rocclr/runtime/device/rocm/rocprogram.cpp
+++ b/projects/clr/rocclr/runtime/device/rocm/rocprogram.cpp
@@ -531,7 +531,10 @@ HSAILProgram::linkImpl_LC(
}
std::vector linkOptions;
- bool ret = C->LinkLLVMBitcode(inputs, output, linkOptions);
+
+ // NOTE: The linkOptions parameter is also used to identy cached code object. This parameter
+ // should not contain any dyanamically generated filename.
+ bool ret = dev().cacheCompilation()->linkLLVMBitcode(C.get(), inputs, output, linkOptions, buildLog_);
buildLog_ += C->Output();
if (!ret) {
buildLog_ += "Error: Linking bitcode failed: linking source & IR libraries.\n";
@@ -770,7 +773,9 @@ HSAILProgram::linkImpl_LC(amd::option::Options *options)
return false;
}
- bool ret = C->LinkLLVMBitcode(inputs, linked_bc, linkOptions);
+ // NOTE: The linkOptions parameter is also used to identy cached code object. This parameter
+ // should not contain any dyanamically generated filename.
+ bool ret = dev().cacheCompilation()->linkLLVMBitcode(C.get(), inputs, linked_bc, linkOptions, buildLog_);
buildLog_ += C->Output();
if (!ret) {
buildLog_ += "Error: Linking bitcode failed: linking source & IR libraries.\n";
@@ -812,10 +817,12 @@ HSAILProgram::linkImpl_LC(amd::option::Options *options)
std::istream_iterator sit(strstr), end;
std::vector params(sit, end);
- ret = C->CompileAndLinkExecutable(inputs, out_exec, params);
+ // NOTE: The params is also used to identy cached code object. This paramete
+ // should not contain any dyanamically generated filename.
+ ret = dev().cacheCompilation()->compileAndLinkExecutable(C.get(), inputs, out_exec, params, buildLog_);
buildLog_ += C->Output();
if (!ret) {
- buildLog_ += "Error: Creating the executable failed: Compiling LLVM IRs to exe.\n";
+ buildLog_ += "Error: Creating the executable failed: Compiling LLVM IRs to exeutable\n";
return false;
}
diff --git a/projects/clr/rocclr/runtime/utils/flags.hpp b/projects/clr/rocclr/runtime/utils/flags.hpp
index 0ea3e12a37..9b185ef41b 100644
--- a/projects/clr/rocclr/runtime/utils/flags.hpp
+++ b/projects/clr/rocclr/runtime/utils/flags.hpp
@@ -198,8 +198,11 @@ release_on_stg(uint, GPU_WAVE_LIMIT_DSC_THRESH, 10, \
release_on_stg(cstring, GPU_WAVE_LIMIT_DUMP, "", \
"File path prefix for dumping wave limiter output") \
release_on_stg(cstring, GPU_WAVE_LIMIT_TRACE, "", \
- "File path prefix for tracing wave limiter")
-
+ "File path prefix for tracing wave limiter") \
+release(bool, OCL_CODE_CACHE_ENABLE, false, \
+ "1 = Enable compiler code cache") \
+release(bool, OCL_CODE_CACHE_RESET, false, \
+ "1 = Reset the compiler code cache storage")
namespace amd {