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

Is there support for a user defined scratch memory pool #232

Open
stgeke opened this issue Dec 2, 2022 · 7 comments
Open

Is there support for a user defined scratch memory pool #232

stgeke opened this issue Dec 2, 2022 · 7 comments

Comments

@stgeke
Copy link

stgeke commented Dec 2, 2022

Many applications use an internal memory pool (scratch space). It would be great if this allocated memory could be recycled by SUNDIALS (e.g. for storing the Krylov basis array etc.) to lower the overall memory footprint.

@drreynolds
Copy link
Collaborator

The majority of memory used in SUNDIALS comes from the vectors themselves. As such, in collaborating with applications we have frequently implemented custom vectors that get their memory from a pool. This generally isn't difficult, since you can clone an existing N_Vector implementation and replace all memory allocation/deallocation to instead work with your pool. Would this kind of thing work for you, or are you asking for a general memory pool API that users can code to?

Regarding a general API -- have you looked at our recent SUNMemory API? It should certainly allow for this kind of thing with GPU-based memory allocation (@balos1 or @gardner48 can comment more directly on that).

@stgeke
Copy link
Author

stgeke commented Dec 2, 2022

Let me be more precise. We want to recycling our internal scratch memory pool. I don't see how a custom N_Vector will help here. There will be vectors with persistent (e.g. state vector + history) and temporary (Krylov basis) data. Scratch memory (shared between different codes) can only be used for the latter type. Am I missing something?

@drreynolds
Copy link
Collaborator

I think I understand. Currently, SUNDIALS allocates all of its Krylov subspace vectors at initialization to improve performance (as compared to repeated allocation/deallocation). You worry that this unnecessarily increases the memory footprint, since those vectors could instead utilize temporary scratch space, space that could also be used in other areas of the code when the linear solver is inactive?

Is the recommendation that we implement a SUNDIALS-wide memory pool, and then we could convert module-specific memory allocations to instead check memory in/out of that pool when it is needed?

@stgeke
Copy link
Author

stgeke commented Dec 2, 2022

Yes, adding a scratch memory pool within Sundials could help to reduce memory footprint. However my request is slightly different. I want to be able to pass a user defined scratch space to Sundials. This way the scratch memory can be shared between application code and Sundials provided it's big enough to make both codes happy.

@drreynolds
Copy link
Collaborator

Got it. I'll discuss this with the rest of the team. I don't recall us ever discussing this before, but I agree that it could certainly help in memory-limited environments (e.g., GPUs).

@stgeke stgeke changed the title Is there support for a user defined memory pool Is there support for a user defined scratch memory pool Dec 3, 2022
@stgeke
Copy link
Author

stgeke commented Feb 20, 2023

Any news?

@balos1
Copy link
Member

balos1 commented Mar 2, 2023

@stgeke We have had internal discussions on what may be done about this, but we do not currently have the bandwidth to implement anything in the near-term.

@balos1 balos1 removed the question label Jun 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants