-
Notifications
You must be signed in to change notification settings - Fork 47
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
Rust - Fix QFunction FFI Inputs/Outputs #1469
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jeremylt
force-pushed
the
jeremy/rust-ci
branch
from
February 10, 2024 16:13
59bb764
to
b74f876
Compare
unsafe extern "C" fn trampoline(
ctx: *mut ::std::os::raw::c_void,
q: bind_ceed::CeedInt,
inputs: *const *const bind_ceed::CeedScalar,
outputs: *const *mut bind_ceed::CeedScalar,
) -> ::std::os::raw::c_int {
let trampoline_data: Pin<&mut QFunctionTrampolineData> = std::mem::transmute(ctx);
// Inputs
let inputs_slice: &[*const bind_ceed::CeedScalar] =
std::slice::from_raw_parts(inputs, MAX_QFUNCTION_FIELDS);
let mut inputs_array: [&[crate::Scalar]; MAX_QFUNCTION_FIELDS] = [&[0.0]; MAX_QFUNCTION_FIELDS];
// BUG STARTS HERE
// unsafe precondition(s) violated: slice::from_raw_parts requires the pointer to be aligned and non-null, and the total size of the slice not to exceed `isize::MAX`
inputs_slice
.iter()
.enumerate()
.map(|(i, &x)| {
std::slice::from_raw_parts(x, trampoline_data.input_sizes[i] * q as usize)
as &[crate::Scalar]
})
.zip(inputs_array.iter_mut())
.for_each(|(x, a)| *a = x);
// Outputs
let outputs_slice: &[*mut bind_ceed::CeedScalar] =
std::slice::from_raw_parts(outputs, MAX_QFUNCTION_FIELDS);
let mut outputs_array: [&mut [crate::Scalar]; MAX_QFUNCTION_FIELDS] =
mut_max_fields!(&mut [0.0]);
outputs_slice
.iter()
.enumerate()
.map(|(i, &x)| {
std::slice::from_raw_parts_mut(x, trampoline_data.output_sizes[i] * q as usize)
as &mut [crate::Scalar]
})
.zip(outputs_array.iter_mut())
.for_each(|(x, a)| *a = x);
// User closure
(trampoline_data.get_unchecked_mut().user_f)(inputs_array, outputs_array)
} |
jeremylt
force-pushed
the
jeremy/rust-ci
branch
from
February 10, 2024 16:42
5b72911
to
58f118f
Compare
jeremylt
changed the title
WIP - fix Rust CI failure
Rust - Fix QFunction FFI Inputs/Outputs
Feb 10, 2024
Found the error - fix was to limit the number of iterations for mapping the input/output C arrays to Rust |
@rezgarshakeri with this fix, your branch should pass fine, so we can merge your branch after this branch merges. |
Great, thanks. |
rezgarshakeri
approved these changes
Feb 10, 2024
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.
thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix new error in Rust wrapper uncovered by changes in Rust nightly