P4 to Git Change 1608975 by gandryey@gera-w8 on 2018/09/20 18:14:01

SWDEV-79445 - OCL generic changes and code clean-up
	Program compilation clean-up. Follwoing CL#1608319:
	- Switch HSAIL GSL path to the common compilation method

Affected files ...

... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpucompiler.cpp#160 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpudevice.hpp#168 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpukernel.cpp#332 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuprogram.cpp#242 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuprogram.hpp#75 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palprogram.cpp#74 edit


[ROCm/clr commit: dbe7f3201d]
This commit is contained in:
foreman
2018-09-20 18:26:16 -04:00
parent d98750b0bb
commit c5b9715a6b
6 changed files with 26 additions and 142 deletions
@@ -114,7 +114,7 @@ bool NullProgram::compileImpl(const std::string& src,
}
if (ACL_SUCCESS !=
aclInsertSection(dev().compiler(), bin, sourceCode.c_str(), sourceCode.size(), aclSOURCE)) {
aclInsertSection(dev().amdilCompiler(), bin, sourceCode.c_str(), sourceCode.size(), aclSOURCE)) {
LogWarning("aclInsertSection failed");
aclBinaryFini(bin);
return false;
@@ -190,10 +190,10 @@ bool NullProgram::compileImpl(const std::string& src,
pos = newOpt.find("-fno-bin-llvmir");
}
err = aclCompile(dev().compiler(), bin, newOpt.c_str(), ACL_TYPE_OPENCL, ACL_TYPE_LLVMIR_BINARY,
err = aclCompile(dev().amdilCompiler(), bin, newOpt.c_str(), ACL_TYPE_OPENCL, ACL_TYPE_LLVMIR_BINARY,
NULL);
buildLog_ += aclGetCompilerLog(dev().compiler());
buildLog_ += aclGetCompilerLog(dev().amdilCompiler());
if (err != ACL_SUCCESS) {
LogWarning("aclCompile failed");
@@ -202,7 +202,7 @@ bool NullProgram::compileImpl(const std::string& src,
}
size_t len = 0;
const void* ir = aclExtractSection(dev().compiler(), bin, &len, aclLLVMIR, &err);
const void* ir = aclExtractSection(dev().amdilCompiler(), bin, &len, aclLLVMIR, &err);
if (err != ACL_SUCCESS) {
LogWarning("aclExtractSection failed");
aclBinaryFini(bin);
@@ -269,7 +269,7 @@ int NullProgram::compileBinaryToIL(amd::option::Options* options) {
}
if (ACL_SUCCESS !=
aclInsertSection(dev().compiler(), bin, llvmBinary_.data(), llvmBinary_.size(), spirFlag)) {
aclInsertSection(dev().amdilCompiler(), bin, llvmBinary_.data(), llvmBinary_.size(), spirFlag)) {
LogWarning("aclInsertSection failed");
aclBinaryFini(bin);
return CL_BUILD_PROGRAM_FAILURE;
@@ -293,8 +293,8 @@ int NullProgram::compileBinaryToIL(amd::option::Options* options) {
type = ACL_TYPE_ISA;
}
err = aclCompile(dev().compiler(), bin, optionStr.c_str(), aclTypeBinaryUsed, type, NULL);
buildLog_ += aclGetCompilerLog(dev().compiler());
err = aclCompile(dev().amdilCompiler(), bin, optionStr.c_str(), aclTypeBinaryUsed, type, NULL);
buildLog_ += aclGetCompilerLog(dev().amdilCompiler());
if (err != ACL_SUCCESS) {
LogWarning("aclCompile failed");
@@ -317,7 +317,7 @@ int NullProgram::compileBinaryToIL(amd::option::Options* options) {
}
size_t len = 0;
const void* amdil = aclExtractSection(dev().compiler(), bin, &len, aclCODEGEN, &err);
const void* amdil = aclExtractSection(dev().amdilCompiler(), bin, &len, aclCODEGEN, &err);
if (err != ACL_SUCCESS) {
LogWarning("aclExtractSection failed");
aclBinaryFini(bin);
@@ -330,117 +330,4 @@ int NullProgram::compileBinaryToIL(amd::option::Options* options) {
return CL_SUCCESS;
}
bool HSAILProgram::compileImpl(const std::string& sourceCode,
const std::vector<const std::string*>& headers,
const char** headerIncludeNames, amd::option::Options* options) {
acl_error errorCode;
aclTargetInfo target;
std::string arch = "hsail";
if (dev().settings().use64BitPtr_) {
arch += "64";
}
target = aclGetTargetInfo(arch.c_str(), dev().hwInfo()->targetName_, &errorCode);
// end if asic info is ready
// We dump the source code for each program (param: headers)
// into their filenames (headerIncludeNames) into the TEMP
// folder specific to the OS and add the include path while
// compiling
// Find the temp folder for the OS
std::string tempFolder = amd::Os::getTempPath();
std::string tempFileName = amd::Os::getTempFileName();
// Iterate through each source code and dump it into tmp
std::fstream f;
std::vector<std::string> headerFileNames(headers.size());
std::vector<std::string> newDirs;
for (size_t i = 0; i < headers.size(); ++i) {
std::string headerPath = tempFolder;
std::string headerIncludeName(headerIncludeNames[i]);
// replace / in path with current os's file separator
if (amd::Os::fileSeparator() != '/') {
for (auto& it : headerIncludeName) {
if (it == '/') it = amd::Os::fileSeparator();
}
}
size_t pos = headerIncludeName.rfind(amd::Os::fileSeparator());
if (pos != std::string::npos) {
headerPath += amd::Os::fileSeparator();
headerPath += headerIncludeName.substr(0, pos);
headerIncludeName = headerIncludeName.substr(pos + 1);
}
if (!amd::Os::pathExists(headerPath)) {
bool ret = amd::Os::createPath(headerPath);
assert(ret && "failed creating path!");
newDirs.push_back(headerPath);
}
std::string headerFullName = headerPath + amd::Os::fileSeparator() + headerIncludeName;
headerFileNames[i] = headerFullName;
f.open(headerFullName.c_str(), std::fstream::out);
// Should we allow asserts
assert(!f.fail() && "failed creating header file!");
f.write(headers[i]->c_str(), headers[i]->length());
f.close();
}
// Create Binary
binaryElf_ = aclBinaryInit(sizeof(aclBinary), &target, &binOpts_, &errorCode);
if (errorCode != ACL_SUCCESS) {
buildLog_ += "Error: aclBinary init failure\n";
LogWarning("aclBinaryInit failed");
return false;
}
// Insert opencl into binary
errorCode = aclInsertSection(dev().hsaCompiler(), binaryElf_, sourceCode.c_str(),
strlen(sourceCode.c_str()), aclSOURCE);
if (errorCode != ACL_SUCCESS) {
buildLog_ += "Error: Inserting openCl Source to binary\n";
}
// Set the options for the compiler
// Set the include path for the temp folder that contains the includes
if (!headers.empty()) {
compileOptions_.append(" -I");
compileOptions_.append(tempFolder);
}
// Add only for CL2.0 and above
if (options->oVariables->CLStd[2] >= '2') {
std::stringstream opts;
opts << " -D"
<< "CL_DEVICE_MAX_GLOBAL_VARIABLE_SIZE=" << device().info().maxGlobalVariableSize_;
compileOptions_.append(opts.str());
}
#if !defined(_LP64) && defined(ATI_OS_LINUX)
if (options->origOptionStr.find("-cl-std=CL2.0") != std::string::npos &&
!dev().settings().force32BitOcl20_) {
errorCode = ACL_UNSUPPORTED;
LogWarning("aclCompile failed");
return false;
}
#endif
// Compile source to IR
compileOptions_.append(hsailOptions());
errorCode = aclCompile(dev().hsaCompiler(), binaryElf_, compileOptions_.c_str(), ACL_TYPE_OPENCL,
ACL_TYPE_LLVMIR_BINARY, NULL);
buildLog_ += aclGetCompilerLog(dev().hsaCompiler());
if (errorCode != ACL_SUCCESS) {
LogWarning("aclCompile failed");
buildLog_ += "Error: Compiling CL to IR\n";
return false;
}
clBinary()->storeCompileOptions(compileOptions_);
// Save the binary in the interface class
saveBinaryAndSetType(TYPE_COMPILED);
return true;
}
} // namespace gpu
@@ -39,8 +39,9 @@ class NullDevice : public amd::Device {
static aclCompiler* hsaCompiler_;
public:
aclCompiler* compiler() const { return compiler_; }
aclCompiler* amdilCompiler() const { return compiler_; }
aclCompiler* hsaCompiler() const { return hsaCompiler_; }
aclCompiler* compiler() const { return hsaCompiler_; }
static bool init(void);
@@ -652,7 +652,7 @@ bool NullKernel::create(const std::string& code, const std::string& metadata,
}
if (ACL_SUCCESS !=
aclInsertSection(nullDev().compiler(), bin, code.data(), code.size(), aclSOURCE)) {
aclInsertSection(nullDev().amdilCompiler(), bin, code.data(), code.size(), aclSOURCE)) {
LogWarning("aclInsertSection failed");
aclBinaryFini(bin);
return false;
@@ -672,10 +672,10 @@ bool NullKernel::create(const std::string& code, const std::string& metadata,
// pass kernel name to compiler
Opts->setCurrKernelName(name().c_str());
err = aclCompile(nullDev().compiler(), bin, options->origOptionStr.c_str(), ACL_TYPE_AMDIL_TEXT,
err = aclCompile(nullDev().amdilCompiler(), bin, options->origOptionStr.c_str(), ACL_TYPE_AMDIL_TEXT,
ACL_TYPE_ISA, NULL);
buildLog_ += aclGetCompilerLog(nullDev().compiler());
buildLog_ += aclGetCompilerLog(nullDev().amdilCompiler());
if (err != ACL_SUCCESS) {
LogWarning("aclCompile failed");
@@ -688,7 +688,7 @@ bool NullKernel::create(const std::string& code, const std::string& metadata,
return true;
}
size_t len;
const void* isa = aclExtractSection(nullDev().compiler(), bin, &len, aclTEXT, &err);
const void* isa = aclExtractSection(nullDev().amdilCompiler(), bin, &len, aclTEXT, &err);
if (err != ACL_SUCCESS) {
LogWarning("aclExtractSection failed");
aclBinaryFini(bin);
@@ -538,7 +538,7 @@ bool NullProgram::linkImpl(const std::vector<device::Program*>& inputPrograms,
} else {
aclTypeUsed = aclLLVMIR;
}
err = aclInsertSection(dev().compiler(), libs[i], llvmBinaries[i]->data(),
err = aclInsertSection(dev().amdilCompiler(), libs[i], llvmBinaries[i]->data(),
llvmBinaries[i]->size(), aclTypeUsed);
if (err != ACL_SUCCESS) {
LogWarning("aclInsertSection failed");
@@ -555,10 +555,10 @@ bool NullProgram::linkImpl(const std::vector<device::Program*>& inputPrograms,
unsigned int numLibs = libs.size() - 1;
if (numLibs > 0) {
err = aclLink(dev().compiler(), libs[0], numLibs, &libs[1], ACL_TYPE_LLVMIR_BINARY,
err = aclLink(dev().amdilCompiler(), libs[0], numLibs, &libs[1], ACL_TYPE_LLVMIR_BINARY,
"-create-library", NULL);
buildLog_ += aclGetCompilerLog(dev().compiler());
buildLog_ += aclGetCompilerLog(dev().amdilCompiler());
if (err != ACL_SUCCESS) {
LogWarning("aclLink failed");
@@ -575,7 +575,7 @@ bool NullProgram::linkImpl(const std::vector<device::Program*>& inputPrograms,
} else {
aclTypeUsed = aclLLVMIR;
}
const void* llvmir = aclExtractSection(dev().compiler(), libs[0], &size, aclTypeUsed, &err);
const void* llvmir = aclExtractSection(dev().amdilCompiler(), libs[0], &size, aclTypeUsed, &err);
if (err != ACL_SUCCESS) {
LogWarning("aclExtractSection failed");
break;
@@ -1532,6 +1532,7 @@ HSAILProgram::HSAILProgram(Device& device)
maxScratchRegs_(0),
executable_(NULL),
loaderContext_(this) {
machineTarget_ = dev().hwInfo()->targetName_;
loader_ = amd::hsa::loader::Loader::Create(&loaderContext_);
}
@@ -1543,6 +1544,7 @@ HSAILProgram::HSAILProgram(NullDevice& device)
executable_(NULL),
loaderContext_(this) {
isNull_ = true;
machineTarget_ = dev().hwInfo()->targetName_;
loader_ = amd::hsa::loader::Loader::Create(&loaderContext_);
}
@@ -483,16 +483,6 @@ class HSAILProgram : public device::Program {
//! post-compile setup for GPU
virtual bool finiBuild(bool isBuildGood);
/*! \brief Compiles GPU CL program to LLVM binary (compiler frontend)
*
* \return True if we successefully compiled a GPU program
*/
virtual bool compileImpl(const std::string& sourceCode, //!< the program's source code
const std::vector<const std::string*>& headers,
const char** headerIncludeNames,
amd::option::Options* options //!< compile options's object
);
/* \brief Returns the next stage to compile from, based on sections in binary,
* also returns completeStages in a vector, which contains at least ACL_TYPE_DEFAULT,
* sets needOptionsCheck to true if options check is needed to decide whether or not to recompile
@@ -134,6 +134,7 @@ bool Segment::freeze(bool destroySysmem) {
return result;
}
const static char* Carrizo = "Carrizo";
HSAILProgram::HSAILProgram(Device& device)
: Program(device),
rawBinary_(nullptr),
@@ -145,7 +146,6 @@ HSAILProgram::HSAILProgram(Device& device)
loaderContext_(this) {
xnackEnabled_ = dev().hwInfo()->xnackEnabled_;
if (dev().properties().revision == Pal::AsicRevision::Bristol) {
const static char* Carrizo = "Carrizo";
machineTarget_ = Carrizo;
} else {
machineTarget_ = dev().hwInfo()->targetName_;
@@ -164,7 +164,11 @@ HSAILProgram::HSAILProgram(NullDevice& device)
loaderContext_(this) {
isNull_ = true;
xnackEnabled_ = dev().hwInfo()->xnackEnabled_;
machineTarget_ = dev().hwInfo()->targetName_;
if (dev().properties().revision == Pal::AsicRevision::Bristol) {
machineTarget_ = Carrizo;
} else {
machineTarget_ = dev().hwInfo()->targetName_;
}
loader_ = amd::hsa::loader::Loader::Create(&loaderContext_);
}