20 #include <sys/types.h>
27 #include <memoryapi.h>
34 struct _stat64i32 buf;
35 const auto err = _fstat64i32(fd, &buf);
41 auto handle = _get_osfhandle(fd);
43 CreateFileMapping(reinterpret_cast<HANDLE>(handle), NULL, PAGE_READWRITE, 0, 0, 0);
45 auto map_ptr = MapViewOfFile(map_handle, FILE_MAP_WRITE | FILE_MAP_READ, 0, 0, sz);
47 CHECK(CloseHandle(map_handle) != 0);
52 CHECK(UnmapViewOfFile(addr) != 0);
55 int msync(
void* addr,
size_t length,
bool async) {
56 auto err = FlushViewOfFile(addr, length);
57 return err != 0 ? 0 : -1;
62 auto file = _fdopen(fd,
"a+");
66 int open(
const char* path,
int flags,
int mode) {
67 return _open(path, flags, mode);
70 void close(
const int fd) {
76 auto err = fopen_s(&f, filename, mode);
79 auto max_handles = _getmaxstdio();
80 if (max_handles < 8192) {
81 auto res = _setmaxstdio(8192);
83 LOG(
FATAL) <<
"Cannot increase maximum number of open files";
85 err = fopen_s(&f, filename, mode);
88 CHECK(!err) <<
"ERROR [" << filename <<
":" << mode <<
"[" << err <<
"]";
92 ::FILE*
popen(
const char* command,
const char*
type) {
93 return _popen(command, type);
96 int32_t
pclose(::FILE* fh) {
104 int32_t
ftruncate(
const int32_t fd, int64_t length) {
105 return _chsize_s(fd, length);
int32_t pclose(::FILE *fh)
::FILE * popen(const char *command, const char *type)
future< Result > async(Fn &&fn, Args &&...args)
int open(const char *path, int flags, int mode)
::FILE * fopen(const char *filename, const char *mode)
torch::Tensor f(torch::Tensor x, torch::Tensor W_target, torch::Tensor b_target)
int msync(void *addr, size_t length, bool async)
std::string filename(char const *path)
void checked_munmap(void *addr, size_t length)
int32_t ftruncate(const int32_t fd, int64_t length)
size_t file_size(const int fd)
void * checked_mmap(const int fd, const size_t sz)