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

Basic math operations with nested adjoint and transpose #1940

Closed
albertomercurio opened this issue Jun 5, 2023 · 1 comment
Closed

Basic math operations with nested adjoint and transpose #1940

albertomercurio opened this issue Jun 5, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@albertomercurio
Copy link
Contributor

Hello,

I need to make the following code working for CUDA too:

A = rand(ComplexF64, 10, 10)
adjoint(transpose(A')) - adjoint(transpose(A'))

10×10 Matrix{ComplexF64}:
 0.0+0.0im  0.0+0.0im  0.0+0.0im    0.0+0.0im  0.0+0.0im  0.0+0.0im
 0.0+0.0im  0.0+0.0im  0.0+0.0im     0.0+0.0im  0.0+0.0im  0.0+0.0im
 0.0+0.0im  0.0+0.0im  0.0+0.0im     0.0+0.0im  0.0+0.0im  0.0+0.0im
 0.0+0.0im  0.0+0.0im  0.0+0.0im     0.0+0.0im  0.0+0.0im  0.0+0.0im
 0.0+0.0im  0.0+0.0im  0.0+0.0im     0.0+0.0im  0.0+0.0im  0.0+0.0im
 0.0+0.0im  0.0+0.0im  0.0+0.0im    0.0+0.0im  0.0+0.0im  0.0+0.0im
 0.0+0.0im  0.0+0.0im  0.0+0.0im     0.0+0.0im  0.0+0.0im  0.0+0.0im
 0.0+0.0im  0.0+0.0im  0.0+0.0im     0.0+0.0im  0.0+0.0im  0.0+0.0im
 0.0+0.0im  0.0+0.0im  0.0+0.0im     0.0+0.0im  0.0+0.0im  0.0+0.0im
 0.0+0.0im  0.0+0.0im  0.0+0.0im     0.0+0.0im  0.0+0.0im  0.0+0.0im

But if I try to do it with a CuArray if fails:

A = CUDA.rand(ComplexF64, 10, 10)
adjoint(transpose(A')) - adjoint(transpose(A'))

Scalar indexing is disallowed.
Invocation of getindex resulted in scalar indexing of a GPU array.
This is typically caused by calling an iterating implementation of a method.
Such implementations *do not* execute on the GPU, but very slowly on the CPU,
and therefore are only permitted from the REPL for prototyping purposes.
If you did intend to index this array, annotate the caller with @allowscalar.

It would be nice to introduce such an implementation, perhaps even for CuSparse matrices.

@albertomercurio albertomercurio added the enhancement New feature or request label Jun 5, 2023
@maleadt
Copy link
Member

maleadt commented Jun 6, 2023

That's unfortunately not straightforward. Closing as a dup of JuliaGPU/Adapt.jl#21.

For some more context, this needs better support in Base, either through a better type-hierarchy or via a trait-like system. We cannot simply add specializations for every combination of nested wrappers here in CUDA.jl, not only would that take many definitions, it would also severely impact load time.

@maleadt maleadt closed this as completed Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants