Skip to content

Commit

Permalink
Merge pull request #3 from vyast-softserveinc/update_occa_transpiler
Browse files Browse the repository at this point in the history
update occa-transpiler to latest devel branch
  • Loading branch information
vyast-softserveinc authored Apr 16, 2024
2 parents 941c94c + d55cc5b commit bd9fcae
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 49 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
25 changes: 16 additions & 9 deletions src/occa/internal/bin/occa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
#include <occa/internal/modes.hpp>

#ifdef BUILD_WITH_OCCA_TRANSPILER
#include <occa/internal/utils/transpiler_utils.h>
#include "oklt/pipeline/normalizer_and_transpiler.h"
#include "oklt/core/error.h"
#include "oklt/util/io_helper.h"
#endif
#include <occa/internal/utils/transpiler_utils.h>


namespace occa {
namespace bin {
Expand Down Expand Up @@ -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<char>(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));

Expand Down Expand Up @@ -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;
Expand Down
38 changes: 21 additions & 17 deletions src/occa/internal/core/launchedDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
#include <occa/internal/modes/serial/device.hpp>
#include <occa/internal/modes/serial/kernel.hpp>
#include <occa/internal/utils/string.hpp>
#include <occa/internal/utils/transpiler_utils.h>


#ifdef BUILD_WITH_OCCA_TRANSPILER
#include <occa/internal/utils/transpiler_utils.h>
#include "oklt/pipeline/normalizer_and_transpiler.h"
#include "oklt/util/io_helper.h"
#include "oklt/core/error.h"
#endif

#include <map>
#include <fstream>

namespace occa {
launchedModeDevice_t::launchedModeDevice_t(const occa::json &properties_) :
Expand Down Expand Up @@ -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<char>(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)
};
Expand All @@ -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;
}
Expand Down
28 changes: 17 additions & 11 deletions src/occa/internal/modes/openmp/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <occa/internal/utils/transpiler_utils.h>
#include "oklt/pipeline/normalizer_and_transpiler.h"
#include "oklt/core/error.h"
#include <fstream>
#include "oklt/util/io_helper.h"
#endif

namespace occa {
Expand Down Expand Up @@ -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<char>(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)
};
Expand All @@ -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
Expand Down
28 changes: 17 additions & 11 deletions src/occa/internal/modes/serial/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <occa/internal/utils/transpiler_utils.h>
#include "oklt/pipeline/normalizer_and_transpiler.h"
#include "oklt/core/error.h"
#include <fstream>
#include "oklt/util/io_helper.h"
#endif

namespace occa {
Expand Down Expand Up @@ -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<char>(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)
};
Expand All @@ -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
Expand Down

0 comments on commit bd9fcae

Please sign in to comment.