DirectXShaderCompiler icon indicating copy to clipboard operation
DirectXShaderCompiler copied to clipboard

Support IMul/UMul/UDiv with two outputs from HLSL

Open tex3d opened this issue 5 years ago • 9 comments

IMul/UMul/UDiv ops with two outputs have been part of the shader models since 4.0, but HLSL has never explicitly exposed these to HLSL so they could be fully used.

This is the suggestion that we should add new intrinsic functions to HLSL that map to these DXIL ops, which could open up scenarios without requiring the optional 64-bit support to be used.

tex3d avatar Apr 10 '20 00:04 tex3d

The UMul instruction, in particular, is useful for implementing the Philox-4x32 pseudorandom number generator. This is one of the fastest PRNGs available for GPUs, since it is non-sequential, and mulhi/mullo (the two outputs of UMul) are at at the core of the Philox algorithm. Philox is commonly used for hardware-accelerated machine learning frameworks to initialize random weights in a model.

This instruction is exposed as umulExtended in GLSL.

jstoecker avatar Apr 10 '20 00:04 jstoecker

@tex3d Needing this even more now, after having implemented several int64 operators in DirectML. The equivalent emulation is very verbose.

fdwr avatar Dec 03 '21 06:12 fdwr

+1

oscarbg avatar Aug 19 '22 11:08 oscarbg

@tex3d, while these operations have been defined in older shader models we don’t have any tests for them at runtime. Is this something we could safely expose without a shader model revision, or do we need to gate this on a new shader model?

llvm-beanz avatar Jul 13 '23 02:07 llvm-beanz

@llvm-beanz

we don’t have any tests for them at runtime

The shader5x HLK test does test these operations for D3D11, and we test them in DXIL by running that test, through translation. That means we should be able to safely expose these operations to HLSL.

tex3d avatar Jul 13 '23 19:07 tex3d

Sounds good. Tagging this as a feature request. We'll need to prioritize this request and spec it out.

llvm-beanz avatar Jul 13 '23 20:07 llvm-beanz

Tagging this as a feature request.

Cool. Will be happy to simplify affected parts of the DirectML code 🙂.

fdwr avatar Jul 13 '23 20:07 fdwr

This does not require a SM change. We need to add new intrinsics and can enable them retrospectively for older SM's, but we already have other code paths that generate these DXIL operations.

damyanp avatar Jun 26 '24 17:06 damyanp

@davidcook-msft to figure out priority/urgency for this with impacted teams.

damyanp avatar Jun 26 '24 17:06 damyanp