P4 to Git Change 1610043 by gandryey@gera-w8 on 2018/09/24 18:08:36
SWDEV-79445 - OCL generic changes and code clean-up Program compilation clean-up. Step#3: - Move getCompilationStagesFromBinary and getNextCompilationStageFromBinary to the abstraction layer. - Share the same functionality across GSL, PAL and ROCr backends Affected files ... ... //depot/stg/opencl/drivers/opencl/runtime/device/devprogram.cpp#3 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/devprogram.hpp#3 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuprogram.cpp#243 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuprogram.hpp#76 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/paldefs.hpp#39 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palprogram.cpp#75 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palprogram.hpp#31 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocprogram.cpp#88 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocprogram.hpp#37 edit
This commit is contained in:
@@ -1698,214 +1698,6 @@ bool HSAILProgram::linkImpl(const std::vector<device::Program*>& inputPrograms,
|
||||
return linkImpl(options);
|
||||
}
|
||||
|
||||
aclType HSAILProgram::getCompilationStagesFromBinary(std::vector<aclType>& completeStages,
|
||||
bool& needOptionsCheck) {
|
||||
acl_error errorCode;
|
||||
size_t secSize = 0;
|
||||
completeStages.clear();
|
||||
aclType from = ACL_TYPE_DEFAULT;
|
||||
needOptionsCheck = true;
|
||||
size_t boolSize = sizeof(bool);
|
||||
//! @todo Should we also check for ACL_TYPE_OPENCL & ACL_TYPE_LLVMIR_TEXT?
|
||||
// Checking llvmir in .llvmir section
|
||||
bool containsSpirv = true;
|
||||
errorCode = aclQueryInfo(dev().hsaCompiler(), binaryElf_, RT_CONTAINS_SPIRV, NULL, &containsSpirv,
|
||||
&boolSize);
|
||||
if (errorCode != ACL_SUCCESS) {
|
||||
containsSpirv = false;
|
||||
}
|
||||
if (containsSpirv) {
|
||||
completeStages.push_back(from);
|
||||
from = ACL_TYPE_SPIRV_BINARY;
|
||||
}
|
||||
bool containsSpirText = true;
|
||||
errorCode = aclQueryInfo(dev().hsaCompiler(), binaryElf_, RT_CONTAINS_SPIR, NULL,
|
||||
&containsSpirText, &boolSize);
|
||||
if (errorCode != ACL_SUCCESS) {
|
||||
containsSpirText = false;
|
||||
}
|
||||
if (containsSpirText) {
|
||||
completeStages.push_back(from);
|
||||
from = ACL_TYPE_SPIR_BINARY;
|
||||
}
|
||||
bool containsLlvmirText = true;
|
||||
errorCode = aclQueryInfo(dev().hsaCompiler(), binaryElf_, RT_CONTAINS_LLVMIR, NULL,
|
||||
&containsLlvmirText, &boolSize);
|
||||
if (errorCode != ACL_SUCCESS) {
|
||||
containsLlvmirText = false;
|
||||
}
|
||||
// Checking compile & link options in .comment section
|
||||
bool containsOpts = true;
|
||||
errorCode = aclQueryInfo(dev().hsaCompiler(), binaryElf_, RT_CONTAINS_OPTIONS, NULL,
|
||||
&containsOpts, &boolSize);
|
||||
if (errorCode != ACL_SUCCESS) {
|
||||
containsOpts = false;
|
||||
}
|
||||
if (containsLlvmirText && containsOpts) {
|
||||
completeStages.push_back(from);
|
||||
from = ACL_TYPE_LLVMIR_BINARY;
|
||||
}
|
||||
// Checking HSAIL in .cg section
|
||||
bool containsHsailText = true;
|
||||
errorCode = aclQueryInfo(dev().hsaCompiler(), binaryElf_, RT_CONTAINS_HSAIL, NULL,
|
||||
&containsHsailText, &boolSize);
|
||||
if (errorCode != ACL_SUCCESS) {
|
||||
containsHsailText = false;
|
||||
}
|
||||
// Checking BRIG sections
|
||||
bool containsBrig = true;
|
||||
errorCode = aclQueryInfo(dev().hsaCompiler(), binaryElf_, RT_CONTAINS_BRIG, NULL, &containsBrig,
|
||||
&boolSize);
|
||||
if (errorCode != ACL_SUCCESS) {
|
||||
containsBrig = false;
|
||||
}
|
||||
if (containsBrig) {
|
||||
completeStages.push_back(from);
|
||||
from = ACL_TYPE_HSAIL_BINARY;
|
||||
} else if (containsHsailText) {
|
||||
completeStages.push_back(from);
|
||||
from = ACL_TYPE_HSAIL_TEXT;
|
||||
}
|
||||
// Checking Loader Map symbol from CG section
|
||||
bool containsLoaderMap = true;
|
||||
errorCode = aclQueryInfo(dev().hsaCompiler(), binaryElf_, RT_CONTAINS_LOADER_MAP, NULL,
|
||||
&containsLoaderMap, &boolSize);
|
||||
if (errorCode != ACL_SUCCESS) {
|
||||
containsLoaderMap = false;
|
||||
}
|
||||
if (containsLoaderMap) {
|
||||
completeStages.push_back(from);
|
||||
from = ACL_TYPE_CG;
|
||||
}
|
||||
// Checking ISA in .text section
|
||||
bool containsShaderIsa = true;
|
||||
errorCode = aclQueryInfo(dev().hsaCompiler(), binaryElf_, RT_CONTAINS_ISA, NULL,
|
||||
&containsShaderIsa, &boolSize);
|
||||
if (errorCode != ACL_SUCCESS) {
|
||||
containsShaderIsa = false;
|
||||
}
|
||||
if (containsShaderIsa) {
|
||||
completeStages.push_back(from);
|
||||
from = ACL_TYPE_ISA;
|
||||
}
|
||||
std::string sCurOptions = compileOptions_ + linkOptions_;
|
||||
amd::option::Options curOptions;
|
||||
if (!amd::option::parseAllOptions(sCurOptions, curOptions)) {
|
||||
buildLog_ += curOptions.optionsLog();
|
||||
LogError("Parsing compile options failed.");
|
||||
return ACL_TYPE_DEFAULT;
|
||||
}
|
||||
switch (from) {
|
||||
// compile from HSAIL text, no matter prev. stages and options
|
||||
case ACL_TYPE_HSAIL_TEXT:
|
||||
needOptionsCheck = false;
|
||||
break;
|
||||
case ACL_TYPE_HSAIL_BINARY:
|
||||
// do not check options, if LLVMIR is absent or might be absent or options are absent
|
||||
if (!curOptions.oVariables->BinLLVMIR || !containsLlvmirText || !containsOpts) {
|
||||
needOptionsCheck = false;
|
||||
}
|
||||
break;
|
||||
case ACL_TYPE_CG:
|
||||
case ACL_TYPE_ISA:
|
||||
// do not check options, if LLVMIR is absent or might be absent or options are absent
|
||||
if (!curOptions.oVariables->BinLLVMIR || !containsLlvmirText || !containsOpts) {
|
||||
needOptionsCheck = false;
|
||||
}
|
||||
// do not check options, if BRIG is absent or might be absent or LoaderMap is absent
|
||||
if (!curOptions.oVariables->BinCG || !containsBrig || !containsLoaderMap) {
|
||||
needOptionsCheck = false;
|
||||
}
|
||||
break;
|
||||
// recompilation might be needed
|
||||
case ACL_TYPE_LLVMIR_BINARY:
|
||||
case ACL_TYPE_DEFAULT:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return from;
|
||||
}
|
||||
|
||||
aclType HSAILProgram::getNextCompilationStageFromBinary(amd::option::Options* options) {
|
||||
aclType continueCompileFrom = ACL_TYPE_DEFAULT;
|
||||
binary_t binary = this->binary();
|
||||
// If the binary already exists
|
||||
if ((binary.first != NULL) && (binary.second > 0)) {
|
||||
void* mem = const_cast<void*>(binary.first);
|
||||
acl_error errorCode;
|
||||
binaryElf_ = aclReadFromMem(mem, binary.second, &errorCode);
|
||||
if (errorCode != ACL_SUCCESS) {
|
||||
buildLog_ += "Error: Reading the binary from memory failed.\n";
|
||||
return continueCompileFrom;
|
||||
}
|
||||
// Calculate the next stage to compile from, based on sections in binaryElf_;
|
||||
// No any validity checks here
|
||||
std::vector<aclType> completeStages;
|
||||
bool needOptionsCheck = true;
|
||||
continueCompileFrom = getCompilationStagesFromBinary(completeStages, needOptionsCheck);
|
||||
// Saving binary in the interface class,
|
||||
// which also load compile & link options from binary
|
||||
setBinary(static_cast<char*>(mem), binary.second);
|
||||
if (!options || !needOptionsCheck) {
|
||||
return continueCompileFrom;
|
||||
}
|
||||
bool recompile = false;
|
||||
//! @todo Should we also check for ACL_TYPE_OPENCL & ACL_TYPE_LLVMIR_TEXT?
|
||||
switch (continueCompileFrom) {
|
||||
case ACL_TYPE_HSAIL_BINARY:
|
||||
case ACL_TYPE_CG:
|
||||
case ACL_TYPE_ISA: {
|
||||
// Compare options loaded from binary with current ones, recompile if differ;
|
||||
// If compile options are absent in binary, do not compare and recompile
|
||||
if (compileOptions_.empty()) break;
|
||||
const oclBIFSymbolStruct* symbol = findBIF30SymStruct(symOpenclCompilerOptions);
|
||||
assert(symbol && "symbol not found");
|
||||
std::string symName =
|
||||
std::string(symbol->str[bif::PRE]) + std::string(symbol->str[bif::POST]);
|
||||
size_t symSize = 0;
|
||||
const void* opts = aclExtractSymbol(dev().hsaCompiler(), binaryElf_, &symSize, aclCOMMENT,
|
||||
symName.c_str(), &errorCode);
|
||||
if (errorCode != ACL_SUCCESS) {
|
||||
recompile = true;
|
||||
break;
|
||||
}
|
||||
std::string sBinOptions = std::string((char*)opts, symSize);
|
||||
std::string sCurOptions = compileOptions_ + linkOptions_;
|
||||
amd::option::Options curOptions, binOptions;
|
||||
if (!amd::option::parseAllOptions(sBinOptions, binOptions)) {
|
||||
buildLog_ += binOptions.optionsLog();
|
||||
LogError("Parsing compile options from binary failed.");
|
||||
return ACL_TYPE_DEFAULT;
|
||||
}
|
||||
if (!amd::option::parseAllOptions(sCurOptions, curOptions)) {
|
||||
buildLog_ += curOptions.optionsLog();
|
||||
LogError("Parsing compile options failed.");
|
||||
return ACL_TYPE_DEFAULT;
|
||||
}
|
||||
if (!curOptions.equals(binOptions)) {
|
||||
recompile = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (recompile) {
|
||||
while (!completeStages.empty()) {
|
||||
continueCompileFrom = completeStages.back();
|
||||
if (continueCompileFrom == ACL_TYPE_SPIRV_BINARY ||
|
||||
continueCompileFrom == ACL_TYPE_LLVMIR_BINARY ||
|
||||
continueCompileFrom == ACL_TYPE_SPIR_BINARY ||
|
||||
continueCompileFrom == ACL_TYPE_DEFAULT) {
|
||||
break;
|
||||
}
|
||||
completeStages.pop_back();
|
||||
}
|
||||
}
|
||||
}
|
||||
return continueCompileFrom;
|
||||
}
|
||||
|
||||
inline static std::vector<std::string> splitSpaceSeparatedString(char* str) {
|
||||
std::string s(str);
|
||||
std::stringstream ss(s);
|
||||
|
||||
Reference in New Issue
Block a user