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

Fix signature of torch allocator callbacks #1408

Closed
wants to merge 1 commit into from

Conversation

wence-
Copy link
Contributor

@wence- wence- commented Dec 12, 2023

Description

The deallocation function now also takes the device id.

Since both halves of the pair now receive the device on which to perform the (de)allocation, we switch from using
get_current_device_resource to using the (more correct) get_per_device_resource. This necessitates a workaround in Cython: rmm::cuda_device_id has no nullary constructor, and so cannot be stack-allocated the way Cython transpiles code. Instead perform a heap allocation and then delete it.

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

The deallocation function now also takes the device id.

Since both halves of the pair now receive the device on which to
perform the (de)allocation, we switch from using
get_current_device_resource to using the (more correct)
get_per_device_resource. This necessitates a workaround in Cython:
rmm::cuda_device_id has no nullary constructor, and so cannot be
stack-allocated the way Cython transpiles code. Instead perform a heap
allocation and then delete it.

- Closes rapidsai#1405
@github-actions github-actions bot added the Python Related to RMM Python API label Dec 12, 2023
@wence-
Copy link
Contributor Author

wence- commented Dec 12, 2023

This is a worse version of #1407 that doesn't require me to know cmake to figure out how to build a standalone shared library

) except * with gil:
cdef device_memory_resource* mr = get_current_device_resource()
cdef cuda_device_id* device_id
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason not to use a smart pointer 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 need this allocation to live for about one line. I guess I could use a smart pointer but it seems not particularly necessary.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah it's just one less thing to worry about if we ever add/refactor code here

@wence-
Copy link
Contributor Author

wence- commented Dec 12, 2023

Closing in favour of #1407.

@wence- wence- closed this Dec 12, 2023
@wence- wence- deleted the wence/fix/1405-worse branch December 13, 2023 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Python Related to RMM Python API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Unexpected memory usage on GPU0
2 participants