Skip to content

Commit

Permalink
Update pr 520 (#638)
Browse files Browse the repository at this point in the history
* fsync kernel build output

* Syncs kernel binaries after check for successful compilation.

* Syncs files correctly for different operating systems.

Co-authored-by: Stefan <stefanke@zzzl.shinternet.ch>
  • Loading branch information
kris-rowe and Stefan authored Dec 2, 2022
1 parent 2134896 commit afa4e89
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 4 deletions.
26 changes: 24 additions & 2 deletions src/occa/internal/io/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stddef.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>

#include <occa/defines.hpp>

Expand All @@ -14,6 +15,7 @@
# include <windows.h>
# include <string>
# include <algorithm> // std::replace
# include <io.h> // for _commit
#endif

#include <occa/utils/hash.hpp>
Expand Down Expand Up @@ -429,6 +431,27 @@ namespace occa {
return contents;
}

void sync(const std::string &filename) {
const std::string filedir(dirname(filename));
int fd;

fd = open(filename.c_str(), O_RDONLY);
#if (OCCA_OS & (OCCA_LINUX_OS | OCCA_MACOS_OS))
fsync(fd);
#else
_commit(fd);
#endif
close(fd);

fd = open(filedir.c_str(), O_RDONLY);
#if (OCCA_OS & (OCCA_LINUX_OS | OCCA_MACOS_OS))
fsync(fd);
#else
_commit(fd);
#endif
close(fd);
}

void write(const std::string &filename,
const std::string &content) {
std::string expFilename = io::expandFilename(filename);
Expand All @@ -439,9 +462,8 @@ namespace occa {
fp != 0);

fputs(content.c_str(), fp);

fsync(fileno(fp));
fclose(fp);
io::sync(expFilename);
}

void stageFile(
Expand Down
2 changes: 2 additions & 0 deletions src/occa/internal/io/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ namespace occa {
std::string read(const std::string &filename,
const enums::FileType fileType = enums::FILE_TYPE_TEXT);

void sync(const std::string &filename);

void write(const std::string &filename,
const std::string &content);

Expand Down
3 changes: 2 additions & 1 deletion src/occa/internal/modes/cuda/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,8 @@ namespace occa {
} else if (verbose) {
io::stdout << "Output:\n\n" << commandOutput << "\n";
}
//================================

io::sync(binaryFilename);
}

modeKernel_t* device::buildOKLKernelFromBinary(const hash_t kernelHash,
Expand Down
2 changes: 2 additions & 0 deletions src/occa/internal/modes/dpcpp/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ namespace occa
} else if (verbose) {
io::stdout << "Output:\n\n" << commandOutput << "\n";
}

io::sync(binaryFilename);
}

modeKernel_t *device::buildOKLKernelFromBinary(const hash_t kernelHash,
Expand Down
3 changes: 2 additions & 1 deletion src/occa/internal/modes/hip/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ namespace occa {
} else if (verbose) {
io::stdout << "Output:\n\n" << commandOutput << "\n";
}
//================================

io::sync(binaryFilename);
}

modeKernel_t* device::buildOKLKernelFromBinary(const hash_t kernelHash,
Expand Down
1 change: 1 addition & 0 deletions src/occa/internal/modes/metal/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ namespace occa {
io::stdout << "Output:\n\n" << commandOutput << "\n";
}

io::sync(tempFilename);
return true;
}
);
Expand Down
1 change: 1 addition & 0 deletions src/occa/internal/modes/opencl/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ namespace occa {
FILE *fp = fopen(binaryFile.c_str(), "wb");
fwrite(binary, 1, binaryBytes, fp);
fclose(fp);
io::sync(binaryFile);

delete [] binary;

Expand Down
1 change: 1 addition & 0 deletions src/occa/internal/modes/serial/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ namespace occa {
);
}

io::sync(binaryFilename);
return true;
}
);
Expand Down

0 comments on commit afa4e89

Please sign in to comment.