Skip to content

Commit 2101583

Browse files
authored
Add cuda-toolkit/13.3.1 (#8)
1 parent 15515aa commit 2101583

6 files changed

Lines changed: 251 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ jobs:
2020
cuda-version: "13.2"
2121
- os: ubuntu-24.04-arm
2222
cuda-version: "13.2"
23+
- os: ubuntu-latest
24+
cuda-version: "13.3"
25+
- os: ubuntu-24.04-arm
26+
cuda-version: "13.3"
2327
# Windows:
2428
# cuda <13.2 requires Visual Studio 2022, available on windows-2022 runner
2529
- os: windows-2022
@@ -29,6 +33,8 @@ jobs:
2933
# cuda >=13.2 can run on windows-latest (Visual Studio 2026)
3034
- os: windows-latest
3135
cuda-version: "13.2"
36+
- os: windows-latest
37+
cuda-version: "13.3"
3238
# 13.4.0-preview developer preview: Windows x86_64 and arm64
3339
- os: windows-latest
3440
cuda-version: "13.4"
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
import os
2+
import json
3+
from pathlib import Path
4+
5+
from conan import ConanFile
6+
from conan.errors import ConanInvalidConfiguration
7+
from conan.tools.files import copy, download, get, load, rename, replace_in_file
8+
9+
class CudaToolkitConan(ConanFile):
10+
name = "cuda-toolkit"
11+
package_type = "shared-library"
12+
version = "13.3.1"
13+
license = "CUDA Toolkit End-User License Agreement"
14+
url = "https://github.com/conan-io/cuda-conan"
15+
homepage = "https://developer.nvidia.com/cuda-toolkit"
16+
description = "A development environment for creating high performance GPU-accelerated applications"
17+
settings = "os", "arch", "compiler", "build_type"
18+
19+
def validate(self):
20+
if self.settings.os not in ["Windows", "Linux"]:
21+
raise ConanInvalidConfiguration("Operating system not supported")
22+
23+
# TODO: Add checks for supported compilers as per https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#id56
24+
25+
def build(self):
26+
base_url = "https://developer.download.nvidia.com/compute/cuda/redist"
27+
distrib = f"redistrib_{self.version}.json"
28+
json_distrib = f"{base_url}/{distrib}"
29+
download(self, url=json_distrib, filename=distrib)
30+
json_content = load(self, distrib)
31+
cuda_distrib = json.loads(json_content)
32+
33+
if self.settings.os == "Linux" and self.settings.arch == "armv8":
34+
cuda_platform = "linux-sbsa"
35+
else:
36+
cuda_platform = f"{str(self.settings.os).lower()}-{self.settings.arch}"
37+
38+
self.output.info(f"About to download CUDA toolkit components for {cuda_platform}")
39+
40+
components = [
41+
"cccl",
42+
"cuda_crt",
43+
"cuda_cudart",
44+
"cuda_cupti",
45+
"cuda_cuxxfilt",
46+
"cuda_nvcc",
47+
"cuda_nvml_dev",
48+
"cuda_nvrtc",
49+
"cuda_nvtx",
50+
"cuda_profiler_api",
51+
"cuda_sanitizer_api",
52+
"libcublas",
53+
"libcufft",
54+
"libcurand",
55+
"libcusolver",
56+
"libcusparse",
57+
"libnpp",
58+
"libnvfatbin",
59+
"libnvjitlink",
60+
"libnvjpeg",
61+
"libnvptxcompiler",
62+
"libnvvm",
63+
"cuda_tileiras",
64+
]
65+
66+
platform_components = {
67+
"linux-x86_64": ["libcufile", "cuda_sandbox_dev", "cuda_opencl", "cuda_culibos", "cuda_compat", "libcuobjclient"],
68+
"linux-sbsa": ["libcufile", "cuda_sandbox_dev", "cuda_culibos", "cuda_compat", "cuda_compat_orin", "libcudla", "libcuobjclient"],
69+
"windows-x86_64": ["cuda_opencl", "visual_studio_integration"],
70+
}
71+
components += platform_components.get(cuda_platform, [])
72+
73+
for component_name, data in cuda_distrib.items():
74+
if component_name not in components:
75+
self.output.info(f"Skipping {component_name}")
76+
continue
77+
else:
78+
self.output.info(f"About to download {component_name} for {cuda_platform}")
79+
80+
url = f"{base_url}/{(data[cuda_platform]['cuda13.3'] if component_name == 'cuda_compat' else data[cuda_platform])['relative_path']}"
81+
checksum = (data[cuda_platform]['cuda13.3'] if component_name == 'cuda_compat' else data[cuda_platform])['sha256']
82+
83+
get(self, url, sha256=checksum, destination="cuda", strip_root=True, keep_permissions=False)
84+
rename(self, f"{self.build_folder}/cuda/LICENSE", f"LICENSE_{component_name}")
85+
if self.settings.os == "Linux":
86+
# When crossbuilding, point nvcc to the target directory in the "host" package (for the target architecture),
87+
# rather than have it look relative to itself (which is the current architecture of the build machine)
88+
replace_in_file(self, "cuda/bin/nvcc.profile", '$(TOP)/$(_TARGET_DIR_)/', '$(CONAN_CUDA_TARGET_DIR)/')
89+
replace_in_file(self, "cuda/bin/nvcc.profile", "lib$(_TARGET_SIZE_)", "lib" )
90+
91+
def package(self):
92+
copy(self, "LICENSE*", src=self.build_folder, dst=os.path.join(self.package_folder, "licenses"))
93+
94+
for folder in ["bin", "nvml", "nvvm", "compat", "compat_orin"]:
95+
copy(self, "*", src=os.path.join(self.build_folder, "cuda", folder), dst=os.path.join(self.package_folder, folder))
96+
97+
if self.settings.os == "Linux":
98+
arch = "sbsa" if self.settings.arch == "armv8" else str(self.settings.arch)
99+
targets_folder = f"targets/{arch}-linux"
100+
copy(self, "*", src=os.path.join(self.build_folder, "cuda", "lib"), dst=os.path.join(self.package_folder, targets_folder, "lib"))
101+
copy(self, "*", src=os.path.join(self.build_folder, "cuda", "include"), dst=os.path.join(self.package_folder, targets_folder, "include"))
102+
copy(self, "*", src=os.path.join(self.build_folder, "cuda", "res"), dst=os.path.join(self.package_folder, targets_folder, "res"))
103+
104+
include_symlink = Path(f"targets/{arch}-linux/include")
105+
lib64_symlink = Path(f"targets/{arch}-linux/lib")
106+
res_symlink = Path(f"targets/{arch}-linux/res")
107+
include = Path(os.path.join(self.package_folder, "include"))
108+
lib = Path(os.path.join(self.package_folder, "lib64"))
109+
res = Path(os.path.join(self.package_folder, "res"))
110+
include.symlink_to(include_symlink)
111+
lib.symlink_to(lib64_symlink)
112+
res.symlink_to(res_symlink)
113+
elif self.settings.os == "Windows":
114+
for folder in ["compute-sanitizer", "include", "lib"]:
115+
copy(self, "*", src=os.path.join(self.build_folder, "cuda", folder), dst=os.path.join(self.package_folder, folder))
116+
117+
copy(self, "*", src=os.path.join(self.build_folder, "cuda", "visual_studio_integration"),
118+
dst=os.path.join(self.package_folder, "extras", "visual_studio_integration") )
119+
120+
def package_id(self):
121+
# only os and arch matter for this package
122+
self.info.settings.rm_safe("compiler")
123+
self.info.settings.rm_safe("build_type")
124+
125+
def package_info(self):
126+
self.cpp_info.set_property("cmake_file_name", "CUDAToolkit") # what consumers will expect
127+
self.cpp_info.set_property("cmake_find_mode", "none") # but don't generate it
128+
self.cpp_info.set_property("cmake_target_name", "CUDA::toolkit")
129+
130+
nvcc = "nvcc.exe" if self.settings.os == "Windows" else "nvcc"
131+
self.buildenv_info.define_path("CUDACXX", os.path.join(self.package_folder, "bin", nvcc))
132+
133+
if not self.settings_target:
134+
arch = "sbsa" if self.settings.arch == "armv8" else str(self.settings.arch)
135+
self.buildenv_info.define_path("CUDAToolkit_ROOT", self.package_folder)
136+
self.buildenv_info.define_path("CONAN_CUDA_TARGET_DIR", os.path.join(self.package_folder, "targets", f"{arch}-linux"))
137+
138+
if self.settings.os == "Linux":
139+
self.cpp_info.libdirs = ["lib64"]
140+
else:
141+
self.cpp_info.libdirs = ["lib", "lib/x64"]
142+
self.cpp_info.bindirs = ["bin", "bin/x64"]
143+
144+
if self.settings_build.os == "Windows":
145+
# Only has effect when Windows and the CMake generator is Visual Studio
146+
package_folder = f"{self.package_folder}".replace('\\', '/')
147+
self.conf_info.define("tools.cmake.cmaketoolchain:toolset_cuda", package_folder)
148+
149+
if self.settings_target and self.settings_target.get_safe("build_type"):
150+
self.conf_info.update("tools.cmake.cmaketoolchain:extra_variables",
151+
{"CMAKE_TRY_COMPILE_CONFIGURATION": str(self.settings_target.build_type)})
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
cmake_minimum_required(VERSION 3.25)
2+
3+
project(PackageTest LANGUAGES CXX CUDA)
4+
5+
find_package(CUDAToolkit REQUIRED)
6+
7+
message("CUDAToolkit_VERSION: ${CUDAToolkit_VERSION}")
8+
message("CUDAToolkit_BIN_DIR: ${CUDAToolkit_BIN_DIR}")
9+
message("CUDAToolkit_LIBRARY_DIR: ${CUDAToolkit_LIBRARY_DIR}")
10+
message("CUDAToolkit_LIBRARY_ROOT: ${CUDAToolkit_LIBRARY_ROOT}")
11+
message("CUDAToolkit_NVCC_EXECUTABLE: ${CUDAToolkit_NVCC_EXECUTABLE}")
12+
13+
add_executable(example hello_cuda.cu)
14+
target_compile_options(example PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:--verbose>)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import os
2+
3+
from conan import ConanFile
4+
from conan.tools.build import can_run
5+
from conan.tools.cmake import CMake, cmake_layout
6+
7+
8+
class CudatoolkitTestConan(ConanFile):
9+
settings = "os", "compiler", "build_type", "arch"
10+
generators = "CMakeDeps", "CMakeToolchain"
11+
12+
def requirements(self):
13+
self.requires(self.tested_reference_str)
14+
self.tool_requires(self.tested_reference_str)
15+
16+
def layout(self):
17+
cmake_layout(self, src_folder='.')
18+
19+
def build(self):
20+
cmake = CMake(self)
21+
cmake.configure()
22+
cmake.build()
23+
24+
def test(self):
25+
if can_run(self):
26+
bin_path = os.path.join(self.cpp.build.bindirs[0], "example")
27+
self.run(bin_path, env="conanrun")
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include <stdio.h>
2+
#include <cuda_runtime.h>
3+
4+
__global__ void helloKernel(void) {
5+
printf("Hello from GPU thread (%d, %d)\n",
6+
blockIdx.x, threadIdx.x);
7+
}
8+
9+
int main(void) {
10+
/* ── 1. Check driver / runtime availability ── */
11+
int driverVersion = 0, runtimeVersion = 0;
12+
cudaError_t err;
13+
14+
err = cudaDriverGetVersion(&driverVersion);
15+
if (err != cudaSuccess || driverVersion == 0) {
16+
printf("Hello from CPU! (no CUDA driver: %s)\n",
17+
cudaGetErrorString(err));
18+
return 0;
19+
}
20+
21+
cudaRuntimeGetVersion(&runtimeVersion);
22+
23+
/* ── 2. Enumerate devices ── */
24+
int deviceCount = 0;
25+
err = cudaGetDeviceCount(&deviceCount);
26+
if (err != cudaSuccess || deviceCount == 0) {
27+
printf("Hello from CPU! (no CUDA devices: %s)\n",
28+
cudaGetErrorString(err));
29+
return 0;
30+
}
31+
32+
/* ── 3. Print basic device info ── */
33+
cudaDeviceProp prop;
34+
cudaGetDeviceProperties(&prop, 0);
35+
printf("CUDA driver %d.%d | runtime %d.%d | device 0: %s\n",
36+
driverVersion / 1000, (driverVersion % 100) / 10,
37+
runtimeVersion / 1000, (runtimeVersion % 100) / 10,
38+
prop.name);
39+
40+
/* ── 4. Launch kernel ── */
41+
helloKernel<<<2, 4>>>();
42+
43+
err = cudaDeviceSynchronize();
44+
if (err != cudaSuccess) {
45+
fprintf(stderr, "Kernel failed: %s\n", cudaGetErrorString(err));
46+
return 1;
47+
}
48+
49+
printf("Hello from CPU! (kernel completed successfully)\n");
50+
return 0;
51+
}

recipes/cuda-toolkit/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
versions:
22
"13.4.0-preview":
33
folder: "13.4"
4+
"13.3.1":
5+
folder: "13.3"
46
"13.2.2":
57
folder: "13.2"
68
"13.0.3":

0 commit comments

Comments
 (0)