11# Package extension for adding CUDA-based features to Trixi.jl
22module 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
56import Trixi
67
78function 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)
103104end
104105
105106function 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
109110end
0 commit comments