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

Compatibility with CUDA.jl #58

Open
weiyuanlou opened this issue Feb 16, 2022 · 2 comments
Open

Compatibility with CUDA.jl #58

weiyuanlou opened this issue Feb 16, 2022 · 2 comments

Comments

@weiyuanlou
Copy link

Dear QuadGK developers:
I'm attempting to calculate multiple 1D integrals in parallel using GPU via CUDA.jl. However currently QuadGK does not seem to be GPU-compatible (with CUDA.jl). A simple example below generates errors ( see the attached text file ). Is it possible, perhaps for the 1D integrals with limited options, to become compatible with CUDA.jl? Thanks.

using CUDA
using QuadGK

Z = Array([z for z in 1:1:4]);
Zcu = CuArray([z for z in 1:1:4]);

function f_int(z_ob) 

    iii(z) =  z_ob - z  
    
    return quadgk(z -> iii(z), 0, 1, rtol=1e-4)[1]
    
end

f_int.(Z)  # This works 

f_int.(Zcu) # This does not work

QUADgk error with CUDA.txt

@tomchor
Copy link

tomchor commented Apr 5, 2023

It seems that this issue didn't attention from the devs. @weiyuanlou were you able to make this work?

@lxvm
Copy link
Contributor

lxvm commented Sep 23, 2023

Hi,
I don't think f_int.(Zcu), which is solving multiple integrals in parallel, can be currently solved with QuadGK.jl. The adaptation logic in the code will not port well to the GPU.

You could attempt using quadgk! to evaluate an inplace integrand that evaluates all of your different integrands on the GPU in an embarrasingly parallel fashion.

using CUDA
using QuadGK

Z = Array([z for z in 1:1:4]);
Zcu = CuArray([z for z in 1:1:4]);

function f_int(z_ob) 

    iii(z) =  z_ob - z  
    
    return quadgk(z -> iii(z), 0, 1, rtol=1e-4)[1]
    
end

f_int.(Z)  # This works 

quadgk!((y, z) -> y .= Zcu .- z, similar(Zcu), 0, 1, rtol=1e-4) # try this

I haven't tested this (I don't have a gpu), and I think it should parallelize well for large Zcu.

Now, with version 2.9 you will be able to use a BatchIntegrand to parallelize the evaluation of a single integral. That pr (#80) should allow, for example BatchIntegrand((y, x) -> y .= f.(x), CuArray{Float64}(undef, 1000), CuVector{Float64}(undef, 1000); max_batch=1000). This is not embarrasingly parallel since it only parallelizes within each adaptive step

QuadGK.jl is missing support for batched+inplace integrands, which would allow for more parallelism, but it would be worth trying to see how much mileage you can get out of either of the above approaches first.

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

No branches or pull requests

3 participants