Skip to content

Conversation

@sclaus2
Copy link
Contributor

@sclaus2 sclaus2 commented Dec 5, 2025

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.

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.
@sclaus2 sclaus2 requested a review from jhale December 5, 2025 13:47
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]
Copy link
Member

@jhale jhale Dec 5, 2025

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.

Copy link
Contributor Author

@sclaus2 sclaus2 Dec 5, 2025

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.

@coveralls
Copy link

coveralls commented Dec 5, 2025

Coverage Status

coverage: 83.075% (+0.03%) from 83.044%
when pulling 4fe1280 on sclaus2/add_voidptr_cast_intrinsic
into 818267a on main.

…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.
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.

5 participants