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

[HLSL] generate hlsl.wavesize attribute #107176

Merged
merged 2 commits into from
Sep 18, 2024
Merged

Conversation

python3kgae
Copy link
Contributor

Generate function attribute hlsl.wavesize from [WaveSize].

For #70118

@python3kgae python3kgae added the HLSL HLSL Language Support label Sep 4, 2024
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:codegen labels Sep 4, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 4, 2024

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-hlsl

Author: Xiang Li (python3kgae)

Changes

Generate function attribute hlsl.wavesize from [WaveSize].

For #70118


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

2 Files Affected:

  • (modified) clang/lib/CodeGen/CGHLSLRuntime.cpp (+7)
  • (added) clang/test/CodeGenHLSL/wavesize.hlsl (+25)
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 4bd7b6ba58de0d..28ff1153c8e1e3 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -337,6 +337,13 @@ void clang::CodeGen::CGHLSLRuntime::setHLSLEntryAttributes(
                 NumThreadsAttr->getZ());
     Fn->addFnAttr(NumThreadsKindStr, NumThreadsStr);
   }
+  if (HLSLWaveSizeAttr *WaveSizeAttr = FD->getAttr<HLSLWaveSizeAttr>()) {
+    const StringRef WaveSizeKindStr = "hlsl.wavesize";
+    std::string WaveSizeStr =
+        formatv("{0},{1},{2}", WaveSizeAttr->getMin(), WaveSizeAttr->getMax(),
+                WaveSizeAttr->getPreferred());
+    Fn->addFnAttr(WaveSizeKindStr, WaveSizeStr);
+  }
 }
 
 static Value *buildVectorInput(IRBuilder<> &B, Function *F, llvm::Type *Ty) {
diff --git a/clang/test/CodeGenHLSL/wavesize.hlsl b/clang/test/CodeGenHLSL/wavesize.hlsl
new file mode 100644
index 00000000000000..ae4b2f17c543e0
--- /dev/null
+++ b/clang/test/CodeGenHLSL/wavesize.hlsl
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.6-compute %s -DSM66 -hlsl-entry foo \
+// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s
+
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.8-compute %s -hlsl-entry foo \
+// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s --check-prefix=CHECK-SM68
+
+
+// Make sure wavesize attribute get correct value for sm66 and sm68.
+// CHECK:define void @foo()
+// CHECK:"hlsl.wavesize"="8,0,0"
+
+// CHECK-SM68:define void @foo()
+// CHECK-SM68:"hlsl.wavesize"="8,128,64"
+
+[numthreads(16,8,1)]
+#ifdef SM66
+[WaveSize(8)]
+#else
+[WaveSize(8, 128, 64)]
+#endif
+void foo() {
+
+}

Generate function attribute hlsl.wavesize from [WaveSize].

For llvm#70118
@python3kgae python3kgae merged commit 0f77bdd into llvm:main Sep 18, 2024
8 checks passed
@python3kgae python3kgae deleted the wave_size_gen branch September 18, 2024 03:00
tmsri pushed a commit to tmsri/llvm-project that referenced this pull request Sep 19, 2024
Generate function attribute hlsl.wavesize from [WaveSize].

For llvm#70118
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:codegen clang Clang issues not falling into any other category HLSL HLSL Language Support
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants