From cd6aeebfeed02babfdc302e00129253918e9fd1a Mon Sep 17 00:00:00 2001 From: qazal <77887910+Qazalin@users.noreply.github.com> Date: Mon, 13 Oct 2025 17:26:12 +0800 Subject: [PATCH] sqtt: osx decoder installer (#12637) --- autogen_stubs.sh | 4 ++-- extra/sqtt/rocprof/install.py | 18 ++++++++++++++++++ extra/sqtt/rocprof/rocprof.py | 5 ++--- 3 files changed, 22 insertions(+), 5 deletions(-) create mode 100755 extra/sqtt/rocprof/install.py diff --git a/autogen_stubs.sh b/autogen_stubs.sh index 1ea3b583db..4577bbde85 100755 --- a/autogen_stubs.sh +++ b/autogen_stubs.sh @@ -435,8 +435,8 @@ generate_sqtt() { -o extra/sqtt/rocprof/rocprof.py fixup extra/sqtt/rocprof/rocprof.py sed -i '1s/^/# pylint: skip-file\n/' extra/sqtt/rocprof/rocprof.py - sed -i "s/import ctypes/import ctypes\nfrom tinygrad.helpers import fetch/g" extra/sqtt/rocprof/rocprof.py - sed -i "s|FunctionFactoryStub()|ctypes.CDLL(str(fetch('https://github.com/ROCm/rocprof-trace-decoder/raw/5420409ad0963b2d76450add067b9058493ccbd0/releases/linux_glibc_2_28_x86_64/librocprof-trace-decoder.so')))|g" extra/sqtt/rocprof/rocprof.py + sed -i "s/import ctypes/import ctypes, ctypes.util/g" extra/sqtt/rocprof/rocprof.py + sed -i "s|FunctionFactoryStub()|ctypes.CDLL(ctypes.util.find_library('rocprof-trace-decoder'))|g" extra/sqtt/rocprof/rocprof.py } generate_webgpu() { diff --git a/extra/sqtt/rocprof/install.py b/extra/sqtt/rocprof/install.py new file mode 100755 index 0000000000..5243180602 --- /dev/null +++ b/extra/sqtt/rocprof/install.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python3 +import os, shutil +from pathlib import Path +from tinygrad.helpers import fetch, OSX + +DEST = Path("/usr/local/lib") +DEST.mkdir(exist_ok=True) + +if __name__ == "__main__": + if OSX: + fp = fetch("https://github.com/ROCm/rocprof-trace-decoder/releases/download/0.1.4/rocprof-trace-decoder-macos-arm64-0.1.4-Darwin.sh") + lib = fp.parent/"rocprof-trace-decoder-macos-arm64-0.1.4-Darwin"/"lib"/"librocprof-trace-decoder.dylib" + os.chmod(fp, 0o755) + os.system(f"sudo {fp} --prefix={fp.parent} --include-subdir") + else: + lib = fetch("https://github.com/ROCm/rocprof-trace-decoder/raw/5420409ad0963b2d76450add067b9058493ccbd0/releases/linux_glibc_2_28_x86_64/librocprof-trace-decoder.so", name="librocprof-trace-decoder.so") + shutil.copy2(lib, DEST) + print(f"Installed {lib.name} to", DEST) diff --git a/extra/sqtt/rocprof/rocprof.py b/extra/sqtt/rocprof/rocprof.py index 1d0b151bb1..bded16acc2 100644 --- a/extra/sqtt/rocprof/rocprof.py +++ b/extra/sqtt/rocprof/rocprof.py @@ -7,8 +7,7 @@ # POINTER_SIZE is: 8 # LONGDOUBLE_SIZE is: 16 # -import ctypes -from tinygrad.helpers import fetch +import ctypes, ctypes.util class AsDictMixin: @@ -156,7 +155,7 @@ class FunctionFactoryStub: # You can either re-run clan2py with -l /path/to/library.so # Or manually fix this by comment the ctypes.CDLL loading _libraries = {} -_libraries['FIXME_STUB'] = ctypes.CDLL(str(fetch('https://github.com/ROCm/rocprof-trace-decoder/raw/5420409ad0963b2d76450add067b9058493ccbd0/releases/linux_glibc_2_28_x86_64/librocprof-trace-decoder.so'))) # ctypes.CDLL('FIXME_STUB') +_libraries['FIXME_STUB'] = ctypes.CDLL(ctypes.util.find_library('rocprof-trace-decoder')) # ctypes.CDLL('FIXME_STUB')