diff --git a/tinygrad/runtime/support/hcq.py b/tinygrad/runtime/support/hcq.py index 804224ce41..318737b6a4 100644 --- a/tinygrad/runtime/support/hcq.py +++ b/tinygrad/runtime/support/hcq.py @@ -1,6 +1,6 @@ from __future__ import annotations from typing import cast, Callable, Type, TypeVar, Generic, Any -import contextlib, decimal, statistics, time, ctypes, array, os, fcntl, struct, traceback, collections +import contextlib, decimal, statistics, time, ctypes, array, os, struct, traceback, collections from tinygrad.helpers import PROFILE, getenv, to_mv, round_up, ProfileRangeEvent from tinygrad.renderer import Renderer from tinygrad.device import BufferSpec, Compiler, Compiled, LRUAllocator, ProfileDeviceEvent, ProfileProgramEvent @@ -25,7 +25,9 @@ class FileIOInterface: self.fd:int = fd or os.open(path, flags) def __del__(self): if hasattr(self, 'fd'): os.close(self.fd) - def ioctl(self, request, arg): return fcntl.ioctl(self.fd, request, arg) + def ioctl(self, request, arg): + import fcntl # to support windows + return fcntl.ioctl(self.fd, request, arg) def mmap(self, start, sz, prot, flags, offset): x = libc.mmap(start, sz, prot, flags, self.fd, offset) if x == 0xffffffffffffffff: raise OSError(f"Failed to mmap {sz} bytes at {hex(start)}: {os.strerror(ctypes.get_errno())}") diff --git a/tinygrad/runtime/support/system.py b/tinygrad/runtime/support/system.py index 4014aff5be..169407aad9 100644 --- a/tinygrad/runtime/support/system.py +++ b/tinygrad/runtime/support/system.py @@ -1,4 +1,4 @@ -import os, mmap, array, functools, ctypes, select, contextlib, dataclasses, sys, fcntl +import os, mmap, array, functools, ctypes, select, contextlib, dataclasses, sys from typing import cast, ClassVar from tinygrad.helpers import round_up, to_mv, getenv, OSX, temp from tinygrad.runtime.autogen import libc, vfio @@ -55,6 +55,8 @@ class _System: except OSError: return None def flock_acquire(self, name:str) -> int: + import fcntl # to support windows + os.umask(0) # Set umask to 0 to allow creating files with 0666 permissions # Avoid O_CREAT because we don’t want to re-create/replace an existing file (triggers extra perms checks) when opening as non-owner.