CUPTI
CUPTI, the CUDA Profiling Tools Interface, is what CUDA.jl's profilers are built on. Most users should use those instead: CUDA.@profile traces API calls and kernels, CUDA.@metrics collects hardware metrics for each kernel, and CUDA.@sample samples where kernels spend their time.
The module offers CUPTI at two levels:
- The functions documented below wrap CUPTI's APIs for tools: callbacks on API calls and other events (
CallbackConfig), tracing of activity such as kernel launches and memory copies (ActivityConfig), hardware metrics per kernel (range_profile) and PC sampling (pc_sample). They are not exported, so call them asCUPTI.range_profile(...). - The generated bindings in
libcupti.jlfollow NVIDIA's C API, and change with the CUDA toolkit. The recordsprocesspasses and the enum values the configurations take come from there.
CUPTI reports two versions. CUPTI.version is the version of its API, which looks like a CUDA version and only changes when the API does, so check it for API features. CUPTI.library_version is the release of the library, which is numbered by year (e.g. v"2026.4.0") and changes with every CUDA update release, so it identifies a library with a known bug.
Profiling may need permissions: see can_profile, and NVIDIA's documentation on ERR_NVGPUCTRPERM for hardware metrics and PC sampling. A failing CUPTI call throws a CUPTIError.
Public
CUPTI.CUPTI — Module
Julia wrappers for CUPTI, the CUDA Profiling Tools Interface, which CUDA.jl's profilers (CUDA.@profile, CUDA.@metrics, CUDA.@sample) are built on. See CUPTI.ActivityConfig, CUPTI.range_profile and CUPTI.pc_sample.
CUPTI.ActivityConfig — Type
CUPTI.ActivityConfig(activity_kinds::Vector{CUpti_ActivityKind}) -> ActivityConfigConfiguration for CUPTI's activity API, which records the given kinds of activity (e.g. CUPTI_ACTIVITY_KIND_CONCURRENT_KERNEL or CUPTI_ACTIVITY_KIND_MEMCPY) while the configuration is enabled with CUPTI.enable!, using cuptiActivityEnable. The records are kept in the configuration, and can be read afterwards with CUPTI.process. Activity kinds that the loaded CUPTI doesn't support are skipped.
cfg = CUPTI.ActivityConfig([CUPTI.CUPTI_ACTIVITY_KIND_CONCURRENT_KERNEL])CUPTI.enable!(cfg) do # do stuffendCUPTI.process(cfg) do ctx, stream_id, record # inspect recordendCUPTI.CUPTIError — Type
CUPTIErrorThe exception the functions in this module throw when a CUPTI call fails. Its code field is the CUptiResult code, e.g. ERROR_INSUFFICIENT_PRIVILEGES when the user isn't allowed to profile, or ERROR_HARDWARE_BUSY when another process is using the profiling hardware.
CUPTI.CallbackConfig — Type
CUPTI.CallbackConfig(callback, domains::Vector{CUpti_CallbackDomain}) -> CallbackConfigConfiguration for CUPTI's callback API, which calls callback(domain, id, data) on every event in the callback domains (e.g. CUPTI_CB_DOMAIN_DRIVER_API or CUPTI_CB_DOMAIN_RESOURCE) while the configuration is enabled with CUPTI.enable!. id identifies the event (e.g. a CUpti_driver_api_trace_cbid for the driver API domain), and data is a copy of the record CUPTI passes, whose type depends on the domain: CUpti_CallbackData for the driver and runtime API domains, CUpti_ResourceData, CUpti_SynchronizeData or CUpti_NvtxData for the others. The copy is shallow: memory that the record points to, such as the arguments of an API call, is only valid until callback returns, so copy what you want to keep.
callback runs on the thread that triggered the event, possibly on several threads at once and while CUPTI or the driver hold internal locks. It must not yield, e.g. by doing I/O or waiting on a lock, and must not call the CUDA driver or runtime APIs, except for what CUPTI's documentation allows.
cfg = CUPTI.CallbackConfig([CUPTI.CUPTI_CB_DOMAIN_DRIVER_API]) do domain, id, data # inspect dataendCUPTI.enable!(cfg) do # do stuffendCUPTI.PCSamples — Type
CUPTI.PCSamplesPC samples collected by CUPTI.pc_sample:
reasons: the name of every stall reason, by CUPTI's index;pcs: for every sampled PC, keyed by the CRC of its cubin (as computed byCUPTI.cubin_crc), its function's name and the offset of the PC in that function, the number of samples per stall reason index;total: the number of samples, including dropped ones and samples in kernels that CUPTI doesn't report (e.g. in the driver);dropped: the number of samples that were lost because CUPTI's buffers were full.
CUPTI.ProfilerHost — Type
CUPTI.ProfilerHost(f, ctx::CuContext) -> result of f(host)Create a profiler host object for the device of ctx, which configures and evaluates range profiler metrics, pass it to f, and return the result of f. The object is only valid while f runs, and its fields are not part of the API. Wraps cuptiProfilerHostInitialize, which needs CUPTI from CUDA 12.6 or later.
CUPTI.can_profile — Method
can_profile() -> BoolWhether CUDA.jl should attempt to use CUPTI in the current process.
On Tegra, CUDA 10 through 12 require root, while CUDA 13 and later require read/write access to a profiling device node. This check is intentionally conservative because some CUPTI versions crash in cuptiSubscribe when that access is missing. On other systems, CUPTI reports permission errors normally, so this function returns true and lets CUPTI handle them.
CUPTI.check_pc_sampling_support — Method
CUPTI.check_pc_sampling_support(dev::CuDevice) -> nothingThrow an error explaining why dev doesn't support PC sampling, if it doesn't. Wraps cuptiProfilerDeviceSupported.
CUPTI.check_profiler_support — Method
CUPTI.check_profiler_support(dev::CuDevice; api=CUPTI_PROFILER_RANGE_PROFILING,
feature="hardware metrics") -> nothingThrow an error explaining why dev doesn't support the profiling api, if it doesn't. feature names what the API is used for in the error message. Wraps cuptiProfilerDeviceSupported.
CUPTI.clock_status — Function
CUPTI.clock_status(ctx::CuContext=context()) -> Union{Nothing,CUpti_ClockControl_Status}The clock control state of the device of ctx, e.g. CUPTI_CLOCK_CONTROL_STATUS_LOCKED, or nothing if the device or CUPTI doesn't support clock control (it needs CUPTI from CUDA 13.4 or later). On a MIG instance, this is the state of the GPU the instance belongs to, whose clocks CUPTI can't lock but an administrator can. Wraps cuptiClockControlGetStatus.
CUPTI.cubin_crc — Method
CUPTI.cubin_crc(cubin::Vector) -> UInt64The CRC that CUPTI uses to identify cubin in PC sampling records. Wraps cuptiGetCubinCrc.
CUPTI.enable! — Method
CUPTI.enable!(f, cfg::Union{CUPTI.ActivityConfig,CUPTI.CallbackConfig}) -> result of f()Enable the activities or callbacks configured by cfg while calling f(), and return its result.
For an ActivityConfig, CUPTI's activity records are flushed into cfg when f returns (cuptiActivityFlushAll). Records of work that hasn't completed by then are incomplete or missing, so synchronize at the end of f. For a CallbackConfig, it subscribes to the configured callback domains (cuptiSubscribe and cuptiEnableDomain).
Only one configuration of each kind can be enabled at a time: an enable! in another task waits for the previous one to finish, while nesting enable! calls for the same kind of configuration in one task is not supported. CUPTI only supports a single callback subscriber per process, so a CallbackConfig can't be enabled while another tool (e.g. a profiler) is subscribed.
CUPTI.has_pc_sampling — Method
CUPTI.has_pc_sampling() -> BoolWhether the loaded CUPTI library supports PC sampling as CUPTI.pc_sample uses it: this wrapper needs CUPTI from CUDA 13 or later, although CUPTI offered PC sampling before.
CUPTI.has_range_profiler — Method
CUPTI.has_range_profiler() -> BoolWhether the loaded CUPTI library provides the range profiler (CUDA 12.6 Update 2 and later). The API version doesn't change between update releases, so look for the symbol.
CUPTI.library_version — Method
CUPTI.library_version() -> VersionNumberThe release version of the loaded CUPTI library, e.g. v"2026.4.0", which recent CUPTI releases number by year. It changes with every release, so use it to work around bugs in a specific CUPTI library, and CUPTI.version to check for API features. CUPTI has no API for it, so it is read from the library's file name on Linux, as NVIDIA suggests, and from the DLL's version resource on Windows.
CUPTI.lock_clocks — Function
CUPTI.lock_clocks(f, mode=CUPTI_CLOCK_CONTROL_MODE_BASE; ctx=context())
-> result of f()Run f() with the clocks of the device of ctx locked to their base frequency (mode CUPTI_CLOCK_CONTROL_MODE_BASE) or their boost frequency (CUPTI_CLOCK_CONTROL_MODE_BOOST), so that GPU Boost doesn't change how fast kernels run. The lock applies to the whole device, including other processes using it, and is released when f returns or throws.
f runs with unlocked clocks when the device or CUPTI doesn't support clock control (see CUPTI.clock_status), and on MIG instances, which can't lock their GPU's clocks. Calls that overlap in this process (nested, or in other tasks) share the lock the first one took, in its mode, and can't lock the clocks of another device. Clocks that CUPTI reports as locked, e.g. by another process, are left alone: CUPTI doesn't track whose lock that is, so unlocking would release it. This check races with other processes locking the clocks at the same time. Clocks locked with nvidia-smi --lock-gpu-clocks are not reported as locked; the lock taken here overrides them while f runs.
If the process crashes while f runs, the clocks stay locked, which nvidia-smi --reset-gpu-clocks doesn't undo. Locking and unlocking them through CUPTI does:
CUPTI.cuptiClockControlLock(context(), CUPTI.CUPTI_CLOCK_CONTROL_MODE_BASE)CUPTI.cuptiClockControlUnlock()Wraps cuptiClockControlLock.
CUPTI.metric_properties — Method
CUPTI.metric_properties(host::ProfilerHost, metric::String)
-> @NamedTuple{description::String, hw_unit::String, dim_unit::String,
type::CUpti_MetricType}Look up the description and unit of metric (e.g. dram__bytes or dram__bytes.sum), or throw a CUPTIError with code CUPTI_ERROR_INVALID_METRIC_NAME if it doesn't exist. Wraps cuptiProfilerHostGetMetricProperties, which needs CUPTI from CUDA 12.6 or later.
CUPTI.pc_sample — Method
CUPTI.pc_sample(f; ctx=context(), period=14) -> CUPTI.PCSamplesSample the PCs of warps executing kernels in ctx while executing f(), once every 2^period cycles on each SM. Samples are only collected while f runs, so synchronize the context before calling pc_sample, and at the end of f, before it returns. Only one profiling session, of this function or CUPTI.range_profile, can be active at a time.
This uses CUPTI's PC sampling API (cuptiPCSamplingEnable and related routines) in continuous mode. This wrapper needs CUPTI from CUDA 13 or later (see CUPTI.has_pc_sampling) and a device that supports it (see CUPTI.check_pc_sampling_support).
With CUPTI 13.2 and later, loading a module after PC sampling was disabled makes enabling PC sampling or the range profiler fail with CUPTI_ERROR_INVALID_OPERATION, even in other contexts. Call cuptiFinalize when CUPTI isn't in use anymore (e.g., after unsubscribing from callbacks) to avoid that.
CUPTI.process — Method
CUPTI.process(f, cfg::CUPTI.ActivityConfig) -> nothingCall f(ctx, stream_id, record) for every activity record collected in cfg, in the order CUPTI delivered them. ctx and stream_id are the CuContext (or nothing) and the CUPTI stream ID that CUPTI reported for the buffer holding the record. record is a copy of the record, as the newest CUPTI struct that the loaded CUDA version writes for its kind: e.g. CUpti_ActivityAPI for driver and runtime API calls, or CUpti_ActivityKernel9 for kernels on CUDA 12. Records of kinds this function doesn't know about are skipped with a warning. Wraps cuptiActivityGetNextRecord.
CUPTI.range_profile — Method
CUPTI.range_profile(f, metrics::Vector{String}; ctx=context(), max_ranges=1024,
clock_control=nothing, cache_control=CUPTI_CACHE_CONTROL_MODE_NONE)
-> @NamedTuple{values::Matrix{Float64}, passes::Int}Collect metrics for every kernel launched in ctx while executing f(), and return a named tuple with a ranges × metrics matrix of values and the number of passes each kernel was replayed. Ranges are numbered in the order the kernels executed, which is serialized by CUPTI; at most max_ranges kernels are profiled.
To make results repeatable, clock_control can lock the clocks during the session to CUPTI_CLOCK_CONTROL_MODE_BASE or CUPTI_CLOCK_CONTROL_MODE_BOOST (see CUPTI.lock_clocks), and cache_control can reset caches before every replay pass: all of them (CUPTI_CACHE_CONTROL_MODE_ALL) or only L2 (CUPTI_CACHE_CONTROL_MODE_L2). Both need CUPTI from CUDA 13.4 or later, and are ignored by older versions.
This uses CUPTI's range profiler in auto-range, kernel-replay mode, which needs CUPTI from CUDA 12.6 Update 2 or later (see CUPTI.has_range_profiler) and a device that supports it (see CUPTI.check_profiler_support). Only one profiling session, of this function or CUPTI.pc_sample, can be active at a time.
CUPTI.version — Method
CUPTI.version() -> VersionNumberThe version of CUPTI's API, e.g. v"12.9.1" or v"13.5.0", to check for API features. Wraps cuptiGetVersion. Before CUDA 13, CUPTI reports a revision number, which this function maps to the CUDA release that introduced it; several releases can share a revision (e.g. v"10.0" covers CUDA 10.0 to 10.2). From CUDA 13, CUPTI reports a version whose patch number is CUPTI's own. Either way, the version only changes when the API does, so it can't identify features or fixes added in an update release: look for the symbol of a new routine instead (as CUPTI.has_range_profiler does), or use CUPTI.library_version.
CUPTI.@enable! — Macro
CUPTI.@enable! cfg expr -> value of exprMacro version of CUPTI.enable!(f, cfg) that evaluates expr without creating a closure, similar to @lock vs lock(f, l), and returns its value.
Private
CUPTI.chip_name — Method
CUPTI.chip_name(dev::CuDevice) -> StringThe name of the chip of dev, as used to configure the profiler (e.g. "GB203").
CUPTI.config_image — Method
CUPTI.config_image(host::ProfilerHost, metrics::Vector{String}) -> Vector{UInt8}Build the configuration image that makes the range profiler collect metrics.
CUPTI.num_passes — Method
CUPTI.num_passes(config::Vector{UInt8}) -> IntThe number of times each kernel needs to be replayed to collect the metrics in config.
CUPTI.profiler_params — Method
CUPTI.profiler_params(T, lastfield; fields...)Construct a zero-initialized profiler API parameter struct of type T, setting the given fields. structSize covers the fields up to and including lastfield, which should be the last field the oldest supported CUPTI knows about: CUPTI appends fields to these structs, and rejects sizes it doesn't recognize.