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

Add support for spreadinterponly in finufft #599

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

chaithyagr
Copy link
Contributor

This resolves #598 just like as done in #564 for cufinufft.

@chaithyagr
Copy link
Contributor Author

I am still thinking on good ways to have tests for it, we will merge only when we have tests up, to prevent instability.

Comment on lines 15 to 18
// Simple helper to wrap pointer in std::vector and release it later
template <class T>
void wrapArrayInVector( T *sourceArray, size_t arraySize, std::vector<T, xsimd::aligned_allocator<T, 64> > &targetVector ) {
typename std::_Vector_base<T, xsimd::aligned_allocator<T, 64> >::_Vector_impl *vectorPtr =
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had to rely on some hacky way to move a piointer data to a std::vector, without any copies. Anyone has any ideas on how to make this better? Also, it seems to fail on MAC, but I dont know if std:: changes in mac, I am not used to it. Can someone help here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to use std::reference_wrapper, but I think that still wont work.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do you need to create a vector from a pointer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think what i need to do is point incoming memory pointer fk to fwbatch, so that the spread / interpolate directly happens on input/ output. In the cufinufft versions, it was fairly straightforward as the memory for fwbatch was not std::vector. Any ideas why you chose it so here?

I see the underlying kernels use pointers anyway exposed through .data().
Another option can be to overload the function and add support for when we send pointer to memory, although the current spread / interpolate doesn't directly take the fwbatch vector as input, but rather the plan itself.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Either we template more, so that functions can accepts both pointers and vectors as both have [] operator. Or thsi is a use case for a span. Vector is owning so should not be used thsi way.

We might need to write a simple span implementation since it is available in c++20 onwards

Copy link
Collaborator

Choose a reason for hiding this comment

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

We aim to remove all pointers ad c++ data structures are safer. Pointers can cause memory leaks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree about leaks, i have suffered fixing them in gpuNUFFT. Did you happen to use std:: reference_wrapper? I think it's built for this and i somehow am not able to get it work for our use case:
https://en.cppreference.com/w/cpp/utility/functional/reference_wrapper

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In fact reference wrapper is cleaner and way less hacky than what i have now

Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you remove all of this? I cannot find the hacky code anymore

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup :) No hacks, only clean code :P ... Just changed the function API.

@mreineck
Copy link
Collaborator

mreineck commented Dec 6, 2024

I had to rely on some hacky way to move a piointer data to a std::vector, without any copies.

I am quite sure that this is not possible in any portable way. std::vector always owns its data, so it cannot be attached to a memory region that is supplied from outside.

@chaithyagr
Copy link
Contributor Author

@DiamonDinoia , I made some fixes. Please check if this is okay for you . This is a minor change in internal function calls.

@DiamonDinoia
Copy link
Collaborator

@DiamonDinoia , I made some fixes. Please check if this is okay for you . This is a minor change in internal function calls.

It will take me some time to get back to this. If it is urgent I can assign other reviewers. In the meantime, have you thought of potential tests?

@chaithyagr
Copy link
Contributor Author

@DiamonDinoia I dont think its that urgent. In fact, I would prefer to have tests so that this code is more clear. Also, I think there's some work on documentation side still for me.

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.

Add support for spreadinterp_only in the flags on finufft and tests
3 participants