Skip to main content

singe_loader/
libraries.rs

1// The NVIDIA libraries the `*-sys` crates load, by the file names each platform gives them, so a crate names its library and never a file.
2// Each entry states its library's major version once, and every file name and doc comment is built from it, so a version bump is a one-token change.
3// The major version is that of the bindings its crate is generated from, or the soname's version for a library without one, such as the driver.
4// The Windows names follow NVIDIA's naming and are unverified until a Windows machine loads them; a library NVIDIA ships only for Linux has none.
5
6use crate::Library;
7
8// The file names of the current platform: Linux's, Windows', or none elsewhere, where loading fails at once.
9const fn files(
10    linux: &'static [&'static str],
11    windows: &'static [&'static str],
12) -> &'static [&'static str] {
13    if cfg!(target_os = "linux") {
14        linux
15    } else if cfg!(target_os = "windows") {
16        windows
17    } else {
18        &[]
19    }
20}
21
22// Builds a file name from literal parts, where the token `major` stands for the library's major version.
23macro_rules! file_name {
24    ($major:literal; $($part:tt)+) => {
25        concat!($(file_name!(@part $major; $part)),+)
26    };
27    (@part $major:literal; major) => {
28        $major
29    };
30    (@part $major:literal; $part:literal) => {
31        $part
32    };
33}
34
35// The doc comment line that introduces a platform's files, or says it has none.
36macro_rules! platform_files {
37    ($platform:literal;) => {
38        concat!("It has no files on ", $platform, ".")
39    };
40    ($platform:literal; $($file:tt)+) => {
41        concat!("Its files on ", $platform, ":")
42    };
43}
44
45// Declares one constructor per library from its name, its major version, and the parts of its file names on Linux and Windows.
46macro_rules! libraries {
47    ($(
48        $(#[doc = $doc:literal])*
49        $constructor:ident => $name:literal, major $major:literal,
50        linux [$([$($linux:tt)+]),* $(,)?],
51        windows [$([$($windows:tt)+]),* $(,)?];
52    )+) => {
53        impl Library {
54            $(
55                #[doc = concat!("Creates the library for ", $name, ", whose files carry major version ", $major, ".")]
56                $(#[doc = ""] #[doc = $doc])*
57                #[doc = ""]
58                #[doc = platform_files!("Linux"; $([$($linux)+])*)]
59                #[doc = ""]
60                $(#[doc = concat!("- `", file_name!($major; $($linux)+), "`")])*
61                #[doc = ""]
62                #[doc = platform_files!("Windows"; $([$($windows)+])*)]
63                #[doc = ""]
64                $(#[doc = concat!("- `", file_name!($major; $($windows)+), "`")])*
65                #[must_use]
66                pub const fn $constructor() -> Self {
67                    Self::new(
68                        $name,
69                        files(
70                            &[$(file_name!($major; $($linux)+)),*],
71                            &[$(file_name!($major; $($windows)+)),*],
72                        ),
73                    )
74                }
75            )+
76        }
77    };
78}
79
80libraries! {
81    cuda_driver => "the CUDA driver", major "1",
82        linux [["libcuda.so." major]],
83        windows [["nvcuda.dll"]];
84
85    cuda_runtime => "the CUDA runtime", major "13",
86        linux [["libcudart.so." major]],
87        windows [["cudart64_" major ".dll"]];
88
89    nvrtc => "NVRTC", major "13",
90        linux [["libnvrtc.so." major]],
91        windows [["nvrtc64_" major "0_0.dll"]];
92
93    nvjitlink => "nvJitLink", major "13",
94        linux [["libnvJitLink.so." major]],
95        windows [["nvJitLink_" major "0_0.dll"]];
96
97    nvvm => "NVVM", major "4",
98        linux [["libnvvm.so." major]],
99        windows [["nvvm64_" major "0_0.dll"]];
100
101    /// NVTX's headers implement it inline; this library exports the same functions for languages that cannot use them.
102    nvtx => "NVTX", major "1",
103        linux [["libnvtx3interop.so." major]],
104        windows [["nvtx3interop.dll"]];
105
106    nvml => "NVML", major "1",
107        linux [["libnvidia-ml.so." major]],
108        windows [["nvml.dll"]];
109
110    cublas => "cuBLAS", major "13",
111        linux [["libcublas.so." major]],
112        windows [["cublas64_" major ".dll"]];
113
114    cublas_lt => "cuBLASLt", major "13",
115        linux [["libcublasLt.so." major]],
116        windows [["cublasLt64_" major ".dll"]];
117
118    /// cuDNN loads its own sub-libraries.
119    cudnn => "cuDNN", major "9",
120        linux [["libcudnn.so." major]],
121        windows [["cudnn64_" major ".dll"]];
122
123    cudss => "cuDSS", major "1",
124        linux [["libcudss.so." major]],
125        windows [["cudss64_" major ".dll"]];
126
127    cufft => "cuFFT", major "12",
128        linux [["libcufft.so." major]],
129        windows [["cufft64_" major ".dll"]];
130
131    /// cuFile has no Windows release.
132    cufile => "cuFile", major "0",
133        linux [["libcufile.so." major]],
134        windows [];
135
136    /// Windows' CUPTI carries its release in its name, as `cupti64_2025.4.0.dll`, which no fixed name matches.
137    cupti => "CUPTI", major "13",
138        linux [["libcupti.so." major]],
139        windows [];
140
141    curand => "cuRAND", major "10",
142        linux [["libcurand.so." major]],
143        windows [["curand64_" major ".dll"]];
144
145    cusolver => "cuSOLVER", major "12",
146        linux [["libcusolver.so." major]],
147        windows [["cusolver64_" major ".dll"]];
148
149    cusparse => "cuSPARSE", major "12",
150        linux [["libcusparse.so." major]],
151        windows [["cusparse64_" major ".dll"]];
152
153    cutensor => "cuTENSOR", major "2",
154        linux [["libcutensor.so." major]],
155        windows [["cutensor.dll"]];
156
157    cutensor_mg => "cuTENSORMg", major "2",
158        linux [["libcutensorMg.so." major]],
159        windows [["cutensorMg.dll"]];
160
161    /// cuTENSORMp runs over NCCL, which is Linux-only.
162    cutensor_mp => "cuTENSORMp", major "2",
163        linux [["libcutensorMp.so." major]],
164        windows [];
165
166    nccl => "NCCL", major "2",
167        linux [["libnccl.so." major]],
168        windows [];
169
170    /// NPP's functions are spread over its core library and ten by domain.
171    npp => "NPP", major "13",
172        linux [
173            ["libnppc.so." major],
174            ["libnppial.so." major],
175            ["libnppicc.so." major],
176            ["libnppidei.so." major],
177            ["libnppif.so." major],
178            ["libnppig.so." major],
179            ["libnppim.so." major],
180            ["libnppist.so." major],
181            ["libnppisu.so." major],
182            ["libnppitc.so." major],
183            ["libnpps.so." major],
184        ],
185        windows [
186            ["nppc64_" major ".dll"],
187            ["nppial64_" major ".dll"],
188            ["nppicc64_" major ".dll"],
189            ["nppidei64_" major ".dll"],
190            ["nppif64_" major ".dll"],
191            ["nppig64_" major ".dll"],
192            ["nppim64_" major ".dll"],
193            ["nppist64_" major ".dll"],
194            ["nppisu64_" major ".dll"],
195            ["nppitc64_" major ".dll"],
196            ["npps64_" major ".dll"],
197        ];
198
199    nvcomp => "nvCOMP", major "6",
200        linux [["libnvcomp.so." major]],
201        windows [["nvcomp64_" major ".dll"]];
202
203    nvimagecodec => "nvImageCodec", major "0",
204        linux [["libnvimgcodec.so." major]],
205        windows [["nvimgcodec_" major ".dll"]];
206
207    nvjpeg => "nvJPEG", major "13",
208        linux [["libnvjpeg.so." major]],
209        windows [["nvjpeg64_" major ".dll"]];
210
211    nvjpeg2k => "nvJPEG2000", major "0",
212        linux [["libnvjpeg2k.so." major]],
213        windows [["nvjpeg2k_" major ".dll"]];
214
215    nvtiff => "nvTIFF", major "0",
216        linux [["libnvtiff.so." major]],
217        windows [["nvtiff_" major ".dll"]];
218}