Skip to content

Commit

Permalink
remove file writing in metal ops (tinygrad#2369)
Browse files Browse the repository at this point in the history
* remove file writing in metal ops

* remove unused import

---------

Co-authored-by: ductm104 <ductm>
  • Loading branch information
ductm104 committed Nov 21, 2023
1 parent c4cc496 commit 179551a
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions tinygrad/runtime/ops_metal.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# pip3 install pyobjc-framework-Metal pyobjc-framework-Cocoa pyobjc-framework-libdispatch
import os, subprocess, pathlib, ctypes, tempfile
import Metal, Cocoa, libdispatch
import Metal, libdispatch
from typing import List, Any, Tuple, Dict, Union, Set, cast
from tinygrad.codegen.kernel import LinearizerOptions
from tinygrad.helpers import prod, getenv, DEBUG, DType, dtypes, diskcache, dedup
Expand Down Expand Up @@ -53,10 +53,7 @@ def compile_metal(prg, use_xcode=bool(getenv("METAL_XCODE"))) -> bytes:
return subprocess.check_output(['xcrun', '-sdk', 'macosx', 'metallib', '-', '-o', '-'], input=air)
options = Metal.MTLCompileOptions.new()
library = unwrap(METAL.device.newLibraryWithSource_options_error_(prg, options, None))
# TODO: avoid file write here?
with tempfile.NamedTemporaryFile(delete=True) as output_file:
unwrap(library.serializeToURL_error_(Cocoa.NSURL.URLWithString_(f"file:https://{output_file.name}"), None))
return pathlib.Path(output_file.name).read_bytes()
return library.libraryDataContents().bytes().tobytes()

class MetalProgram:
def __init__(self, name:str, lib:bytes):
Expand Down

0 comments on commit 179551a

Please sign in to comment.