我正在考虑将一些数学运算卸载到 GPU。因为我已经在使用 D3D11,所以我会使用计算着色器来完成这项工作。但问题是我需要相同输入的结果相同,无论用户可能拥有什么 GPU。(仅要求它支持计算着色器 4.0)。
那么 GPU 上的浮点数学是确定性的吗?
如果不是,GPU 是否支持整数数学?
我正在考虑将一些数学运算卸载到 GPU。因为我已经在使用 D3D11,所以我会使用计算着色器来完成这项工作。但问题是我需要相同输入的结果相同,无论用户可能拥有什么 GPU。(仅要求它支持计算着色器 4.0)。
那么 GPU 上的浮点数学是确定性的吗?
如果不是,GPU 是否支持整数数学?
I haven't used DirectCompute, only OpenCL.
GPUs definitely support integer math, both 32-bit and 64-bit integers. A couple of questions already have this discussion:
Basically, on modern GPUs 32-bit float and integer operations are equivalent in performance.
As for deterministic results, it depends on your code. For example, if you rely on multiple threads performing atomic operations on the same memory then reading that memory from other threads and performing operations depending on that value, then results may not be exactly the same every time.
From personal experience, I needed to generate random numbers but also required consistent results. So basically I had a largish array of seeds, one for each thread, and each one was completely independent. Other random number generators which rely on atomic operations and barriers would not have been.
The other half of having deterministic results is having the same result given different hardware. With integer operations you should be fairly safe. With floating point operations in OpenCL, avoiding the fast relaxed math option and the native variants of functions would increase chances of getting the same results on different hardware.