P4 to Git Change 1602604 by gandryey@gera-ocl-lc on 2018/09/06 15:25:43

SWDEV-79445 - OCL generic changes and code clean-up
	- Combine opencl compiler options under a single function.

Affected files ...

... //depot/stg/opencl/drivers/opencl/runtime/device/device.cpp#229 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/device.hpp#317 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpusettings.hpp#102 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palcompiler.cpp#25 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palprogram.cpp#68 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palprogram.hpp#23 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palsettings.cpp#55 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palsettings.hpp#19 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/roccompiler.cpp#44 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocprogram.cpp#84 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocprogram.hpp#34 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocsettings.hpp#17 edit
This commit is contained in:
foreman
2018-09-06 15:37:37 -04:00
szülő d305283689
commit 1d5f2b6dac
12 fájl változott, egészen pontosan 109 új sor hozzáadva és 221 régi sor törölve
@@ -5,6 +5,7 @@
#include "device/device.hpp"
#include "thread/atomic.hpp"
#include "thread/monitor.hpp"
#include "utils/options.hpp"
#if defined(WITH_HSA_DEVICE)
#include "device/rocm/rocdevice.hpp"
@@ -953,6 +954,92 @@ cl_int Program::build(const std::string& sourceCode, const char* origOptions,
return buildError();
}
std::string Program::ProcessOptions(amd::option::Options* options) {
std::string optionsStr;
#ifndef WITH_LIGHTNING_COMPILER
optionsStr.append(" -D__AMD__=1");
optionsStr.append(" -D__").append(device().info().name_).append("__=1");
optionsStr.append(" -D__").append(device().info().name_).append("=1");
#endif
#ifdef WITH_LIGHTNING_COMPILER
int major, minor;
::sscanf(device().info().version_, "OpenCL %d.%d ", &major, &minor);
std::stringstream ss;
ss << " -D__OPENCL_VERSION__=" << (major * 100 + minor * 10);
optionsStr.append(ss.str());
#endif
if (device().info().imageSupport_ && options->oVariables->ImageSupport) {
optionsStr.append(" -D__IMAGE_SUPPORT__=1");
}
#ifndef WITH_LIGHTNING_COMPILER
// Set options for the standard device specific options
// All our devices support these options now
if (device().settings().reportFMAF_) {
optionsStr.append(" -DFP_FAST_FMAF=1");
}
if (device().settings().reportFMA_) {
optionsStr.append(" -DFP_FAST_FMA=1");
}
#endif
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());
}
#if !defined(WITH_LIGHTNING_COMPILER)
if (!device().settings().singleFpDenorm_) {
optionsStr.append(" -cl-denorms-are-zero");
}
// Check if the host is 64 bit or 32 bit
LP64_ONLY(optionsStr.append(" -m64"));
#endif // !defined(WITH_LIGHTNING_COMPILER)
// Tokenize the extensions string into a vector of strings
std::istringstream istrstr(device().info().extensions_);
std::istream_iterator<std::string> sit(istrstr), end;
std::vector<std::string> extensions(sit, end);
if (IS_LIGHTNING && !options->oVariables->Legacy) {
// FIXME_lmoriche: opencl-c.h defines 'cl_khr_depth_images', so
// remove it from the command line. Should we fix opencl-c.h?
auto found = std::find(extensions.begin(), extensions.end(), "cl_khr_depth_images");
if (found != extensions.end()) {
extensions.erase(found);
}
if (!extensions.empty()) {
std::ostringstream clext;
clext << " -Xclang -cl-ext=+";
std::copy(extensions.begin(), extensions.end() - 1,
std::ostream_iterator<std::string>(clext, ",+"));
clext << extensions.back();
optionsStr.append(clext.str());
}
} else {
for (auto e : extensions) {
optionsStr.append(" -D").append(e).append("=1");
}
}
return optionsStr;
}
bool Program::getCompileOptionsAtLinking(const std::vector<Program*>& inputPrograms,
const amd::option::Options* linkOptions) {
amd::option::Options compileOptions;
+9 -3
Fájl megtekintése
@@ -504,6 +504,7 @@ class Settings : public amd::HeapObject {
uint64_t extensions_; //!< Supported OCL extensions
union {
struct {
uint apuSystem_ : 1; //!< Device is APU system with shared memory
uint partialDispatch_ : 1; //!< Enables partial dispatch
uint supportRA_ : 1; //!< Support RA channel order format
uint waitCommand_ : 1; //!< Enables a wait for every submitted command
@@ -511,7 +512,10 @@ class Settings : public amd::HeapObject {
// that replaces generic OS allocation routines
uint supportDepthsRGB_ : 1; //!< Support DEPTH and sRGB channel order format
uint enableHwDebug_ : 1; //!< Enable HW debug support
uint reserved_ : 26;
uint reportFMAF_ : 1; //!< Report FP_FAST_FMAF define in CL program
uint reportFMA_ : 1; //!< Report FP_FAST_FMA define in CL program
uint singleFpDenorm_ : 1; //!< Support Single FP Denorm
uint reserved_ : 22;
};
uint value_;
};
@@ -916,9 +920,11 @@ class Program : public amd::HeapObject {
virtual bool isElf(const char* bin) const = 0;
//! Returns all the options to be appended while passing to the compiler library
std::string ProcessOptions(amd::option::Options* options);
//! At linking time, get the set of compile options to be used from
//! the set of input program, warn if they have inconsisten compile
//! options.
//! the set of input program, warn if they have inconsisten compile options.
bool getCompileOptionsAtLinking(const std::vector<Program*>& inputPrograms,
const amd::option::Options* linkOptions);
@@ -45,8 +45,6 @@ class Settings : public device::Settings {
uint disablePersistent_ : 1; //!< Disables using persistent memory for staging
uint imageSupport_ : 1; //!< Report images support
uint doublePrecision_ : 1; //!< Enables double precision support
uint reportFMAF_ : 1; //!< Report FP_FAST_FMAF define in CL program
uint reportFMA_ : 1; //!< Report FP_FAST_FMA define in CL program
uint use64BitPtr_ : 1; //!< Use 64bit pointers on GPU
uint force32BitOcl20_ : 1; //!< Force 32bit apps to take CLANG/HSAIL path on GPU
uint imageDMA_ : 1; //!< Enable direct image DMA transfers
@@ -62,11 +60,9 @@ class Settings : public device::Settings {
uint stagingWritePersistent_ : 1; //!< Enables persistent writes
uint svmAtomics_ : 1; //!< SVM device atomics
uint svmFineGrainSystem_ : 1; //!< SVM fine grain system support
uint apuSystem_ : 1; //!< Device is APU system with shared memory
uint asyncMemCopy_ : 1; //!< Use async memory transfers
uint useDeviceQueue_ : 1; //!< Submit to separate device queue
uint singleFpDenorm_ : 1; //!< Support Single FP Denorm
uint reserved_ : 5;
uint reserved_ : 9;
};
uint value_;
};
@@ -120,7 +120,7 @@ bool HSAILProgram::compileImpl(const std::string& sourceCode,
#endif
// Compile source to IR
compileOptions_.append(hsailOptions(options));
compileOptions_.append(ProcessOptions(options));
errorCode = aclCompile(dev().compiler(), binaryElf_, compileOptions_.c_str(), ACL_TYPE_OPENCL,
ACL_TYPE_LLVMIR_BINARY, nullptr);
buildLog_ += aclGetCompilerLog(dev().compiler());
@@ -258,7 +258,7 @@ bool LightningProgram::compileImpl(const std::string& sourceCode,
}
driverOptions.append(options->llvmOptions);
driverOptions.append(hsailOptions(options));
driverOptions.append(ProcessOptions(options));
// Set whole program mode
driverOptions.append(" -mllvm -amdgpu-early-inline-all -mllvm -amdgpu-prelink");
@@ -572,7 +572,7 @@ bool HSAILProgram::linkImpl(amd::option::Options* options) {
// Compilation from ACL_TYPE_HSAIL_TEXT to ACL_TYPE_CG in cases:
// 1. if the program is created with binary and contains only hsail text
case ACL_TYPE_HSAIL_TEXT: {
std::string curOptions = options->origOptionStr + hsailOptions(options);
std::string curOptions = options->origOptionStr + ProcessOptions(options);
errorCode = aclCompile(dev().compiler(), binaryElf_, curOptions.c_str(), continueCompileFrom,
ACL_TYPE_CG, nullptr);
buildLog_ += aclGetCompilerLog(dev().compiler());
@@ -594,7 +594,7 @@ bool HSAILProgram::linkImpl(amd::option::Options* options) {
return false;
}
if (finalize) {
std::string fin_options(options->origOptionStr + hsailOptions(options));
std::string fin_options(options->origOptionStr + ProcessOptions(options));
// Append an option so that we can selectively enable a SCOption on CZ
// whenever IOMMUv2 is enabled.
if (dev().settings().svmFineGrainSystem_) {
@@ -669,7 +669,7 @@ bool HSAILProgram::linkImpl(amd::option::Options* options) {
std::string openclKernelName = device::Kernel::openclMangledName(kernelName);
HSAILKernel* aKernel =
new HSAILKernel(kernelName, this, options->origOptionStr + hsailOptions(options));
new HSAILKernel(kernelName, this, options->origOptionStr + ProcessOptions(options));
kernels()[kernelName] = aKernel;
amd::hsa::loader::Symbol* sym = executable_->GetSymbol(openclKernelName.c_str(), &agent);
@@ -704,92 +704,6 @@ bool HSAILProgram::linkImpl(amd::option::Options* options) {
bool HSAILProgram::createBinary(amd::option::Options* options) { return true; }
std::string HSAILProgram::hsailOptions(amd::option::Options* options) {
std::string hsailOptions;
#ifndef WITH_LIGHTNING_COMPILER
hsailOptions.append(" -D__AMD__=1");
hsailOptions.append(" -D__").append(device().info().name_).append("__=1");
hsailOptions.append(" -D__").append(device().info().name_).append("=1");
#endif
int major, minor;
::sscanf(device().info().version_, "OpenCL %d.%d ", &major, &minor);
#ifdef WITH_LIGHTNING_COMPILER
std::stringstream ss;
ss << " -D__OPENCL_VERSION__=" << (major * 100 + minor * 10);
hsailOptions.append(ss.str());
#endif
if (device().info().imageSupport_ && options->oVariables->ImageSupport) {
hsailOptions.append(" -D__IMAGE_SUPPORT__=1");
}
#ifndef WITH_LIGHTNING_COMPILER
// Set options for the standard device specific options
// All our devices support these options now
if (dev().settings().reportFMAF_) {
hsailOptions.append(" -DFP_FAST_FMAF=1");
}
if (dev().settings().reportFMA_) {
hsailOptions.append(" -DFP_FAST_FMA=1");
}
#endif
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_;
hsailOptions.append(opts.str());
}
#if !defined(WITH_LIGHTNING_COMPILER)
if (!dev().settings().singleFpDenorm_) {
hsailOptions.append(" -cl-denorms-are-zero");
}
#endif // !defined(WITH_LIGHTNING_COMPILER)
// Check if the host is 64 bit or 32 bit
LP64_ONLY(hsailOptions.append(" -m64"));
// Tokenize the extensions string into a vector of strings
std::istringstream istrstr(device().info().extensions_);
std::istream_iterator<std::string> sit(istrstr), end;
std::vector<std::string> extensions(sit, end);
#if defined(WITH_LIGHTNING_COMPILER)
// FIXME_lmoriche: opencl-c.h defines 'cl_khr_depth_images', so
// remove it from the command line. Should we fix opencl-c.h?
auto found = std::find(extensions.begin(), extensions.end(), "cl_khr_depth_images");
if (found != extensions.end()) {
extensions.erase(found);
}
if (!extensions.empty()) {
std::ostringstream clext;
clext << " -Xclang -cl-ext=+";
std::copy(extensions.begin(), extensions.end() - 1,
std::ostream_iterator<std::string>(clext, ",+"));
clext << extensions.back();
hsailOptions.append(clext.str());
}
#else // !defined(WITH_LIGHTNING_COMPILER)
for (auto e : extensions) {
hsailOptions.append(" -D").append(e).append("=1");
}
#endif // !defined(WITH_LIGHTNING_COMPILER)
return hsailOptions;
}
bool HSAILProgram::allocKernelTable() {
uint size = kernels().size() * sizeof(size_t);
@@ -1594,7 +1508,7 @@ bool LightningProgram::setKernels(amd::option::Options* options, void* binary, s
for (auto& kernelName : kernelNameList) {
auto kernel =
new LightningKernel(kernelName, this, options->origOptionStr + hsailOptions(options));
new LightningKernel(kernelName, this, options->origOptionStr + ProcessOptions(options));
kernels()[kernelName] = kernel;
@@ -230,10 +230,6 @@ class HSAILProgram : public device::Program {
HSAILProgram& operator=(const HSAILProgram&);
protected:
//! Returns all the options to be appended while passing to the
// compiler library
std::string hsailOptions(amd::option::Options* options);
//! Allocate kernel table
bool allocKernelTable();
@@ -241,7 +241,7 @@ bool Settings::create(const Pal::DeviceProperties& palProp,
case Pal::AsicRevision::Hawaii:
threadTraceEnable_ = AMD_THREAD_TRACE_ENABLE;
reportFMAF_ = false;
if (palProp.revision == Pal::AsicRevision::Hawaii) {
if ((palProp.revision == Pal::AsicRevision::Hawaii) || aiPlus_) {
reportFMAF_ = true;
}
// Cache line size is 64 bytes
@@ -45,8 +45,6 @@ class Settings : public device::Settings {
uint disablePersistent_ : 1; //!< Disables using persistent memory for staging
uint imageSupport_ : 1; //!< Report images support
uint doublePrecision_ : 1; //!< Enables double precision support
uint reportFMAF_ : 1; //!< Report FP_FAST_FMAF define in CL program
uint reportFMA_ : 1; //!< Report FP_FAST_FMA define in CL program
uint use64BitPtr_ : 1; //!< Use 64bit pointers on GPU
uint force32BitOcl20_ : 1; //!< Force 32bit apps to take CLANG/HSAIL path on GPU
uint imageDMA_ : 1; //!< Enable direct image DMA transfers
@@ -60,13 +58,11 @@ class Settings : public device::Settings {
uint stagingWritePersistent_ : 1; //!< Enables persistent writes
uint svmAtomics_ : 1; //!< SVM device atomics
uint svmFineGrainSystem_ : 1; //!< SVM fine grain system support
uint apuSystem_ : 1; //!< Device is APU system with shared memory
uint useDeviceQueue_ : 1; //!< Submit to separate device queue
uint singleFpDenorm_ : 1; //!< Support Single FP Denorm
uint sdamPageFaultWar_ : 1; //!< SDMA page fault workaround
uint rgpSqttWaitIdle_: 1; //!< Wait for idle after SQTT trace
uint rgpSqttForceDisable_: 1; //!< Disables SQTT
uint reserved_ : 6;
uint reserved_ : 10;
};
uint value_;
};
@@ -129,17 +129,8 @@ bool HSAILProgram::compileImpl(const std::string& sourceCode,
this->compileOptions_.append(tempFolder);
}
// Add only for CL2.0 and later
if (options->oVariables->CLStd[2] >= '2') {
std::stringstream opts;
opts << " -D"
<< "CL_DEVICE_MAX_GLOBAL_VARIABLE_SIZE=" << device().info().maxGlobalVariableSize_;
compileOptions_.append(opts.str());
}
// Compile source to IR
this->compileOptions_.append(preprocessorOptions(options));
this->compileOptions_.append(codegenOptions(options));
this->compileOptions_.append(ProcessOptions(options));
errorCode = aclCompile(device().compiler(), binaryElf_,
//"-Wf,--support_all_extensions",
@@ -225,7 +216,7 @@ bool LightningProgram::compileImpl(const std::string& sourceCode,
// Set whole program mode
driverOptions.append(" -mllvm -amdgpu-early-inline-all -mllvm -amdgpu-prelink");
driverOptions.append(preprocessorOptions(options));
driverOptions.append(ProcessOptions(options));
// Find the temp folder for the OS
std::string tempFolder = amd::Os::getEnvironment("TEMP");
@@ -274,98 +274,6 @@ aclType Program::getNextCompilationStageFromBinary(amd::option::Options* options
return continueCompileFrom;
}
#if defined(WITH_COMPILER_LIB)
std::string HSAILProgram::codegenOptions(amd::option::Options* options) {
std::string optionsStr;
if (dev().deviceInfo().gfxipVersion_ < 900 || !dev().settings().singleFpDenorm_) {
optionsStr.append(" -cl-denorms-are-zero");
}
// check if the host is 64 bit or 32 bit
LP64_ONLY(optionsStr.append(" -m64"));
return optionsStr;
}
#endif // defined(WITH_COMPILER_LIB)
std::string Program::preprocessorOptions(amd::option::Options* options) {
std::string optionsStr;
// Set options for the standard device specific options
#ifndef WITH_LIGHTNING_COMPILER
optionsStr.append(" -D__AMD__=1");
optionsStr.append(" -D__").append(device().info().name_).append("__=1");
optionsStr.append(" -D__").append(device().info().name_).append("=1");
#endif
int major, minor;
::sscanf(device().info().version_, "OpenCL %d.%d ", &major, &minor);
std::stringstream ss;
ss << " -D__OPENCL_VERSION__=" << (major * 100 + minor * 10);
optionsStr.append(ss.str());
if (device().info().imageSupport_ && options->oVariables->ImageSupport) {
optionsStr.append(" -D__IMAGE_SUPPORT__=1");
}
#ifndef WITH_LIGHTNING_COMPILER
// This is just for legacy compiler code
// All our devices support these options now
if (options->oVariables->FastFMA) {
optionsStr.append(" -DFP_FAST_FMA=1");
}
if (options->oVariables->FastFMAF) {
optionsStr.append(" -DFP_FAST_FMAF=1");
}
#endif
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());
}
// Tokenize the extensions string into a vector of strings
std::istringstream istrstr(device().info().extensions_);
std::istream_iterator<std::string> sit(istrstr), end;
std::vector<std::string> extensions(sit, end);
if (IS_LIGHTNING && !options->oVariables->Legacy) {
// FIXME_lmoriche: opencl-c.h defines 'cl_khr_depth_images', so
// remove it from the command line. Should we fix opencl-c.h?
auto found = std::find(extensions.begin(), extensions.end(), "cl_khr_depth_images");
if (found != extensions.end()) {
extensions.erase(found);
}
if (!extensions.empty()) {
std::ostringstream clext;
clext << " -Xclang -cl-ext=+";
std::copy(extensions.begin(), extensions.end() - 1,
std::ostream_iterator<std::string>(clext, ",+"));
clext << extensions.back();
optionsStr.append(clext.str());
}
} else {
for (auto e : extensions) {
optionsStr.append(" -D").append(e).append("=1");
}
}
return optionsStr;
}
#if defined(WITH_COMPILER_LIB)
HSAILProgram::HSAILProgram(roc::NullDevice& device) : roc::Program(device) {
}
@@ -613,7 +521,7 @@ bool HSAILProgram::linkImpl(amd::option::Options* options) {
// 1. if the program is created with binary and contains only hsail text
case ACL_TYPE_HSAIL_TEXT: {
std::string curOptions =
options->origOptionStr + preprocessorOptions(options) + codegenOptions(options);
options->origOptionStr + ProcessOptions(options);
errorCode = aclCompile(device().compiler(), binaryElf_, curOptions.c_str(),
continueCompileFrom, ACL_TYPE_CG, logFunction);
buildLog_ += aclGetCompilerLog(device().compiler());
@@ -94,10 +94,6 @@ class Program : public device::Program {
Program& operator=(const Program&) = delete;
protected:
//! Returns all the options to be appended while passing to the
// compiler
std::string preprocessorOptions(amd::option::Options* options);
// aclBinary and aclCompiler - for the compiler library
aclBinary* binaryElf_; //!< Binary for the new compiler library
aclBinaryOptions binOpts_; //!< Binary options to create aclBinary
@@ -27,9 +27,7 @@ class Settings : public device::Settings {
uint imageDMA_ : 1; //!< Enable direct image DMA transfers
uint stagedXferRead_ : 1; //!< Uses a staged buffer read
uint stagedXferWrite_ : 1; //!< Uses a staged buffer write
uint singleFpDenorm_ : 1; //!< Support Single FP Denorm
uint apuSystem_ : 1; //!< APU system
uint reserved_ : 22;
uint reserved_ : 24;
};
uint value_;
};