Status Update
Comments
ma...@gmail.com <ma...@gmail.com> #2
With the latest commit on my RISC-V branch of Swiftshader I'm finally getting to the point of producing a JIT related error within Swiftshader (still using llvm10):
[ RUN ] DrawTest.VertexShaderNoPositionOutput
vk::DynamicLoader exception: Failed to load vulkan library!
Falling back to loading SwiftShader directly (i.e. no validation layers)
JIT session error: Symbols not found: [ __muldi3 ]
JIT session error: Symbols not found: [ __addsf3, __divdi3, __divsf3, __eqsf2, __fixsfdi, __floatsisf, __gesf2, __gtsf2, __ltsf2, __moddi3, __muldi3, __mulsf3, __subsf3, __unordsf2 ]
JIT session error: Symbols not found: [ __fixsfdi, __floatsisf, __gtsf2, __ltsf2, __muldi3, __mulsf3 ]
[16737.053636] Thread<00>[7888]: unhandled signal 11 code 0x2 at 0x0000003f7c0f93b0
I am now checking if this is due to missing relocations or another issue specific to LLVM JIT on RISC-V.
ni...@google.com <ni...@google.com> #3
Thanks for opening a tracker issue for this!
LLVM obtains the address of external symbols through the Resolver
class
ma...@gmail.com <ma...@gmail.com> #4
Apparently jitTargetMachineBuilder
was just lacking the right features for floating point operations.
After adding:
+ jitTargetMachineBuilder.getFeatures().AddFeature("+m");
+ jitTargetMachineBuilder.getFeatures().AddFeature("+a");
+ jitTargetMachineBuilder.getFeatures().AddFeature("+f");
+ jitTargetMachineBuilder.getFeatures().AddFeature("+d");
+ jitTargetMachineBuilder.getFeatures().AddFeature("+c");
the test now passes:
[----------] 1 test from DrawTest
[ RUN ] DrawTest.VertexShaderNoPositionOutput
vk::DynamicLoader exception: Failed to load vulkan library!
Falling back to loading SwiftShader directly (i.e. no validation layers)
[ OK ] DrawTest.VertexShaderNoPositionOutput (5155 ms)
[----------] 1 test from DrawTest (5156 ms total)
However I'm not sure what that vk::DynamicLoader exception: Failed to load vulkan library!
warning is about.
It does not occur on my x86 system.
ma...@gmail.com <ma...@gmail.com> #5
On top of that the remaining tests from the vk-unittests
test suite are also passing:
[----------] Global test environment tear-down
[==========] 139 tests from 3 test suites ran. (60747 ms total)
[ PASSED ] 139 tests.
This is a bit surprising to me considering that llvm10 JIT does not support any relocations for RISC-V. For reference even the most basic "hello world" using LLVM JIT requires relocations.
So I guess there would be three possible explanations:
- The way Swiftshader uses LLVM JIT just does not lead to any relocations being generated ever.
- The test cases in
vk-unittests
don't lead to relocations being generated (but other uses of Swiftshader might?). - The test cases have some fundamental issue on RISC-V which makes them pass even though they should not.
I would be happy if you could add your thoughts.
ma...@gmail.com <ma...@gmail.com> #6
So to see if Swiftshader now actually works I tried headless the compute and rendering examples from Sascha Willems.
Unfortunately both of them fail (non deterministic either Illegal instruction
or Segmentation fault
) right after submitting the actual compute/render command buffer:
https://github.com/SaschaWillems/Vulkan/blob/master/examples/computeheadless/computeheadless.cpp#L475 https://github.com/SaschaWillems/Vulkan/blob/master/examples/renderheadless/renderheadless.cpp#L681
Example output from the headless rendering:
Running headless rendering example
GPU: SwiftShader Device (LLVM 10.0.0)
[93802.782734] Thread<02>[20046]: unhandled signal 4 code 0x1 at 0x0000003f9241d0c8
[93802.783081] Thread<00>[20044]: unhandled signal 4 code 0x1 at 0x0000003f9241d0c8
....
[93802.802700] status: 0000000000004020 badaddr: 0000000000000000 cause: 0000000000000002
Illegal instruction
Is there maybe a compile setting specific to Swiftshader that I could be missing? If not do you have advice on how I could go about debugging this issue?
ni...@google.com <ni...@google.com> #7
That's a great start! I wonder if LLVM 10 supports the relocations for Position Independent Code (PIC), which are just relative offsets and don't require any 'linking' relocations for external symbols? I believe that theory could be tested by running ReactorUnitTests
, where only some of the tests use external symbols.
Note that upgrading all of SwiftShader to a newer version of LLVM could be a lot of work and affects numerous projects, so to avoid such complication I'd like to reiterate my suggestion from the e-mail thread: Add a CMake build option to
ma...@gmail.com <ma...@gmail.com> #8
Thanks for pointing out the ReactorUnitTests
. I just ran it and for the Swizzle4
testcase I'm also running into an Illegal instruction
. I'll see what this test case is about and what is the cause for the failure.
While I was at it I also ran the system-unittest
which fails for the following test cases:
[ FAILED ] 4 tests, listed below:
[ FAILED ] MemFd.AllocatingConstructor
[ FAILED ] MemFd.ExplicitAllocation
[ FAILED ] MemFd.Close
[ FAILED ] MemFd.ExportImportFd
I will investigate those too.
Regarding the Update SwiftShader to use llvm-14 in the original in the first post:
For now my plan is to investigate this further only when I have confirmed that my issues are definitely related to missing relocations or some other missing llvm-14 feature. That way I can then implement them prioritised by their usage in Swiftshader. If so I'll follow your advice to make it a CMake build option.
On first glance it seems like this comes down to replacing the link to libllvm.a
with all the individual libLLVM*.a
library files that the regular build of llvm creates.
ma...@gmail.com <ma...@gmail.com> #9
So I did walk through the remaining test cases in ReactorUnitTests
.
The following test cases crash with an Illegal instruction
error:
Swizzle4
Shuffle
MinMax
NotNeg
Call*
CToReactorTCastTestTypes for std::pair<float, Float>
Fibonacci
Coroutines*
IntrinsicTest_Float*
FRem
Multithreaded_Coroutine
Arithmetic_ConstantArgs
Out of the remaining 94 test cases another 5 of them failed:
[==========] 94 tests from 31 test suites ran. (111757 ms total)
[ PASSED ] 89 tests.
[ FAILED ] 5 tests, listed below:
[ FAILED ] ReactorUnitTests.RoundInt
[ FAILED ] ReactorUnitTests.Args_2Mixed
[ FAILED ] ReactorUnitTests.Args_4Mixed
[ FAILED ] ReactorUnitTests.Args_5Mixed
[ FAILED ] ReactorUnitTests.Args_GreaterThan5Mixed
5 FAILED TESTS
ma...@gmail.com <ma...@gmail.com> #10
So I finally managed to link with llvm-13. Besides a few minor changes it was pretty straight forward.
Now when upgrading to llvm-14 I'm running into an issue as gtest;gtest_main
are used by llvm and swiftshader so the target definitions overlap.
I'm not sure if llvm-13 didn't use Google Test or why exactly this is occuring to me.
I'll see if I can disable the gtest;gtest_main
targets for llvm and resolve this conflict.
ma...@gmail.com <ma...@gmail.com> #11
Seems like I was building llvm with LLVM_INCLUDE_TESTS
off for llvm-13 and LLVM_INCLUDE_TESTS
on for llvm-14.
Now I managed to link against llvm-14 as well. The behavior for the ReactorUnitTests
tests remains the same.
I will check back with the llvm developers to see if they have some tips on debugging the jit crashes.
For the lli
tool they were able to adjust the output such that instead of simply crashing it would spit out the missing relocation.
I'll check if I can do something similar for the current version of swiftshader.
ma...@gmail.com <ma...@gmail.com> #12
After talking to the llvm developers I now know that for RISC-V we need to use llvm::orc::ObjectLinkingLayer
instead of llvm::orc::RTDyldObjectLinkingLayer
.
With this change and llvm-14 now quite a few more unit tests pass or at least fail gracefully. There still some left however that cause a segmentation fault. I will make a list and look into them over the next few days.
Most excitingly now the examples from Sascha's repository work. So here are the first triangles rendered with Swiftshader on RISC-V! Finally seeing some visual progress is super cool.
ni...@google.com <ni...@google.com> #13
That's amazing progress! Feel free to upload a patch to build with LLVM 14.
I've found that ReactorUnitTests.RoundInt
actually also fails with LLVM 10 when we disable our x86-specific code path, due to RoundIntClamped()
returning 0 for an out-of-range input . That even happens when using both an upper and lower clamp operation. I'll try to find a more robust baseline implementation.
ni...@google.com <ni...@google.com> #14
Patch:
ma...@gmail.com <ma...@gmail.com> #15
Sorry for the late response...I was busy with exams this week.
I tried your patch and it resolves the ReactorUnitTests.RoundInt
issue. Also commented that in the review tool. Is there something else I should do on there?
As for adding the LLVM 14 changes: Would you add the full llvm repo as a submodule? Currently I'm just providing the path of either my LLVM 14 build or the system LLVM (13) to find_package
in my CMakeLists.txt
for Reactor. Probably the submodule way is better in terms of reproducability.
Addditionally: (How) would I have to adjust the BUILD.gn
for Reactor?
ap...@google.com <ap...@google.com> #16
Branch: master
commit 4f504b04291bd47fa7b246f7ed3a59da041a074b
Author: Nicolas Capens <capn@google.com>
Date: Thu Feb 10 14:13:50 2022
Fix rr::RoundIntClamped() for architectures other than x86 and ARM
Previously we assumed that non-x86 architectures return clamped results
for out-of-range inputs to casting floating-point numbers to integers.
This is true at least for ARM, but not for RISC-V and possibly others.
An implementation which depends on LLVM's fptosi_sat intrinsic has been
added, which requires a recent version of LLVM. When not available, we
fall back to explicitly clamping both the upper and lower bound.
Bug:
Bug:
Change-Id: Ia5f1f6de395f52852044c7e1f875c1164b18f09b
Reviewed-on:
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
M src/Reactor/LLVMReactor.cpp
ni...@google.com <ni...@google.com> #17
As for adding the LLVM 14 changes: Would you add the full llvm repo as a submodule? Currently I'm just providing the path of either my LLVM 14 build or the system LLVM (13) to find_package in my CMakeLists.txt for Reactor. Probably the submodule way is better in terms of reproducability.
Yes, as a submodule would be great. FYI, we're set up to have all submodules be optional (mandatory third-party dependencies are an integral part of our repo using git subtree
).
Addditionally: (How) would I have to adjust the BUILD.gn for Reactor?
No, that's the build file for Chromium, which can keep using Subzero and LLVM 10 as JIT compilers. But thanks for checking!
ma...@gmail.com <ma...@gmail.com> #18
Ok so I separated the LLVM update changes from the RISC-V changes and put the LLVM changes up for review.
I'm looking forward to your feedback on
ap...@google.com <ap...@google.com> #19
Branch: master
commit 5ff2f732f22209099eeb63d25255bc032513a650
Author: Martin Troiber <martin.troiber@gmail.com>
Date: Fri Feb 25 00:17:06 2022
Add LLVM-Submodule backend option
Bug:
Change-Id: I68c569ca3e2a7a88debb5a95d438a7dce9f6fc09
Reviewed-on:
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
Presubmit-Ready: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
Commit-Queue: Martin Troiber <martin.troiber@gmail.com>
A third_party/llvm-project
M .gitmodules
M src/Reactor/CMakeLists.txt
M CMakeLists.txt
M src/Reactor/LLVMJIT.cpp
ma...@gmail.com <ma...@gmail.com> #20
Now for the RISC-V specific changes I would also like to commit them as soon as possible. Since they touch quite a few files having them upstreamed would help me with merge conflicts when rebasing.
Therefore I was wondering what the smallest possible commit would be. Right now quite a few test cases are still failing but the triangle demo works as shown above. This is probably due to issues/relocations on the LLVM side (but could also be on the Swiftshader side).
Additionally I was wondering whether there a way to imstrument gtest to only run a certain subset of test cases? Currently I'm commenting out the test cases that lead to crashes but there has to be a better way.
Also is there a setting for gtest to pass on the console output that Swiftshader generates? This would help with debugging those tests that fail gracefully.
ni...@google.com <ni...@google.com> #21
Therefore I was wondering what the smallest possible commit would be.
Feel free to upload a work-in-progress patch and I'll help see how we can best approach readying it for commit.
Additionally I was wondering whether there a way to imstrument gtest to only run a certain subset of test cases? Currently I'm commenting out the test cases that lead to crashes but there has to be a better way.
Yes, the --gtest_filter
Also is there a setting for gtest to pass on the console output that Swiftshader generates? This would help with debugging those tests that fail gracefully.
It redirects stdout/stderr to not disturb the actual test result output, but you can programmatically make it capture it and retrieve it:
ma...@gmail.com <ma...@gmail.com> #22
Turns out after reversing all the update script adjustments the changes are quite minimal.
I put out
ma...@gmail.com <ma...@gmail.com> #23
So if I look at the log I would assume that those tests that fail are related to an issue with the calling convention.
ap...@google.com <ap...@google.com> #24
Branch: master
commit 1884ffdf7a9289c2ea8a04afcaa8b1c17aeb570e
Author: Rebecca Chang Swee Fun <rebecca.chang@starfivetech.com>
Date: Fri Apr 01 06:39:45 2022
Reactor: riscv64 is not supported in subzero
Bug:
Signed-off-by: Rebecca Chang Swee Fun <rebecca.chang@starfivetech.com>
Change-Id: Icb7d1471eb254c2f1afac8d601c10836d38d3531
Reviewed-on:
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
M src/Reactor/reactor.gni
ap...@google.com <ap...@google.com> #25
Branch: master
commit 08403654611316acb84b94a731491ac036c481de
Author: Rebecca Chang Swee Fun <rebecca.chang@starfivetech.com>
Date: Fri Apr 01 06:39:05 2022
llvm-10.0: add configs/common and configs/linux for riscv64
Bug:
Signed-off-by: Rebecca Chang Swee Fun <rebecca.chang@starfivetech.com>
Change-Id: Ice4e65ca943f8dd98cb858d67725d88996937d9a
Reviewed-on:
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
M third_party/llvm-10.0/configs/linux/include/llvm/Config/AsmParsers.def
M third_party/llvm-10.0/configs/linux/include/llvm/Config/config.h
M third_party/llvm-10.0/configs/linux/include/llvm/Config/AsmPrinters.def
A third_party/llvm-10.0/configs/common/lib/Target/RISCV/RISCVGenCompressInstEmitter.inc
A third_party/llvm-10.0/configs/common/lib/Target/RISCV/RISCVGenDAGISel.inc
A third_party/llvm-10.0/configs/common/lib/Target/RISCV/RISCVGenMCCodeEmitter.inc
A third_party/llvm-10.0/configs/common/lib/Target/RISCV/RISCVGenRegisterInfo.inc
A third_party/llvm-10.0/configs/common/lib/Target/RISCV/RISCVGenGlobalISel.inc
M third_party/llvm-10.0/configs/linux/include/llvm/Config/abi-breaking.h
M third_party/llvm-10.0/CMakeLists.txt
A third_party/llvm-10.0/configs/common/lib/Target/RISCV/RISCVGenInstrInfo.inc
A third_party/llvm-10.0/configs/common/lib/Target/RISCV/RISCVGenSubtargetInfo.inc
M third_party/llvm-10.0/configs/linux/include/llvm/Config/Targets.def
M third_party/llvm-10.0/configs/linux/include/llvm/Config/llvm-config.h
A third_party/llvm-10.0/configs/common/lib/Target/RISCV/RISCVGenSystemOperands.inc
M third_party/llvm-10.0/configs/linux/include/llvm/Config/Disassemblers.def
A third_party/llvm-10.0/configs/common/lib/Target/RISCV/RISCVGenRegisterBank.inc
A third_party/llvm-10.0/configs/common/lib/Target/RISCV/RISCVGenAsmMatcher.inc
A third_party/llvm-10.0/configs/common/lib/Target/RISCV/RISCVGenAsmWriter.inc
A third_party/llvm-10.0/configs/common/lib/Target/RISCV/RISCVGenMCPseudoLowering.inc
A third_party/llvm-10.0/configs/common/lib/Target/RISCV/RISCVGenDisassemblerTables.inc
M third_party/llvm-10.0/BUILD.gn
ap...@google.com <ap...@google.com> #26
Branch: master
commit 0e110e6bd4d126d84e1f568f28583a67bc1f6f3c
Author: Rebecca Chang Swee Fun <rebecca.chang@starfivetech.com>
Date: Fri Apr 01 06:38:18 2022
llvm-10.0: update script to include riscv64 target
Bug:
Signed-off-by: Rebecca Chang Swee Fun <rebecca.chang@starfivetech.com>
Change-Id: Ied6840b43065f281fde4a4ccb85296e818b1cb35
Reviewed-on:
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
M third_party/llvm-10.0/scripts/update.py
ap...@google.com <ap...@google.com> #27
Branch: master
commit 716a7d9c73d3fcabcc36916830a52d774c5928df
Author: Rebecca Chang Swee Fun <rebecca.chang@starfivetech.com>
Date: Fri Apr 01 06:36:21 2022
marl: add new source file for riscv64
Bug:
Signed-off-by: Rebecca Chang Swee Fun <rebecca.chang@starfivetech.com>
Change-Id: Ib1284d9bf41f77a1f0ad148a0b61c9771619ddbf
Reviewed-on:
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
M third_party/marl/BUILD.gn
ap...@google.com <ap...@google.com> #28
Branch: master
commit 0b87966e0b127ea59f9b00d3c9871665412984d8
Author: Jean-Francois Geyelin <jif@google.com>
Date: Thu Mar 23 10:21:11 2023
Add riscv to the list of configs generated on android.
Bug:
Change-Id: I434454b18c1940c50abe7301507dc61f2d79d10f
Reviewed-on:
Tested-by: Jean-François Geyelin <jif@google.com>
Commit-Queue: Jean-François Geyelin <jif@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro-Result: kokoro <noreply+kokoro@google.com>
M third_party/llvm-16.0/scripts/update.py
ma...@gmail.com <ma...@gmail.com> #31
As part of my Master thesis I have now added support for the RISC-V vector extension.
More details on the progress can be found at:
Description
The two missing pieces are:
- Implement missing RISC-V relocations for LLVM JIT
- Update SwiftShader to use llvm-14
The original discussions can be found here:
- Swiftshader side:
- LLVM JIT side:
- LLVM JIT bug tracker: