mirror of
https://github.com/tinygrad/tinygrad.git
synced 2026-01-09 23:18:04 -05:00
improve pre-commit [pr] (#7256)
* improve pre-commit [pr] * mypy passes on windows
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
# on Windows -- $env:SKIP="devicetests,tests,example"
|
||||
repos:
|
||||
- repo: local
|
||||
hooks:
|
||||
@@ -7,15 +8,15 @@ repos:
|
||||
language: system
|
||||
always_run: true
|
||||
pass_filenames: false
|
||||
- id: mypy
|
||||
name: mypy
|
||||
entry: python3 -m mypy tinygrad/ --strict-equality
|
||||
- id: tiny
|
||||
name: tiny tests
|
||||
entry: python3 -m pytest test/test_tiny.py
|
||||
language: system
|
||||
always_run: true
|
||||
pass_filenames: false
|
||||
- id: docs2
|
||||
name: docs2
|
||||
entry: python3 docs/abstractions2.py
|
||||
- id: mypy
|
||||
name: mypy
|
||||
entry: python3 -m mypy tinygrad/ --strict-equality
|
||||
language: system
|
||||
always_run: true
|
||||
pass_filenames: false
|
||||
|
||||
@@ -56,8 +56,8 @@ class TimeoutException(Exception): pass
|
||||
def timeout_handler(signum, frame): raise TimeoutException()
|
||||
|
||||
def _try_compile_linearized_w_idx(x:Tuple[int,Kernel], compiler:Compiler) -> Tuple[int, Optional[Tuple[Program, bytes, float]]]:
|
||||
if hasattr(signal, "SIGALRM"):
|
||||
signal.signal(signal.SIGALRM, timeout_handler)
|
||||
if hasattr(signal, "alarm"):
|
||||
signal.signal(getattr(signal, 'SIGALRM'), timeout_handler)
|
||||
# set timeout
|
||||
signal.alarm(getenv("BEAM_TIMEOUT_SEC", 10))
|
||||
ret = None
|
||||
@@ -74,7 +74,7 @@ def _try_compile_linearized_w_idx(x:Tuple[int,Kernel], compiler:Compiler) -> Tup
|
||||
except Exception as e:
|
||||
if getenv("BEAM_STRICT_MODE"): raise e
|
||||
finally:
|
||||
if hasattr(signal, "SIGALRM"): signal.alarm(0)
|
||||
if hasattr(signal, "alarm"): signal.alarm(0)
|
||||
return x[0], ret
|
||||
|
||||
# workers should ignore ctrl c
|
||||
|
||||
@@ -254,7 +254,7 @@ class MetalRenderer(CStyleLanguage):
|
||||
tensor_cores = [TensorCore(dims=(8,8,8),threads=[(0,2),(1,4),(0,2),(1,2)],expanded_shape=(2,2,2,2),upcast_axes=([(1,2)],[(1,2)],[(1,2)]),
|
||||
st1_pattern=(((1,1),(0,1),(1,0),(0,3)),((0,0),(0,2),(1,3),(1,2))),st2_pattern=(((0,0),(1,1),(1,2),(0,2),(1,0)),((0,1),(0,3),(1,3))),
|
||||
dtype_in=di,dtype_out=do,reduce_axes=[(0,8)]) for di,do in [(dtypes.float,dtypes.float),(dtypes.half,dtypes.float),(dtypes.half,dtypes.half)]]
|
||||
def __init__(self): self.tensor_cores = MetalRenderer.tensor_cores if os.uname().machine == "arm64" else []
|
||||
def __init__(self): self.tensor_cores = MetalRenderer.tensor_cores if hasattr(os, 'uname') and os.uname().machine == "arm64" else []
|
||||
|
||||
# language options
|
||||
kernel_prefix = "kernel "
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
from typing import Tuple, List, Any
|
||||
import os, ctypes, ctypes.util, functools, pathlib, mmap, errno, time, array, contextlib, decimal
|
||||
import os, ctypes, ctypes.util, functools, pathlib, mmap, errno, time, array, contextlib, decimal, sys
|
||||
assert sys.platform != 'win32'
|
||||
from dataclasses import dataclass
|
||||
from tinygrad.runtime.support.hcq import HCQCompiled, HCQAllocator, HCQBuffer, HWComputeQueue, HWCopyQueue, HCQArgsState, HCQSignal, HCQProgram
|
||||
from tinygrad.device import BufferOptions
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from __future__ import annotations
|
||||
import os, sys, mmap, io, ctypes, ctypes.util, platform, contextlib
|
||||
import os, sys, mmap, io, ctypes, ctypes.util, contextlib
|
||||
from typing import Optional, Generator, Tuple, Callable, List
|
||||
from tinygrad.helpers import OSX, round_up
|
||||
from tinygrad.device import Compiled, Allocator
|
||||
@@ -84,7 +84,7 @@ class DiskDevice(Compiled):
|
||||
filename = self.dname[len("disk:"):]
|
||||
self.size = size
|
||||
|
||||
if filename.startswith("shm:"):
|
||||
if sys.platform != "win32" and filename.startswith("shm:"):
|
||||
fd = _posixshmem.shm_open("/"+filename[4:].lstrip("/"), os.O_RDWR, 0o600)
|
||||
self.mem = mmap.mmap(fd, self.size, mmap.MAP_SHARED | MAP_POPULATE | MAP_LOCKED)
|
||||
os.close(fd)
|
||||
@@ -93,7 +93,7 @@ class DiskDevice(Compiled):
|
||||
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)
|
||||
if (hp := getattr(mmap, "MADV_HUGEPAGE", None)) is not None:
|
||||
if hasattr(self.mem, 'madvise') and (hp := getattr(mmap, "MADV_HUGEPAGE", None)) is not None:
|
||||
with contextlib.suppress(OSError): self.mem.madvise(hp) # some systems have transparent_hugepage disabled
|
||||
def _might_close(self):
|
||||
self.count -= 1
|
||||
@@ -103,8 +103,7 @@ class DiskDevice(Compiled):
|
||||
def _iouring_setup(self):
|
||||
DiskDevice._tried_io_uring_init = True
|
||||
|
||||
if platform.system() != 'Linux' or hasattr(sys, "getandroidapilevel"): return
|
||||
|
||||
if sys.platform == 'linux' and not hasattr(sys, "getandroidapilevel"):
|
||||
fd = libc.syscall(io_uring.NR_io_uring_setup, 4096, ctypes.byref(p:=io_uring.struct_io_uring_params()))
|
||||
if fd < 0: return
|
||||
|
||||
@@ -115,7 +114,8 @@ class DiskDevice(Compiled):
|
||||
mmap.PROT_READ | mmap.PROT_WRITE, mmap.MAP_SHARED | MAP_POPULATE, fd, io_uring.IORING_OFF_SQES)
|
||||
|
||||
def u32ptr(val): return ctypes.cast(val, ctypes.POINTER(ctypes.c_uint32))
|
||||
sqdesc = io_uring.struct_io_uring_sq(khead=u32ptr(sq_ptr+p.sq_off.head), ktail=u32ptr(sq_ptr+p.sq_off.tail), array=u32ptr(sq_ptr+p.sq_off.array),
|
||||
sqdesc = io_uring.struct_io_uring_sq(khead=u32ptr(sq_ptr+p.sq_off.head), ktail=u32ptr(sq_ptr+p.sq_off.tail),
|
||||
array=u32ptr(sq_ptr+p.sq_off.array),
|
||||
kring_mask=u32ptr(sq_ptr+p.sq_off.ring_mask), sqes=ctypes.cast(sqes, ctypes.POINTER(io_uring.struct_io_uring_sqe)))
|
||||
|
||||
cqdesc = io_uring.struct_io_uring_cq(khead=u32ptr(cq_ptr+p.cq_off.head), ktail=u32ptr(cq_ptr+p.cq_off.tail),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
from typing import Tuple, Any
|
||||
import ctypes, os, mmap, tempfile, pathlib, array, functools, threading, contextlib
|
||||
import ctypes, os, mmap, tempfile, pathlib, array, functools, threading, contextlib, sys
|
||||
assert sys.platform != 'win32'
|
||||
from tinygrad.device import BufferOptions, Compiled, Allocator
|
||||
from tinygrad.helpers import from_mv, getenv, DEBUG, round_up, mv_address, to_mv, cpu_objdump
|
||||
from tinygrad.runtime.ops_clang import ClangCompiler
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from __future__ import annotations
|
||||
import os, ctypes, contextlib, re, fcntl, functools, mmap, struct, array, decimal
|
||||
import os, ctypes, contextlib, re, fcntl, functools, mmap, struct, array, decimal, sys
|
||||
assert sys.platform != 'win32'
|
||||
from typing import Tuple, List, Any, cast, Union, Dict, Type
|
||||
from dataclasses import dataclass
|
||||
from tinygrad.runtime.support.hcq import HCQCompiled, HCQAllocator, HCQBuffer, HWCommandQueue, HWComputeQueue, HWCopyQueue, hcq_command
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from __future__ import annotations
|
||||
import os, ctypes, functools, mmap, struct, array, decimal, math
|
||||
import os, ctypes, functools, mmap, struct, array, decimal, math, sys
|
||||
assert sys.platform != 'win32'
|
||||
from types import SimpleNamespace
|
||||
from typing import Tuple, List, Any, cast
|
||||
from tinygrad.device import BufferOptions
|
||||
|
||||
Reference in New Issue
Block a user