mirror of
https://github.com/tinygrad/tinygrad.git
synced 2026-08-31 12:06:07 +00:00
add cpu objdump to LLVM/CLANG (#4537)
This commit is contained in:
+11
-1
@@ -19,5 +19,15 @@ if __name__ == "__main__":
|
||||
|
||||
with Profiling(PROFILE):
|
||||
with Timing("***** model lower in "):
|
||||
ei = list(lower_schedule(sched))
|
||||
eis = list(lower_schedule(sched))
|
||||
|
||||
# random makes this slow
|
||||
#with Profiling(PROFILE):
|
||||
# with Timing("***** model run in "):
|
||||
# for ei in eis: ei.run()
|
||||
|
||||
# this is all wait
|
||||
#with Profiling(PROFILE):
|
||||
# with Timing("***** model finish in "):
|
||||
# out.data()
|
||||
|
||||
|
||||
+6
-1
@@ -1,6 +1,6 @@
|
||||
from __future__ import annotations
|
||||
import os, functools, platform, time, re, contextlib, operator, hashlib, pickle, sqlite3, cProfile, pstats, tempfile, pathlib, string, ctypes
|
||||
import itertools, urllib.request
|
||||
import itertools, urllib.request, subprocess
|
||||
from tqdm import tqdm
|
||||
from typing import Dict, Tuple, Union, List, ClassVar, Optional, Iterable, Any, TypeVar, TYPE_CHECKING, Callable, Sequence
|
||||
if TYPE_CHECKING: # TODO: remove this and import TypeGuard from typing once minimum python supported version is 3.10
|
||||
@@ -220,6 +220,11 @@ def cpu_time_execution(cb, enable):
|
||||
cb()
|
||||
if enable: return time.perf_counter()-st
|
||||
|
||||
def cpu_objdump(lib):
|
||||
with tempfile.NamedTemporaryFile(delete=True) as f:
|
||||
pathlib.Path(f.name).write_bytes(lib)
|
||||
print(subprocess.check_output(['objdump', '-d', f.name]).decode('utf-8'))
|
||||
|
||||
# *** ctypes helpers
|
||||
|
||||
# TODO: make this work with read only memoryviews (if possible)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import ctypes, subprocess, pathlib, tempfile
|
||||
from tinygrad.device import Compiled, Compiler, MallocAllocator
|
||||
from tinygrad.helpers import cpu_time_execution
|
||||
from tinygrad.helpers import cpu_time_execution, DEBUG, cpu_objdump
|
||||
from tinygrad.renderer.cstyle import ClangRenderer
|
||||
|
||||
class ClangCompiler(Compiler):
|
||||
@@ -13,6 +13,7 @@ class ClangCompiler(Compiler):
|
||||
|
||||
class ClangProgram:
|
||||
def __init__(self, name:str, lib:bytes):
|
||||
if DEBUG >= 6: cpu_objdump(lib)
|
||||
self.name, self.lib = name, lib
|
||||
# write to disk so we can load it
|
||||
with tempfile.NamedTemporaryFile(delete=True) as cached_file_path:
|
||||
|
||||
@@ -2,7 +2,7 @@ from __future__ import annotations
|
||||
import ctypes, functools
|
||||
from typing import Tuple
|
||||
from tinygrad.device import Compiled, Compiler, MallocAllocator
|
||||
from tinygrad.helpers import DEBUG, cpu_time_execution
|
||||
from tinygrad.helpers import DEBUG, cpu_time_execution, cpu_objdump
|
||||
from tinygrad.renderer.llvmir import LLVMRenderer
|
||||
import llvmlite.binding as llvm
|
||||
|
||||
@@ -19,6 +19,7 @@ class LLVMCompiler(Compiler):
|
||||
|
||||
class LLVMProgram:
|
||||
def __init__(self, device:LLVMDevice, name:str, lib:bytes):
|
||||
if DEBUG >= 6: cpu_objdump(lib)
|
||||
self.name, self.lib = name, lib
|
||||
device.engine.add_object_file(llvm.object_file.ObjectFileRef.from_data(lib))
|
||||
self.fxn = device.engine.get_function_address(name)
|
||||
|
||||
Reference in New Issue
Block a user