Skip to content

Support CUDA arrays#84

Merged
YingboMa merged 5 commits into
SciML:masterfrom
GiggleLiu:jg/supportcuda
May 2, 2022
Merged

Support CUDA arrays#84
YingboMa merged 5 commits into
SciML:masterfrom
GiggleLiu:jg/supportcuda

Conversation

@GiggleLiu
Copy link
Copy Markdown
Contributor

This PR will make time evolution in CuYao (the CUDA version of Yao, https://github.com/QuantumBFS/CuYao.jl) work properly.

@GiggleLiu
Copy link
Copy Markdown
Contributor Author

@ChrisRackauckas In case you did not see this PR.

Comment thread .gitignore
*.jl.mem
deps/deps.jl
Manifest.toml
.vscode No newline at end of file
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

BTW, you can set up global gitignore.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the tip, should I revert this file?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nah, it's fine.

Comment thread src/arnoldi.jl
# V stores the Krylov vectors
V = similar(b, T, (n, m + 1))
# H is a small dense array in tridiagonal form
H = zeros(U, (m+1, m))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

H will alway be Matrix if you don't use similar. Is that intended?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is intended. This matrix is usually a very small one that can be easily diagonalized on CPU.
Also, there are a lot of element-wise operations to it.

Comment thread src/krylov_phiv.jl Outdated
lmul!(beta, mul!(w, @view(V[:, 1:m]), match_array_type(V, expHe))) # exp(A) ≈ norm(b) * V * exp(H)e
end
# NOTE: this function is for CuArrays, which fall back to identity, i.e. keep the source a dense CPU array as it is.
match_array_type(target::AbstractArray, source::AbstractArray) = source
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

@GiggleLiu GiggleLiu Apr 27, 2022

Choose a reason for hiding this comment

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

Good point, I found the following API that can do this trick

julia> ArrayInterface.restructure(CUDA.randn(2,2),x )
2×2 CuArray{Int64, 2, CUDA.Mem.DeviceBuffer}:
 1  2
 3  4

Copy link
Copy Markdown
Contributor Author

@GiggleLiu GiggleLiu Apr 27, 2022

Choose a reason for hiding this comment

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

Oops, this interface is not the desired one cause it also changes the shape.

Copy link
Copy Markdown
Contributor Author

@GiggleLiu GiggleLiu Apr 27, 2022

Choose a reason for hiding this comment

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

I reverted the change, and rename the match_array_type to compatible_multiplicative_operand.
Because it is not for matching certain array types, e.g. for sparse arrays, the operand is preferred to be dense.

I do think this function should be in ArrayInterface, but that PR might require some work to understand different array libraries, let start by posting an issue there. We can change it later if this interface can go to ArrayInterface later.

@ChrisRackauckas
Copy link
Copy Markdown
Member

Should we just merge this?

@GiggleLiu
Copy link
Copy Markdown
Contributor Author

Should we just merge this?

That would be great!

@YingboMa YingboMa merged commit fc2fa5b into SciML:master May 2, 2022
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.

3 participants