OpenCL's round function matches math.round so we can directly lower to
the op, this includes adding the op definition to the SPIRV OCL ops.
GLSL does not guarantee rounding direction so we include custom rounding
code to guarantee correct rounding direction.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Nice, thanks for supporting this, @rsuderman!
mlir/lib/Conversion/MathToSPIRV/MathToSPIRV.cpp | ||
---|---|---|
237 | Nit: ... to GLSL SPIR-V extended ops. | |
260 | Hmm, this is using expensive FMul and FDiv ops. What about using FAdd like the expansion pattern in the below? | |
mlir/lib/Dialect/Math/Transforms/ExpandPatterns.cpp | ||
57 | Missing a test for this? | |
68 | This should be math::FloorOp? | |
133 | This should be exposed in the .h file? |
mlir/lib/Conversion/MathToSPIRV/MathToSPIRV.cpp | ||
---|---|---|
237 | Fixed. | |
260 | I discovered an error with the add that causes unintentional double rounding. Specifically the case of 0.49999997f + 0,5f -> 1.0. I can see if there is an alternative solution? One option is to do more bit magic instead but my f32 mantissa manipulations are not fantastic. |
mlir/lib/Conversion/MathToSPIRV/MathToSPIRV.cpp | ||
---|---|---|
260 | Ha, interesting. Okay that makes sense then. Could you add comments in the code explaining this so later when we come back to this we can still understand why doing mul & div? |
mlir/lib/Conversion/MathToSPIRV/MathToSPIRV.cpp | ||
---|---|---|
260 | Changed to use a select operation. It is slightly more ops but should be computationally faster. |
Nit: ... to GLSL SPIR-V extended ops.