SWDEV-252745 - Adding precompiled headers to build option
Change-Id: Iab03e8a75215d80c91817ee0227d034fefa9dfad
[ROCm/clr commit: 5cfea2981b]
Этот коммит содержится в:
коммит произвёл
Jatin Chaudhary
родитель
e60c7aa890
Коммит
43a470093d
@@ -118,10 +118,11 @@ void Program::clear() {
|
||||
|
||||
// ================================================================================================
|
||||
bool Program::compileImpl(const std::string& sourceCode,
|
||||
const std::vector<const std::string*>& headers,
|
||||
const char** headerIncludeNames, amd::option::Options* options) {
|
||||
const std::vector<const std::string*>& headers,
|
||||
const char** headerIncludeNames, amd::option::Options* options,
|
||||
const std::vector<std::string>& preCompiledHeaders) {
|
||||
if (isLC()) {
|
||||
return compileImplLC(sourceCode, headers, headerIncludeNames, options);
|
||||
return compileImplLC(sourceCode, headers, headerIncludeNames, options, preCompiledHeaders);
|
||||
} else {
|
||||
return compileImplHSAIL(sourceCode, headers, headerIncludeNames, options);
|
||||
}
|
||||
@@ -212,6 +213,33 @@ amd_comgr_status_t Program::extractByteCodeBinary(const amd_comgr_data_set_t inD
|
||||
return AMD_COMGR_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
amd_comgr_status_t Program::addPreCompiledHeader(
|
||||
amd_comgr_data_set_t* dataSet, const std::vector<std::string>& preCompiledHeaders) {
|
||||
amd_comgr_status_t status;
|
||||
if (preCompiledHeaders.size() > 0) {
|
||||
for (auto& i : preCompiledHeaders) {
|
||||
amd_comgr_data_t pch_data;
|
||||
status = amd::Comgr::create_data(AMD_COMGR_DATA_KIND_PRECOMPILED_HEADER, &pch_data);
|
||||
if (status != AMD_COMGR_STATUS_SUCCESS) {
|
||||
return status;
|
||||
}
|
||||
|
||||
status = amd::Comgr::set_data(pch_data, i.size(), i.c_str());
|
||||
|
||||
if (status == AMD_COMGR_STATUS_SUCCESS) {
|
||||
status = amd::Comgr::set_data_name(pch_data, "PreCompiledHeader");
|
||||
}
|
||||
|
||||
if (status == AMD_COMGR_STATUS_SUCCESS) {
|
||||
status = amd::Comgr::data_set_add(*dataSet, pch_data);
|
||||
}
|
||||
|
||||
amd::Comgr::release_data(pch_data);
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
amd_comgr_status_t Program::addCodeObjData(const char *source,
|
||||
const size_t size,
|
||||
const amd_comgr_data_kind_t type,
|
||||
@@ -569,7 +597,8 @@ bool Program::compileAndLinkExecutable(const amd_comgr_data_set_t inputs,
|
||||
|
||||
bool Program::compileImplLC(const std::string& sourceCode,
|
||||
const std::vector<const std::string*>& headers,
|
||||
const char** headerIncludeNames, amd::option::Options* options) {
|
||||
const char** headerIncludeNames, amd::option::Options* options,
|
||||
const std::vector<std::string>& preCompiledHeaders) {
|
||||
#if defined(USE_COMGR_LIBRARY)
|
||||
const char* xLang = options->oVariables->XLang;
|
||||
if (xLang != nullptr) {
|
||||
@@ -590,6 +619,13 @@ bool Program::compileImplLC(const std::string& sourceCode,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (preCompiledHeaders.size() > 0)
|
||||
if (addPreCompiledHeader(&inputs, preCompiledHeaders) != AMD_COMGR_STATUS_SUCCESS) {
|
||||
buildLog_ += "Error: COMGR failed to add precompiled Headers.\n";
|
||||
amd::Comgr::destroy_data_set(inputs);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (addCodeObjData(sourceCode.c_str(), sourceCode.length(), AMD_COMGR_DATA_KIND_SOURCE,
|
||||
"CompileSource", &inputs) != AMD_COMGR_STATUS_SUCCESS) {
|
||||
buildLog_ += "Error: COMGR fails to create data from source.\n";
|
||||
@@ -669,6 +705,14 @@ bool Program::compileImplLC(const std::string& sourceCode,
|
||||
buildLog_ += "Warning: opening the file to dump the OpenCL source failed.\n";
|
||||
}
|
||||
}
|
||||
// Append Options provided by user to driver options
|
||||
if (isHIP()) {
|
||||
if (options->origOptionStr.size()) {
|
||||
std::istringstream userOptions{options->origOptionStr};
|
||||
std::copy(std::istream_iterator<std::string>(userOptions),
|
||||
std::istream_iterator<std::string>(), std::back_inserter(driverOptions));
|
||||
}
|
||||
}
|
||||
|
||||
// Append Options provided by user to driver options
|
||||
if (isHIP()) {
|
||||
@@ -1451,7 +1495,7 @@ int32_t Program::compile(const std::string& sourceCode,
|
||||
|
||||
// Compile the source code if any
|
||||
if ((buildStatus_ == CL_BUILD_IN_PROGRESS) && !sourceCode.empty() &&
|
||||
!compileImpl(sourceCode, headers, headerIncludeNames, options)) {
|
||||
!compileImpl(sourceCode, headers, headerIncludeNames, options, {})) {
|
||||
buildStatus_ = CL_BUILD_ERROR;
|
||||
if (buildLog_.empty()) {
|
||||
buildLog_ = "Internal error: Compilation failed.";
|
||||
@@ -1610,7 +1654,8 @@ int32_t Program::link(const std::vector<Program*>& inputPrograms, const char* or
|
||||
|
||||
// ================================================================================================
|
||||
int32_t Program::build(const std::string& sourceCode, const char* origOptions,
|
||||
amd::option::Options* options) {
|
||||
amd::option::Options* options,
|
||||
const std::vector<std::string>& preCompiledHeaders) {
|
||||
uint64_t start_time = 0;
|
||||
if (options->oVariables->EnableBuildTiming) {
|
||||
buildLog_ = "\nStart timing major build components.....\n\n";
|
||||
@@ -1650,9 +1695,10 @@ int32_t Program::build(const std::string& sourceCode, const char* origOptions,
|
||||
bool compileStatus = true;
|
||||
if ((buildStatus_ == CL_BUILD_IN_PROGRESS) && !sourceCode.empty()) {
|
||||
if (!headerIncludeNames.empty()) {
|
||||
compileStatus = compileImpl(sourceCode, headers, &headerIncludeNames[0], options);
|
||||
compileStatus =
|
||||
compileImpl(sourceCode, headers, &headerIncludeNames[0], options, preCompiledHeaders);
|
||||
} else {
|
||||
compileStatus = compileImpl(sourceCode, headers, nullptr, options);
|
||||
compileStatus = compileImpl(sourceCode, headers, nullptr, options, preCompiledHeaders);
|
||||
}
|
||||
}
|
||||
if (!compileStatus) {
|
||||
|
||||
@@ -154,7 +154,7 @@ class Program : public amd::HeapObject {
|
||||
|
||||
//! Builds the device program.
|
||||
int32_t build(const std::string& sourceCode, const char* origOptions,
|
||||
amd::option::Options* options);
|
||||
amd::option::Options* options, const std::vector<std::string>& preCompiledHeaders);
|
||||
|
||||
//! Returns the device object, associated with this program.
|
||||
const amd::Device& device() const { return device_(); }
|
||||
@@ -260,10 +260,10 @@ class Program : public amd::HeapObject {
|
||||
* \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
|
||||
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
|
||||
const std::vector<std::string>& preCompiledHeaders //!< precompiled headers
|
||||
);
|
||||
|
||||
//! Link the device program.
|
||||
@@ -340,9 +340,9 @@ class Program : public amd::HeapObject {
|
||||
|
||||
private:
|
||||
//! Compile the device program with LC path
|
||||
bool compileImplLC(const std::string& sourceCode,
|
||||
const std::vector<const std::string*>& headers,
|
||||
const char** headerIncludeNames, amd::option::Options* options);
|
||||
bool compileImplLC(const std::string& sourceCode, const std::vector<const std::string*>& headers,
|
||||
const char** headerIncludeNames, amd::option::Options* options,
|
||||
const std::vector<std::string>& preCompiledHeaders);
|
||||
|
||||
//! Compile the device program with HSAIL path
|
||||
bool compileImplHSAIL(const std::string& sourceCode,
|
||||
@@ -379,6 +379,10 @@ class Program : public amd::HeapObject {
|
||||
const size_t size, const amd_comgr_data_kind_t type,
|
||||
const char* name, amd_comgr_data_set_t* dataSet);
|
||||
|
||||
//! Add precompiled headers to the data set
|
||||
amd_comgr_status_t addPreCompiledHeader(amd_comgr_data_set_t* dataSet,
|
||||
const std::vector<std::string>& preCompiledHeaders);
|
||||
|
||||
//! Create action for the specified language, target and options
|
||||
amd_comgr_status_t createAction(const amd_comgr_language_t oclvar,
|
||||
const std::vector<std::string>& options, amd_comgr_action_info_t* action,
|
||||
|
||||
@@ -555,7 +555,7 @@ int32_t Program::build(const std::vector<Device*>& devices, const char* options,
|
||||
if (devProgram->buildStatus() != CL_BUILD_NONE) {
|
||||
continue;
|
||||
}
|
||||
int32_t result = devProgram->build(sourceCode_, options, &parsedOptions);
|
||||
int32_t result = devProgram->build(sourceCode_, options, &parsedOptions, precompiledHeaders_);
|
||||
|
||||
// Check if the previous device failed a build
|
||||
if ((result != CL_SUCCESS) && (retval != CL_SUCCESS)) {
|
||||
|
||||
@@ -106,6 +106,7 @@ class Program : public RuntimeObject {
|
||||
|
||||
std::vector<std::string> headerNames_;
|
||||
std::vector<std::string> headers_;
|
||||
std::vector<std::string> precompiledHeaders_; //!< Precompiled Headers
|
||||
std::string sourceCode_; //!< Strings that make up the source code
|
||||
Language language_; //!< Input source language
|
||||
devicebinary_t binary_; //!< The binary image, provided by the app
|
||||
@@ -178,6 +179,8 @@ class Program : public RuntimeObject {
|
||||
//! Append to source code.
|
||||
void appendToSource(const char* newCode) { sourceCode_.append(newCode); }
|
||||
|
||||
void addPreCompiledHeader(const std::string& pch) { precompiledHeaders_.push_back(pch); }
|
||||
|
||||
//! Return the program log.
|
||||
const std::string& programLog() const { return programLog_; }
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user