diff --git a/tinygrad/runtime/support/hcq.py b/tinygrad/runtime/support/hcq.py index 8dbfa1df1c..0dda28f499 100644 --- a/tinygrad/runtime/support/hcq.py +++ b/tinygrad/runtime/support/hcq.py @@ -1,6 +1,8 @@ from __future__ import annotations from typing import cast, Callable, Type, TypeVar, Generic, Any import contextlib, decimal, statistics, time, ctypes, array, os, struct, traceback, collections +try: import fcntl # windows misses that +except ImportError: fcntl = None #type:ignore[assignment] 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,9 +27,7 @@ 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): - import fcntl # to support windows - return fcntl.ioctl(self.fd, request, arg) + def ioctl(self, request, arg): 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())}")