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

targets.py: Add ABIName parameter for RISC-V hard float targets #775

Merged
merged 5 commits into from
Nov 23, 2021

Conversation

occheung
Copy link
Contributor

LLVM requires RISC-V targets to specify ABI if hard float is supported. The current implementation does not allow TargetOptions.McOptions.ABIName to be specified.

This patch exposes the ABIName to the create_target_machine function. So a RISC-V target that supports hard-float can be created like such:

        lltarget = llvm.Target.from_triple("riscv32-unknown-linux")
        llmachine = lltarget.create_target_machine(
                        features="+m,+a,+f,+d",
                        reloc="pic", codemodel="default", abiname="ilp32d")

Similar feature was also added to Rust's LLVM interface: See discussion | See commit

Alternatively, we can also process the target triple and features to deduce the appropriate ABI.

@esc
Copy link
Member

esc commented Oct 12, 2021

@occheung thank you for contributing this. I have added it to the queue for review.

@sbourdeauducq
Copy link

sbourdeauducq commented Nov 8, 2021

Can we get this merged? Sounds like a simple and valid change.

@esc
Copy link
Member

esc commented Nov 8, 2021

Can we get this merged? Sounds like a simple and valid change.

@sbourdeauducq I think the problem is that access to RISC-V is limited. Have you been able to test this on some real hardware?

@gmarkall
Copy link
Member

gmarkall commented Nov 8, 2021

I can test this - will post an update once I've done so.

@sbourdeauducq
Copy link

Have you been able to test this on some real hardware?

Definitely - our compiler uses llvmlite with the patch and we test it on our FPGA board, we even have hardware-in-the-loop CI.

@gmarkall
Copy link
Member

@sbourdeauducq How are you building and testing this? Are you building an llvmlite with the RISCV target enabled?

@sbourdeauducq
Copy link

sbourdeauducq commented Nov 15, 2021

If you meant LLVM with the RISCV target enabled - yes.
Then we have a FPGA board with MiSoC and VexRiscv.

@gmarkall
Copy link
Member

Thanks... I was originally going about testing this the wrong way - I was building on a RISC-V host and trying to find a way to get the LLVM JIT to work so the whole test suite could run - I've not completed testing this PR yet but haven't forgotten it.

@sbourdeauducq
Copy link

If you don't have any hardware to test, QEMU can emulate RISC-V. Or just looking at the generated assembly should be enough anyway.

@gmarkall
Copy link
Member

In that case, is it possible to add a test that can run on the host with a RISC-V target that can check for the expected output in the generated assembly? That would make it a lot easier to check that I'm checking this PR correctly (and also lay a good foundation for future RISC-V-specific code generation functionality and tests).

@seibert
Copy link
Contributor

seibert commented Nov 15, 2021

#785 is related, as we will want to add RISCV as a target in our LLVM builds in order to run any RISC-V tests in our CI systems.

@occheung
Copy link
Contributor Author

In that case, is it possible to add a test that can run on the host with a RISC-V target that can check for the expected output in the generated assembly?

Tests regarding the impact of ABI are performed in LLVM already, such as this (albeit in later LLVM version).

AFAIK the ABIs should have no influence on how the LLVM IR needs be written?

@sbourdeauducq
Copy link

AFAIK the ABIs should have no influence on how the LLVM IR needs be written?

Yes.
The only thing that can be tested here is that when the ABI option is set from the high-level Python code, the assembly (machine, not IR) code generated at the end by LLVM is affected appropriately.

@occheung
Copy link
Contributor Author

occheung commented Nov 16, 2021

Added test to show difference between ABIs. Tests passed locally. Do I enable RISC-V target in LLVM? (Is it through this file?)

@gmarkall
Copy link
Member

Many thanks for adding the tests! I think that you have found the correct location to modify, but I'm not sure if there's additional places it would need modifying too - I will check.

@occheung occheung force-pushed the riscv-abiname branch 2 times, most recently from ef8d72f to 864c95f Compare November 16, 2021 09:38
@gmarkall
Copy link
Member

Many thanks for adding the RISCV target - note that this will need the llvmdev / llvmlite packages to be rebuilt on our channel before the test starts to pass in CI.

@esc
Copy link
Member

esc commented Nov 16, 2021

@gmarkall thank you for tending to this PR. We will need to decide what llvmlite version this should be a part of.

@sbourdeauducq
Copy link

From our perspective we would really appreciate a Conda Win64 package with RISC-V, this, and #702.
It's easy to have patches on our Hydra CI server and NixOS machines, but for Windows it's a very different story.

Copy link
Member

@gmarkall gmarkall left a comment

Choose a reason for hiding this comment

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

This generally looks good to me. Some notes:

  • WIth Add RISC-V + all default targets to LLVM build #788, the tests passed. 🎉
  • I was a little concerned about fragility of the test because it checks the assembly strings line-for-line, but on reflection I don't think they are likely to change unless we upgrade LLVM, so they will likely be stable enough in their current form.
  • The documentation in docs/source/user-guide/binding/target-information.rst will also need updating, as it isn't generated from the docstring.

@gmarkall
Copy link
Member

@occheung Many thanks for updating the docs!

A side note: could I please ask that for future changes you merge master rather than rebasing please? The reason for this is that Github doesn't make it easy to track what happened on the reviewing side in newly-added commits. I think the only substantive change in your last push is the addition of the docs, but it's quite hard for me to tell for certain. Many thanks in advance!

Copy link
Member

@gmarkall gmarkall left a comment

Choose a reason for hiding this comment

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

This looks good to me, assuming that CI passes after new packages have been built following the merge of #788.

@gmarkall
Copy link
Member

/azp run

@azure-pipelines
Copy link
Contributor

Commenter does not have sufficient privileges for PR 775 in repo numba/llvmlite

@esc
Copy link
Member

esc commented Nov 23, 2021

/azp run

@azure-pipelines
Copy link
Contributor

Pull request contains merge conflicts.

@esc
Copy link
Member

esc commented Nov 23, 2021

@gmarkall I have pushed the conflict resolution patch.

@esc
Copy link
Member

esc commented Nov 23, 2021

@gmarkall it looks like this is still bust

@gmarkall
Copy link
Member

@esc Let's discuss this a little in the dev meeting if there's time.

@stuartarchibald
Copy link
Contributor

Is the issue that the build scripts are looking in channel numba and picking up build 3:
https://github.com/numba/llvmlite/blob/master/buildscripts/incremental/setup_conda_environment.sh#L30
Log extract:

2021-11-23T12:23:01.4828781Z   added / updated specs:
2021-11-23T12:23:01.4830437Z     - llvmdev=11
2021-11-23T12:23:01.4830913Z 
2021-11-23T12:23:01.4831264Z 
2021-11-23T12:23:01.4831844Z The following packages will be downloaded:
2021-11-23T12:23:01.4832287Z 
2021-11-23T12:23:01.4832844Z     package                    |            build
2021-11-23T12:23:01.4833699Z     ---------------------------|-----------------
2021-11-23T12:23:01.4834640Z     llvmdev-11.1.0             |       he1b5a44_3       374.3 MB  numba
2021-11-23T12:23:01.4835592Z     ------------------------------------------------------------
2021-11-23T12:23:01.4836332Z                                            Total:       374.3 MB
2021-11-23T12:23:01.4836829Z 
2021-11-23T12:23:01.4837394Z The following NEW packages will be INSTALLED:
2021-11-23T12:23:01.4837907Z 
2021-11-23T12:23:01.4838694Z   llvmdev            numba/linux-64::llvmdev-11.1.0-he1b5a44_3

whereas it's build 4 that contains the additional cross targets and they are all in numba/label/ci ?

@esc
Copy link
Member

esc commented Nov 23, 2021

Is the issue that the build scripts are looking in channel numba and picking up build 3: https://github.com/numba/llvmlite/blob/master/buildscripts/incremental/setup_conda_environment.sh#L30 Log extract:

2021-11-23T12:23:01.4828781Z   added / updated specs:
2021-11-23T12:23:01.4830437Z     - llvmdev=11
2021-11-23T12:23:01.4830913Z 
2021-11-23T12:23:01.4831264Z 
2021-11-23T12:23:01.4831844Z The following packages will be downloaded:
2021-11-23T12:23:01.4832287Z 
2021-11-23T12:23:01.4832844Z     package                    |            build
2021-11-23T12:23:01.4833699Z     ---------------------------|-----------------
2021-11-23T12:23:01.4834640Z     llvmdev-11.1.0             |       he1b5a44_3       374.3 MB  numba
2021-11-23T12:23:01.4835592Z     ------------------------------------------------------------
2021-11-23T12:23:01.4836332Z                                            Total:       374.3 MB
2021-11-23T12:23:01.4836829Z 
2021-11-23T12:23:01.4837394Z The following NEW packages will be INSTALLED:
2021-11-23T12:23:01.4837907Z 
2021-11-23T12:23:01.4838694Z   llvmdev            numba/linux-64::llvmdev-11.1.0-he1b5a44_3

whereas it's build 4 that contains the additional cross targets and they are all in numba/label/ci ?

good catch, that may very well be the case!

@esc
Copy link
Member

esc commented Nov 23, 2021

/azp run

@azure-pipelines
Copy link
Contributor

Azure Pipelines successfully started running 1 pipeline(s).

@gmarkall
Copy link
Member

All tests passed now that the llvmdev packages are available on the main channel - many thanks @esc!

@esc
Copy link
Member

esc commented Nov 23, 2021

All tests passed now that the llvmdev packages are available on the main channel - many thanks @esc!

👌 Excellent!

@esc
Copy link
Member

esc commented Nov 23, 2021

@occheung @sbourdeauducq @gmarkall thank you all!

@esc esc merged commit 91f7b6d into numba:master Nov 23, 2021
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.

6 participants