pylint runtime/ and shape/ (#5044)

as pointed out by #4877, need to add `__init__.py` to trigger pylint. fixed some errors except ops_python (will do in a separate pr, it has a lot of errors), and sub-folders in runtime
This commit is contained in:
chenyu
2024-06-18 19:48:18 -04:00
committed by GitHub
parent cc2be9064f
commit a8e9307e0b
10 changed files with 11 additions and 10 deletions

View File

View File

@@ -73,7 +73,7 @@ class AMDCompiler(Compiler):
super().__init__(f"compile_hip_{self.arch}")
def compile(self, src:str) -> bytes:
try: return compile_hip(src, self.arch)
except RuntimeError as e: raise CompileError(e)
except RuntimeError as e: raise CompileError(e) from e
class HWQueue:
def __init__(self): self.q, self.cmd_offsets = [], [0]
@@ -394,7 +394,7 @@ class AMDAllocator(LRUAllocator):
if e.errno == errno.ENOMEM: raise MemoryError("Cannot allocate memory") from e
else: raise
def _free(self, gpumem, options:BufferOptions): self.device._gpu_free(gpumem)
def _free(self, opaque, options:BufferOptions): self.device._gpu_free(opaque)
#def as_buffer(self, src:Any) -> memoryview:
# self.device.synchronize()
# return to_mv(src.va_addr, src.size)

View File

@@ -7,7 +7,7 @@ from tinygrad.helpers import DEBUG, getenv, from_mv, to_char_p_p, init_c_var, in
from tinygrad.device import Compiled, Compiler, CompileError, BufferOptions, LRUAllocator, MallocAllocator
from tinygrad.renderer.cstyle import CUDARenderer
from tinygrad.renderer.assembly import PTXRenderer
if getenv("IOCTL"): import extra.nv_gpu_driver.nv_ioctl # noqa: F401
if getenv("IOCTL"): import extra.nv_gpu_driver.nv_ioctl # noqa: F401 # pylint: disable=unused-import
def pretty_ptx(s):
# all expressions match `<valid_before><expr><valid_after>` and replace it with `<valid_before>color(<expr>)<valid_after>`

View File

@@ -18,7 +18,7 @@ class DiskAllocator(Allocator):
def _alloc(self, size:int, options):
self.device._might_open(size)
return DiskBuffer(self.device, size)
def _free(self, buf, options): self.device._might_close()
def _free(self, opaque, options): self.device._might_close()
def as_buffer(self, src:DiskBuffer): return src._buf()
def copyin(self, dest:DiskBuffer, src:memoryview): dest._buf()[:] = src
def copyout(self, dest:memoryview, src:DiskBuffer):

View File

@@ -67,7 +67,7 @@ class CLAllocator(LRUAllocator):
cl.cl_image_format(cl.CL_RGBA, {2: cl.CL_HALF_FLOAT, 4: cl.CL_FLOAT}[options.image.itemsize]),
options.image.shape[1], options.image.shape[0], 0, None, status := ctypes.c_int32()), status)
return checked(cl.clCreateBuffer(self.device.context, cl.CL_MEM_READ_WRITE, size, None, status := ctypes.c_int32()), status)
def _free(self, buf:ctypes._CData, options:BufferOptions): check(cl.clReleaseMemObject(buf))
def _free(self, opaque:ctypes._CData, options:BufferOptions): check(cl.clReleaseMemObject(opaque))
def copyin(self, dest:ctypes._CData, src:memoryview):
check(cl.clEnqueueWriteBuffer(self.device.queue, dest, False, 0, len(src)*src.itemsize, from_mv(src), 0, None, None))
self.device.pending_copyin.append(src) # NOTE: these can't be freed until the GPU actually executes this command

View File

@@ -23,7 +23,7 @@ class MetalCompiler(Compiler):
options = Metal.MTLCompileOptions.new()
options.setFastMathEnabled_(getenv("METAL_FAST_MATH"))
try: library = unwrap2(self.device.device.newLibraryWithSource_options_error_(src, options, None))
except AssertionError as e: raise CompileError(e)
except AssertionError as e: raise CompileError(e) from e
return library.libraryDataContents().bytes().tobytes()
class MetalProgram:

View File

@@ -2,7 +2,7 @@ import numpy as np
from tinygrad.helpers import flat_mv
from tinygrad.device import Compiled, Allocator
class NpyAllocator(Allocator):
class NpyAllocator(Allocator): # pylint: disable=abstract-method
def copyout(self, dest:memoryview, src:np.ndarray): dest[:] = flat_mv(np.require(src, requirements='C').data)
class NpyDevice(Compiled):

View File

@@ -342,10 +342,10 @@ class NVAllocator(LRUAllocator):
if options.host: return self.device._gpu_host_alloc(size)
return self.device._gpu_alloc(size, map_to_cpu=options.cpu_access, huge_page=(size > (16 << 20)))
def _free(self, gpumem, options:BufferOptions):
def _free(self, opaque, options:BufferOptions):
NVDevice.synchronize_system()
if options.host: self.device._gpu_host_free(gpumem)
else: self.device._gpu_free(gpumem)
if options.host: self.device._gpu_host_free(opaque)
else: self.device._gpu_free(opaque)
def copyin(self, dest, src: memoryview):
for i in range(0, src.nbytes, self.b[0].length):

View File

@@ -1,3 +1,4 @@
# pylint: skip-file
# a python uops emulator
# works to test the tensor cores, and all the uops in general
# this is the (living) definition of uops

View File