From 6deec8cb2235791303d8a7708e70e7d7d4b5dafa Mon Sep 17 00:00:00 2001 From: Viktor Yastrebov Date: Tue, 16 Apr 2024 21:31:05 +0300 Subject: [PATCH 1/2] update occa-transpiler to latest devel branch --- CMakeLists.txt | 4 +-- src/occa/internal/bin/occa.cpp | 25 +++++++++------ src/occa/internal/core/launchedDevice.cpp | 38 +++++++++++++---------- src/occa/internal/modes/openmp/device.cpp | 28 ++++++++++------- src/occa/internal/modes/serial/device.cpp | 28 ++++++++++------- 5 files changed, 73 insertions(+), 50 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 260176ccd..e6f3879ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,7 +37,7 @@ option(OCCA_ENABLE_DPCPP "Build with SYCL/DPCPP if available" ON) option(OCCA_ENABLE_TESTS "Build tests" OFF) option(OCCA_ENABLE_EXAMPLES "Build simple examples" OFF) option(OCCA_ENABLE_FORTRAN "Enable Fortran interface" OFF) -option(OCCA_TRANSPILER "Build with occa-transpiler dependecy" OFF) +option(OCCA_TRANSPILER "Build with occa-transpiler dependecy" ON) if(OCCA_ENABLE_FORTRAN) enable_language(Fortran) @@ -74,7 +74,7 @@ if (OCCA_TRANSPILER) CPMAddPackage( NAME occa-transpiler GITHUB_REPOSITORY libocca/occa-transpiler - GIT_TAG c761972e9158fd29ba1093339c81043a22b78427 + GIT_TAG 2bb202e68de5052ec6e44a086fdf7b36b7e8db88 OPTIONS "TRANSPILER_TESTS OFF" ) endif() diff --git a/src/occa/internal/bin/occa.cpp b/src/occa/internal/bin/occa.cpp index a264e1151..354525fd5 100644 --- a/src/occa/internal/bin/occa.cpp +++ b/src/occa/internal/bin/occa.cpp @@ -16,10 +16,12 @@ #include #ifdef BUILD_WITH_OCCA_TRANSPILER +#include #include "oklt/pipeline/normalizer_and_transpiler.h" #include "oklt/core/error.h" +#include "oklt/util/io_helper.h" #endif -#include + namespace occa { namespace bin { @@ -165,16 +167,21 @@ namespace occa { auto defines = transpiler::buildDefines(kernelProps); auto includes = transpiler::buildIncludes(kernelProps); - std::string fullFilePath = io::expandFilename(filename); - std::ifstream sourceFile(fullFilePath); - std::string sourceCode{std::istreambuf_iterator(sourceFile), {}}; + std::filesystem::path sourcePath = io::expandFilename(filename); + auto sourceCode = oklt::util::readFileAsStr(sourcePath); + if(!sourceCode) { + printError("Can't open file: " + sourcePath.string()); + ::exit(sourceCode.error()); + } + oklt::UserInput input { .backend = transpiler->second, .astProcType = oklt::AstProcessorType::OKL_WITH_SEMA, - .sourceCode = std::move(sourceCode), - .sourcePath = std::filesystem::path(fullFilePath), + .source = std::move(sourceCode.value()), + .headers = {}, + .sourcePath = sourcePath, .inlcudeDirectories = std::move(includes), - .defines = std::move(defines) + .defines = std::move(defines), }; auto result = normalizeAndTranspile(std::move(input)); @@ -211,9 +218,9 @@ namespace occa { transpiler->second == oklt::TargetBackend::HIP || transpiler->second == oklt::TargetBackend::DPCPP; if(printLauncher && hasLauncher) { - io::stdout << userOutput.launcher.sourceCode; + io::stdout << userOutput.launcher.source; } else { - io::stdout << userOutput.kernel.sourceCode; + io::stdout << userOutput.kernel.source; } return true; diff --git a/src/occa/internal/core/launchedDevice.cpp b/src/occa/internal/core/launchedDevice.cpp index 8813d6a90..fece6b4fa 100644 --- a/src/occa/internal/core/launchedDevice.cpp +++ b/src/occa/internal/core/launchedDevice.cpp @@ -5,15 +5,16 @@ #include #include #include -#include + #ifdef BUILD_WITH_OCCA_TRANSPILER +#include #include "oklt/pipeline/normalizer_and_transpiler.h" +#include "oklt/util/io_helper.h" #include "oklt/core/error.h" #endif #include -#include namespace occa { launchedModeDevice_t::launchedModeDevice_t(const occa::json &properties_) : @@ -48,14 +49,20 @@ namespace occa { auto defines = transpiler::buildDefines(kernelProps); auto includes = transpiler::buildIncludes(kernelProps); - std::string fullFilePath = io::expandFilename(filename); - std::ifstream sourceFile(fullFilePath); - std::string sourceCode{std::istreambuf_iterator(sourceFile), {}}; + std::filesystem::path sourcePath = io::expandFilename(filename); + auto sourceCode = oklt::util::readFileAsStr(sourcePath); + if(!sourceCode) { + std::string errorDescription = "Can't read file: "; + OCCA_FORCE_ERROR(errorDescription << sourcePath.string()); + return false; + } + oklt::UserInput input { .backend = targetIter->second, .astProcType = oklt::AstProcessorType::OKL_WITH_SEMA, - .sourceCode = std::move(sourceCode), - .sourcePath = std::filesystem::path(fullFilePath), + .source = std::move(sourceCode.value()), + .headers = {}, + .sourcePath = sourcePath, .inlcudeDirectories = std::move(includes), .defines = std::move(defines) }; @@ -79,19 +86,16 @@ namespace occa { { outputFile, launcherOutputFile }, true, [&](const strVector &tempFilenames) -> bool { - const std::string &tempOutputFilename = tempFilenames[0]; - const std::string &tempLauncherOutputFilename = tempFilenames[1]; - - std::ofstream transpiledTempOutput(tempOutputFilename); - transpiledTempOutput << userOutput.kernel.sourceCode; + std::filesystem::path transpiledSource(tempFilenames[0]); + std::filesystem::path launcherSource(tempFilenames[1]); - std::ofstream laucherOutputFile(tempLauncherOutputFilename); - laucherOutputFile << userOutput.launcher.sourceCode; - return true; + auto ret1 = oklt::util::writeFileAsStr(transpiledSource, userOutput.kernel.source); + auto ret2 = oklt::util::writeFileAsStr(launcherSource, userOutput.launcher.source); + return ret1 && ret2; }); - transpiler::makeMetadata(launcherMetadata, userOutput.launcher.metadataJson); - transpiler::makeMetadata(deviceMetadata, userOutput.kernel.metadataJson); + transpiler::makeMetadata(launcherMetadata, userOutput.launcher.metadata); + transpiler::makeMetadata(deviceMetadata, userOutput.kernel.metadata); return true; } diff --git a/src/occa/internal/modes/openmp/device.cpp b/src/occa/internal/modes/openmp/device.cpp index 3554ff4e7..80bd5a467 100644 --- a/src/occa/internal/modes/openmp/device.cpp +++ b/src/occa/internal/modes/openmp/device.cpp @@ -10,7 +10,7 @@ #include #include "oklt/pipeline/normalizer_and_transpiler.h" #include "oklt/core/error.h" -#include +#include "oklt/util/io_helper.h" #endif namespace occa { @@ -41,14 +41,20 @@ namespace occa { auto defines = transpiler::buildDefines(kernelProps); auto includes = transpiler::buildIncludes(kernelProps); - std::string fullFilePath = io::expandFilename(filename); - std::ifstream sourceFile(fullFilePath); - std::string sourceCode{std::istreambuf_iterator(sourceFile), {}}; + std::filesystem::path sourcePath = io::expandFilename(filename); + auto sourceCode = oklt::util::readFileAsStr(sourcePath); + if(!sourceCode) { + std::string errorDescription = "Can't read file: "; + OCCA_FORCE_ERROR(errorDescription << sourcePath.string()); + return false; + } + oklt::UserInput input { .backend = oklt::TargetBackend::OPENMP, .astProcType = oklt::AstProcessorType::OKL_WITH_SEMA, - .sourceCode = std::move(sourceCode), - .sourcePath = std::filesystem::path(fullFilePath), + .source = std::move(sourceCode.value()), + .headers = {}, + .sourcePath = sourcePath, .inlcudeDirectories = std::move(includes), .defines = std::move(defines) }; @@ -72,11 +78,11 @@ namespace occa { outputFile, true, [&](const std::string &tempFilename) -> bool { - std::ofstream transpiledTempOutput(tempFilename); - transpiledTempOutput << userOutput.kernel.sourceCode; - return true; - }); - transpiler::makeMetadata(metadata, userOutput.kernel.metadataJson); + std::filesystem::path transpiledSource(tempFilename); + auto ret = oklt::util::writeFileAsStr(tempFilename, userOutput.kernel.source); + return ret.has_value(); + }); + transpiler::makeMetadata(metadata, userOutput.kernel.metadata); return true; } #endif diff --git a/src/occa/internal/modes/serial/device.cpp b/src/occa/internal/modes/serial/device.cpp index 9bfa857f5..3a2db05e0 100644 --- a/src/occa/internal/modes/serial/device.cpp +++ b/src/occa/internal/modes/serial/device.cpp @@ -15,7 +15,7 @@ #include #include "oklt/pipeline/normalizer_and_transpiler.h" #include "oklt/core/error.h" -#include +#include "oklt/util/io_helper.h" #endif namespace occa { @@ -87,14 +87,20 @@ namespace occa { auto defines = transpiler::buildDefines(kernelProps); auto includes = transpiler::buildIncludes(kernelProps); - std::string fullFilePath = io::expandFilename(filename); - std::ifstream sourceFile(fullFilePath); - std::string sourceCode{std::istreambuf_iterator(sourceFile), {}}; + std::filesystem::path sourcePath = io::expandFilename(filename); + auto sourceCode = oklt::util::readFileAsStr(sourcePath); + if(!sourceCode) { + std::string errorDescription = "Can't read file: "; + OCCA_FORCE_ERROR(errorDescription << sourcePath.string()); + return false; + } + oklt::UserInput input { .backend = oklt::TargetBackend::SERIAL, .astProcType = oklt::AstProcessorType::OKL_WITH_SEMA, - .sourceCode = std::move(sourceCode), - .sourcePath = std::filesystem::path(fullFilePath), + .source = std::move(sourceCode.value()), + .headers = {}, + .sourcePath = sourcePath, .inlcudeDirectories = std::move(includes), .defines = std::move(defines) }; @@ -118,11 +124,11 @@ namespace occa { outputFile, true, [&](const std::string &tempFilename) -> bool { - std::ofstream transpiledTempOutput(tempFilename); - transpiledTempOutput << userOutput.kernel.sourceCode; - return true; - }); - transpiler::makeMetadata(metadata, userOutput.kernel.metadataJson); + std::filesystem::path transpiledSourcePath(tempFilename); + auto ret = oklt::util::writeFileAsStr(transpiledSourcePath, userOutput.kernel.source); + return ret.has_value(); + }); + transpiler::makeMetadata(metadata, userOutput.kernel.metadata); return true; } #endif From d55cc5bab3a9f446931c509c936763aad9dc12c1 Mon Sep 17 00:00:00 2001 From: Viktor Yastrebov Date: Tue, 16 Apr 2024 21:33:46 +0300 Subject: [PATCH 2/2] turn off the occa-transpiler by default(typo) --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e6f3879ba..78c2c7fc5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,7 +37,7 @@ option(OCCA_ENABLE_DPCPP "Build with SYCL/DPCPP if available" ON) option(OCCA_ENABLE_TESTS "Build tests" OFF) option(OCCA_ENABLE_EXAMPLES "Build simple examples" OFF) option(OCCA_ENABLE_FORTRAN "Enable Fortran interface" OFF) -option(OCCA_TRANSPILER "Build with occa-transpiler dependecy" ON) +option(OCCA_TRANSPILER "Build with occa-transpiler dependecy" OFF) if(OCCA_ENABLE_FORTRAN) enable_language(Fortran)