torch.autograd.emit_nvtx
function emit_nvtx(options?: EmitNvtxOptions): EmitNvtxContextfunction emit_nvtx(enabled: boolean, options?: EmitNvtxOptions): EmitNvtxContextCreates context for emitting NVIDIA NVTX markers for GPU profiling.
NVTX (NVIDIA Tools Extension) markers are used with NVIDIA's profiling tools (NVIDIA Profiler, NSight) to annotate operations for detailed GPU profiling. This function is a no-op in torch.js (WebGPU doesn't support NVTX), but is provided for PyTorch API compatibility. Useful for:
- GPU profiling integration: Marking operation boundaries for NVIDIA tools
- Custom kernels: Annotating custom GPU code with named ranges
- Performance analysis: Correlating GPU timeline with PyTorch operations
- API compatibility: Write code that works with both CPU/GPU backends
- Cross-platform code: Code that may run on CUDA or WebGPU
Note: WebGPU does not have direct NVTX support. This function returns a no-op context for compatibility. For WebGPU profiling, use the standard profiler() function instead.
NVIDIA Tools Support: NVTX markers work with:
- NVIDIA Profiler
- NVIDIA NSight Compute
- NVIDIA NSight Systems
WebGPU Alternative: For WebGPU profiling, use profiler() with record_shapes=true instead.
- No-op in WebGPU: Function does nothing in torch.js (no NVTX support)
- API compatibility: Provided for code compatibility with PyTorch
- CUDA-specific: Only works with NVIDIA CUDA backend (not WebGPU)
- Optional: Can be safely ignored in WebGPU contexts
- WebGPU limitation: NVTX markers are not emitted in WebGPU
- Platform-specific: Only meaningful when running on CUDA
- Profiling overhead: Even no-op context has minimal overhead
Parameters
optionsEmitNvtxOptionsoptional
Returns
EmitNvtxContext– EmitNvtxContext object (no-op context in torch.js)Examples
// CUDA (would emit markers with NVIDIA tools)
const ctx = torch.profiler.emit_nvtx(true);
ctx.start(); // Start NVTX range "MyOperation"
// GPU operations here
ctx.stop(); // End NVTX range// WebGPU (no-op, but code is compatible)
const ctx = torch.profiler.emit_nvtx(true);
// In WebGPU, use profiler() instead for similar functionality
const profiler = torch.profiler.profile({ use_cpu: true });// Cross-platform code
const enableProfiling = true;
if (torch.cuda.is_available()) {
// CUDA: Use NVTX markers
const ctx = torch.profiler.emit_nvtx(enableProfiling);
ctx.start();
} else {
// WebGPU: Use standard profiler
const prof = torch.profiler.profile({ use_cpu: true });
prof.start();
}See Also
- PyTorch torch.autograd.profiler.emit_nvtx()
- profile - Standard profiler (works on WebGPU)
- EmitNvtxContext - The returned context object