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

Pin CPU buffers when doing memory copies #735

Closed
maleadt opened this issue Feb 24, 2021 · 0 comments · Fixed by #760
Closed

Pin CPU buffers when doing memory copies #735

maleadt opened this issue Feb 24, 2021 · 0 comments · Fixed by #760
Labels
enhancement New feature or request performance How fast can we go?

Comments

@maleadt
Copy link
Member

maleadt commented Feb 24, 2021

We should explore automatically pinning CPU memory buffers, or async memory copies are really executed synchronously:

using CUDA, LinearAlgebra

function expensive_computation(a,b,c)
    NVTX.@range "mul!" mul!(c, a, b)
    NVTX.@range "broadcast!" broadcast!(sin, c, c)
    Array(c)    # this cannot be executed asynchronously, because the destination memory can be paged out
end

# one "iteration", performing the above calculation twice in two tasks
# and comparing the output.
function iteration(a,b,c)
    results = Vector{Any}(undef, 2)
    NVTX.@range "iteration" @sync begin
        @async begin
            results[1] = NVTX.@range "run 1" expensive_computation(a,b,c)
        end
        @async begin
            results[2] = NVTX.@range "run 2" expensive_computation(a,b,c)
        end
    end
    results[1] == results[2]
end

function main(N=1024)
    a = CUDA.rand(N,N)
    b = CUDA.rand(N,N)
    c = CUDA.rand(N,N)
    synchronize()
    NVTX.@range "warmup" iteration(a,b,c)
    GC.gc(true)
    NVTX.@range "main" iteration(a,b,c)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request performance How fast can we go?
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant