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

Refactor memory wrappers #2335

Merged
merged 25 commits into from
Apr 24, 2024
Merged

Refactor memory wrappers #2335

merged 25 commits into from
Apr 24, 2024

Conversation

maleadt
Copy link
Member

@maleadt maleadt commented Apr 19, 2024

Implements #2236: Each piece of memory now keeps track on which stream is working on it, and whether there's outstanding (non-synchronized) changes within that stream. That makes it possible to accurately and automatically synchronize when we derive a pointer from a CuArray (which is the one and only place where we indicate that we will start using the memory).

I did quite a bit of refactoring as part of this PR, most notably removing the Mem submodule. I added plenty deprecations though, so it should be nonbreaking (although I expect issues and hotfixes when we tag this).


Closes #1566 by making synchronization unnecessary, i.e., the following now "just works":

a = CUDA.zeros(4096, 4096)
b = CUDA.zeros(4096, 4096)
t = @async begin
    # PREVIOUSLY WRONG: using `a` while it may not be ready
    for x in 1:100
        mul!(b, a, a)
    end
    a .= 1
end
wait(t)
# PREVIOUSLY WRONG: using `a` while it may not be ready
display(Array(a)[end])

@vchuravy: much easier than the Task changes we were brainstorming about :-)


Fixes #2323:

julia> using CUDA

julia> CUDA.device!(0)
CuDevice(0): Tesla V100-PCIE-16GB

julia> x = CUDA.ones(2)

2-element CuArray{Float32, 1, CUDA.DeviceMemory}:
 1.0
 1.0

julia> CUDA.device!(1)
CuDevice(1): Tesla V100S-PCIE-32GB

julia> x
2-element CuArray{Float32, 1, CUDA.DeviceMemory}:
 1.0
 1.0

julia> y = x - x;

julia> CUDA.device(x)
CuDevice(0): Tesla V100-PCIE-16GB

julia> CUDA.device(y)
CuDevice(1): Tesla V100S-PCIE-32GB

julia> y
2-element CuArray{Float32, 1, CUDA.DeviceMemory}:
 0.0
 0.0

Hopefully fixes #875

@maleadt maleadt added enhancement New feature or request cuda array Stuff about CuArray. speculative Not sure about this one yet. labels Apr 19, 2024
Copy link

codecov bot commented Apr 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 60.30%. Comparing base (c5fcd73) to head (5f4711a).
Report is 2 commits behind head on master.

❗ Current head 5f4711a differs from pull request most recent head 92ac27b. Consider uploading reports for the commit 92ac27b to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##           master    #2335       +/-   ##
===========================================
- Coverage   71.86%   60.30%   -11.57%     
===========================================
  Files         155      155               
  Lines       15020    14880      -140     
===========================================
- Hits        10794     8973     -1821     
- Misses       4226     5907     +1681     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@maleadt maleadt force-pushed the tb/array_stream branch 2 times, most recently from 12b22e6 to e3bb56f Compare April 22, 2024 12:01
@maleadt maleadt changed the title Keep track of array ownership Refactor memory wrappers Apr 22, 2024
@maleadt maleadt linked an issue Apr 22, 2024 that may be closed by this pull request
@maleadt maleadt marked this pull request as ready for review April 22, 2024 12:35
@maleadt maleadt linked an issue Apr 22, 2024 that may be closed by this pull request
lib/cudadrv/stream.jl Outdated Show resolved Hide resolved
@maleadt maleadt merged commit eb45b2c into master Apr 24, 2024
1 check was pending
@maleadt maleadt deleted the tb/array_stream branch April 24, 2024 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cuda array Stuff about CuArray. enhancement New feature or request speculative Not sure about this one yet.
Projects
None yet
2 participants