From e195bb5eea17a1f8ded2cedf19c2ac863bf3ffba Mon Sep 17 00:00:00 2001
From: foreman
Date: Sun, 21 Aug 2016 17:46:14 -0400
Subject: [PATCH] P4 to Git Change 1305360 by lmoriche@lmoriche_opencl_dev on
2016/08/21 17:34:39
SWDEV-94640 - Set the O# level and cl-std from the command args or default settings.
Select the correct header (CL1.2/C2.0) from the given cl-std.
Reorder the linked libraries in reverse order of dependency (was failing linking).
Make the built-in library objects depend on the pre-compiled header.
Disable the timestamp on the pre-compiled header.
Disable image support reporting.
Affected files ...
... //depot/stg/opencl/drivers/opencl/make/amdgcn.git/headers/build/Makefile.headers#7 edit
... //depot/stg/opencl/drivers/opencl/make/amdgcn.git/irif/build/Makefile.irif#4 edit
... //depot/stg/opencl/drivers/opencl/make/amdgcn.git/ockl/build/Makefile.ockl#5 edit
... //depot/stg/opencl/drivers/opencl/make/amdgcn.git/oclc/build/Makefile.oclc#5 edit
... //depot/stg/opencl/drivers/opencl/make/amdgcn.git/ocml/build/Makefile.ocml#5 edit
... //depot/stg/opencl/drivers/opencl/make/amdgcn.git/opencl/build/Makefile.opencl#6 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/roccompiler.cpp#8 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocdevice.cpp#10 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocprogram.cpp#11 edit
[ROCm/clr commit: 9674e8eb0102a5503c11a32798f8c524351aaf2a]
---
.../runtime/device/rocm/roccompiler.cpp | 78 ++++++++++++-------
.../rocclr/runtime/device/rocm/rocdevice.cpp | 3 +
.../rocclr/runtime/device/rocm/rocprogram.cpp | 10 ++-
3 files changed, 61 insertions(+), 30 deletions(-)
diff --git a/projects/clr/rocclr/runtime/device/rocm/roccompiler.cpp b/projects/clr/rocclr/runtime/device/rocm/roccompiler.cpp
index 7dc342eedc..0f9042beba 100644
--- a/projects/clr/rocclr/runtime/device/rocm/roccompiler.cpp
+++ b/projects/clr/rocclr/runtime/device/rocm/roccompiler.cpp
@@ -40,14 +40,17 @@ HSAILProgram::compileImpl_LC(const std::string& sourceCode,
const char** headerIncludeNames,
amd::option::Options* options)
{
- std::vector inputs;
- amd::opencl_driver::Data* src = device().compiler()->NewBufferReference(
- amd::opencl_driver::DT_CL,sourceCode.c_str(),
- sourceCode.length());
+ using namespace amd::opencl_driver;
+ std::vector inputs;
+
+ Data* src = device().compiler()->NewBufferReference(DT_CL,
+ sourceCode.c_str(), sourceCode.length());
+
if (src == NULL) {
buildLog_ += "Error while creating data from source code";
return false;
}
+
inputs.push_back(src);
//Find the temp folder for the OS
@@ -94,9 +97,8 @@ HSAILProgram::compileImpl_LC(const std::string& sourceCode,
f.write(headers[i]->c_str(), headers[i]->length());
f.close();
- amd::opencl_driver::Data* inc = device().compiler()->NewFileReference(
- amd::opencl_driver::DT_CL_HEADER,
- headerFileNames[i]);
+ Data* inc = device().compiler()->NewFileReference(DT_CL_HEADER,
+ headerFileNames[i]);
inputs.push_back(inc);
}
@@ -108,30 +110,53 @@ HSAILProgram::compileImpl_LC(const std::string& sourceCode,
compileOptions_.append(tempFolder);
}
- //Add only for CL2.0 and later
- if (options->oVariables->CLStd[2] >= '2') {
+ const char* xLang = options->oVariables->XLang;
+ if (xLang != NULL && strcmp(xLang, "cl")) {
+ buildLog_ += "Unsupported OpenCL language.\n";
+ }
+
+ //FIXME_Nikolay: the program manager should be setting the language
+ //compileOptions_.append(" -x cl");
+ //FIXME_Nikolay: the program manager shouls be setting the cl-std. -Xclang
+ //is not necessary, we add it to overridde the flag set in the comp driver.
+ compileOptions_.append(" -Xclang -cl-std=").append(options->oVariables->CLStd);
+
+ std::ostringstream optLevel;
+ optLevel << " -O" << options->oVariables->OptLevel;
+ compileOptions_.append(optLevel.str());
+
+ //FIXME_lmoriche: has the CL option been validated?
+ uint clVer = (options->oVariables->CLStd[2] - '0') * 100
+ + (options->oVariables->CLStd[4] - '0') * 10;
+
+ std::pair hdr;
+ switch(clVer) {
+ case 120: hdr = std::make_pair(opencl1_2_c_amdgcn, opencl1_2_c_amdgcn_size); break;
+ case 200: hdr = std::make_pair(opencl2_0_c_amdgcn, opencl2_0_c_amdgcn_size); break;
+ default:
+ buildLog_ += "Unsupported requested OpenCL C version (-cl-std).\n";
+ return false;
+ }
+
+ File* pch = device().compiler()->NewTempFile(DT_CL_HEADER);
+ if (pch == NULL || !pch->WriteData((const char*) hdr.first, hdr.second)) {
+ buildLog_ += "Error while opening the opencl-c header ";
+ return false;
+ }
+
+ compileOptions_.append(" -Xclang -include-pch -Xclang " + pch->Name());
+ compileOptions_.append(" -Xclang -fno-validate-pch");
+
+ compileOptions_.append(hsailOptions());
+ if (clVer >= 200) {
std::stringstream opts;
+ //Add only for CL2.0 and later
opts << " -D" << "CL_DEVICE_MAX_GLOBAL_VARIABLE_SIZE="
<< device().info().maxGlobalVariableSize_;
compileOptions_.append(opts.str());
}
- amd::opencl_driver::File* pch = device().compiler()->NewTempFile(
- amd::opencl_driver::DT_CL_HEADER);
- if (pch == NULL || !pch->WriteData((const char*) opencl2_0_c_amdgcn,
- opencl2_0_c_amdgcn_size)) {
- buildLog_ += "Error while opening the opencl-c header ";
- return false;
- }
-
- // FIXME_lmoriche: Force OpenCL-C 2.0, since the built-ins are built that way.
- compileOptions_.append(" -Xclang -cl-std=CL2.0");
- compileOptions_.append(" -Xclang -include-pch -Xclang " + pch->Name());
- compileOptions_.append(" -Xclang -fno-validate-pch");
-
- compileOptions_.append(hsailOptions());
-
- amd::opencl_driver::Buffer* output = device().compiler()->NewBuffer(amd::opencl_driver::DT_LLVM_BC);
+ Buffer* output = device().compiler()->NewBuffer(DT_LLVM_BC);
if (output == NULL) {
buildLog_ += "Error while creating buffer for the LLVM bitcode";
return false;
@@ -146,8 +171,7 @@ HSAILProgram::compileImpl_LC(const std::string& sourceCode,
bool ret = device().compiler()->CompileToLLVMBitcode(inputs, output, optionsvec);
buildLog_ += device().compiler()->Output().c_str();
if (!ret) {
- buildLog_ += "Error while compiling \
- opencl source: Compiling CL to IR";
+ buildLog_ += "Error while compiling opencl source: Compiling CL to IR";
return false;
}
diff --git a/projects/clr/rocclr/runtime/device/rocm/rocdevice.cpp b/projects/clr/rocclr/runtime/device/rocm/rocdevice.cpp
index 5d6f6487da..20e724f425 100644
--- a/projects/clr/rocclr/runtime/device/rocm/rocdevice.cpp
+++ b/projects/clr/rocclr/runtime/device/rocm/rocdevice.cpp
@@ -882,6 +882,9 @@ Device::populateOCLDeviceConstants()
assert(HSA_EXTENSION_IMAGES < 8);
const bool image_is_supported =
+#if defined(WITH_LIGHTNING_COMPILER)
+ false && // FIXME_lmoriche: Enable this when the LC is ready.
+#endif // defined(WITH_LIGHTNING_COMPILER)
((hsa_extensions[0] & (1 << HSA_EXTENSION_IMAGES)) != 0);
if (image_is_supported) {
// Images
diff --git a/projects/clr/rocclr/runtime/device/rocm/rocprogram.cpp b/projects/clr/rocclr/runtime/device/rocm/rocprogram.cpp
index a943e0e56d..9c2c58dd7b 100644
--- a/projects/clr/rocclr/runtime/device/rocm/rocprogram.cpp
+++ b/projects/clr/rocclr/runtime/device/rocm/rocprogram.cpp
@@ -638,10 +638,10 @@ namespace roc {
return false;
}
- inputs.push_back(irif_bc);
- inputs.push_back(ocml_bc); // depends on irif
- inputs.push_back(ockl_bc); // depends on irif
inputs.push_back(opencl_bc); // depends on oclm & ockl
+ inputs.push_back(ockl_bc); // depends on irif
+ inputs.push_back(ocml_bc); // depends on irif
+ inputs.push_back(irif_bc);
// open the control functions
std::pair isa_version;
@@ -734,6 +734,10 @@ namespace roc {
optionsstr.append(" -mcpu=");
optionsstr.append(dev().deviceInfo().machineTarget_);
+ std::ostringstream optLevel;
+ optLevel << " -O" << options->oVariables->OptLevel;
+ optionsstr.append(optLevel.str());
+
// Tokenize the options string into a vector of strings
std::istringstream strstr(optionsstr);
std::istream_iterator sit(strstr), end;