-
-
Notifications
You must be signed in to change notification settings - Fork 45
Add Numba void* -> typed-pointer intrinsics and tests #804
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
base: main
Are you sure you want to change the base?
Conversation
create_voidptr_to_dtype_ptr_caster to bitcast void* to typed pointer. Provide convenience casters for common primitives: float64, float32, int32, int64. Add unit tests in test_numba_custom_data.py exercising the new casters: Tests cover basic float/double and int pointer casting and multi-parameter usage.
| b = numba.carray(b_, (1,), dtype=np.float64) | ||
| fptr = voidptr_to_float64_ptr(custom_data) | ||
| iptr = voidptr_to_int32_ptr(custom_data) | ||
| scale = fptr[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bit hairy, in the future we should look and see if we can reinterpret the struct with its fields and let numba/llvm handle the offsets for us.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made some attempts but have not been able to find a nice and robust way yet. I tried with record caster.
…FCx utils ffcx: annotate create_voidptr_to_dtype_ptr_caster with type hints and clarify when void* casts are required. - Add docstring explaining use cases for voidptr cast (custom_data in UFCx kernels). - Validate input types early and raise clear TypingError on invalid source types.
This PR adds a small, reliable Numba intrinsic factory for casting void* (FFCx custom_data) to typed C pointers and provides convenience casters for common primitive types, plus unit tests exercising those casters. This PR is relevant for custom_data functionality in dolfinx https://github.com/FEniCS/dolfinx/pull/4013.