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

backslash with gpu matrices crashes julia #161

Closed
jrebula opened this issue Oct 21, 2018 · 2 comments
Closed

backslash with gpu matrices crashes julia #161

jrebula opened this issue Oct 21, 2018 · 2 comments
Labels
bug Something isn't working cuda array Stuff about CuArray.

Comments

@jrebula
Copy link

jrebula commented Oct 21, 2018

I'm trying to solve a system of linear equations on the GPU, but it crashes julia with no error message. My understanding of a discussion from a year or two ago was that backslash would be the way to access the cusolver routines. The simplest backslash attempt crashes julia with no error message, then since
it appears that cusolver has (a routine that solves a system with a triangular structure)[https://software.intel.com/en-us/mkl-developer-reference-c-trtrs], I tried to get to that by performing a QR decomposition on the cuarrays (which works fine), then solving the triangular version of the problem, with the same result. I couldn't find that routine wrapped in CuArrays.jl anyway though. Backslash seemed the most natural way to do this, but is there an accepted way to do this that I'm missing?

using CuArrays
using LinearAlgebra

A, y = rand(3,4), rand(3)
cuA, cuY = cu(A), cu(y)
getQR(A) = begin
  QR = qr(A)
  return (QR.Q, QR.R)
end
Q, R = getQR(A)
cuQ, cuR = getQR(cuA)

actualSolution = A \ y
solutionFromQR = R \ (Q' * y)
@assert(all(abs.(actualSolution - solutionFromQR) .< 1e-4))
println("all is well thus far")
solutionFromCu = cuA \ cuY # crashes
solutionFromCuQR = cuR \ (cuQ' * cuY) # also crashes

if relevant:

julia> versioninfo()
Julia Version 1.0.1
Commit 0d713926f8 (2018-09-29 19:05 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, skylake)

julia> CUDAdrv.device()
CuDevice(0): GeForce GTX 1050
@andreasnoack
Copy link
Member

There a few missing pieces for this to work. We mainly need to hook \ up with xtrsv and xtrsm that are wrapped but not exposed via high level operators. The problem can be solved with

julia> x = [CuArrays.CUBLAS.trsv!('U','N','N',F.R[:,1:3], F.Q'cuY); 0]
4-element CuArray{Float32,1}:
  0.42201534
  0.063246876
 -0.07105942
  0.0

but that is not really satisfactory. (Notice also that this isn't the minimum norm solution that we use for normal arrays).

First step is to define \ for UpperTriangular and LowerTriangular CuArrays and ideally for views if that is now supported. Once the triangular solves work, it shouldn't be hard to define a QR based underdetermined solve.

@maleadt maleadt transferred this issue from JuliaGPU/CuArrays.jl May 27, 2020
@maleadt maleadt added bug Something isn't working cuda array Stuff about CuArray. labels May 27, 2020
@maleadt
Copy link
Member

maleadt commented Apr 27, 2024

These work now.

@maleadt maleadt closed this as completed Apr 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cuda array Stuff about CuArray.
Projects
None yet
Development

No branches or pull requests

3 participants