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

[Utils][SPIR-V] Adding spirv-sim to LLVM #104020

Merged
merged 7 commits into from
Sep 3, 2024
Merged

[Utils][SPIR-V] Adding spirv-sim to LLVM #104020

merged 7 commits into from
Sep 3, 2024

Conversation

Keenuts
Copy link
Contributor

@Keenuts Keenuts commented Aug 14, 2024

Currently, the testing infrastructure for SPIR-V is based on FileCheck. Those tests are great to check some level of codegen, but when the test needs check both the CFG layout and the content of each basic-block, things becomes messy.

  • Because the CHECK/CHECK-DAG/CHECK-NEXT state is limited, it is sometimes hard to catch the good block: if 2 basic blocks have similar instructions, FileCheck can match the wrong one.

  • Cross-lane interaction can be a bit difficult to understand, and writting a FileCheck test that is strong enough to catch bad CFG transforms while not being broken everytime some unrelated codegen part changes is hard.

And lastly, the spirv-val tooling we have checks that the generated SPIR-V respects the spec, not that it is correct in regards to the source IR.

For those reasons, I believe the best way to test the structurizer is to:

  • run spirv-val to make sure the CFG respects the spec.
  • simulate the function to validate result for each lane, making sure the generated code is correct.

This simulator has no other dependencies than core python. It also only supports a very limited set of instructions as we can test most features through control-flow and some basic cross-lane interactions.

As-is, the added tests are just a harness for the simulator itself. If this gets merged, the structurizer PR will benefit from this as I'll be able to add extensive testing using this.

Copy link

github-actions bot commented Aug 14, 2024

✅ With the latest revision this PR passed the Python code formatter.

llvm/utils/spirv-sim/spirv-sim.py Outdated Show resolved Hide resolved
llvm/utils/spirv-sim/spirv-sim.py Outdated Show resolved Hide resolved
llvm/utils/spirv-sim/spirv-sim.py Outdated Show resolved Hide resolved
llvm/utils/spirv-sim/spirv-sim.py Outdated Show resolved Hide resolved
llvm/utils/spirv-sim/spirv-sim.py Outdated Show resolved Hide resolved
llvm/utils/spirv-sim/spirv-sim.py Outdated Show resolved Hide resolved
llvm/utils/spirv-sim/spirv-sim.py Outdated Show resolved Hide resolved
llvm/utils/spirv-sim/spirv-sim.py Outdated Show resolved Hide resolved
llvm/utils/spirv-sim/instructions.py Outdated Show resolved Hide resolved
llvm/utils/spirv-sim/instructions.py Outdated Show resolved Hide resolved
Copy link
Contributor

@iliya-diyachkov iliya-diyachkov left a comment

Choose a reason for hiding this comment

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

Please fix issues in comments.

llvm/utils/spirv-sim/instructions.py Outdated Show resolved Hide resolved
llvm/utils/spirv-sim/spirv-sim.py Outdated Show resolved Hide resolved
llvm/utils/spirv-sim/spirv-sim.py Outdated Show resolved Hide resolved
llvm/utils/spirv-sim/spirv-sim.py Outdated Show resolved Hide resolved
llvm/utils/spirv-sim/spirv-sim.py Outdated Show resolved Hide resolved
Currently, the testing infrastructure for SPIR-V is based on FileCheck.
Those tests are great to check some level of codegen, but when the test
needs check both the CFG layout and the content of each basic-block,
things becomes messy.

- Because the CHECK/CHECK-DAG/CHECK-NEXT state is limited, it is sometimes
  hard to catch the good block: if 2 basic blocks have similar
  instructions, FileCheck can match the wrong one.

- Cross-lane interaction can be a bit difficult to understand, and writting
  a FileCheck test that is strong enough to catch bad CFG transforms while
  not being broken everytime some unrelated codegen part changes is hard.

And lastly, the spirv-val tooling we have checks that the generated
SPIR-V respects the spec, not that it is correct in regards to the
source IR.

For those reasons, I believe the best way to test the structurizer is
to:
 - run spirv-val to make sure the CFG respects the spec.
 - simulate the function to validate result for each lane, making sure
   the generated code is correct.

This simulator has no other dependencies than code python. It also only
supports a very limited set of instructions as we can test most features
through control-flow and some basic cross-lane interactions.

As-is, the added tests are just a harness for the simulator itself.
If this gets merged, the structurizer PR will benefit from this as I'll
be able to add extensive testing using this.
Signed-off-by: Nathan Gauër <[email protected]>
Signed-off-by: Nathan Gauër <[email protected]>
Signed-off-by: Nathan Gauër <[email protected]>
Signed-off-by: Nathan Gauër <[email protected]>
Signed-off-by: Nathan Gauër <[email protected]>
@Keenuts
Copy link
Contributor Author

Keenuts commented Sep 2, 2024

Thanks! Typos fixed, & rebased

@Keenuts Keenuts merged commit c3d8124 into llvm:main Sep 3, 2024
8 checks passed
@Keenuts Keenuts deleted the spirv-sim branch September 3, 2024 09:46
Keenuts added a commit that referenced this pull request Sep 3, 2024
Keenuts added a commit that referenced this pull request Sep 3, 2024
Reverts #104020

Looks like it caused build failures.
@llvm-ci
Copy link
Collaborator

llvm-ci commented Sep 4, 2024

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

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

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 :: ExecutionEngine/JITLink/AArch64/ELF_relocations.s' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: rm -rf /b/1/llvm-clang-x86_64-expensive-checks-debian/build/test/ExecutionEngine/JITLink/AArch64/Output/ELF_relocations.s.tmp && mkdir -p /b/1/llvm-clang-x86_64-expensive-checks-debian/build/test/ExecutionEngine/JITLink/AArch64/Output/ELF_relocations.s.tmp
+ rm -rf /b/1/llvm-clang-x86_64-expensive-checks-debian/build/test/ExecutionEngine/JITLink/AArch64/Output/ELF_relocations.s.tmp
+ mkdir -p /b/1/llvm-clang-x86_64-expensive-checks-debian/build/test/ExecutionEngine/JITLink/AArch64/Output/ELF_relocations.s.tmp
RUN: at line 2: /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llvm-mc -triple=aarch64-unknown-linux-gnu -x86-relax-relocations=false    -position-independent -filetype=obj -o /b/1/llvm-clang-x86_64-expensive-checks-debian/build/test/ExecutionEngine/JITLink/AArch64/Output/ELF_relocations.s.tmp/elf_reloc.o /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/ExecutionEngine/JITLink/AArch64/ELF_relocations.s
+ /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llvm-mc -triple=aarch64-unknown-linux-gnu -x86-relax-relocations=false -position-independent -filetype=obj -o /b/1/llvm-clang-x86_64-expensive-checks-debian/build/test/ExecutionEngine/JITLink/AArch64/Output/ELF_relocations.s.tmp/elf_reloc.o /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/ExecutionEngine/JITLink/AArch64/ELF_relocations.s
RUN: at line 4: /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llvm-jitlink -noexec               -abs external_data=0xdeadbeef               -abs external_func=0xcafef00d               -check /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/ExecutionEngine/JITLink/AArch64/ELF_relocations.s /b/1/llvm-clang-x86_64-expensive-checks-debian/build/test/ExecutionEngine/JITLink/AArch64/Output/ELF_relocations.s.tmp/elf_reloc.o
+ /b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llvm-jitlink -noexec -abs external_data=0xdeadbeef -abs external_func=0xcafef00d -check /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/ExecutionEngine/JITLink/AArch64/ELF_relocations.s /b/1/llvm-clang-x86_64-expensive-checks-debian/build/test/ExecutionEngine/JITLink/AArch64/Output/ELF_relocations.s.tmp/elf_reloc.o
Expression 'decode_operand(test_adr_gotpage_external, 1) =      (got_addr(elf_reloc.o, external_data)[32:12] -         test_adr_gotpage_external[32:12])' is false: 0x108 != 0xffffffffffe00108
/b/1/llvm-clang-x86_64-expensive-checks-debian/build/bin/llvm-jitlink: Some checks in /b/1/llvm-clang-x86_64-expensive-checks-debian/llvm-project/llvm/test/ExecutionEngine/JITLink/AArch64/ELF_relocations.s failed

--

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


Keenuts added a commit that referenced this pull request Sep 4, 2024
### 2nd submission
The buildbots are using python 3.8, and some type annotations I was
using are only available starting 3.9. The last commit on the pile is
the additional changes compared to the original submission
#104020.

### Original text:
Currently, the testing infrastructure for SPIR-V is based on FileCheck.
Those tests are great to check some level of codegen, but when the test
needs check both the CFG layout and the content of each basic-block,
things becomes messy.

Because the CHECK/CHECK-DAG/CHECK-NEXT state is limited, it is sometimes
hard to catch the good block: if 2 basic blocks have similar
instructions, FileCheck can match the wrong one.

Cross-lane interaction can be a bit difficult to understand, and
writting a FileCheck test that is strong enough to catch bad CFG
transforms while not being broken everytime some unrelated codegen part
changes is hard.

And lastly, the spirv-val tooling we have checks that the generated
SPIR-V respects the spec, not that it is correct in regards to the
source IR.

For those reasons, I believe the best way to test the structurizer is
to:

run spirv-val to make sure the CFG respects the spec.
simulate the function to validate result for each lane, making sure the
generated code is correct.
This simulator has no other dependencies than core python. It also only
supports a very limited set of instructions as we can test most features
through control-flow and some basic cross-lane interactions.

As-is, the added tests are just a harness for the simulator itself. If
this gets merged, the structurizer PR will benefit from this as I'll be
able to add extensive testing using this.

---------

Signed-off-by: Nathan Gauër <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants