Skip to content

[HLSL] Reapply Move length support out of the DirectX Backend (#121611) #122337

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

Merged
merged 3 commits into from
Jan 10, 2025

Conversation

farzonl
Copy link
Member

@farzonl farzonl commented Jan 9, 2025

  • attribute keeps getting deleted on bad rebases

@llvmbot llvmbot added clang Clang issues not falling into any other category backend:X86 clang:headers Headers provided by Clang, e.g. for intrinsics labels Jan 9, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 9, 2025

@llvm/pr-subscribers-llvm-ir
@llvm/pr-subscribers-backend-directx
@llvm/pr-subscribers-hlsl

@llvm/pr-subscribers-backend-x86

Author: Farzon Lotfi (farzonl)

Changes
  • attribute keeps getting deleted on bad rebases

Full diff: https://github.com/llvm/llvm-project/pull/122337.diff

1 Files Affected:

  • (modified) clang/lib/Headers/hlsl/hlsl_intrinsics.h (+2)
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index cf287e598f76ba..7105d83078a9d7 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -1297,9 +1297,11 @@ float4 lerp(float4, float4, float4);
 ///
 /// Length is based on the following formula: sqrt(x[0]^2 + x[1]^2 + ...).
 
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 const inline half length(half X) { return __detail::length_impl(X); }
 const inline float length(float X) { return __detail::length_impl(X); }
 
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 template <int N> const inline half length(vector<half, N> X) {
   return __detail::length_vec_impl(X);
 }

@llvmbot
Copy link
Member

llvmbot commented Jan 9, 2025

@llvm/pr-subscribers-clang

Author: Farzon Lotfi (farzonl)

Changes
  • attribute keeps getting deleted on bad rebases

Full diff: https://github.com/llvm/llvm-project/pull/122337.diff

1 Files Affected:

  • (modified) clang/lib/Headers/hlsl/hlsl_intrinsics.h (+2)
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index cf287e598f76ba..7105d83078a9d7 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -1297,9 +1297,11 @@ float4 lerp(float4, float4, float4);
 ///
 /// Length is based on the following formula: sqrt(x[0]^2 + x[1]^2 + ...).
 
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 const inline half length(half X) { return __detail::length_impl(X); }
 const inline float length(float X) { return __detail::length_impl(X); }
 
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 template <int N> const inline half length(vector<half, N> X) {
   return __detail::length_vec_impl(X);
 }

Copy link
Contributor

@damyanp damyanp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this fix a test failure?

Copy link
Contributor

@inbelic inbelic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, assuming we don't need the other availability denoted

@@ -1297,9 +1297,11 @@ float4 lerp(float4, float4, float4);
///
/// Length is based on the following formula: sqrt(x[0]^2 + x[1]^2 + ...).

_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
const inline half length(half X) { return __detail::length_impl(X); }
const inline float length(float X) { return __detail::length_impl(X); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need _HLSL_AVAILABILITY(shadermodel, 6.2) on the none half variants?

@farzonl
Copy link
Member Author

farzonl commented Jan 9, 2025

Does this fix a test failure?

No failures. We would need to have tests for all intrinsics that if its not SM 6.2 or greater uses of half would error, but we never did that for any of the other intrinsics so we should probably discuss what the test coverage should be and apply it broadly.

## Changes
- Delete DirectX length intrinsic
- Delete HLSL length lang builtin
- Implement length algorithm entirely in the header.

## History
- In the past if an HLSL intrinsic lowered to either a spirv op code or
a DXIL opcode we represented it with intrinsics

## Why we are moving away?
- To make HLSL apis more portable the team decided that it makes sense
for some intrinsics to be defined only in the header.
- Since there tends to be more SPIRV opcodes than DXIL opcodes the plan
is to support SPIRV opcodes either with target specific builtins or via
pattern matching.
@farzonl farzonl force-pushed the fix-length-half-availability branch from 0f0b75d to 6f2da80 Compare January 9, 2025 21:24
@llvmbot llvmbot added clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:codegen IR generation bugs: mangling, exceptions, etc. backend:DirectX HLSL HLSL Language Support llvm:ir labels Jan 9, 2025
@farzonl farzonl changed the title [HLSL] Add 6.2 SM on half availability for length intrinsic [HLSL] Reapply Move length support out of the DirectX Backend (llvm#121611) Jan 9, 2025
@farzonl farzonl changed the title [HLSL] Reapply Move length support out of the DirectX Backend (llvm#121611) [HLSL] Reapply Move length support out of the DirectX Backend (#121611) Jan 9, 2025
- attribute keeps getting deleted on bad rebases
@farzonl farzonl force-pushed the fix-length-half-availability branch from 6f2da80 to 7173a48 Compare January 9, 2025 21:57
Copy link

github-actions bot commented Jan 9, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@llvm-beanz
Copy link
Collaborator

No failures. We would need to have tests for all intrinsics that if its not SM 6.2 or greater uses of half would error, but we never did that for any of the other intrinsics so we should probably discuss what the test coverage should be and apply it broadly.

In practice these are pretty tricky to test on just Clang because the 6.2 attribute only applies when -enable-16bit-types is set, which requires shader model 6.2 or greater. So you shouldn't actually be able to make the compiler fail this.

The point of the attribute is really just for header completeness so that we can drive documentation and LSP tooling from it.

@farzonl
Copy link
Member Author

farzonl commented Jan 10, 2025

@llvm-beanz I'm really confused what is going on here
The length test case passes in the github action: https://github.com/llvm/llvm-project/actions/runs/12699150463?pr=122337
It passes locally on:

  1. MacOS Intel (Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz)
  2. MacOS Apple M3 Max 12 core
  3. Ubuntu 22.04 AMD Ryzen Threadripper PRO 5975WX 32-Cores
  4. Windows AMD Ryzen 9 5900X

BUT its failing in buildkite and on other llvm builders. I'm not sure what could do this.
https://buildkite.com/llvm-project/github-pull-requests/builds/135222

@farzonl
Copy link
Member Author

farzonl commented Jan 10, 2025

@llvm-beanz I'm really confused what is going on here The length test case passes in the github action: https://github.com/llvm/llvm-project/actions/runs/12699150463?pr=122337 It passes locally on:

  1. MacOS Intel (Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz)
  2. MacOS Apple M3 Max 12 core
  3. Ubuntu 22.04 AMD Ryzen Threadripper PRO 5975WX 32-Cores
  4. Windows AMD Ryzen 9 5900X

BUT its failing in buildkite and on other llvm builders. I'm not sure what could do this. https://buildkite.com/llvm-project/github-pull-requests/builds/135222

I figured out what is going on here. On some platforms the loop unroll isn't working

This warning shows up:

warning: loop not unrolled: the optimizer was unable to perform the requested transformation; the transformation might be disabled or specified as part of an unsupported transformation ordering

And there is a br label %for.body.i.

I'm switching to define length as sqrt(dot(x,x)) to avoid the loop.

@farzonl
Copy link
Member Author

farzonl commented Jan 10, 2025

Ok going to try to merge again. no more test failure for length.hlsl in buildkite. only failing test was: Clang.SemaSYCL/sycl-kernel-entry-point-attr-appertainment.cpp

@farzonl farzonl merged commit b900379 into llvm:main Jan 10, 2025
6 of 8 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jan 10, 2025

LLVM Buildbot has detected a new failure on builder llvm-clang-x86_64-expensive-checks-debian running on gribozavr4 while building clang,llvm at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/16/builds/11794

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'LLVM :: tools/llvm-gsymutil/ARM_AArch64/macho-merged-funcs-dwarf.yaml' FAILED ********************
Exit Code: 1

Command Output (stdout):
--
Input file: /b/1/llvm-clang-x86_64-expensive-checks-debian/build/test/tools/llvm-gsymutil/ARM_AArch64/Output/macho-merged-funcs-dwarf.yaml.tmp.dSYM
Output file (aarch64): /b/1/llvm-clang-x86_64-expensive-checks-debian/build/test/tools/llvm-gsymutil/ARM_AArch64/Output/macho-merged-funcs-dwarf.yaml.tmp.default.gSYM
Loaded 3 functions from DWARF.
Loaded 3 functions from symbol table.
warning: same address range contains different debug info. Removing:
[0x0000000000000248 - 0x0000000000000270): Name=0x00000047
addr=0x0000000000000248, file=  3, line=  5
addr=0x0000000000000254, file=  3, line=  7
addr=0x0000000000000258, file=  3, line=  9
addr=0x000000000000025c, file=  3, line=  8
addr=0x0000000000000260, file=  3, line= 11
addr=0x0000000000000264, file=  3, line= 10
addr=0x0000000000000268, file=  3, line=  6


In favor of this one:
[0x0000000000000248 - 0x0000000000000270): Name=0x00000030
addr=0x0000000000000248, file=  2, line=  5
addr=0x0000000000000254, file=  2, line=  7
addr=0x0000000000000258, file=  2, line=  9
addr=0x000000000000025c, file=  2, line=  8
addr=0x0000000000000260, file=  2, line= 11
addr=0x0000000000000264, file=  2, line= 10
addr=0x0000000000000268, file=  2, line=  6


warning: same address range contains different debug info. Removing:
[0x0000000000000248 - 0x0000000000000270): Name=0x00000030
addr=0x0000000000000248, file=  2, line=  5
addr=0x0000000000000254, file=  2, line=  7
addr=0x0000000000000258, file=  2, line=  9
addr=0x000000000000025c, file=  2, line=  8
addr=0x0000000000000260, file=  2, line= 11
addr=0x0000000000000264, file=  2, line= 10
addr=0x0000000000000268, file=  2, line=  6


In favor of this one:
[0x0000000000000248 - 0x0000000000000270): Name=0x00000001
addr=0x0000000000000248, file=  1, line=  5
addr=0x0000000000000254, file=  1, line=  7
addr=0x0000000000000258, file=  1, line=  9
addr=0x000000000000025c, file=  1, line=  8
addr=0x0000000000000260, file=  1, line= 11
addr=0x0000000000000264, file=  1, line= 10
...

BaiXilin pushed a commit to BaiXilin/llvm-fix-vnni-instr-types that referenced this pull request Jan 12, 2025
…21611) (llvm#122337)

## Changes
- Delete DirectX length intrinsic
- Delete HLSL length lang builtin
- Implement length algorithm entirely in the header.

## History
- In the past if an HLSL intrinsic lowered to either a spirv op code or
a DXIL opcode we represented it with intrinsics

## Why we are moving away?
- To make HLSL apis more portable the team decided that it makes sense
for some intrinsics to be defined only in the header.
- Since there tends to be more SPIRV opcodes than DXIL opcodes the plan
is to support SPIRV opcodes either with target specific builtins or via
pattern matching.
@farzonl farzonl deleted the fix-length-half-availability branch January 13, 2025 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:DirectX backend:X86 clang:codegen IR generation bugs: mangling, exceptions, etc. clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:headers Headers provided by Clang, e.g. for intrinsics clang Clang issues not falling into any other category HLSL HLSL Language Support llvm:ir
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants