Skip to content

[SPIR-V] Add SPIRV to LLVM_ALL_TARGETS (reapply) #123733

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

Conversation

michalpaszkowski
Copy link
Member

@michalpaszkowski michalpaszkowski commented Jan 21, 2025

This commit promotes the SPIR-V backend from experimental to official status. As a result, SPIR-V will be built by default, simplifying integration and increasing accessibility for downstream projects.

Discussion and RFC on Discourse: https://discourse.llvm.org/t/rfc-promoting-spir-v-to-an-official-target/83614

The PR reapplies the original patch #119653 and consecutive #123654, reverted due to buildbot failures.

This commit promotes the SPIR-V backend from experimental to official
status. As a result, SPIR-V will be built by default, simplifying
integration and increasing accessibility for downstream projects.

Discussion and RFC on Discourse: https://discourse.llvm.org/t/rfc-promoting-spir-v-to-an-official-target/83614
@llvmbot
Copy link
Member

llvmbot commented Jan 21, 2025

@llvm/pr-subscribers-github-workflow

Author: Michal Paszkowski (michalpaszkowski)

Changes

This commit promotes the SPIR-V backend from experimental to official status. As a result, SPIR-V will be built by default, simplifying integration and increasing accessibility for downstream projects.

Discussion and RFC on Discourse: https://discourse.llvm.org/t/rfc-promoting-spir-v-to-an-official-target/83614


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

4 Files Affected:

  • (modified) .github/workflows/spirv-tests.yml (+1-1)
  • (modified) llvm/CMakeLists.txt (+1-1)
  • (modified) llvm/Maintainers.md (+5-2)
  • (modified) llvm/docs/ReleaseNotes.md (+6)
diff --git a/.github/workflows/spirv-tests.yml b/.github/workflows/spirv-tests.yml
index 34c77a398c1504..ea466dc6c52e57 100644
--- a/.github/workflows/spirv-tests.yml
+++ b/.github/workflows/spirv-tests.yml
@@ -25,5 +25,5 @@ jobs:
     with:
       build_target: check-llvm-codegen-spirv
       projects:
-      extra_cmake_args: '-DLLVM_TARGETS_TO_BUILD="" -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="SPIRV" -DLLVM_INCLUDE_SPIRV_TOOLS_TESTS=ON'
+      extra_cmake_args: '-DLLVM_TARGETS_TO_BUILD="SPIRV" -DLLVM_INCLUDE_SPIRV_TOOLS_TESTS=ON'
       os_list: '["ubuntu-22.04"]'
diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index f14065ab037990..ad12100fdb5b89 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -486,6 +486,7 @@ set(LLVM_ALL_TARGETS
   PowerPC
   RISCV
   Sparc
+  SPIRV
   SystemZ
   VE
   WebAssembly
@@ -498,7 +499,6 @@ set(LLVM_ALL_EXPERIMENTAL_TARGETS
   CSKY
   DirectX
   M68k
-  SPIRV
   Xtensa
 )
 
diff --git a/llvm/Maintainers.md b/llvm/Maintainers.md
index 56457946136f04..534d81e68d0245 100644
--- a/llvm/Maintainers.md
+++ b/llvm/Maintainers.md
@@ -284,8 +284,11 @@ koachan@protonmail.com (email), [koachan](https://github.com/koachan) (GitHub)
 
 #### SPIRV backend
 
-Ilia Diachkov \
-ilia.diachkov@gmail.com (email), [iliya-diyachkov](https://github.com/iliya-diyachkov) (GitHub)
+Vyacheslav Levytskyy \
+vyacheslav.levytskyy@intel.com, vyacheslav.levytskyy@gmail.com (email), [VyacheslavLevytskyy](https://github.com/VyacheslavLevytskyy) (GitHub)
+
+Nathan Gauër \
+brioche@google.com (email), [Keenuts](https://github.com/Keenuts) (GitHub)
 
 #### SystemZ backend
 
diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index 8f88b824f965aa..48f962d212e86d 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -47,6 +47,12 @@ for adding a new subsection. -->
   same semantics. The normalizer makes it easier to spot semantic differences
   when diffing two modules which have undergone different passes.
 
+* The SPIR-V backend is now an official LLVM target, providing OpenCL and SYCL
+  conformance and establishing a foundation for broader applicability to other
+  APIs, including Vulkan, GLSL, and HLSL. This backend aims to offer a unified
+  approach for diverse compute and graphics workloads, providing a robust
+  alternative to the Khronos SPIR-V LLVM Translator.
+
 * ...
 
 <!-- If you would like to document a larger change, then you can add a

@michalpaszkowski michalpaszkowski merged commit cda81b1 into llvm:main Jan 21, 2025
9 of 11 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jan 21, 2025

LLVM Buildbot has detected a new failure on builder reverse-iteration running on hexagon-build-02 while building .github,llvm at step 6 "check_all".

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

Here is the relevant piece of the build log for the reference
Step 6 (check_all) failure: test (failure)
******************** TEST 'LLVM :: CodeGen/SPIRV/debug-info/debug-type-pointer.ll' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: /local/mnt/workspace/bots/hexagon-build-02/reverse-iteration/llvm.obj/bin/llc --verify-machineinstrs --spv-emit-nonsemantic-debug-info --spirv-ext=+SPV_KHR_non_semantic_info --print-after=spirv-nonsemantic-debug-info -O0 -mtriple=spirv64-unknown-unknown /local/mnt/workspace/bots/hexagon-build-02/reverse-iteration/llvm.src/llvm/test/CodeGen/SPIRV/debug-info/debug-type-pointer.ll -o - 2>&1 | /local/mnt/workspace/bots/hexagon-build-02/reverse-iteration/llvm.obj/bin/FileCheck /local/mnt/workspace/bots/hexagon-build-02/reverse-iteration/llvm.src/llvm/test/CodeGen/SPIRV/debug-info/debug-type-pointer.ll --check-prefix=CHECK-MIR
+ /local/mnt/workspace/bots/hexagon-build-02/reverse-iteration/llvm.obj/bin/llc --verify-machineinstrs --spv-emit-nonsemantic-debug-info --spirv-ext=+SPV_KHR_non_semantic_info --print-after=spirv-nonsemantic-debug-info -O0 -mtriple=spirv64-unknown-unknown /local/mnt/workspace/bots/hexagon-build-02/reverse-iteration/llvm.src/llvm/test/CodeGen/SPIRV/debug-info/debug-type-pointer.ll -o -
+ /local/mnt/workspace/bots/hexagon-build-02/reverse-iteration/llvm.obj/bin/FileCheck /local/mnt/workspace/bots/hexagon-build-02/reverse-iteration/llvm.src/llvm/test/CodeGen/SPIRV/debug-info/debug-type-pointer.ll --check-prefix=CHECK-MIR
/local/mnt/workspace/bots/hexagon-build-02/reverse-iteration/llvm.src/llvm/test/CodeGen/SPIRV/debug-info/debug-type-pointer.ll:32:14: error: CHECK-MIR: expected string not found in input
; CHECK-MIR: OpExtInst [[void_type]], 3, 3, [[short]], [[i32_8]], [[i32_0]]
             ^
<stdin>:126:77: note: scanning from here
 %108:id(s32) = OpExtInst %61:type(s64), 3, 3, %95:id(s32), %40:iid, %35:iid
                                                                            ^
<stdin>:126:77: note: with "void_type" equal to "%61:type\\(s64\\)"
 %108:id(s32) = OpExtInst %61:type(s64), 3, 3, %95:id(s32), %40:iid, %35:iid
                                                                            ^
<stdin>:126:77: note: with "short" equal to "%92:id\\(s32\\)"
 %108:id(s32) = OpExtInst %61:type(s64), 3, 3, %95:id(s32), %40:iid, %35:iid
                                                                            ^
<stdin>:126:77: note: with "i32_8" equal to "%40:iid"
 %108:id(s32) = OpExtInst %61:type(s64), 3, 3, %95:id(s32), %40:iid, %35:iid
                                                                            ^
<stdin>:126:77: note: with "i32_0" equal to "%35:iid"
 %108:id(s32) = OpExtInst %61:type(s64), 3, 3, %95:id(s32), %40:iid, %35:iid
                                                                            ^
<stdin>:135:12: note: possible intended match here
 %1:type = OpTypeInt 32, 0
           ^

Input file: <stdin>
Check file: /local/mnt/workspace/bots/hexagon-build-02/reverse-iteration/llvm.src/llvm/test/CodeGen/SPIRV/debug-info/debug-type-pointer.ll

-dump-input=help explains the following input dump.

Input was:
<<<<<<
            .
            .
            .
          121:  %103:id(s32) = OpExtInst %61:type(s64), 3, 3, %84:id(s32), %40:iid, %35:iid 
          122:  %104:id(s32) = OpExtInst %61:type(s64), 3, 3, %86:id(s32), %40:iid, %35:iid 
          123:  %105:id(s32) = OpExtInst %61:type(s64), 3, 3, %88:id(s32), %40:iid, %35:iid 
          124:  %106:id(s32) = OpExtInst %61:type(s64), 3, 3, %90:id(s32), %40:iid, %35:iid 
          125:  %107:id(s32) = OpExtInst %61:type(s64), 3, 3, %92:id(s32), %40:iid, %35:iid 
          126:  %108:id(s32) = OpExtInst %61:type(s64), 3, 3, %95:id(s32), %40:iid, %35:iid 
check:32'0                                                                                 X error: no match found
check:32'1                                                                                   with "void_type" equal to "%61:type\\(s64\\)"
check:32'2                                                                                   with "short" equal to "%92:id\\(s32\\)"
check:32'3                                                                                   with "i32_8" equal to "%40:iid"
...

@michalpaszkowski
Copy link
Member Author

michalpaszkowski commented Jan 21, 2025

LLVM Buildbot has detected a new failure on builder reverse-iteration running on hexagon-build-02 while building .github,llvm at step 6 "check_all".

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

Here is the relevant piece of the build log for the reference

PR fixing the issue reported above:

@llvm-ci
Copy link
Collaborator

llvm-ci commented Jan 22, 2025

LLVM Buildbot has detected a new failure on builder lld-x86_64-win running on as-worker-93 while building .github,llvm at step 7 "test-build-unified-tree-check-all".

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

Here is the relevant piece of the build log for the reference
Step 7 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'LLVM-Unit :: Support/./SupportTests.exe/38/87' FAILED ********************
Script(shard):
--
GTEST_OUTPUT=json:C:\a\lld-x86_64-win\build\unittests\Support\.\SupportTests.exe-LLVM-Unit-1628-38-87.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=87 GTEST_SHARD_INDEX=38 C:\a\lld-x86_64-win\build\unittests\Support\.\SupportTests.exe
--

Script:
--
C:\a\lld-x86_64-win\build\unittests\Support\.\SupportTests.exe --gtest_filter=ProgramEnvTest.CreateProcessLongPath
--
C:\a\lld-x86_64-win\llvm-project\llvm\unittests\Support\ProgramTest.cpp(160): error: Expected equality of these values:
  0
  RC
    Which is: -2

C:\a\lld-x86_64-win\llvm-project\llvm\unittests\Support\ProgramTest.cpp(163): error: fs::remove(Twine(LongPath)): did not return errc::success.
error number: 13
error message: permission denied



C:\a\lld-x86_64-win\llvm-project\llvm\unittests\Support\ProgramTest.cpp:160
Expected equality of these values:
  0
  RC
    Which is: -2

C:\a\lld-x86_64-win\llvm-project\llvm\unittests\Support\ProgramTest.cpp:163
fs::remove(Twine(LongPath)): did not return errc::success.
error number: 13
error message: permission denied




********************


@nikic
Copy link
Contributor

nikic commented Jan 22, 2025

I'm seeing this failure on i686:


******************** TEST 'LLVM-Unit :: Target/SPIRV/./SPIRVTests/1/2' FAILED ********************
Script(shard):
--
GTEST_OUTPUT=json:/builddir/build/BUILD/llvm-20.0.0_pre20250122.gaf84ed8ae5c1a7-build/llvm-project-af84ed8ae5c1a7af96fb745582244dd219e2e481/llvm/redhat-linux-build/unittests/Target/SPIRV/./SPIRVTests-LLVM-Unit-92046-1-2.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=2 GTEST_SHARD_INDEX=1 /builddir/build/BUILD/llvm-20.0.0_pre20250122.gaf84ed8ae5c1a7-build/llvm-project-af84ed8ae5c1a7af96fb745582244dd219e2e481/llvm/redhat-linux-build/unittests/Target/SPIRV/./SPIRVTests
--

Script:
--
/builddir/build/BUILD/llvm-20.0.0_pre20250122.gaf84ed8ae5c1a7-build/llvm-project-af84ed8ae5c1a7af96fb745582244dd219e2e481/llvm/redhat-linux-build/unittests/Target/SPIRV/./SPIRVTests --gtest_filter=SPIRVAPITest.checkTranslateSupportExtensionByArg
--
Invalid optimization level!/builddir/build/BUILD/llvm-20.0.0_pre20250122.gaf84ed8ae5c1a7-build/llvm-project-af84ed8ae5c1a7af96fb745582244dd219e2e481/llvm/unittests/Target/SPIRV/SPIRVAPITest.cpp:122: Failure
Value of: Status && Error.empty() && !Result.empty()
  Actual: false
Expected: true

/builddir/build/BUILD/llvm-20.0.0_pre20250122.gaf84ed8ae5c1a7-build/llvm-project-af84ed8ae5c1a7af96fb745582244dd219e2e481/llvm/unittests/Target/SPIRV/SPIRVAPITest.cpp:123: Failure
Expected equality of these values:
  identify_magic(Result)
    Which is: 0
  file_magic::spirv_object
    Which is: 39


/builddir/build/BUILD/llvm-20.0.0_pre20250122.gaf84ed8ae5c1a7-build/llvm-project-af84ed8ae5c1a7af96fb745582244dd219e2e481/llvm/unittests/Target/SPIRV/SPIRVAPITest.cpp:122
Value of: Status && Error.empty() && !Result.empty()
  Actual: false
Expected: true

/builddir/build/BUILD/llvm-20.0.0_pre20250122.gaf84ed8ae5c1a7-build/llvm-project-af84ed8ae5c1a7af96fb745582244dd219e2e481/llvm/unittests/Target/SPIRV/SPIRVAPITest.cpp:123
Expected equality of these values:
  identify_magic(Result)
    Which is: 0
  file_magic::spirv_object
    Which is: 39


Script:
--
/builddir/build/BUILD/llvm-20.0.0_pre20250122.gaf84ed8ae5c1a7-build/llvm-project-af84ed8ae5c1a7af96fb745582244dd219e2e481/llvm/redhat-linux-build/unittests/Target/SPIRV/./SPIRVTests --gtest_filter=SPIRVAPITest.checkTranslateAllExtensions
--
Invalid optimization level!/builddir/build/BUILD/llvm-20.0.0_pre20250122.gaf84ed8ae5c1a7-build/llvm-project-af84ed8ae5c1a7af96fb745582244dd219e2e481/llvm/unittests/Target/SPIRV/SPIRVAPITest.cpp:140: Failure
Value of: Status && Error.empty() && !Result.empty()
  Actual: false
Expected: true

/builddir/build/BUILD/llvm-20.0.0_pre20250122.gaf84ed8ae5c1a7-build/llvm-project-af84ed8ae5c1a7af96fb745582244dd219e2e481/llvm/unittests/Target/SPIRV/SPIRVAPITest.cpp:141: Failure
Expected equality of these values:
  identify_magic(Result)
    Which is: 0
  file_magic::spirv_object
    Which is: 39


/builddir/build/BUILD/llvm-20.0.0_pre20250122.gaf84ed8ae5c1a7-build/llvm-project-af84ed8ae5c1a7af96fb745582244dd219e2e481/llvm/unittests/Target/SPIRV/SPIRVAPITest.cpp:140
Value of: Status && Error.empty() && !Result.empty()
  Actual: false
Expected: true

/builddir/build/BUILD/llvm-20.0.0_pre20250122.gaf84ed8ae5c1a7-build/llvm-project-af84ed8ae5c1a7af96fb745582244dd219e2e481/llvm/unittests/Target/SPIRV/SPIRVAPITest.cpp:141
Expected equality of these values:
  identify_magic(Result)
    Which is: 0
  file_magic::spirv_object
    Which is: 39

Something not working correctly on 32-bit hosts?

@VyacheslavLevytskyy
Copy link
Contributor

Something not working correctly on 32-bit hosts?

Not that we know about.
The reason for a test to fail is in the log: "Invalid optimization level!", suggesting that CodeGenOpt::parseLevel(...) returns std::nullopt. There is certain weirdness in this, and we are on it.

@nikic
Copy link
Contributor

nikic commented Jan 23, 2025

Looks like the issue didn't occur in today's build, so some change in the meantime fixed it...

@nikic
Copy link
Contributor

nikic commented Jan 27, 2025

Hm, looks like it's not fixed after all :( I'm now seeing the same failure on ppc64le and s390x as well, but it doesn't happen every time.

@nikic
Copy link
Contributor

nikic commented Jan 27, 2025

It looks like parseSPIRVCommandLineOptions is calling cl::ParseCommandLineOptions. This is not legal, as the function isn't thread-safe. (Unless you intended SPIRVTranslateModule to not be thread-safe? In which case the tests can't be executed in paralle.)

@VyacheslavLevytskyy
Copy link
Contributor

It looks like parseSPIRVCommandLineOptions is calling cl::ParseCommandLineOptions. This is not legal, as the function isn't thread-safe. (Unless you intended SPIRVTranslateModule to not be thread-safe? In which case the tests can't be executed in paralle.)

Thanks for the pointer! I'll have a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants