forked from tinygrad/tinygrad
feat: make ops_disk work on block devices (#11291)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import os, sys, mmap, io, ctypes, ctypes.util, contextlib
|
||||
import os, sys, mmap, io, ctypes, contextlib, pathlib
|
||||
from typing import Generator, Callable
|
||||
from tinygrad.helpers import OSX, round_up
|
||||
from tinygrad.device import Compiled, Allocator
|
||||
@@ -31,7 +31,7 @@ class DiskDevice(Compiled):
|
||||
else:
|
||||
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)
|
||||
if not pathlib.Path(filename).is_block_device() and os.fstat(self.fd).st_size < self.size: os.ftruncate(self.fd, self.size)
|
||||
self.mem = mmap.mmap(self.fd, self.size)
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user