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

ACOM crystal.orientation_plan GPU Memory Management #606

Open
joshuaritt opened this issue Feb 22, 2024 · 2 comments
Open

ACOM crystal.orientation_plan GPU Memory Management #606

joshuaritt opened this issue Feb 22, 2024 · 2 comments

Comments

@joshuaritt
Copy link

Describe the bug
When creating an orientation plan within a crystal class with CUDA set to True, GPU memory is continuously filled. I have not been able to figure out a way to dump the GPU memory short of shutting down the kernel and restarting it. Thus when working with multiple crystal classes and detailed orientation plans, GPU resource management is a cumbersome.

To Reproduce
-Build crystal classes (I am doing so from cif files)
-Calculate structure factors
-Generate detailed orientation plans (with small angle_step_zone_axis values)
-If that does not fill up the GPU memory, I also ran into the out of memory error when matching experimental patterns to the generated plans

Expected behavior
-Maybe implement some kind of batching system where GPU can dump to system memory
-Implement way to forcibly clear GPU memory so parameters in generating orientation plan can be tweaked so as to not fill up GPU memory
-Dump GPU memory to system memory after orientation plan has been generated

py4DSTEM version
0.14.9
Python version
python3.11
Operating system
Linux on an HPC cluster
Interfacing with JupyterLab

GPU
If GPU related please provide:

  • CUDA driver - 535.154.05
  • Cuda Version 12.2
  • Cupy Version - 13.0.0

Screenshots
image
image
image

Additional context
Screenshots show extreme example of an orientation plan for illustration of issue

@alex-rakowski
Copy link
Collaborator

alex-rakowski commented Feb 22, 2024

Thanks for this.

Can you try running

import cupy as cp
cp.get_default_memory_pool().free_all_blocks()

In between crystal classes and see if that frees the GPU memory.

@sezelt
Copy link
Member

sezelt commented Mar 8, 2024

If you want to clear the memory from the orientation plan, you have to actually delete the orientation plan first. To do so you will likely have to delete the Crystal object, then use the block Alex suggested.

del crystal_BCC_MP
import cupy as cp
cp.get_default_memory_pool().free_all_blocks()

As for streaming, this is not something we anticipate , so the only way forward will be to shrink the size of the orientation plan by reducing k_max or by using coarser sampling. Using 0.1 degrees in the in-plane orientation is likely not necessary because the correlation is done to subpixel precision in this dimension at the end anyway, so the default of 0.5 or even 1.0 should work just as well.

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

No branches or pull requests

3 participants