teeny_cuda/lib.rs
1/*
2 * Copyright (c) 2026 Teenygrad.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17//! The CUDA device backend for [teenygrad](https://teenygrad.org) — driver bindings (via
18//! `bindgen` against the CUDA headers), device/runtime abstraction ([`device`], [`runtime`]),
19//! and the AOT/JIT kernel-compilation path ([`compiler`]) used by `teeny-kernels`' `cuda`
20//! feature.
21//!
22//! Building this crate requires the CUDA toolkit headers/libs on the host (`build.rs` links
23//! against them unconditionally); see the crate README for `CUDA_INCLUDE_DIR`/`CUDA_LIB_DIR` and
24//! the separate, runtime-only `teenyc`/`TEENYC_PATH` requirement for actually compiling kernels.
25
26#![warn(missing_docs)]
27
28/// AOT/JIT kernel compilation.
29pub mod compiler;
30/// Device and context management.
31pub mod device;
32/// Error types.
33pub mod errors;
34/// Loaded-model execution.
35pub mod model;
36/// CUDA runtime abstraction (streams, memory, launches).
37pub mod runtime;
38/// Test helpers for `teeny-cuda`'s own test suite.
39pub mod testing;
40
41mod cuda;
42
43/// Signal nsys (or any CUDA profiler) to start capturing.
44///
45/// # Safety
46/// Calls `cudaProfilerStart` via the CUDA runtime. Safe to call multiple times;
47/// has no effect if no profiler is attached.
48pub unsafe fn cuda_profiler_start() {
49 unsafe { cuda::cudaProfilerStart() };
50}
51
52/// Signal nsys (or any CUDA profiler) to stop capturing.
53///
54/// # Safety
55/// Calls `cudaProfilerStop` via the CUDA runtime.
56pub unsafe fn cuda_profiler_stop() {
57 unsafe { cuda::cudaProfilerStop() };
58}