Skip to content

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

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 8 commits into from
Sep 4, 2024
Merged

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

merged 8 commits into from
Sep 4, 2024

Conversation

Keenuts
Copy link
Contributor

@Keenuts Keenuts commented Sep 3, 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.

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]>
Buildbots are using python3.8, so this commits changes the type
annotations to use ones this version supports.

Signed-off-by: Nathan Gauër <[email protected]>
@Keenuts Keenuts merged commit 5914566 into llvm:main Sep 4, 2024
9 checks passed
@Keenuts Keenuts deleted the spirv-sim branch September 4, 2024 09:24
@joker-eph
Copy link
Collaborator

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.

I have quite some concerns with this line of arguments: this seems to go against the way virtually all of LLVM is currently tested.
While this seems like a valuable discussion to have, I see this as a major departure from the current testing approach, and as such this needs a clear RFC on the Discourse forum about the kind of testing we expect in LLVM (unit-testing vs integration tests) and all the associated tradeoffs.

In the meantime, please don't consider this as a valid alternative to unit-test / FileCheck tests.

(if this RFC / discussion already happened and I missed it, then please just point me to the discussion :) )

@Keenuts
Copy link
Contributor Author

Keenuts commented Sep 10, 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.

I have quite some concerns with this line of arguments: this seems to go against the way virtually all of LLVM is currently tested. While this seems like a valuable discussion to have, I see this as a major departure from the current testing approach, and as such this needs a clear RFC on the Discourse forum about the kind of testing we expect in LLVM (unit-testing vs integration tests) and all the associated tradeoffs.

In the meantime, please don't consider this as a valid alternative to unit-test / FileCheck tests.

(if this RFC / discussion already happened and I missed it, then please just point me to the discussion :) )

Hi Mehdi!
There was no discourse thread, we discussed that in the LLVM SPIR-V backend meetings (each monday).
Yes, this is a different method, and I can see why some would disagree. I'll open a discourse thread so we can have a discussion in a more suited place then.

(FYI @michalpaszkowski @s-perron )

@Keenuts
Copy link
Contributor Author

Keenuts commented Sep 10, 2024

@joker-eph
I opened an RFC (https://discourse.llvm.org/t/rfc-spir-v-simulator/81168)

Additional node: do keep in mind that this is an additional tool to what we have today.
Today we already use FileCheck and spirv-val for the SPIR-V backend. This just come in addition to all that, to test cases for which FileCheck has IMO strong limits.
The goal is not to rely only on spirv-sim to test the SPIR-V backend.

@joker-eph
Copy link
Collaborator

Thanks for the quick follow-up!

I understand the positioning, but this is still a departure: for example the X86 backend could easily just use lli and the JIT to run a bunch of similar tests, but this was deemed not desirable.

@Keenuts
Copy link
Contributor Author

Keenuts commented Sep 10, 2024

I understand the positioning, but this is still a departure: for example the X86 backend could easily just use lli and the JIT to run a bunch of similar tests, but this was deemed not desirable.

Do you have some thread/context on why this was deemed not desirable? I'd be interested in reading about this.

@joker-eph
Copy link
Collaborator

I'd have to do more archive search on [email protected] (or [email protected]), but some info:

This was discussed a few time before that of course over the lifetime of the project, it's just hard to find all the discussions on the topic.

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.

3 participants