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

Upgrade handle support #43

Merged
merged 2 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[compat]
CEnum = "0.4, 0.5"
CUDA = "5.3.0 - 5.3.5"
CUDA = "5.4.0"
CUDSS_jll = "0.2.1"
julia = "1.6"
LinearAlgebra = "1.6"
Expand Down
2 changes: 1 addition & 1 deletion src/CUDSS.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module CUDSS

using CUDA, CUDA.CUSPARSE
using CUDA, CUDA.APIUtils, CUDA.CUSPARSE
using CUDSS_jll
using LinearAlgebra
using SparseArrays
Expand Down
26 changes: 16 additions & 10 deletions src/management.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,20 @@ version() = VersionNumber(cudssGetProperty(CUDA.MAJOR_VERSION),
cudssGetProperty(CUDA.MINOR_VERSION),
cudssGetProperty(CUDA.PATCH_LEVEL))

# cache for created, but unused handles
const idle_handles = CUDA.HandleCache{CuContext,cudssHandle_t}()
## handles

function handle_ctor(ctx)
context!(ctx) do
cudssCreate()
end
end
function handle_dtor(ctx, handle)
context!(ctx; skip_destroyed=true) do
cudssDestroy(handle)
end
end

const idle_handles = HandleCache{CuContext,cudssHandle_t}(handle_ctor, handle_dtor)

function handle()
cuda = CUDA.active_state()
Expand All @@ -30,16 +42,10 @@ function handle()

# get library state
@noinline function new_state(cuda)
new_handle = pop!(idle_handles, cuda.context) do
cudssCreate()
end
new_handle = pop!(idle_handles, cuda.context)

finalizer(current_task()) do task
push!(idle_handles, cuda.context, new_handle) do
context!(cuda.context; skip_destroyed=true) do
cudssDestroy(new_handle)
end
end
push!(idle_handles, cuda.context, new_handle)
end

cudssSetStream(new_handle, cuda.stream)
Expand Down
Loading