From 5fa5387781052bd3bd81e6d4254676af6a69cad3 Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Wed, 12 Jun 2024 10:16:59 +0000 Subject: [PATCH] fix(ocloc): remove incorrect ir binary caching during build from source Signed-off-by: Mateusz Jablonski --- .github/lint.yml | 1 + .../offline_compiler_tests.cpp | 7 ++--- .../source/offline_compiler.cpp | 30 +++++++------------ 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/.github/lint.yml b/.github/lint.yml index 58d576bffb..182accfee3 100644 --- a/.github/lint.yml +++ b/.github/lint.yml @@ -91,6 +91,7 @@ lint: - ocl - wa - internal + - ocloc mandatory_tracker: types: - feature diff --git a/opencl/test/unit_test/offline_compiler/offline_compiler_tests.cpp b/opencl/test/unit_test/offline_compiler/offline_compiler_tests.cpp index 25507e6ba1..5013cd13f2 100644 --- a/opencl/test/unit_test/offline_compiler/offline_compiler_tests.cpp +++ b/opencl/test/unit_test/offline_compiler/offline_compiler_tests.cpp @@ -2584,10 +2584,9 @@ TEST(OfflineCompilerTest, givenAllowCachingWhenBuildSourceCodeThenGenBinaryIsCac ASSERT_NE(0u, mockOfflineCompiler->irBinarySize); // 0 - buildIrBinary > irBinary - // 1 - buildSourceCode > irBinary - // 2 - buildSourceCode > genBinary - // 3 - buildSourceCode > debugDataBinary - const auto givenCacheBinaryGenHash = cacheMock->cacheBinaryKernelFileHashes[2]; + // 1 - buildSourceCode > genBinary + // 2 - buildSourceCode > debugDataBinary + const auto givenCacheBinaryGenHash = cacheMock->cacheBinaryKernelFileHashes[1]; const auto expectedCacheBinaryGenHash = cacheMock->getCachedFileName(mockOfflineCompiler->getHardwareInfo(), ArrayRef(mockOfflineCompiler->irBinary, mockOfflineCompiler->irBinarySize), mockOfflineCompiler->options, diff --git a/shared/offline_compiler/source/offline_compiler.cpp b/shared/offline_compiler/source/offline_compiler.cpp index 519c6f88d9..d4c8946177 100644 --- a/shared/offline_compiler/source/offline_compiler.cpp +++ b/shared/offline_compiler/source/offline_compiler.cpp @@ -579,15 +579,18 @@ int OfflineCompiler::buildSourceCode() { if (sourceCode.empty()) { 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 auto igcLibSize = igcFacade->getIgcLibSize(); const auto igcLibMTime = igcFacade->getIgcLibMTime(); if (allowCaching) { - irHash = cache->getCachedFileName(getHardwareInfo(), sourceCode, options, internalOptions, ArrayRef(), ArrayRef(), igcRevision, igcLibSize, igcLibMTime); - irBinary = cache->loadCachedBinary(irHash, irBinarySize).release(); - genHash = cache->getCachedFileName(getHardwareInfo(), ArrayRef(irBinary, irBinarySize), options, internalOptions, ArrayRef(), ArrayRef(), igcRevision, igcLibSize, igcLibMTime); genBinary = cache->loadCachedBinary(genHash, genBinarySize).release(); @@ -597,7 +600,7 @@ int OfflineCompiler::buildSourceCode() { debugDataBinary = cache->loadCachedBinary(dbgHash, debugDataBinarySize).release(); } - if (irBinary && genBinary) { + if (genBinary) { bool isZebin = isDeviceBinaryFormat(ArrayRef(reinterpret_cast(genBinary), genBinarySize)); auto asBitcode = ArrayRef::fromAny(irBinary, irBinarySize); @@ -610,10 +613,7 @@ int OfflineCompiler::buildSourceCode() { } } - delete[] irBinary; delete[] genBinary; - irBinary = nullptr; - irBinarySize = 0; genBinary = nullptr; genBinarySize = 0; } @@ -624,23 +624,17 @@ int OfflineCompiler::buildSourceCode() { this->argHelper->printf(inputTypeWarnings.c_str()); CIF::RAII::UPtr_t 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) { - retVal = buildIrBinary(); - if (retVal != OCLOC_SUCCESS) - return retVal; - auto igcTranslationCtx = igcFacade->createTranslationContext(pBuildInfo->intermediateRepresentation, IGC::CodeType::oclGenBin); - igcOutput = igcTranslationCtx->Translate(pBuildInfo->fclOutput->GetOutput(), pBuildInfo->fclOptions.get(), - pBuildInfo->fclInternalOptions.get(), - nullptr, 0); + auto igcSrc = igcFacade->createConstBuffer(irBinary, irBinarySize); + igcOutput = igcTranslationCtx->Translate(igcSrc.get(), igcOptions.get(), igcInternalOptions.get(), nullptr, 0); } else { storeBinary(irBinary, irBinarySize, sourceCode.c_str(), sourceCode.size()); isSpirV = inputFileSpirV; 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); igcOutput = igcTranslationCtx->Translate(igcSrc.get(), igcOptions.get(), igcInternalOptions.get(), nullptr, 0); } @@ -659,8 +653,6 @@ int OfflineCompiler::buildSourceCode() { storeBinary(debugDataBinary, debugDataBinarySize, igcOutput->GetDebugData()->GetMemory(), igcOutput->GetDebugData()->GetSizeRaw()); } if (allowCaching) { - genHash = cache->getCachedFileName(getHardwareInfo(), ArrayRef(irBinary, irBinarySize), options, internalOptions, ArrayRef(), ArrayRef(), igcRevision, igcLibSize, igcLibMTime); - cache->cacheBinary(irHash, irBinary, static_cast(irBinarySize)); cache->cacheBinary(genHash, genBinary, static_cast(genBinarySize)); cache->cacheBinary(dbgHash, debugDataBinary, static_cast(debugDataBinarySize)); }