diff --git a/src/occa/internal/io/utils.cpp b/src/occa/internal/io/utils.cpp index 98f858c22..58627ff83 100644 --- a/src/occa/internal/io/utils.cpp +++ b/src/occa/internal/io/utils.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include @@ -14,6 +15,7 @@ # include # include # include // std::replace +# include // for _commit #endif #include @@ -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); @@ -439,9 +462,8 @@ namespace occa { fp != 0); fputs(content.c_str(), fp); - - fsync(fileno(fp)); fclose(fp); + io::sync(expFilename); } void stageFile( diff --git a/src/occa/internal/io/utils.hpp b/src/occa/internal/io/utils.hpp index fa0da3d91..23f063240 100644 --- a/src/occa/internal/io/utils.hpp +++ b/src/occa/internal/io/utils.hpp @@ -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); diff --git a/src/occa/internal/modes/cuda/device.cpp b/src/occa/internal/modes/cuda/device.cpp index 47ac92567..3f08db0f7 100644 --- a/src/occa/internal/modes/cuda/device.cpp +++ b/src/occa/internal/modes/cuda/device.cpp @@ -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, diff --git a/src/occa/internal/modes/dpcpp/device.cpp b/src/occa/internal/modes/dpcpp/device.cpp index 2401880cc..d143a1279 100644 --- a/src/occa/internal/modes/dpcpp/device.cpp +++ b/src/occa/internal/modes/dpcpp/device.cpp @@ -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, diff --git a/src/occa/internal/modes/hip/device.cpp b/src/occa/internal/modes/hip/device.cpp index 8a690a044..2b9576dcf 100644 --- a/src/occa/internal/modes/hip/device.cpp +++ b/src/occa/internal/modes/hip/device.cpp @@ -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, diff --git a/src/occa/internal/modes/metal/device.cpp b/src/occa/internal/modes/metal/device.cpp index c7cddd106..c5487fdc8 100644 --- a/src/occa/internal/modes/metal/device.cpp +++ b/src/occa/internal/modes/metal/device.cpp @@ -181,6 +181,7 @@ namespace occa { io::stdout << "Output:\n\n" << commandOutput << "\n"; } + io::sync(tempFilename); return true; } ); diff --git a/src/occa/internal/modes/opencl/utils.cpp b/src/occa/internal/modes/opencl/utils.cpp index aa9f1f9c3..63aaf3cde 100644 --- a/src/occa/internal/modes/opencl/utils.cpp +++ b/src/occa/internal/modes/opencl/utils.cpp @@ -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; diff --git a/src/occa/internal/modes/serial/device.cpp b/src/occa/internal/modes/serial/device.cpp index a2ad041f7..f79a68668 100644 --- a/src/occa/internal/modes/serial/device.cpp +++ b/src/occa/internal/modes/serial/device.cpp @@ -373,6 +373,7 @@ namespace occa { ); } + io::sync(binaryFilename); return true; } );