Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

crusaderky
Copy link
Contributor

Salvaged from #293
Simplify to_device and asarray for cupy and implement copy=False

@Copilot Copilot AI review requested due to automatic review settings April 18, 2025 14:57
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
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Issue fixed in 2021

Copy link
Contributor

@Copilot Copilot AI left a 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):

Comment on lines 93 to 94
if not copy and res is not obj:
raise ValueError("Unable to avoid copy while creating an array as requested")
Copy link
Contributor Author

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

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.

1 participant