Skip to content

Commit 8a4cbde

Browse files
authored
Move CUDNN and CUTENSOR into separate packages (#1624)
1 parent c0ff18c commit 8a4cbde

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+1816
-1679
lines changed

.buildkite/pipeline.yml

Lines changed: 383 additions & 336 deletions
Large diffs are not rendered by default.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
.vscode
66
lcov.info
77
build/
8+
lib/**/Manifest.toml

deps/bindeps.jl

Lines changed: 1 addition & 212 deletions
Original file line numberDiff line numberDiff line change
@@ -534,126 +534,6 @@ function find_libcudadevrt(cuda::LocalToolkit)
534534
end
535535

536536

537-
#
538-
# CUDNN
539-
#
540-
541-
export libcudnn, has_cudnn
542-
543-
const __libcudnn = Ref{Union{String,Nothing}}()
544-
function libcudnn(; throw_error::Bool=true)
545-
path = @initialize_ref __libcudnn begin
546-
# CUDNN depends on CUBLAS
547-
libcublas()
548-
549-
find_cudnn(toolkit(), v"8")
550-
end CUDA.CUDNN.__runtime_init__()
551-
if path === nothing && throw_error
552-
error("This functionality is unavailabe as CUDNN is missing.")
553-
end
554-
path
555-
end
556-
has_cudnn() = libcudnn(throw_error=false) !== nothing
557-
558-
function find_cudnn(cuda::ArtifactToolkit, version)
559-
artifact_dir = cuda_artifact("CUDNN", cuda.release)
560-
if artifact_dir === nothing
561-
return nothing
562-
end
563-
path = artifact_library(artifact_dir, "cudnn", [version])
564-
565-
# HACK: eagerly open CUDNN sublibraries to avoid dlopen discoverability issues
566-
for sublibrary in ("ops_infer", "ops_train",
567-
"cnn_infer", "cnn_train",
568-
"adv_infer", "adv_train")
569-
sublibrary_path = artifact_library(artifact_dir, "cudnn_$(sublibrary)", [version])
570-
Libdl.dlopen(sublibrary_path)
571-
end
572-
573-
@debug "Using CUDNN from an artifact at $(artifact_dir)"
574-
Libdl.dlopen(path)
575-
return path
576-
end
577-
578-
function find_cudnn(cuda::LocalToolkit, version)
579-
path = find_library("cudnn", [version]; locations=cuda.dirs)
580-
if path === nothing
581-
return nothing
582-
end
583-
584-
# with a local CUDNN version, we shouldn't need to eagerly open sublibraries,
585-
# as they are expected to be globally discoverable next to libcudnn.so
586-
587-
@debug "Using local CUDNN at $(path)"
588-
Libdl.dlopen(path)
589-
return path
590-
end
591-
592-
593-
#
594-
# CUTENSOR
595-
#
596-
597-
export libcutensor, libcutensormg, has_cutensor, has_cutensormg
598-
599-
const __libcutensor = Ref{Union{String,Nothing}}()
600-
function libcutensor(; throw_error::Bool=true)
601-
path = @initialize_ref __libcutensor begin
602-
# CUTENSOR depends on CUBLAS
603-
libcublas()
604-
605-
find_cutensor(toolkit(), "cutensor", v"1")
606-
end
607-
if path === nothing && throw_error
608-
error("This functionality is unavailabe as CUTENSOR is missing.")
609-
end
610-
path
611-
end
612-
has_cutensor() = libcutensor(throw_error=false) !== nothing
613-
614-
const __libcutensormg = Ref{Union{String,Nothing}}()
615-
function libcutensormg(; throw_error::Bool=true)
616-
path = @initialize_ref __libcutensor begin
617-
# CUTENSORMg additionally depends on CUDARt
618-
libcudart()
619-
620-
if CUTENSOR.version() < v"1.4"
621-
nothing
622-
else
623-
find_cutensor(toolkit(), "cutensorMg", v"1")
624-
end
625-
end
626-
if path === nothing && throw_error
627-
error("This functionality is unavailabe as CUTENSORMg is missing.")
628-
end
629-
path
630-
end
631-
has_cutensormg() = libcutensormg(throw_error=false) !== nothing
632-
633-
function find_cutensor(cuda::ArtifactToolkit, name, version)
634-
artifact_dir = cuda_artifact("CUTENSOR", cuda.release)
635-
if artifact_dir === nothing
636-
return nothing
637-
end
638-
path = artifact_library(artifact_dir, name, [version])
639-
640-
@debug "Using CUTENSOR library $name from an artifact at $(artifact_dir)"
641-
Libdl.dlopen(path)
642-
return path
643-
end
644-
645-
function find_cutensor(cuda::LocalToolkit, name, version)
646-
path = find_library(name, [version]; locations=cuda.dirs)
647-
if path === nothing
648-
return nothing
649-
end
650-
651-
@debug "Using local CUTENSOR library $name at $(path)"
652-
Libdl.dlopen(path)
653-
return path
654-
end
655-
656-
657537
#
658538
# NCCL
659539
#
@@ -666,7 +546,7 @@ function libnccl(; throw_error::Bool=true)
666546
find_nccl(toolkit(), "nccl", v"1")
667547
end
668548
if path === nothing && throw_error
669-
error("This functionality is unavailabe as CUTENSOR is missing.")
549+
error("This functionality is unavailabe as NCCL is missing.")
670550
end
671551
path
672552
end
@@ -696,97 +576,6 @@ function find_nccl(cuda::LocalToolkit, name, version)
696576
end
697577

698578

699-
#
700-
# CUQUANTUM
701-
#
702-
703-
export libcutensornet, has_cutensornet, libcustatevec, has_custatevec
704-
705-
const __libcutensornet = Ref{Union{String,Nothing}}()
706-
function libcutensornet(; throw_error::Bool=true)
707-
path = @initialize_ref __libcutensornet begin
708-
# CUTENSORNET depends on CUTENSOR
709-
libcutensor(throw_error=throw_error)
710-
711-
if CUDA.runtime_version() < v"11"
712-
# XXX: bound this using tags in the Artifact.toml?
713-
nothing
714-
else
715-
find_cutensornet(toolkit(), "cutensornet", v"0.1.0")
716-
end
717-
end
718-
if path === nothing && throw_error
719-
error("This functionality is unavailabe as CUTENSORNET is missing.")
720-
end
721-
return path
722-
end
723-
has_cutensornet() = has_cutensor() && libcutensornet(throw_error=false) !== nothing
724-
725-
const __libcustatevec = Ref{Union{String,Nothing}}()
726-
function libcustatevec(; throw_error::Bool=true)
727-
path = @initialize_ref __libcustatevec begin
728-
729-
if CUDA.runtime_version() < v"11"
730-
# XXX: bound this using tags in the Artifact.toml?
731-
nothing
732-
else
733-
find_custatevec(toolkit(), "custatevec", v"0.1.0")
734-
end
735-
end
736-
if path === nothing && throw_error
737-
error("This functionality is unavailabe as CUSTATEVEC is missing.")
738-
end
739-
return path
740-
end
741-
has_custatevec() = libcustatevec(throw_error=false) !== nothing
742-
743-
function find_cutensornet(cuda::ArtifactToolkit, name, version)
744-
artifact_dir = generic_artifact("cuQuantum")
745-
if artifact_dir === nothing
746-
return nothing
747-
end
748-
path = artifact_library(artifact_dir, name, [version])
749-
750-
@debug "Using CUTENSORNET library $name from an artifact at $(artifact_dir)"
751-
Libdl.dlopen(path)
752-
return path
753-
end
754-
755-
function find_cutensornet(cuda::LocalToolkit, name, version)
756-
path = find_library(name, [version]; locations=cuda.dirs)
757-
if path === nothing
758-
return nothing
759-
end
760-
761-
@debug "Using local CUTENSORNET library $name at $(path)"
762-
Libdl.dlopen(path)
763-
return path
764-
end
765-
766-
function find_custatevec(cuda::ArtifactToolkit, name, version)
767-
artifact_dir = cuda_artifact("cuQuantum", v"0.1.3")
768-
if artifact_dir === nothing
769-
return nothing
770-
end
771-
path = artifact_library(artifact_dir, name, [version])
772-
773-
@debug "Using CUSTATEVEC library $name from an artifact at $(artifact_dir)"
774-
Libdl.dlopen(path)
775-
return path
776-
end
777-
778-
function find_custatevec(cuda::LocalToolkit, name, version)
779-
path = find_library(name, [version]; locations=cuda.dirs)
780-
if path === nothing
781-
return nothing
782-
end
783-
784-
@debug "Using local CUSTATEVEC library $name at $(path)"
785-
Libdl.dlopen(path)
786-
return path
787-
end
788-
789-
790579
#
791580
# Utilities
792581
#

lib/cudnn/Project.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name = "CUDNN"
2+
uuid = "02a925ec-e4fe-4b08-9a7e-0d78e3d38ccd"
3+
authors = ["Tim Besard <tim.besard@gmail.com>"]
4+
version = "0.1.0"
5+
6+
[deps]
7+
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"
8+
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
9+
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"

lib/cudnn/CUDNN.jl renamed to lib/cudnn/src/CUDNN.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
"""
2-
CUDA.CUDNN
2+
CUDNN
33
44
High level interface to cuDNN functions. See
5-
https://github.com/JuliaGPU/CUDA.jl/blob/master/lib/state/README.md
6-
for a design overview.
5+
[README.md](https://github.com/JuliaGPU/CUDA.jl/blob/master/lib/cudnn/README.md) for a
6+
design overview.
77
"""
88
module CUDNN
99

10-
using ..APIUtils
11-
12-
using ..CUDA
13-
using ..CUDA: CUstream, libraryPropertyType
14-
using ..CUDA: libcudnn, @retry_reclaim, isdebug, initialize_context
10+
using CUDA
11+
using CUDA.APIUtils
12+
using CUDA: CUstream, libraryPropertyType
13+
using CUDA: @retry_reclaim, isdebug, initialize_context
1514

1615
using CEnum: @cenum
1716

17+
include("bindeps.jl")
1818

1919
# core library
2020
include("libcudnn_common.jl")
File renamed without changes.
File renamed without changes.

lib/cudnn/src/bindeps.jl

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using CUDA.Deps: @initialize_ref, libcublas, cuda_artifact, artifact_library, find_library,
2+
LocalToolkit, ArtifactToolkit, toolkit
3+
4+
import Libdl
5+
6+
export libcudnn, has_cudnn
7+
8+
const __libcudnn = Ref{Union{String,Nothing}}()
9+
function libcudnn(; throw_error::Bool=true)
10+
path = @initialize_ref __libcudnn begin
11+
# CUDNN depends on CUBLAS
12+
libcublas()
13+
14+
find_cudnn(toolkit(), v"8")
15+
end __runtime_init__()
16+
if path === nothing && throw_error
17+
error("This functionality is unavailabe as CUDNN is missing.")
18+
end
19+
path
20+
end
21+
has_cudnn() = libcudnn(throw_error=false) !== nothing
22+
23+
function find_cudnn(cuda::ArtifactToolkit, version)
24+
artifact_dir = cuda_artifact("CUDNN", cuda.release)
25+
if artifact_dir === nothing
26+
return nothing
27+
end
28+
path = artifact_library(artifact_dir, "cudnn", [version])
29+
30+
# HACK: eagerly open CUDNN sublibraries to avoid dlopen discoverability issues
31+
for sublibrary in ("ops_infer", "ops_train",
32+
"cnn_infer", "cnn_train",
33+
"adv_infer", "adv_train")
34+
sublibrary_path = artifact_library(artifact_dir, "cudnn_$(sublibrary)", [version])
35+
Libdl.dlopen(sublibrary_path)
36+
end
37+
38+
@debug "Using CUDNN from an artifact at $(artifact_dir)"
39+
Libdl.dlopen(path)
40+
return path
41+
end
42+
43+
function find_cudnn(cuda::LocalToolkit, version)
44+
path = find_library("cudnn", [version]; locations=cuda.dirs)
45+
if path === nothing
46+
return nothing
47+
end
48+
49+
# with a local CUDNN version, we shouldn't need to eagerly open sublibraries,
50+
# as they are expected to be globally discoverable next to libcudnn.so
51+
52+
@debug "Using local CUDNN at $(path)"
53+
Libdl.dlopen(path)
54+
return path
55+
end
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)