mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-09 06:23:01 +08:00
fix: create temporary main.cl with kernel source when -g debug flag is used
Implements mechanism in ocloc to generate a temporary main.cl file containing kernel source code when compiling with the debug (-g) flag and the source file does not exist. This enables proper source code annotations in generated assembly for SYCL/online compilation workflows. Related-To: NEO-11900 Signed-off-by: Aleksandra Nizio <aleksandra.nizio@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
2b96f54a9f
commit
dfc97c016e
@@ -15,6 +15,7 @@
|
||||
#include "shared/offline_compiler/source/ocloc_supported_devices_helper.h"
|
||||
#include "shared/offline_compiler/source/queries.h"
|
||||
#include "shared/offline_compiler/source/utilities/get_git_version_info.h"
|
||||
#include "shared/source/compiler_interface/compiler_cache.h"
|
||||
#include "shared/source/compiler_interface/compiler_options.h"
|
||||
#include "shared/source/compiler_interface/compiler_options_extra.h"
|
||||
#include "shared/source/compiler_interface/default_cache_config.h"
|
||||
@@ -28,6 +29,8 @@
|
||||
#include "shared/source/helpers/compiler_options_parser.h"
|
||||
#include "shared/source/helpers/compiler_product_helper.h"
|
||||
#include "shared/source/helpers/debug_helpers.h"
|
||||
#include "shared/source/helpers/file_io.h"
|
||||
#include "shared/source/helpers/hash.h"
|
||||
#include "shared/source/helpers/string.h"
|
||||
#include "shared/source/helpers/validators.h"
|
||||
#include "shared/source/os_interface/debug_env_reader.h"
|
||||
@@ -37,6 +40,7 @@
|
||||
#include "neo_aot_platforms.h"
|
||||
#include "offline_compiler_ext.h"
|
||||
|
||||
#include <filesystem>
|
||||
#include <iomanip>
|
||||
#include <iterator>
|
||||
#include <list>
|
||||
@@ -616,6 +620,7 @@ int OfflineCompiler::buildSourceCode() {
|
||||
}
|
||||
auto inputTypeWarnings = validateInputType(sourceCode, inputFileLlvm(), inputFileSpirV());
|
||||
this->argHelper->printf(inputTypeWarnings.c_str());
|
||||
|
||||
if (isIntermediateRepresentation(this->inputCodeType)) {
|
||||
storeBinary(irBinary, irBinarySize, sourceCode.c_str(), sourceCode.size());
|
||||
pBuildInfo->intermediateRepresentation = this->inputCodeType;
|
||||
@@ -737,6 +742,10 @@ int OfflineCompiler::build() {
|
||||
return igcInitializationResult;
|
||||
}
|
||||
|
||||
if (!inputFileSpirV()) {
|
||||
createTempSourceFileForDebug();
|
||||
}
|
||||
|
||||
int retVal = OCLOC_SUCCESS;
|
||||
if (isOnlySpirV()) {
|
||||
retVal = buildToIrBinary();
|
||||
@@ -1554,6 +1563,32 @@ bool OfflineCompiler::generateElfBinary() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void OfflineCompiler::createTempSourceFileForDebug() {
|
||||
if (!CompilerOptions::contains(options, CompilerOptions::generateDebugInfo)) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string sourcePathOption = CompilerOptions::generateSourcePath.str();
|
||||
size_t sourcePosInOpts = options.find(sourcePathOption);
|
||||
|
||||
if (sourcePosInOpts != std::string::npos) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint64_t sourceHash = NEO::Hash::hash(sourceCode.c_str(), sourceCode.size());
|
||||
std::string tempFilePath = "main_" + std::to_string(sourceHash) + ".cl";
|
||||
std::filesystem::path absTempFilePath = std::filesystem::absolute(tempFilePath);
|
||||
|
||||
writeDataToFile(absTempFilePath.string().c_str(), std::string_view(sourceCode.c_str(), sourceCode.size()));
|
||||
|
||||
if (argHelper && !isQuiet()) {
|
||||
argHelper->printf("Temporary source file for debug info created: %s\n", absTempFilePath.string().c_str());
|
||||
}
|
||||
|
||||
std::string sourcePathWithFile = sourcePathOption + " " + CompilerOptions::wrapInQuotes(absTempFilePath.string());
|
||||
options = CompilerOptions::concatenate(options, sourcePathWithFile);
|
||||
}
|
||||
|
||||
void OfflineCompiler::writeOutAllFiles() {
|
||||
std::string fileBase;
|
||||
std::string fileTrunk = getFileNameTrunk(inputFile);
|
||||
|
||||
@@ -269,6 +269,7 @@ All supported acronyms: %s.
|
||||
IGC::CodeType::CodeType_t intermediateRepresentation = IGC::CodeType::undefined;
|
||||
|
||||
OclocArgHelper *argHelper = nullptr;
|
||||
MOCKABLE_VIRTUAL void createTempSourceFileForDebug();
|
||||
};
|
||||
|
||||
static_assert(NEO::NonCopyableAndNonMovable<OfflineCompiler>);
|
||||
|
||||
Reference in New Issue
Block a user