P4 to Git Change 1170011 by kebai@kebai-lnx-desktop on 2015/07/13 13:47:29

ECR #304775 - Bug 10752 kernel caching feature (AMDIL and HSAIL path)
	1. For the stage we want to cache, call getCacheEntry() followed by makeCacheEntry() if the get fails; otherwise directly return cached data.
	a. Each device have a separate cache directory
	b. It logs caching errors, so we can debug the cache and/or detect collisions
	2. Implementeded cache size tracking, so we can evict old data when cache files are too large
	3. Added file/path access permission control on both windows and linux
	4. Have read/write file lock protection
	5. -kcache-disable flag can be used to turn on/off the caching functionality
	6. AMD_FORCE_KCACHE_TEST env variable is used for internal testing

	TO DO:
	1. Tracking of timestamps for cache entries
	-LRU eviction when cache grows too large
	2. Track cache entries per application

Affected files ...

... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/common/cache.cpp#1 add
... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/common/cache.hpp#1 add
... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/common/frontend.cpp#34 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/common/frontend_clang.cpp#20 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/common/v0_8/if_acl.cpp#68 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/gpu/amdil_be.cpp#43 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/gpu/hsail_be.cpp#42 edit
... //depot/stg/opencl/drivers/opencl/compiler/lib/utils/OPTIONS.def#124 edit
... //depot/stg/opencl/drivers/opencl/tests/kcache/Makefile#1 add
... //depot/stg/opencl/drivers/opencl/tests/kcache/build/Makefile#1 add
... //depot/stg/opencl/drivers/opencl/tests/kcache/build/Makefile.kcache#1 add
... //depot/stg/opencl/drivers/opencl/tests/kcache/kCacheTest_std.txt#1 add
... //depot/stg/opencl/drivers/opencl/tests/kcache/kernel.cl#1 add
... //depot/stg/opencl/drivers/opencl/tests/kcache/main.cpp#1 add
This commit is contained in:
foreman
2015-07-13 18:11:44 -04:00
parent 9945a3f7f1
commit 4b6f2324d0
6 changed files with 1508 additions and 11 deletions
@@ -4,6 +4,8 @@
#include "top.hpp"
#include "frontend.hpp"
#include "bif/bifbase.hpp"
#include "cache.hpp"
#include "../../../sc/Interface/SCLib_Ver.h"
#include "utils/libUtils.h"
#include "utils/target_mappings.h"
#include "utils/options.hpp"
@@ -219,7 +221,55 @@ amdcl::OCLFrontend::compileCommand(const std::string& singleSrc)
if (!checkFlag(aclutGetCaps(Elf()), capSaveSOURCE)) {
CL()->clAPI.remSec(CL(), Elf(), aclSOURCE);
}
int ret = openclFrontEnd(frontendCmd.c_str(), &Source(), NULL);
int ret = 0;
KernelCache kc;
KernelCacheData clSrc;
std::string kernelID;
char *llvmIR = NULL;
unsigned int llvmIRSize = 0;
bool isCacheReady = false, kernelCached = false;
bool canUseCache = !Options()->oVariables->DisableKernelCaching;
bool kCacheTest = kc.internalKCacheTestSwitch(canUseCache);
size_t pos = frontendCmd.find("--error_output");
std::string buildOpts = frontendCmd.substr(0, pos);
if (canUseCache && Options()->oVariables->OptLevel > 0) {
std::string deviceName(getDeviceName(Elf()->target));
isCacheReady = kc.cacheInit(SC_BUILD_NUMBER, deviceName);
if (!isCacheReady) {
kc.saveLogToFile();
} else {
unsigned int hashVal = 0;
const char *name = Options()->getCurrKernelName();
kernelID = name ? name : " ";
clSrc.data = const_cast<char *>(singleSrc.c_str());
clSrc.dataSize = singleSrc.size();
kernelCached = kc.getCacheEntry((const KernelCacheData *)&clSrc, 1, buildOpts, kernelID, &llvmIR, llvmIRSize, hashVal);
if (!kc.ErrorMsg().empty()) {
kc.saveLogToFile();
}
}
}
if (kernelCached) {
if (kCacheTest) {
fprintf(stdout, "FE to IR stage is cached!\n");
fflush(stdout);
}
source_.assign(llvmIR, llvmIRSize);
if (llvmIR) delete[] llvmIR;
} else {
if (kCacheTest) {
fprintf(stdout, "FE to IR stage is not cached!\n");
fflush(stdout);
}
ret = openclFrontEnd(frontendCmd.c_str(), &Source(), NULL);
// Caching LLVM IR
if (isCacheReady && !kc.makeCacheEntry((const KernelCacheData *)&clSrc, 1, buildOpts, kernelID, Source().data(), Source().size())) {
kc.saveLogToFile();
}
}
// We dump the preprocessed code by invoking clc a second time after the
// original call, just in case somthing really bad happens in the original