From f798b6033861217e413090974003c470b07eeb00 Mon Sep 17 00:00:00 2001 From: chenyu Date: Sun, 11 Feb 2024 04:26:09 -0500 Subject: [PATCH] add METAL_FAST_MATH env var to disable metal fast math (#3369) * env var METAL_FAST_MATH to disable fastmath for metal use this to test impact of fast math. might need to disable compiler cache with DISABLE_COMPILER_CACHE * failed onnx test with fast math METAL_FAST_MATH=0 DISABLE_COMPILER_CACHE=1 NOOPT=1 python -m pytest -n=auto test/external/external_test_onnx_backend.py -k test_MaxPool3d_stride_padding_cpu --- test/external/external_test_onnx_backend.py | 4 ++++ tinygrad/runtime/ops_metal.py | 1 + 2 files changed, 5 insertions(+) diff --git a/test/external/external_test_onnx_backend.py b/test/external/external_test_onnx_backend.py index 7130d4b85a..d8b8890079 100644 --- a/test/external/external_test_onnx_backend.py +++ b/test/external/external_test_onnx_backend.py @@ -172,6 +172,10 @@ if Device.DEFAULT == "METAL" or (OSX and Device.DEFAULT == "GPU"): backend_test.exclude('test_mish_cpu') backend_test.exclude('test_mish_expanded_cpu') +if Device.DEFAULT == 'METAL': + # with default fast math enabled, padding -inf does not work + backend_test.exclude('test_MaxPool3d_stride_padding_cpu') + # TODO: llvm has problems with inf if Device.DEFAULT in ['LLVM']: backend_test.exclude('test_isinf_cpu') diff --git a/tinygrad/runtime/ops_metal.py b/tinygrad/runtime/ops_metal.py index f20173a873..03e71b2b22 100644 --- a/tinygrad/runtime/ops_metal.py +++ b/tinygrad/runtime/ops_metal.py @@ -20,6 +20,7 @@ class MetalCompiler(Compiler): return subprocess.check_output(['xcrun', '-sdk', 'macosx', 'metallib', '-', '-o', '-'], input=air) else: options = Metal.MTLCompileOptions.new() + options.setFastMathEnabled_(getenv("METAL_FAST_MATH", 1)) library = unwrap2(self.device.device.newLibraryWithSource_options_error_(src, options, None)) return library.libraryDataContents().bytes().tobytes()