beautiful mnist works on windows (#7100)

* beautiful mnist works on windows [pr]

* add comment for that (no pr)
This commit is contained in:
George Hotz 2024-10-16 23:00:05 +08:00 committed by GitHub
parent fc306ba89d
commit cd61e81f55
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 5 deletions

View File

@ -91,8 +91,8 @@ class dtypes:
uint16: Final[DType] = DType(4, 2, "unsigned short", 'H', 1)
int32: Final[DType] = DType(5, 4, "int", 'i', 1)
uint32: Final[DType] = DType(6, 4, "unsigned int", 'I', 1)
int64: Final[DType] = DType(7, 8, "long", 'l', 1)
uint64: Final[DType] = DType(8, 8, "unsigned long", 'L', 1)
int64: Final[DType] = DType(7, 8, "long", 'q', 1)
uint64: Final[DType] = DType(8, 8, "unsigned long", 'Q', 1)
float16: Final[DType] = DType(9, 2, "half", 'e', 1)
# bfloat16 has higher priority than float16, so least_upper_dtype(dtypes.int64, dtypes.uint64) = dtypes.float16
bfloat16: Final[DType] = DType(10, 2, "__bf16", None, 1)

View File

@ -13,8 +13,12 @@ def prod(x:Iterable[T]) -> Union[T,int]: return functools.reduce(operator.mul, x
# NOTE: helpers is not allowed to import from anything else in tinygrad
OSX = platform.system() == "Darwin"
WIN = platform.system() == "Windows"
CI = os.getenv("CI", "") != ""
# fix colors on Windows, https://stackoverflow.com/questions/12492810/python-how-can-i-make-the-ansi-escape-codes-to-work-also-in-windows
if WIN: os.system("")
def dedup(x:Iterable[T]): return list(dict.fromkeys(x)) # retains list order
def argfix(*x):
if x and x[0].__class__ in (tuple, list):

View File

@ -1,9 +1,11 @@
from __future__ import annotations
import os, sys, mmap, _posixshmem, io, ctypes, ctypes.util, platform, contextlib
import os, sys, mmap, io, ctypes, ctypes.util, platform, contextlib
from typing import Optional, Generator, Tuple, Callable, List
from tinygrad.helpers import OSX, round_up
from tinygrad.device import Compiled, Allocator
from tinygrad.runtime.autogen import io_uring, libc
with contextlib.suppress(ImportError):
import _posixshmem
from tinygrad.runtime.autogen import io_uring, libc
class DiskBuffer:
def __init__(self, device:DiskDevice, size:int, offset=0):
@ -87,7 +89,7 @@ class DiskDevice(Compiled):
self.mem = mmap.mmap(fd, self.size, mmap.MAP_SHARED | MAP_POPULATE | MAP_LOCKED)
os.close(fd)
else:
try: self.fd = os.open(filename, os.O_RDWR|os.O_CREAT|(0 if OSX else os.O_DIRECT))
try: self.fd = os.open(filename, os.O_RDWR|os.O_CREAT|getattr(os, "O_DIRECT", 0))
except OSError: self.fd = os.open(filename, os.O_RDWR|os.O_CREAT)
if os.fstat(self.fd).st_size < self.size: os.ftruncate(self.fd, self.size)
self.mem = mmap.mmap(self.fd, self.size)