From f986e12f91291bbaa0187814127c58f070885afb Mon Sep 17 00:00:00 2001 From: nimlgen <138685161+nimlgen@users.noreply.github.com> Date: Fri, 21 Feb 2025 00:43:39 +0300 Subject: [PATCH] metal: choose compile spec based on macos (#9188) * metal: choose compile spec based on macos * correction --- tinygrad/runtime/ops_metal.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tinygrad/runtime/ops_metal.py b/tinygrad/runtime/ops_metal.py index 6a7e195f74..b81a801925 100644 --- a/tinygrad/runtime/ops_metal.py +++ b/tinygrad/runtime/ops_metal.py @@ -1,4 +1,4 @@ -import os, pathlib, struct, ctypes, tempfile, functools, contextlib, decimal +import os, pathlib, struct, ctypes, tempfile, functools, contextlib, decimal, platform from typing import Any, Union, cast from tinygrad.helpers import prod, to_mv, getenv, round_up, cache_dir, T, init_c_struct_t, PROFILE from tinygrad.device import Compiled, Compiler, CompileError, LRUAllocator, cpu_profile, ProfileDeviceEvent, ProfileRangeEvent @@ -117,9 +117,14 @@ class MetalCompiler(Compiler): ret = reply[sum(struct.unpack('= 14 else "metal3.0" if macos_major >= 13 else "macos-metal2.0" + # llvm will create modules.timestamp in cache path and cache compilation of metal stdlib (250ms => 8ms compilation time) # note that llvm won't necessarily create anything else here as apple has prebuilt versions of many standard libraries - params = f'-fno-fast-math -std=metal3.1 --driver-mode=metal -x metal -fmodules-cache-path="{cache_dir}" -fno-caret-diagnostics' + params = f'-fno-fast-math -std={metal_version} --driver-mode=metal -x metal -fmodules-cache-path="{cache_dir}" -fno-caret-diagnostics' # source blob has to be padded to multiple of 4 but at least one 'b\x00' should be added, params blob just has to be null terminated src_padded, params_padded = src.encode() + b'\x00'*(round_up(len(src) + 1, 4) - len(src)), params.encode() + b'\x00' request = struct.pack('