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

bug: to_cupy_conditional device selection #579

Closed
mrava87 opened this issue May 22, 2024 · 1 comment · Fixed by #580
Closed

bug: to_cupy_conditional device selection #579

mrava87 opened this issue May 22, 2024 · 1 comment · Fixed by #580

Comments

@mrava87
Copy link
Collaborator

mrava87 commented May 22, 2024

The to_cupy_conditional method creates cupy array on the current device instead of the device of x.

Proposed solution in #578:

def to_cupy_conditional(x: npt.ArrayLike, y: npt.ArrayLike) -> NDArray:
    if deps.cupy_enabled:
        if cp.get_array_module(x) == cp and cp.get_array_module(y) == np:
            with cp.cuda.Device(x.device):
                y = cp.asarray(y)
    return y
mrava87 added a commit to mrava87/pylops that referenced this issue May 22, 2024
@mrava87
Copy link
Collaborator Author

mrava87 commented May 22, 2024

Indeed, after the suggested fix, this code:

cp.cuda.Device(device=0).use()

xcurrent = cp.ones(10)

with cp.cuda.Device(1):
    xother = cp.ones(10)

print(xcurrent.device, xother.device)

y = np.zeros(5)

# from current device
ycurrent = to_cupy_conditional(xcurrent, y)

# from other device
yother = to_cupy_conditional(xother, y)

print(ycurrent.device, yother.device)

gives:

<CUDA Device 0> <CUDA Device 1>
<CUDA Device 0> <CUDA Device 1>

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 a pull request may close this issue.

1 participant