From 70acf47d09feb320a761b6b98a592ddce6479673 Mon Sep 17 00:00:00 2001
From: foreman
Date: Tue, 20 Sep 2016 20:53:50 -0400
Subject: [PATCH] P4 to Git Change 1316785 by lmoriche@lmoriche_opencl_dev on
2016/09/20 20:47:40
SWDEV-94610 - Add gfx700 to the list of suported targets in HSAILProgram::linkImpl_LC. When dumping the source (-save-temps), print the options actually sent to clang as well as the options passed to OpenCL.
Affected files ...
... //depot/stg/opencl/drivers/opencl/library/build/Makefile.library#56 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/amdgpu_metadata.cpp#5 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/roccompiler.cpp#18 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocprogram.cpp#36 edit
[ROCm/clr commit: 383e97425b3a9fdaa8d12f99827de16fa05515ed]
---
.../runtime/device/rocm/amdgpu_metadata.cpp | 5 +-
.../runtime/device/rocm/roccompiler.cpp | 74 +++++++++----------
.../rocclr/runtime/device/rocm/rocprogram.cpp | 53 +++++++------
3 files changed, 70 insertions(+), 62 deletions(-)
diff --git a/projects/clr/rocclr/runtime/device/rocm/amdgpu_metadata.cpp b/projects/clr/rocclr/runtime/device/rocm/amdgpu_metadata.cpp
index 1faa04da6b..1c5d76ea00 100644
--- a/projects/clr/rocclr/runtime/device/rocm/amdgpu_metadata.cpp
+++ b/projects/clr/rocclr/runtime/device/rocm/amdgpu_metadata.cpp
@@ -211,8 +211,11 @@ namespace code {
if (kind == Image || kind == Pipe) {
out << " Access: " << AccessQualToString(accQual);
}
+ if (kind == GlobalBuffer || kind == DynamicSharedPointer) {
+ out
+ << " Address: " << (unsigned) addrQual;
+ }
out
- << " Address: " << (unsigned) addrQual
<< " Size: " << size
<< " Align: " << align;
if (kind == DynamicSharedPointer) {
diff --git a/projects/clr/rocclr/runtime/device/rocm/roccompiler.cpp b/projects/clr/rocclr/runtime/device/rocm/roccompiler.cpp
index fc2c4cfa5e..d1bbe6804e 100644
--- a/projects/clr/rocclr/runtime/device/rocm/roccompiler.cpp
+++ b/projects/clr/rocclr/runtime/device/rocm/roccompiler.cpp
@@ -55,17 +55,6 @@ HSAILProgram::compileImpl_LC(
std::auto_ptr C(newCompilerInstance());
std::vector inputs;
- if (options->isDumpFlagSet(amd::option::DUMP_CL)) {
- std::ofstream f(options->getDumpFileName(".cl").c_str(), std::ios::trunc);
- if(f.is_open()) {
- f << "/* Compiler options:\n" << options->origOptionStr
- << "\n*/\n\n" << sourceCode;
- } else {
- buildLog_ +=
- "Warning: opening the file to dump the OpenCL source failed.\n";
- }
- }
-
Data* input = C->NewBufferReference(DT_CL,
sourceCode.c_str(), sourceCode.length());
if (input == NULL) {
@@ -147,20 +136,50 @@ HSAILProgram::compileImpl_LC(
//FIXME_Nikolay: the program manager should be setting the language
//driverOptions.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.
- driverOptions.append(" -Xclang -cl-std=").append(options->oVariables->CLStd);
+ driverOptions.append(" -cl-std=").append(options->oVariables->CLStd);
+
+ // Set the -O#
std::ostringstream optLevel;
optLevel << " -O" << options->oVariables->OptLevel;
driverOptions.append(optLevel.str());
//FIXME_lmoriche: has the CL option been validated?
- uint clVer = (options->oVariables->CLStd[2] - '0') * 100
+ uint clcStd = (options->oVariables->CLStd[2] - '0') * 100
+ (options->oVariables->CLStd[4] - '0') * 10;
+ driverOptions.append(preprocessorOptions(options));
+
+ Buffer* output = C->NewBuffer(DT_LLVM_BC);
+ if (output == NULL) {
+ buildLog_ += "Error while creating buffer for the LLVM bitcode";
+ return false;
+ }
+
+ // Set fp32-denormals and fp64-denormals
+ bool fp32Denormals = !options->oVariables->DenormsAreZero
+ && dev().deviceInfo().gfxipVersion_ >= 900;
+
+ driverOptions.append(" -Xclang -target-feature -Xclang ");
+ driverOptions.append(fp32Denormals ? "+" : "-")
+ .append("fp32-denormals,+fp64-denormals");
+
+ if (options->isDumpFlagSet(amd::option::DUMP_CL)) {
+ std::ofstream f(options->getDumpFileName(".cl").c_str(), std::ios::trunc);
+ if(f.is_open()) {
+ f << "/* Original options: " << options->origOptionStr
+ << "\n Generated options:\n"
+ << " -c -emit-llvm -target amdgcn--amdhsa -x cl"
+ << " -include opencl-c.h " << driverOptions
+ << "\n*/\n\n" << sourceCode;
+ } else {
+ buildLog_ +=
+ "Warning: opening the file to dump the OpenCL source failed.\n";
+ }
+ }
+
std::pair hdr;
- switch(clVer) {
+ switch(clcStd) {
case 120:
hdr = std::make_pair(opencl1_2_c_amdgcn, opencl1_2_c_amdgcn_size);
break;
@@ -181,29 +200,6 @@ HSAILProgram::compileImpl_LC(
driverOptions.append(" -include-pch " + pch->Name());
driverOptions.append(" -Xclang -fno-validate-pch");
- driverOptions.append(preprocessorOptions(options));
- if (clVer >= 200) {
- std::stringstream opts;
- //Add only for CL2.0 and later
- opts << " -D" << "CL_DEVICE_MAX_GLOBAL_VARIABLE_SIZE="
- << device().info().maxGlobalVariableSize_;
- driverOptions.append(opts.str());
- }
-
- Buffer* output = C->NewBuffer(DT_LLVM_BC);
- if (output == NULL) {
- buildLog_ += "Error while creating buffer for the LLVM bitcode";
- return false;
- }
-
- // Set fp32-denormals and fp64-denormals
- bool fp32Denormals = !options->oVariables->DenormsAreZero
- && dev().deviceInfo().gfxipVersion_ >= 900;
-
- driverOptions.append(" -Xclang -target-feature -Xclang ");
- driverOptions.append(fp32Denormals ? "+" : "-")
- .append("fp32-denormals,+fp64-denormals");
-
// Tokenize the options string into a vector of strings
std::istringstream istrstr(driverOptions);
std::istream_iterator sit(istrstr), end;
diff --git a/projects/clr/rocclr/runtime/device/rocm/rocprogram.cpp b/projects/clr/rocclr/runtime/device/rocm/rocprogram.cpp
index 2668557ccb..d49f1c27de 100644
--- a/projects/clr/rocclr/runtime/device/rocm/rocprogram.cpp
+++ b/projects/clr/rocclr/runtime/device/rocm/rocprogram.cpp
@@ -800,28 +800,25 @@ HSAILProgram::linkImpl_LC(amd::option::Options *options)
// open the control functions
std::pair isa_version;
switch (dev().deviceInfo().gfxipVersion_) {
- case 701:
- isa_version = std::make_pair(
+ case 700: isa_version = std::make_pair(
+ oclc_isa_version_700_amdgcn, oclc_isa_version_700_amdgcn_size);
+ break;
+ case 701: isa_version = std::make_pair(
oclc_isa_version_701_amdgcn, oclc_isa_version_701_amdgcn_size);
break;
- case 800:
- isa_version = std::make_pair(
+ case 800: isa_version = std::make_pair(
oclc_isa_version_800_amdgcn, oclc_isa_version_800_amdgcn_size);
break;
- case 801:
- isa_version = std::make_pair(
+ case 801: isa_version = std::make_pair(
oclc_isa_version_801_amdgcn, oclc_isa_version_801_amdgcn_size);
break;
- case 802:
- isa_version = std::make_pair(
+ case 802: isa_version = std::make_pair(
oclc_isa_version_802_amdgcn, oclc_isa_version_802_amdgcn_size);
break;
- case 803:
- isa_version = std::make_pair(
+ case 803: isa_version = std::make_pair(
oclc_isa_version_803_amdgcn, oclc_isa_version_803_amdgcn_size);
break;
- case 810:
- isa_version = std::make_pair(
+ case 810: isa_version = std::make_pair(
oclc_isa_version_810_amdgcn, oclc_isa_version_810_amdgcn_size);
break;
default:
@@ -919,9 +916,6 @@ HSAILProgram::linkImpl_LC(amd::option::Options *options)
}
}
- std::ostringstream optLevel;
- optLevel << "-O" << options->oVariables->OptLevel;
-
inputs.clear();
inputs.push_back(linked_bc);
@@ -938,6 +932,8 @@ HSAILProgram::linkImpl_LC(amd::option::Options *options)
codegenOptions.append(dev().deviceInfo().machineTarget_);
// Set the -O#
+ std::ostringstream optLevel;
+ optLevel << "-O" << options->oVariables->OptLevel;
codegenOptions.append(" ").append(optLevel.str());
// Tokenize the options string into a vector of strings
@@ -953,7 +949,7 @@ HSAILProgram::linkImpl_LC(amd::option::Options *options)
}
if (options->isDumpFlagSet(amd::option::DUMP_O)) {
- std::ofstream f(options->getDumpFileName(".co").c_str(), std::ios::trunc);
+ std::ofstream f(options->getDumpFileName(".so").c_str(), std::ios::trunc);
if(f.is_open()) {
f.write(out_exec->Buf().data(), out_exec->Size());
} else {
@@ -1499,7 +1495,10 @@ HSAILProgram::preprocessorOptions(amd::option::Options* options)
//Set options for the standard device specific options
- optionsStr.append(" -D__AMD__");
+ optionsStr.append(" -D__AMD__=1");
+
+ optionsStr.append(" -D__").append(device().info().name_).append("__=1");
+ optionsStr.append(" -D__").append(device().info().name_).append("=1");
int major, minor;
::sscanf(device().info().version_, "OpenCL %d.%d ", &major, &minor);
@@ -1509,16 +1508,27 @@ HSAILProgram::preprocessorOptions(amd::option::Options* options)
optionsStr.append(ss.str());
if (device().info().imageSupport_ && options->oVariables->ImageSupport) {
- optionsStr.append(" -D__IMAGE_SUPPORT__");
+ optionsStr.append(" -D__IMAGE_SUPPORT__=1");
}
//This is just for legacy compiler code
// All our devices support these options now
if (options->oVariables->FastFMA) {
- optionsStr.append(" -DFP_FAST_FMA");
+ optionsStr.append(" -DFP_FAST_FMA=1");
}
if (options->oVariables->FastFMAF) {
- optionsStr.append(" -DFP_FAST_FMAF");
+ optionsStr.append(" -DFP_FAST_FMAF=1");
+ }
+
+ uint clcStd = (options->oVariables->CLStd[2] - '0') * 100
+ + (options->oVariables->CLStd[4] - '0') * 10;
+
+ if (clcStd >= 200) {
+ std::stringstream opts;
+ //Add only for CL2.0 and later
+ opts << " -D" << "CL_DEVICE_MAX_GLOBAL_VARIABLE_SIZE="
+ << device().info().maxGlobalVariableSize_;
+ optionsStr.append(opts.str());
}
//Now append each extension supported by the device
@@ -1534,8 +1544,7 @@ HSAILProgram::preprocessorOptions(amd::option::Options* options)
if (options->oVariables->CLStd[2] >= '2'
&& token == "cl_khr_depth_images") continue;
#endif // defined(WITH_LIGHTHNING_COMPILER)
- optionsStr.append(" -D");
- optionsStr.append(token);
+ optionsStr.append(" -D").append(token).append("=1");
}
}
return optionsStr;