Skip to content

Commit

Permalink
Include original file name in the cached sources (#700)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkbosmans committed Aug 17, 2023
1 parent 1110c4c commit 1590291
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
8 changes: 4 additions & 4 deletions src/occa/internal/core/launchedDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ namespace occa {
const bool usingOkl,
const occa::json &kernelProps) {
const std::string hashDir = io::hashDir(filename, kernelHash);
std::string sourceFilename = hashDir + kc::sourceFile;
std::string sourceFilename = hashDir + kc::cachedSourceFilename(filename);
const std::string binaryFilename = hashDir + kc::binaryFile;

// Check if binary exists and is finished
Expand Down Expand Up @@ -140,12 +140,12 @@ namespace occa {
// Cache raw origin
sourceFilename = (
io::cacheFile(filename,
kc::cppRawSourceFile,
kc::cachedRawSourceFilename(filename),
kernelHash,
assembleKernelHeader(kernelProps))
);

const std::string outputFile = hashDir + kc::sourceFile;
const std::string outputFile = hashDir + kc::cachedSourceFilename(filename);
const std::string launcherOutputFile = hashDir + kc::launcherSourceFile;
bool valid = parseFile(sourceFilename,
outputFile,
Expand Down Expand Up @@ -180,7 +180,7 @@ namespace occa {
// Cache in sourceFile to directly compile file
sourceFilename = (
io::cacheFile(filename,
kc::sourceFile,
kc::cachedSourceFilename(filename),
kernelHash,
assembleKernelHeader(kernelProps))
);
Expand Down
13 changes: 10 additions & 3 deletions src/occa/internal/io/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
namespace occa {
// Kernel Caching
namespace kc {
const std::string cppRawSourceFile = "raw_source.cpp";
const std::string cRawSourceFile = "raw_source.c";
const std::string sourceFile = "source.cpp";
const std::string launcherSourceFile = "launcher_source.cpp";
const std::string buildFile = "build.json";
const std::string launcherBuildFile = "launcher_build.json";
Expand All @@ -43,6 +40,16 @@ namespace occa {
const std::string binaryFile = "binary.dll";
const std::string launcherBinaryFile = "launcher_binary.dll";
#endif

std::string cachedRawSourceFilename(std::string filename, bool compilingCpp) {
const std::string basename = io::basename(filename, false);
const std::string extension = compilingCpp ? ".cpp" : ".c";
return basename + std::string(".raw_source") + extension;
}
std::string cachedSourceFilename(std::string filename) {
const std::string basename = io::basename(filename, false);
return basename + std::string(".source.cpp");
}
}

namespace io {
Expand Down
6 changes: 3 additions & 3 deletions src/occa/internal/io/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
namespace occa {
// Kernel Caching
namespace kc {
extern const std::string cppRawSourceFile;
extern const std::string cRawSourceFile;
extern const std::string sourceFile;
extern const std::string binaryFile;
extern const std::string buildFile;
extern const std::string launcherSourceFile;
extern const std::string launcherBinaryFile;
extern const std::string launcherBuildFile;

std::string cachedRawSourceFilename(std::string filename, bool compilingCpp=true);
std::string cachedSourceFilename(std::string filename);
}

namespace io {
Expand Down
10 changes: 2 additions & 8 deletions src/occa/internal/modes/serial/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,22 +276,16 @@ namespace occa {
if (isLauncherKernel) {
sourceFilename = filename;
} else {
const std::string &rawSourceFile = (
compilingCpp
? kc::cppRawSourceFile
: kc::cRawSourceFile
);

// Cache raw origin
sourceFilename = (
io::cacheFile(filename,
rawSourceFile,
kc::cachedRawSourceFilename(filename, compilingCpp),
kernelHash,
assembleKernelHeader(kernelProps))
);

if (compilingOkl) {
const std::string outputFile = hashDir + kc::sourceFile;
const std::string outputFile = hashDir + kc::cachedSourceFilename(filename);
bool valid = parseFile(sourceFilename,
outputFile,
kernelProps,
Expand Down

0 comments on commit 1590291

Please sign in to comment.