Hauptinhalt

Create GPU Kernel Profiles for Generated Code

R2026b
Since R2026b

The GPU Performance Analyzer profiles generated code by measuring the execution time of events such as for-loops and GPU kernels in the generated code. If a GPU kernel dominates your application run time, you can generate a kernel profile. The kernel profile includes additional performance metrics for the GPU kernel, such as:

  • Achieved occupancy

  • Compute throughput

  • GPU memory throughput

  • Floating-point unit throughput

Use these metrics to understand which GPU resources constrain the kernel execution. For example, if the floating-point unit throughput is high, the floating-point pipeline might limit the kernel performance.

Before generating a kernel profile, enable access to performance counters on your GPU. For more information, see Permission Issue with Performance Counters on the NVIDIA® website.

Enable Kernel Profiling

To generate a kernel profile, you must create a MEX code configuration object and use the object with the GPU Performance Analyzer. You can only generate a kernel profile for MEX functions.

Create a coder.MexCodeConfig object by using the coder.gpuConfig function.

cfg = coder.gpuConfig("mex");

To enable kernel profiling, call the gpuPerformanceAnalyzer function and set the KernelProfile name-value argument to true. The GPU Performance Analyzer generates code for the entry-point function and profiles the application by running the code twice. Then, the analyzer runs the application again to profile the GPU kernels.

gpuPerformanceAnalyzer(functionName,inputArgs,Config=cfg,KernelProfile=true);
### Starting GPU code generation
Code generation successful: View report

### GPU code generation finished
### Starting application profiling
### Application profiling finished
### Starting kernel range profiling
### Kernel range profiling finished
### Starting profiling data processing
### Profiling data processing finished
### Showing profiling data

Examine Kernel Profile Metrics

After kernel profiling finishes, the GPU Performance Analyzer opens. To retrieve the kernel profile metrics, in the Profiling Timeline, in the GPU Activities row, select the kernel event. The Event Statistics pane shows a Kernel Profile Metrics section for the kernel.

Event statistics pane showing the GPU Kernel Profile metrics section for a kernel

To read the description for a metric, point to the metric name. This table lists the metrics in a kernel profile:

MetricDescriptionHow to Use
Achieved occupancyIndicates how efficiently the kernel uses the streaming multiprocessors (SMs) on the GPU by measuring the average percentage of active warps relative to the hardware maximum.

Low occupancy indicates the kernel launches with little parallelism or that the computations have high latency. High occupancy indicates that many warps are active, but other factors can limit the kernel performance.

Compute throughputMeasures how much of the computational capacity of the GPU that the kernel uses.

High compute throughput indicates that the computational capacity limits the kernel. Low compute throughput suggests a latency or memory bandwidth limitation.

GPU memory throughputMeasures memory system utilization, including the L1 cache, L2 cache, and global memory.Compare the GPU memory throughput with the GPU DRAM throughput. If the GPU memory throughput is significantly greater than the GPU DRAM throughput, the kernel benefits from reusing the cache. If both metrics are high, the kernel moves a substantial amount of data to and from global memory.
GPU DRAM throughputMeasures how much of the bandwidth between the L2 cache and global memory (DRAM) that the kernel uses. High GPU DRAM throughput suggests that global memory bandwidth limits kernel performance.
Global Memory Access EfficiencyReports the average number of bytes the kernel accesses per 32-byte memory sector. This metric represents how efficiently the kernel accesses global memory.Values approximately equal to 32 indicate that the kernel accesses global memory in a coalesced manner. Low values indicate inefficient global memory access.
ALU throughputMeasures the use of the arithmetic logic unit (ALU) pipeline.High values indicate the kernel performs many integer or logical operations.
FP32 throughputMeasures the percentage of single-precision (FP32) floating-point units the kernel uses.High values indicate the kernel performs many single-precision floating-point computations.
FP64 throughputMeasures the percentage of double-precision (FP64) floating-point units the kernel uses.High values indicate the kernel performs many double-precision floating-point computations. For NVIDIA GPUs, single-precision data types can produce higher throughput and lower memory usage than double-precision data types.
Tensor Core throughputMeasures the use of NVIDIA Tensor Cores, which accelerate matrix operations during deep learning workloads.High values indicate the kernel uses Tensor Cores. If Tensor Core throughput is low, the kernel does not map computations to Tensor Cores.

See Also

Functions

Tools

Topics