Use MTLCompiler directly (v2) (#7920)

* Use MTLCompiler directly (v2)

* to_block_literal and REQUEST_TYPE_COMPILE

* Rewrite command encoding

* Revert to_block_literal

* Maybe that's more readable to some people?

* Typo and comment about stdlib caching

* Update ops_metal.py

* Update ops_metal.py

* Update ops_metal.py

---------

Co-authored-by: George Hotz <72895+geohot@users.noreply.github.com>
This commit is contained in:
uuuvn
2024-12-04 10:36:48 +02:00
committed by GitHub
parent bb98bae751
commit e9c5b23ba1
3 changed files with 41 additions and 23 deletions

View File

@@ -225,6 +225,6 @@ from tinygrad.runtime.ops_metal import MetalDevice, MetalCompiler, MetalProgram
if __name__ == "__main__":
dev = MetalDevice("METAL")
lib = MetalCompiler(dev).compile(src)
lib = MetalCompiler().compile(src)
prg = MetalProgram(dev, "r_64_32_8_16_4_6_6_4", lib)

View File

@@ -10,14 +10,12 @@ class TestMetal(unittest.TestCase):
device.allocator.alloc(10000000000000000000)
def test_compile_error(self):
device = MetalDevice("metal")
compiler = MetalCompiler(device)
compiler = MetalCompiler()
with self.assertRaises(CompileError):
compiler.compile("this is not valid metal")
def test_compile_success(self):
device = MetalDevice("metal")
compiler = MetalCompiler(device)
compiler = MetalCompiler()
ret = compiler.compile("""
#include <metal_stdlib>
using namespace metal;
@@ -41,7 +39,7 @@ class TestMetal(unittest.TestCase):
def test_failed_newLibraryWithData(self):
device = MetalDevice("metal")
compiler = MetalCompiler(device)
compiler = MetalCompiler()
compiled = compiler.compile("""
#include <metal_stdlib>
kernel void r_5(device int* data0, const device int* data1, uint3 gid [[threadgroup_position_in_grid]], uint3 lid [[thread_position_in_threadgroup]]){