hcq: prepare for windows (#11293)

* hcq: prepare for windows

* comments
This commit is contained in:
nimlgen
2025-07-21 13:08:56 +03:00
committed by GitHub
parent df3ba0a7c0
commit e87a42e243
2 changed files with 7 additions and 3 deletions

View File

@@ -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())}")

View File

@@ -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 dont want to re-create/replace an existing file (triggers extra perms checks) when opening as non-owner.