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
This commit is contained in:
chenyu
2024-02-11 04:26:09 -05:00
committed by GitHub
parent 1156a27619
commit f798b60338
2 changed files with 5 additions and 0 deletions

View File

@@ -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()