1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
//! Launch telemetry / tracing integration.
//!
//! This module provides the [`kernel_launch_span!`] macro that emits a
//! `tracing` instrumentation span around every kernel launch when the
//! `tracing` Cargo feature is enabled. When the feature is disabled the
//! macro expands to a unit expression `()` with zero overhead.
//!
//! # Feature gate
//!
//! Add `tracing` to the features in `Cargo.toml` to enable live spans:
//!
//! ```toml
//! [dependencies]
//! oxicuda-launch = { version = "*", features = ["tracing"] }
//! ```
//!
//! # Span fields
//!
//! When enabled, each span carries:
//!
//! | Field | Type | Description |
//! |----------|----------|------------------------------------------|
//! | `kernel` | `&str` | Function name as passed to `Kernel::new` |
//! | `grid` | Debug | Grid dimensions `(x, y, z)` |
//! | `block` | Debug | Block dimensions `(x, y, z)` |
//!
//! # Example (with tracing enabled)
//!
//! ```rust
//! use oxicuda_launch::trace::kernel_launch_span;
//!
//! let _span = kernel_launch_span!("my_kernel", (4u32, 1u32, 1u32), (256u32, 1u32, 1u32));
//! // The span is entered while `_span` is in scope.
//! ```
// =========================================================================
// kernel_launch_span! macro
// =========================================================================
/// Emit a tracing span for a kernel launch.
///
/// # Arguments
///
/// * `$name` — kernel function name (string literal or `&str`).
/// * `$grid` — grid dimensions (anything that implements `Debug`).
/// * `$block` — block dimensions (anything that implements `Debug`).
///
/// # Behaviour
///
/// * With the `tracing` feature: returns an [`tracing::Span`] entered at
/// `INFO` level. Assign the result to a variable; the span closes when
/// the variable is dropped.
/// * Without the `tracing` feature: expands to `()`.
/// No-op version used when the `tracing` feature is disabled.
// Re-export so callers can use `oxicuda_launch::trace::kernel_launch_span`.
pub use kernel_launch_span;
// =========================================================================
// KernelSpanGuard — RAII wrapper that enters/exits the span
// =========================================================================
/// RAII guard that enters a kernel-launch tracing span and exits on drop.
///
/// When the `tracing` feature is disabled this struct is zero-sized.
///
/// # Usage
///
/// ```rust
/// use oxicuda_launch::trace::KernelSpanGuard;
///
/// let _guard = KernelSpanGuard::enter("vector_add", (4u32, 1u32, 1u32), (256u32, 1u32, 1u32));
/// // Span active here — dropped at end of scope.
/// ```
// =========================================================================
// Tests
// =========================================================================