diff --git a/tinygrad/runtime/ops_disk.py b/tinygrad/runtime/ops_disk.py index d71bbe3609..1f810ec98f 100644 --- a/tinygrad/runtime/ops_disk.py +++ b/tinygrad/runtime/ops_disk.py @@ -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