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

Fix incorrect byval and other attributes on LLVM 14 #950

Merged
merged 4 commits into from Jun 5, 2023
Merged

Fix incorrect byval and other attributes on LLVM 14 #950

merged 4 commits into from Jun 5, 2023

Conversation

apmasell
Copy link
Contributor

@apmasell apmasell commented May 17, 2023

Some attributes now need type information. This preserves it.

Closes #946

Some attributes now need type information. This preserves it.
@esc
Copy link
Member

esc commented May 18, 2023

Two high-level questions from my initial look:

  • Can the tests be made to invoke LLVM and check against the produced output, in addition to checking for the "canned" result we have now?

  • What happens to the additional parameter attributes that were added in LLVM 14 -- like byref? Will you add support for these too?

@apmasell
Copy link
Contributor Author

For the first, I don't know how to do that given the way I can get the plumbing to work with pickle. If you have a design, I'm happy to hear it.

For the second, until we have a true way to control LLVM backend version, we should only do that if we raise the minimum LLVM version. Are we prepared to do that in a patch release?

@thomasfire
Copy link

For the first, I don't know how to do that given the way I can get the plumbing to work with pickle. If you have a design, I'm happy to hear it.

Is it possible to integrate these pieces of IR from tests to some function and see if LLVM compiles it?

@apmasell
Copy link
Contributor Author

That's what the current test does.

@esc
Copy link
Member

esc commented May 25, 2023

OK, so just to double check, the way this works now:

a) We have code to add the types to the Parameter Attributes
b) The "canned" tests have been updated, but they only test for the sret parameter attribute
c) We have a generated test, where we test byval -- such that we generate some IR and then ensure that the given version of LLVM can indeed parse this IR

The question I have, and I have no idea if this even needs to be asked: so it seems that we only check for sret and byval, but these are not the only parameter attributes? Do we need to -- or should we -- test the other attributes too?

The second question that I have is if we can ask anyone from the artiq project to check this PR with their code? This is where these issues were originally detected, and perhaps this is a good test case for this PR: m-labs/artiq#2050 @thomasfire would you be able to facilitate this?

@sklam
Copy link
Member

sklam commented May 26, 2023

The question I have, and I have no idea if this even needs to be asked: so it seems that we only check for sret and byval, but these are not the only parameter attributes? Do we need to -- or should we -- test the other attributes too?

I think we should proactively test for all the parameter attributes. The test should be easy to write and we just need to send it through parse_assembly().

@apmasell
Copy link
Contributor Author

Added.

@thomasfire
Copy link

I've tested our code against this branch, and would confirm that this fixes the issue

@esc
Copy link
Member

esc commented May 29, 2023

I've tested our code against this branch, and would confirm that this fixes the issue

Awesome, thank you for your feedback!

@thomasfire would you like to be added to our RC-Testers group on our discourse:

https://numba.discourse.group/

it's a group of folks who are interested in new Numba/llvmlite release candidates, perhaps this could be of interest to you? It would perhaps help with future llvmlite testing?

@thomasfire
Copy link

would you like to be added to our RC-Testers group on our discourse:

Yes, you can add me, username is same as github's

Copy link
Member

@esc esc left a comment

Choose a reason for hiding this comment

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

I have a suggestion to make about using slightly more Pythonic syntax.

llvmlite/ir/values.py Outdated Show resolved Hide resolved
Co-authored-by: esc <esc@users.noreply.github.com>
@esc
Copy link
Member

esc commented Jun 1, 2023

would you like to be added to our RC-Testers group on our discourse:

Yes, you can add me, username is same as github's

You should have received an invite now.

@esc
Copy link
Member

esc commented Jun 1, 2023

Since this also supports LLVM 11 -- I was wanting to build this PR and test against that. However, I am having trouble getting a development environment setup. Mostly I am troubled with conda environment conflicts.

@esc
Copy link
Member

esc commented Jun 1, 2023

So I tried this locally, by applying the patches from this PR to the https://github.com/numba/llvmlite/tree/release0.40 branch. I then compiled this against an llvmdev=11 from the numba channel on anaconda.org.

When running the tests, I receive:

======================================================================
ERROR: test_arg_attributes (llvmlite.tests.test_ir.TestBuildInstructions)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/vhaenel/git/llvmlite/llvmlite/tests/test_ir.py", line 1852, in test_arg_attributes
    llvm.parse_assembly(gen_code(attr_name))
  File "/Users/vhaenel/git/llvmlite/llvmlite/binding/module.py", line 25, in parse_assembly
    raise RuntimeError("LLVM IR parsing error\n{0}".format(errmsg))
RuntimeError: LLVM IR parsing error
<string>:5:24: error: expected ')' at end of argument list
define i32 @"sum"(i32* byref %".1", i32 %".2")

@apmasell
Copy link
Contributor Author

apmasell commented Jun 2, 2023

I've added a commit that should make it work properly on LLVM 11. Some of the attributes being tested weren't supported on LLVM 11.

@esc
Copy link
Member

esc commented Jun 2, 2023

I've added a commit that should make it work properly on LLVM 11. Some of the attributes being tested weren't supported on LLVM 11.

Thank you, I can confirm that with the commit efb856a the llvmlite test suite passes with LLVM 11.

@esc
Copy link
Member

esc commented Jun 2, 2023

So I tried running the Numba main test-suite against an llvmlite from this PR built against LLVM 11 -- I received one error, but I am not sure this is related to my work:

======================================================================
FAIL: test_parfor_race_1 (numba.tests.test_parfors.TestPrangeSpecific)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/esc/git/numba/numba/tests/test_parfors.py", line 4091, in test_parfor_race_1
    self.assertIn(expected_msg, str(warning_obj.message))
AssertionError: 'Variable k used in parallel loop may be written to simultaneously by multiple workers and may result in non-deterministic or unintended results.' not found in 'A Numba config file is found but YAML parsing capabilities appear to be missing. To use this feature please install `pyyaml`. e.g. `conda install pyyaml`.'

@apmasell
Copy link
Contributor Author

apmasell commented Jun 2, 2023

That's exciting and I desperately hope not related to these changes.

@esc
Copy link
Member

esc commented Jun 2, 2023

That's exciting and I desperately hope not related to these changes.

No, it wasn't, it was a side effect of not having pyyaml installed.

@esc
Copy link
Member

esc commented Jun 2, 2023

I am now hitting:

.Assertion failed: (isInt<33>(Addend) && "Invalid page reloc value."), function encodeAddend, file /Users/ci/miniconda3-arm64/conda-bld/llvmdev_1643905487494/work/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOAArch64.h, line 210.
Fatal Python error: Aborted

Current thread 0x0000000104d34580 (most recent call first):
  File "/Users/vhaenel/git/llvmlite/llvmlite/binding/ffi.py", line 152 in __call__
  File "/Users/vhaenel/git/llvmlite/llvmlite/binding/executionengine.py", line 92 in finalize_object
  File "/Users/vhaenel/git/numba/numba/core/codegen.py", line 1060 in wrapper
  File "/Users/vhaenel/git/numba/numba/core/codegen.py", line 999 in _finalize_specific
  File "/Users/vhaenel/git/numba/numba/core/codegen.py", line 797 in _finalize_final_module

Which I believe is known issue on Mac ARM64?

@esc
Copy link
Member

esc commented Jun 2, 2023

I am now hitting:

.Assertion failed: (isInt<33>(Addend) && "Invalid page reloc value."), function encodeAddend, file /Users/ci/miniconda3-arm64/conda-bld/llvmdev_1643905487494/work/lib/ExecutionEngine/RuntimeDyld/Targets/RuntimeDyldMachOAArch64.h, line 210.
Fatal Python error: Aborted

Current thread 0x0000000104d34580 (most recent call first):
  File "/Users/vhaenel/git/llvmlite/llvmlite/binding/ffi.py", line 152 in __call__
  File "/Users/vhaenel/git/llvmlite/llvmlite/binding/executionengine.py", line 92 in finalize_object
  File "/Users/vhaenel/git/numba/numba/core/codegen.py", line 1060 in wrapper
  File "/Users/vhaenel/git/numba/numba/core/codegen.py", line 999 in _finalize_specific
  File "/Users/vhaenel/git/numba/numba/core/codegen.py", line 797 in _finalize_final_module

Which I believe is known issue on Mac ARM64?

It is this one here: numba/numba#8567

OK, I ran it again and it seems like the issue is transient, so I would say this did indeed pass a spot check, with LLVM 11.

Copy link
Member

@esc esc left a comment

Choose a reason for hiding this comment

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

Question: can we compile?

'zeroext',
) + supplemental:
# If this parses, we emitted the right byval attribute format
llvm.parse_assembly(gen_code(attr_name))
Copy link
Member

Choose a reason for hiding this comment

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

Would it be possible to try to compile this too? Or is the test-code not self-sufficient?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're applying attributes in ways that don't really make sense, so I'm guessing most of these would be ignored at best or cause compilation problems. We'd need to design a test case for each attribute.

Copy link
Member

Choose a reason for hiding this comment

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

ok, that makes sense, thank you.

@esc
Copy link
Member

esc commented Jun 5, 2023

This is now going in, thank you for the patch!

@esc esc merged commit 70f057b into numba:main Jun 5, 2023
18 checks passed
@apmasell apmasell deleted the llvm14_attributes branch June 6, 2023 00:59
esc added a commit to esc/llvmlite that referenced this pull request Jun 6, 2023
Fix incorrect `byval` and other attributes on LLVM 14
@esc esc mentioned this pull request Jun 6, 2023
30 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Wrong syntax for LLVM 14 argument attributes
4 participants