Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the WaveActiveSum HLSL Function #70106

Open
12 tasks
Tracked by #99235 ...
llvm-beanz opened this issue Oct 24, 2023 · 1 comment
Open
12 tasks
Tracked by #99235 ...

Implement the WaveActiveSum HLSL Function #70106

llvm-beanz opened this issue Oct 24, 2023 · 1 comment
Assignees
Labels
HLSL HLSL Language Support

Comments

@llvm-beanz
Copy link
Collaborator

llvm-beanz commented Oct 24, 2023

  • Implement WaveActiveSum clang builtin,
  • Link WaveActiveSum clang builtin with hlsl_intrinsics.h
  • Add sema checks for WaveActiveSum to CheckHLSLBuiltinFunctionCall in SemaChecking.cpp
  • Add codegen for WaveActiveSum to EmitHLSLBuiltinExpr in CGBuiltin.cpp
  • Add codegen tests to clang/test/CodeGenHLSL/builtins/WaveActiveSum.hlsl
  • Add sema tests to clang/test/SemaHLSL/BuiltIns/WaveActiveSum-errors.hlsl
  • Create the int_dx_WaveActiveSum intrinsic in IntrinsicsDirectX.td
  • Create the DXILOpMapping of int_dx_WaveActiveSum to 119 in DXIL.td
  • Create the WaveActiveSum.ll and WaveActiveSum_errors.ll tests in llvm/test/CodeGen/DirectX/
  • Create the int_spv_WaveActiveSum intrinsic in IntrinsicsSPIRV.td
  • In SPIRVInstructionSelector.cpp create the WaveActiveSum lowering and map it to int_spv_WaveActiveSum in SPIRVInstructionSelector::selectIntrinsic.
  • Create SPIR-V backend test case in llvm/test/CodeGen/SPIRV/hlsl-intrinsics/WaveActiveSum.ll

DirectX

DXIL Opcode DXIL OpName Shader Model Shader Stages
119 WaveActiveOp 6.0 ('library', 'compute', 'amplification', 'mesh', 'pixel', 'vertex', 'hull', 'domain', 'geometry', 'raygeneration', 'intersection', 'anyhit', 'closesthit', 'miss', 'callable', 'node')

SPIR-V

OpGroupNonUniformFAdd:

Description:

A floating point add group operation of all Value
operands contributed by active invocations in the
group.

Result Type must be a scalar or vector of floating-point
type
.

Execution is a Scope that identifies the group of
invocations affected by this command. It must be Subgroup.

The identity I for Operation is 0. If Operation is
ClusteredReduce, ClusterSize must be present.

The type of Value must be the same as Result Type. The method used
to perform the group operation on the contributed Value(s) from active
invocations is implementation defined.

ClusterSize is the size of cluster to use. ClusterSize must be a
scalar of integer type, whose Signedness operand is 0.
ClusterSize must come from a constant
instruction
. Behavior is undefined unless
ClusterSize is at least 1 and a power of 2. If ClusterSize is
greater than the size of the group, executing this instruction
results in undefined behavior.

Capability:
GroupNonUniformArithmetic, GroupNonUniformClustered,
GroupNonUniformPartitionedNV

Missing before version 1.3.

Word Count Opcode Results Operands

6 + variable

350

<id>
Result Type

Result <id>

Scope <id>
Execution

Group Operation
Operation

<id>
Value

Optional
<id>
ClusterSize

Test Case(s)

Example 1

//dxc WaveActiveSum_test.hlsl -T lib_6_8 -E fn -enable-16bit-types -spirv -fspv-target-env=universal1.5 -fcgl -O0

export float4 fn(float4 p1) {
    return WaveActiveSum(p1);
}

Example 2

//dxc WaveActiveSum_1_test.hlsl -T lib_6_8 -enable-16bit-types -O0

export uint4 fn(uint4 p1) {
    return WaveActiveSum(p1);
}

Example 3

//dxc WaveActiveSum_2_test.hlsl -T lib_6_8 -enable-16bit-types -O0

export int4 fn(int4 p1) {
    return WaveActiveSum(p1);
}

HLSL:

Sums up the value of the expression across all active lanes in the current wave and replicates it to all lanes in the current wave.

Syntax

<type> WaveActiveSum(
   <type> expr
);

Parameters

expr

The expression to evaluate.

Return value

The sum value.

Remarks

The order of operations is undefined.

This function is supported from shader model 6.0 in all shader stages.

 

Examples

float3 total = WaveActiveSum( position ); // sum positions in wave
float3 center = total/count;           // compute average of these positions

See also

Overview of Shader Model 6

Shader Model 6

@llvm-beanz llvm-beanz added the HLSL HLSL Language Support label Oct 24, 2023
@farzonl farzonl changed the title [HLSL] implement WaveActiveSum intrinsic Implement the WaveActiveSum HLSL Function Jul 16, 2024
@damyanp
Copy link
Contributor

damyanp commented Oct 4, 2024

Marking re-estimate this. Since this was originally refined, we have a different approach to implementing intrinsics and the way we've been estimating intrinsics has changed quite a bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
HLSL HLSL Language Support
Projects
Status: Ready
Development

No branches or pull requests

3 participants