Support CUDA arrays#84
Conversation
|
@ChrisRackauckas In case you did not see this PR. |
| *.jl.mem | ||
| deps/deps.jl | ||
| Manifest.toml | ||
| .vscode No newline at end of file |
There was a problem hiding this comment.
BTW, you can set up global gitignore.
There was a problem hiding this comment.
Thanks for the tip, should I revert this file?
| # 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)) |
There was a problem hiding this comment.
H will alway be Matrix if you don't use similar. Is that intended?
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
Should this go to https://github.com/JuliaArrays/ArrayInterface.jl ?
There was a problem hiding this comment.
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 4There was a problem hiding this comment.
Oops, this interface is not the desired one cause it also changes the shape.
There was a problem hiding this comment.
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.
|
Should we just merge this? |
That would be great! |
This PR will make time evolution in CuYao (the CUDA version of Yao, https://github.com/QuantumBFS/CuYao.jl) work properly.