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

Fixing issue 7693 #7712

Merged
merged 16 commits into from
Jan 26, 2022
Merged

Fixing issue 7693 #7712

merged 16 commits into from
Jan 26, 2022

Conversation

luk-f-a
Copy link
Contributor

@luk-f-a luk-f-a commented Jan 7, 2022

Fixes the lowering of setitem of a nestedarray into the nestedarray field of a record. Changes to the generated LLVM IR in those cases, to prevent the metadata (strides, etc) of the source being copied into the data buffer of the destination array.

fixes #7693

@gmarkall
Copy link
Member

gmarkall commented Jan 7, 2022

This also fixes the other reproducer from 7693

import numpy as np
from numba import njit

dest_dtype = np.dtype([("array1", np.int16, (3,))], align=True)


@njit
def ex1(dest):
    tmp = (np.arange(3) + 1).astype(np.int16)
    dest['array1'] = tmp 


dest = np.empty(5, dtype=dest_dtype)
expected = np.empty(5, dtype=dest_dtype)
ex1(dest[0])
ex1.py_func(expected[0])

print(expected[0])
print(dest[0])

which gives:

$ python ex1.py 
([1, 2, 3],)
([1, 2, 3],)

with this PR.

@gmarkall gmarkall added this to the Numba 0.55 RC2 milestone Jan 7, 2022
@gmarkall
Copy link
Member

gmarkall commented Jan 7, 2022

Thanks for looking at this so far! I hope you don't mind that I pushed a fix for the flake8 issues, just to make it a little clearer where the "true" failures are.

@gmarkall
Copy link
Member

gmarkall commented Jan 7, 2022

Note that the failures are all variations on the same issue:

TypeError: Can only insert float at [0] in [6 x float]: got i8*

where [6x float] is the data for the nested array.

@gmarkall
Copy link
Member

gmarkall commented Jan 7, 2022

@luk-f-a I have added the two reproducers we have for #7693 as tests as well - they seem to be passing for me locally.

@luk-f-a
Copy link
Contributor Author

luk-f-a commented Jan 7, 2022

@luk-f-a I have added the two reproducers we have for #7693 as tests as well - they seem to be passing for me locally.

oh, I didn't see the message and added one too. I'll remove it later. For now, I'm trying to fix the tests that the previous push broke. Some of them are passing locally, I hope I've fixed all of them.

@luk-f-a
Copy link
Contributor Author

luk-f-a commented Jan 8, 2022

open question for a reviewer:

  • is the if in function record_setattr the best way to product the special behaviour needed for nested arrays? That's as close to LLVM IR as I could take it. Alternatively, it could be done upstream from there, maybe here?

    numba/numba/np/arrayobj.py

    Lines 2630 to 2640 in bf480b9

    @lower_builtin('static_setitem', types.Record, types.StringLiteral, types.Any)
    def record_static_setitem_str(context, builder, sig, args):
    """
    Record.__setitem__ redirects to setattr()
    """
    recty, _, valty = sig.args
    rec, idx, val = args
    getattr_sig = signature(sig.return_type, recty, valty)
    impl = context.get_setattr(idx, getattr_sig)
    assert impl is not None
    return impl(builder, (rec, val))

@gmarkall
Copy link
Member

gpuci run tests

@gmarkall
Copy link
Member

@luk-f-a Many thanks for the fixes - from a preliminary glance this is looking promising - do you consider this non-draft / ready for review now?

  • is the if in function record_setattr the best way to product the special behaviour needed for nested arrays?

I think it's as good as we can do given the way the NestedArray abstraction is - I don't see a problem with this pattern. It's also consistent with some of the other implementation from #7359.

  • Alternatively, it could be done upstream from there, maybe here?

I think it's better to keep it where it is because some code sets attrs on structured types rather than using setitem, and the current implementation will handle both cases.

@luk-f-a
Copy link
Contributor Author

luk-f-a commented Jan 11, 2022

thanks for the feedback, I'll remove the duplicated test and promote to non-draft

@luk-f-a
Copy link
Contributor Author

luk-f-a commented Jan 11, 2022

@gmarkall do the new tests need a cuda version?

@luk-f-a luk-f-a changed the title Experiment for issue 7693 Fixing issue 7693 Jan 11, 2022
@gmarkall
Copy link
Member

@gmarkall do the new tests need a cuda version?

Ah, that's a good point - I'm not a sure if this woudl work with regualr arrays in CUDA, so I#ll have a quick check to see.

@gmarkall
Copy link
Member

gpuci run tests

@gmarkall
Copy link
Member

It turns out that the new tests do work in CUDA, so I've added them.

The lack of a py_func in the FakeCUDAKernel is a slightly surprising
omission, although it must have been missed for a long time as many CUDA
tests have to be skipped with the simulator.

Since it brings the API into line with the hardware target and fixes a
record dtype test without requiring any complex / invasive changes, we
add it here.
@gmarkall
Copy link
Member

gpuci run tests

@gmarkall
Copy link
Member

@stuartarchibald Many thanks for the review and suggested fixes. I also thought this might fail assigning an array to a whole array's worth of nested arrays, but it fails in typing as required, so I've just added an additional test to ensure that we continue to produce a typing error in this case (instead of it sneaking past typing and miscompiling or raising a lowering error.

I've also merged from master, but there were no conflicts.

@gmarkall
Copy link
Member

gpuci run tests

@gmarkall
Copy link
Member

The gpuCI fail should be resolved when #7740 is merged.

@gmarkall gmarkall added 4 - Waiting on reviewer Waiting for reviewer to respond to author and removed 4 - Waiting on author Waiting for author to respond to review labels Jan 25, 2022
@gmarkall
Copy link
Member

gpuci run tests

Copy link
Contributor

@stuartarchibald stuartarchibald left a comment

Choose a reason for hiding this comment

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

Thanks for the patch and fixes, looks good.

@stuartarchibald
Copy link
Contributor

@gmarkall please could you review/approve too RE patch 364fe7b from #7712 (comment) as I'm author. Thanks.

@stuartarchibald stuartarchibald added the 4 - Waiting on CI Review etc done, waiting for CI to finish label Jan 26, 2022
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.

Approved re patch 364fe7b, of which @stuartarchibald is the author.

@stuartarchibald
Copy link
Contributor

Approved re patch 364fe7b, of which @stuartarchibald is the author.

Thanks @gmarkall

@stuartarchibald stuartarchibald added Pending BuildFarm For PRs that have been reviewed but pending a push through our buildfarm and removed 4 - Waiting on reviewer Waiting for reviewer to respond to author labels Jan 26, 2022
@esc
Copy link
Member

esc commented Jan 26, 2022

Build numba_smoketest_cuda_yaml_114 has started

@esc
Copy link
Member

esc commented Jan 26, 2022

Build numba_smoketest_cuda_yaml_114 has started

all green

@esc esc added BuildFarm Passed For PRs that have been through the buildfarm and passed 5 - Ready to merge Review and testing done, is ready to merge and removed Pending BuildFarm For PRs that have been reviewed but pending a push through our buildfarm 4 - Waiting on CI Review etc done, waiting for CI to finish labels Jan 26, 2022
@stuartarchibald
Copy link
Contributor

Build numba_smoketest_cuda_yaml_114 has started

all green

Thanks @esc

@stuartarchibald
Copy link
Contributor

Thanks for all your work on this @luk-f-a and @gmarkall, glad to see this going into 0.55.1!

@sklam sklam merged commit 8a3d9be into numba:master Jan 26, 2022
esc pushed a commit to esc/numba that referenced this pull request Jan 27, 2022
esc pushed a commit to esc/numba that referenced this pull request Jan 27, 2022
@luk-f-a luk-f-a deleted the issue-7693 branch February 13, 2022 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5 - Ready to merge Review and testing done, is ready to merge BuildFarm Passed For PRs that have been through the buildfarm and passed Effort - medium Medium size effort needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect result copying array-typed field of structured array in 0.55.0rc1
5 participants