Skip to content

Commit 4e65a74

Browse files
committed
make CUDA extension for CUDACore and CUDATools instead of complete CUDA
1 parent 64f2464 commit 4e65a74

2 files changed

Lines changed: 29 additions & 26 deletions

File tree

Project.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
5656

5757
[weakdeps]
5858
AMDGPU = "21141c5a-9bdb-4563-92ae-f87d6854732e"
59-
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
59+
CUDACore = "bd0ed864-bdfe-4181-a5ed-ce625a5fdea2"
60+
CUDATools = "9ec180c6-1c07-47c7-9e6e-ebefa4d1f6d0"
6061
Convex = "f65535da-76fb-5f13-bab9-19810c17039a"
6162
ECOS = "e2685f51-7e38-5353-a97d-a921fd2c8199"
6263
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
@@ -67,7 +68,7 @@ SparseConnectivityTracer = "9f842d2f-2579-4b1d-911e-f412cf18a3f5"
6768

6869
[extensions]
6970
TrixiAMDGPUExt = "AMDGPU"
70-
TrixiCUDAExt = "CUDA"
71+
TrixiCUDAExt = ["CUDACore", "CUDATools"]
7172
TrixiConvexECOSExt = ["Convex", "ECOS"]
7273
TrixiMakieExt = "Makie"
7374
TrixiNLsolveExt = "NLsolve"
@@ -80,7 +81,8 @@ AMDGPU = "2.2.1"
8081
AcceleratedKernels = "0.4.3"
8182
Accessors = "0.1.42"
8283
Adapt = "4.4"
83-
CUDA = "5.9.1, 6"
84+
CUDACore = "6"
85+
CUDATools = "6"
8486
CodeTracking = "1.0.5, 2, 3"
8587
ConstructionBase = "1.5.8"
8688
Convex = "0.16"

ext/TrixiCUDAExt.jl

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Package extension for adding CUDA-based features to Trixi.jl
22
module TrixiCUDAExt
33

4-
using CUDA: CUDA, CuArray, CuDeviceArray, CUDABackend, KernelAdaptor, @device_override
4+
using CUDACore: CUDACore, CuArray, CuDeviceArray, CUDABackend, KernelAdaptor, @device_override
5+
using CUDATools: CUDATools, NVML, has_nvml
56
import Trixi
67

78
function Trixi.storage_type(::Type{<:CuArray})
@@ -28,68 +29,68 @@ function Trixi.trixi_backend_info!(setup, ::CUDABackend)
2829
push!(setup, "Backend" => "KernelAbstractions CUDA")
2930
# Reimplementation of CUDA.versioninfo() to fit with Trixi's summary box format
3031
# see https://github.com/JuliaGPU/CUDA.jl/blob/9f56ee20afef4a770a028066d2fa9e7825d258da/src/utilities.jl#L41
31-
if !CUDA.functional()
32+
if !CUDACore.functional()
3233
push!(setup, "CUDA" => "CUDA not functional")
3334
return nothing
3435
end
3536

3637
push!(setup, "CUDA toolchain:" => "")
37-
push!(setup, " - runtime" => string(CUDA.runtime_version()))
38+
push!(setup, " - runtime" => string(CUDACore.runtime_version()))
3839
push!(setup,
39-
" - toolkit" => CUDA.local_toolkit ? "local installation" :
40+
" - toolkit" => CUDACore.local_toolkit ? "local installation" :
4041
"artifact installation")
4142

42-
if CUDA.has_nvml()
43-
driver_str = string(CUDA.NVML.driver_version())
43+
if has_nvml()
44+
driver_str = string(NVML.driver_version())
4445
else
4546
driver_str = "unknown"
4647
end
47-
driver_str *= " for $(CUDA.driver_version())"
48+
driver_str *= " for $(CUDACore.driver_version())"
4849
push!(setup, " - driver" => driver_str)
49-
push!(setup, " - compiler" => string(CUDA.compiler_version()))
50+
push!(setup, " - compiler" => string(CUDACore.compiler_version()))
5051

5152
# Skip CUDA libraries
5253
# Skip Julia packages
5354
# Skip Toolchain
5455
# Skip Environment
5556
# Skip Preferences
5657

57-
devs = CUDA.devices()
58+
devs = CUDACore.devices()
5859
if isempty(devs)
5960
push!(setup, "CUDA devices" => "none")
6061
else
6162
push!(setup, "CUDA devices:" => "")
6263
end
6364
for (i, dev) in enumerate(devs)
6465
function query_nvml()
65-
mig = CUDA.uuid(dev) != CUDA.parent_uuid(dev)
66-
nvml_gpu = CUDA.NVML.Device(CUDA.parent_uuid(dev))
67-
nvml_dev = CUDA.NVML.Device(CUDA.uuid(dev); mig)
66+
mig = CUDACore.uuid(dev) != CUDACore.parent_uuid(dev)
67+
nvml_gpu = NVML.Device(CUDACore.parent_uuid(dev))
68+
nvml_dev = NVML.Device(CUDACore.uuid(dev); mig)
6869

69-
str = CUDA.NVML.name(nvml_dev)
70-
cap = CUDA.NVML.compute_capability(nvml_gpu)
71-
mem = CUDA.NVML.memory_info(nvml_dev)
70+
str = NVML.name(nvml_dev)
71+
cap = NVML.compute_capability(nvml_gpu)
72+
mem = NVML.memory_info(nvml_dev)
7273

7374
(; str, cap, mem)
7475
end
7576

7677
function query_cuda()
77-
str = CUDA.name(dev)
78-
cap = CUDA.capability(dev)
79-
mem = CUDA.device!(dev) do
78+
str = CUDACore.name(dev)
79+
cap = CUDACore.capability(dev)
80+
mem = CUDACore.device!(dev) do
8081
# this requires a device context, so we prefer NVML
81-
(free = CUDA.free_memory(), total = CUDA.total_memory())
82+
(free = CUDACore.free_memory(), total = CUDACore.total_memory())
8283
end
8384
(; str, cap, mem)
8485
end
8586

86-
str, cap, mem = if CUDA.has_nvml()
87+
str, cap, mem = if has_nvml()
8788
try
8889
query_nvml()
8990
catch err
90-
if !isa(err, CUDA.NVML.NVMLError) ||
91+
if !isa(err, NVML.NVMLError) ||
9192
!in(err.code,
92-
[CUDA.NVML.ERROR_NOT_SUPPORTED, CUDA.NVML.ERROR_NO_PERMISSION])
93+
[NVML.ERROR_NOT_SUPPORTED, NVML.ERROR_NO_PERMISSION])
9394
rethrow()
9495
end
9596
query_cuda()
@@ -103,7 +104,7 @@ function Trixi.trixi_backend_info!(setup, ::CUDABackend)
103104
end
104105

105106
function Trixi.trixi_device_memory_use(::CUDABackend)
106-
info = CUDA.MemoryInfo()
107+
info = CUDACore.MemoryInfo()
107108
used_bytes = info.total_bytes - info.free_bytes
108109
return used_bytes
109110
end

0 commit comments

Comments
 (0)