gpt4 book ai didi

swift - 设置 fastMathEnabled 以便在 swift 中进行精确计算

转载 作者:行者123 更新时间:2023-11-28 14:28:55 28 4
gpt4 key购买 nike

由于我不需要在计算中优化浮点运算,我该如何在 swift 中将 fastMathEnabled 设置为 false?

最佳答案

如果您希望它应用于由 Xcode 编译并包含在默认库中的所有着色器,您可以将选项 -fno-fast-math 添加到 MTL_COMPILER_FLAGS(其他 Metal 编译器标志) 在 Xcode build设置中设置。来源:Apple Metal Shading Language Specification .

如果您在运行时编译着色器,则将选项传递给 MTLDevice makeLibrary function :

let device = MTLCreateSystemDefaultDevice()!
let options = MTLCompileOptions()
options.fastMathEnabled = false
try device.makeLibrary(source: source, options: options)

其中 source 是包含您要编译的着色器源代码的字符串。

关于swift - 设置 fastMathEnabled 以便在 swift 中进行精确计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51375608/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com