cuda_std/
misc.rs

1//! Misc functions that do not exactly fit into other categories.
2
3use crate::gpu_only;
4
5/// Suspends execution of the kernel, usually to pause at a specific point when debugging in a debugger.
6#[gpu_only]
7#[inline(always)]
8pub fn breakpoint() {
9    unsafe {
10        asm!("brkpt");
11    }
12}
13
14/// Increments a hardware counter between `0` and `7` (inclusive).
15/// This function will increment the counter by one per warp.
16///
17/// # Panics
18///
19/// Panics if `counter` is not in the range of `0..=7`.
20#[gpu_only]
21#[inline(always)]
22pub fn profiler_counter(counter: u32) {
23    assert!(
24        (0..=7).contains(&counter),
25        "Profiler counter value must be in the range of 0..=7"
26    );
27    unsafe {
28        asm!(
29            "pmevent {}",
30            in(reg32) counter
31        )
32    }
33}
34
35/// Returns the value of a per-multiprocessor counter incremented on every clock cycle.
36#[gpu_only]
37#[inline(always)]
38pub fn clock() -> u64 {
39    let mut clock;
40    unsafe {
41        asm!(
42            "mov.u64 {}, %clock64",
43            out(reg64) clock
44        )
45    }
46    clock
47}