fix(ocloc): remove incorrect ir binary caching during build from source

Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2024-06-12 10:16:59 +00:00
committed by Compute-Runtime-Automation
parent 2e9bb26708
commit 5fa5387781
3 changed files with 15 additions and 23 deletions

1
.github/lint.yml vendored
View File

@@ -91,6 +91,7 @@ lint:
- ocl - ocl
- wa - wa
- internal - internal
- ocloc
mandatory_tracker: mandatory_tracker:
types: types:
- feature - feature

View File

@@ -2584,10 +2584,9 @@ TEST(OfflineCompilerTest, givenAllowCachingWhenBuildSourceCodeThenGenBinaryIsCac
ASSERT_NE(0u, mockOfflineCompiler->irBinarySize); ASSERT_NE(0u, mockOfflineCompiler->irBinarySize);
// 0 - buildIrBinary > irBinary // 0 - buildIrBinary > irBinary
// 1 - buildSourceCode > irBinary // 1 - buildSourceCode > genBinary
// 2 - buildSourceCode > genBinary // 2 - buildSourceCode > debugDataBinary
// 3 - buildSourceCode > debugDataBinary const auto givenCacheBinaryGenHash = cacheMock->cacheBinaryKernelFileHashes[1];
const auto givenCacheBinaryGenHash = cacheMock->cacheBinaryKernelFileHashes[2];
const auto expectedCacheBinaryGenHash = cacheMock->getCachedFileName(mockOfflineCompiler->getHardwareInfo(), const auto expectedCacheBinaryGenHash = cacheMock->getCachedFileName(mockOfflineCompiler->getHardwareInfo(),
ArrayRef<const char>(mockOfflineCompiler->irBinary, mockOfflineCompiler->irBinarySize), ArrayRef<const char>(mockOfflineCompiler->irBinary, mockOfflineCompiler->irBinarySize),
mockOfflineCompiler->options, mockOfflineCompiler->options,

View File

@@ -579,15 +579,18 @@ int OfflineCompiler::buildSourceCode() {
if (sourceCode.empty()) { if (sourceCode.empty()) {
return OCLOC_INVALID_PROGRAM; return OCLOC_INVALID_PROGRAM;
} }
bool inputIsIntermediateRepresentation = inputFileLlvm || inputFileSpirV;
if (false == inputIsIntermediateRepresentation) {
retVal = buildIrBinary();
if (retVal != OCLOC_SUCCESS)
return retVal;
}
const std::string igcRevision = igcFacade->getIgcRevision(); const std::string igcRevision = igcFacade->getIgcRevision();
const auto igcLibSize = igcFacade->getIgcLibSize(); const auto igcLibSize = igcFacade->getIgcLibSize();
const auto igcLibMTime = igcFacade->getIgcLibMTime(); const auto igcLibMTime = igcFacade->getIgcLibMTime();
if (allowCaching) { if (allowCaching) {
irHash = cache->getCachedFileName(getHardwareInfo(), sourceCode, options, internalOptions, ArrayRef<const char>(), ArrayRef<const char>(), igcRevision, igcLibSize, igcLibMTime);
irBinary = cache->loadCachedBinary(irHash, irBinarySize).release();
genHash = cache->getCachedFileName(getHardwareInfo(), ArrayRef<const char>(irBinary, irBinarySize), options, internalOptions, ArrayRef<const char>(), ArrayRef<const char>(), igcRevision, igcLibSize, igcLibMTime); genHash = cache->getCachedFileName(getHardwareInfo(), ArrayRef<const char>(irBinary, irBinarySize), options, internalOptions, ArrayRef<const char>(), ArrayRef<const char>(), igcRevision, igcLibSize, igcLibMTime);
genBinary = cache->loadCachedBinary(genHash, genBinarySize).release(); genBinary = cache->loadCachedBinary(genHash, genBinarySize).release();
@@ -597,7 +600,7 @@ int OfflineCompiler::buildSourceCode() {
debugDataBinary = cache->loadCachedBinary(dbgHash, debugDataBinarySize).release(); debugDataBinary = cache->loadCachedBinary(dbgHash, debugDataBinarySize).release();
} }
if (irBinary && genBinary) { if (genBinary) {
bool isZebin = isDeviceBinaryFormat<DeviceBinaryFormat::zebin>(ArrayRef<uint8_t>(reinterpret_cast<uint8_t *>(genBinary), genBinarySize)); bool isZebin = isDeviceBinaryFormat<DeviceBinaryFormat::zebin>(ArrayRef<uint8_t>(reinterpret_cast<uint8_t *>(genBinary), genBinarySize));
auto asBitcode = ArrayRef<const uint8_t>::fromAny(irBinary, irBinarySize); auto asBitcode = ArrayRef<const uint8_t>::fromAny(irBinary, irBinarySize);
@@ -610,10 +613,7 @@ int OfflineCompiler::buildSourceCode() {
} }
} }
delete[] irBinary;
delete[] genBinary; delete[] genBinary;
irBinary = nullptr;
irBinarySize = 0;
genBinary = nullptr; genBinary = nullptr;
genBinarySize = 0; genBinarySize = 0;
} }
@@ -624,23 +624,17 @@ int OfflineCompiler::buildSourceCode() {
this->argHelper->printf(inputTypeWarnings.c_str()); this->argHelper->printf(inputTypeWarnings.c_str());
CIF::RAII::UPtr_t<IGC::OclTranslationOutputTagOCL> igcOutput; CIF::RAII::UPtr_t<IGC::OclTranslationOutputTagOCL> igcOutput;
bool inputIsIntermediateRepresentation = inputFileLlvm || inputFileSpirV; auto igcOptions = igcFacade->createConstBuffer(options.c_str(), options.size());
auto igcInternalOptions = igcFacade->createConstBuffer(internalOptions.c_str(), internalOptions.size());
if (false == inputIsIntermediateRepresentation) { if (false == inputIsIntermediateRepresentation) {
retVal = buildIrBinary();
if (retVal != OCLOC_SUCCESS)
return retVal;
auto igcTranslationCtx = igcFacade->createTranslationContext(pBuildInfo->intermediateRepresentation, IGC::CodeType::oclGenBin); auto igcTranslationCtx = igcFacade->createTranslationContext(pBuildInfo->intermediateRepresentation, IGC::CodeType::oclGenBin);
igcOutput = igcTranslationCtx->Translate(pBuildInfo->fclOutput->GetOutput(), pBuildInfo->fclOptions.get(), auto igcSrc = igcFacade->createConstBuffer(irBinary, irBinarySize);
pBuildInfo->fclInternalOptions.get(), igcOutput = igcTranslationCtx->Translate(igcSrc.get(), igcOptions.get(), igcInternalOptions.get(), nullptr, 0);
nullptr, 0);
} else { } else {
storeBinary(irBinary, irBinarySize, sourceCode.c_str(), sourceCode.size()); storeBinary(irBinary, irBinarySize, sourceCode.c_str(), sourceCode.size());
isSpirV = inputFileSpirV; isSpirV = inputFileSpirV;
auto igcSrc = igcFacade->createConstBuffer(sourceCode.c_str(), sourceCode.size()); auto igcSrc = igcFacade->createConstBuffer(sourceCode.c_str(), sourceCode.size());
auto igcOptions = igcFacade->createConstBuffer(options.c_str(), options.size());
auto igcInternalOptions = igcFacade->createConstBuffer(internalOptions.c_str(), internalOptions.size());
auto igcTranslationCtx = igcFacade->createTranslationContext(inputFileSpirV ? IGC::CodeType::spirV : IGC::CodeType::llvmBc, IGC::CodeType::oclGenBin); auto igcTranslationCtx = igcFacade->createTranslationContext(inputFileSpirV ? IGC::CodeType::spirV : IGC::CodeType::llvmBc, IGC::CodeType::oclGenBin);
igcOutput = igcTranslationCtx->Translate(igcSrc.get(), igcOptions.get(), igcInternalOptions.get(), nullptr, 0); igcOutput = igcTranslationCtx->Translate(igcSrc.get(), igcOptions.get(), igcInternalOptions.get(), nullptr, 0);
} }
@@ -659,8 +653,6 @@ int OfflineCompiler::buildSourceCode() {
storeBinary(debugDataBinary, debugDataBinarySize, igcOutput->GetDebugData()->GetMemory<char>(), igcOutput->GetDebugData()->GetSizeRaw()); storeBinary(debugDataBinary, debugDataBinarySize, igcOutput->GetDebugData()->GetMemory<char>(), igcOutput->GetDebugData()->GetSizeRaw());
} }
if (allowCaching) { if (allowCaching) {
genHash = cache->getCachedFileName(getHardwareInfo(), ArrayRef<const char>(irBinary, irBinarySize), options, internalOptions, ArrayRef<const char>(), ArrayRef<const char>(), igcRevision, igcLibSize, igcLibMTime);
cache->cacheBinary(irHash, irBinary, static_cast<uint32_t>(irBinarySize));
cache->cacheBinary(genHash, genBinary, static_cast<uint32_t>(genBinarySize)); cache->cacheBinary(genHash, genBinary, static_cast<uint32_t>(genBinarySize));
cache->cacheBinary(dbgHash, debugDataBinary, static_cast<uint32_t>(debugDataBinarySize)); cache->cacheBinary(dbgHash, debugDataBinary, static_cast<uint32_t>(debugDataBinarySize));
} }