-
Notifications
You must be signed in to change notification settings - Fork 33
ENH: Simplify CuPy asarray
and to_device
#314
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
base: main
Are you sure you want to change the base?
Conversation
elif not isinstance(device, _Device): | ||
raise ValueError(f"Unsupported device {device!r}") | ||
else: | ||
# see cupy/cupy#5985 for the reason how we handle device/stream here |
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.
Issue fixed in 2021
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.
Pull Request Overview
This PR simplifies CuPy’s asarray and to_device functions by streamlining the handling of the copy parameter and device context, and by updating test exclusions accordingly.
- Removed outdated test references regarding copy=False from cupy-xfails.txt
- Updated the asarray function in cupy/_aliases.py to accept copy as None and handle it via cp.asarray
- Revised device and stream handling in _helpers.py to use direct type checks against cp.cuda.Device and cp.cuda.Stream
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
cupy-xfails.txt | Removed xfail tests related to copy=False implementation |
array_api_compat/cupy/_aliases.py | Simplified asarray implementation and removed legacy copy handling and device context management |
array_api_compat/common/_helpers.py | Updated device and stream handling in to_device |
Comments suppressed due to low confidence (1)
array_api_compat/common/_helpers.py:791
- The updated type check for device using cp.cuda.Device is concise; however, verify that this check fully replaces the earlier logic and correctly handles all valid device cases in production.
if not isinstance(device, cp.cuda.Device):
array_api_compat/cupy/_aliases.py
Outdated
if not copy and res is not obj: | ||
raise ValueError("Unable to avoid copy while creating an array as requested") |
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.
This is less than ideal as it causes a brief spike in memory usage, but IMHO it's better than outright failing
d922875
to
8c31248
Compare
Salvaged from #293
Simplify to_device and asarray for cupy and implement copy=False