From c5b9715a6ba9b99458f061f6ab65e1e169f1b600 Mon Sep 17 00:00:00 2001
From: foreman
Date: Thu, 20 Sep 2018 18:26:16 -0400
Subject: [PATCH] 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: dbe7f3201d85d28562340ba5d8fd465db1b158b0]
---
.../rocclr/runtime/device/gpu/gpucompiler.cpp | 129 ++----------------
.../rocclr/runtime/device/gpu/gpudevice.hpp | 3 +-
.../rocclr/runtime/device/gpu/gpukernel.cpp | 8 +-
.../rocclr/runtime/device/gpu/gpuprogram.cpp | 10 +-
.../rocclr/runtime/device/gpu/gpuprogram.hpp | 10 --
.../rocclr/runtime/device/pal/palprogram.cpp | 8 +-
6 files changed, 26 insertions(+), 142 deletions(-)
diff --git a/projects/clr/rocclr/runtime/device/gpu/gpucompiler.cpp b/projects/clr/rocclr/runtime/device/gpu/gpucompiler.cpp
index 1de5bbcd14..6e71b83259 100644
--- a/projects/clr/rocclr/runtime/device/gpu/gpucompiler.cpp
+++ b/projects/clr/rocclr/runtime/device/gpu/gpucompiler.cpp
@@ -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& 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 headerFileNames(headers.size());
- std::vector 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
diff --git a/projects/clr/rocclr/runtime/device/gpu/gpudevice.hpp b/projects/clr/rocclr/runtime/device/gpu/gpudevice.hpp
index 468dd7d6a4..cf5cc8b59b 100644
--- a/projects/clr/rocclr/runtime/device/gpu/gpudevice.hpp
+++ b/projects/clr/rocclr/runtime/device/gpu/gpudevice.hpp
@@ -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);
diff --git a/projects/clr/rocclr/runtime/device/gpu/gpukernel.cpp b/projects/clr/rocclr/runtime/device/gpu/gpukernel.cpp
index 68d7a777eb..a2cb603834 100644
--- a/projects/clr/rocclr/runtime/device/gpu/gpukernel.cpp
+++ b/projects/clr/rocclr/runtime/device/gpu/gpukernel.cpp
@@ -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);
diff --git a/projects/clr/rocclr/runtime/device/gpu/gpuprogram.cpp b/projects/clr/rocclr/runtime/device/gpu/gpuprogram.cpp
index 3bf5816bff..407afe8440 100644
--- a/projects/clr/rocclr/runtime/device/gpu/gpuprogram.cpp
+++ b/projects/clr/rocclr/runtime/device/gpu/gpuprogram.cpp
@@ -538,7 +538,7 @@ bool NullProgram::linkImpl(const std::vector& 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& 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& 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_);
}
diff --git a/projects/clr/rocclr/runtime/device/gpu/gpuprogram.hpp b/projects/clr/rocclr/runtime/device/gpu/gpuprogram.hpp
index cbbb4590cd..85ed58c715 100644
--- a/projects/clr/rocclr/runtime/device/gpu/gpuprogram.hpp
+++ b/projects/clr/rocclr/runtime/device/gpu/gpuprogram.hpp
@@ -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& 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
diff --git a/projects/clr/rocclr/runtime/device/pal/palprogram.cpp b/projects/clr/rocclr/runtime/device/pal/palprogram.cpp
index 071004789b..a48939df9d 100644
--- a/projects/clr/rocclr/runtime/device/pal/palprogram.cpp
+++ b/projects/clr/rocclr/runtime/device/pal/palprogram.cpp
@@ -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_);
}