SanitizerApiGuide
SanitizerApiGuide
Reference Manual
TABLE OF CONTENTS
Chapter 1. Introduction.........................................................................................1
1.1. Overview................................................................................................... 1
Chapter 2. Usage................................................................................................. 2
2.1. Compatibility and Requirements....................................................................... 2
2.2. Callback API............................................................................................... 2
2.2.1. Driver and Runtime API Callbacks................................................................ 3
2.2.2. Resource Callbacks.................................................................................. 4
2.2.3. Synchronization Callbacks..........................................................................4
2.2.4. Launch Callbacks.................................................................................... 5
2.2.5. Memcpy Callbacks................................................................................... 5
2.2.6. Memset Callbacks................................................................................... 5
2.2.7. Batch Memory Operations Callbacks............................................................. 5
2.3. Patching API............................................................................................... 5
2.3.1. Writing a Patch...................................................................................... 6
2.3.2. Insert a Patch........................................................................................ 6
2.4. Memory API................................................................................................ 7
2.5. Special cases.............................................................................................. 8
2.5.1. Device graph launch................................................................................ 8
Chapter 3. Limitations.......................................................................................... 9
www.nvidia.com
Sanitizer API v2024.1.1 | ii
Chapter 1.
INTRODUCTION
1.1. Overview
The Compute Sanitizer API enables the creation of sanitizing and tracing tools that
target CUDA applications. Examples of such tools are memory and race condition
checkers. The Compute Sanitizer API is composed of three APIs: the callback API, the
patching API and the memory API. It is delivered as a dynamic library on supported
platforms.
www.nvidia.com
Sanitizer API v2024.1.1 | 1
Chapter 2.
USAGE
www.nvidia.com
Sanitizer API v2024.1.1 | 2
Usage
Sanitizer_SubscriberHandle handle;
MyDataStruct *my_data = ...;
...
sanitizerSubscribe(&handle, my_callback, my_data);
sanitizerEnableDomain(1, handle, SANITIZER_CB_DOMAIN_RUNTIME_API);
www.nvidia.com
Sanitizer API v2024.1.1 | 3
Usage
void SANITIZERAPI
my_callback(void *userdata,
Sanitizer_CallbackDomain domain,
Sanitizer_CallbackId cbid,
const void *cbdata)
{
const Sanitizer_CallbackData *cbInfo = (Sanitizer_CallbackData *)cbdata;
MyDataStruct *my_data = (MyDataStruct *)userdata;
www.nvidia.com
Sanitizer API v2024.1.1 | 4
Usage
www.nvidia.com
Sanitizer API v2024.1.1 | 5
Usage
modified so that a patch gets executed either before or after the patched event. All
patches are executed prior to the event, with the exception of device-side malloc.
‣ Patch: A CUDA __device__ function that the Compute Sanitizer will insert
into another existing CUDA code. Patch function signatures must match the one
expected by the API (see below for the expected signature types).
return SANITIZER_PATCH_SUCCESS;
}
In this patch, we log write and read accesses to a structure we allocated previously.
extern "C" ensures that the patch name will not be mangled, allowing us to use its
name as a string directly in calls to sanitizerPatchInstructions (see below).
There can be multiple patches defined in a single CUDA file. This file must then be
compiled using the following nvcc options:
The --cubin option can be replaced by --fatbin if a fatbin is preferred over a cubin as
the output file.
www.nvidia.com
Sanitizer API v2024.1.1 | 6
Usage
sanitizerPatchModule(module);
MyDeviceDataTracker *deviceDataTracker;
cudaMalloc(&deviceDataTracker, sizeof(*deviceDataTracker));
CUfunction function = ... // kernel to be launched for which we want to set the
callbackdata for the patches
sanitizerSetCallbackData(function, deviceDataTracker);
All subsequent launches using code from this CUDA module will be instrumented and
my_memory_access_callback will be invoked before every memory access. However,
the callback data is only set for all subsequent launches of the given kernel. An easy way
to have a kernel CUfunction, is through the Sanitizer launch callbacks. Instrumentation
can be removed by using the sanitizerUnpatchModule API.
www.nvidia.com
Sanitizer API v2024.1.1 | 7
Usage
www.nvidia.com
Sanitizer API v2024.1.1 | 8
Chapter 3.
LIMITATIONS
www.nvidia.com
Sanitizer API v2024.1.1 | 9
Notice
ALL NVIDIA DESIGN SPECIFICATIONS, REFERENCE BOARDS, FILES, DRAWINGS,
DIAGNOSTICS, LISTS, AND OTHER DOCUMENTS (TOGETHER AND SEPARATELY,
"MATERIALS") ARE BEING PROVIDED "AS IS." NVIDIA MAKES NO WARRANTIES,
EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO THE
MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF
NONINFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A PARTICULAR
PURPOSE.
Information furnished is believed to be accurate and reliable. However, NVIDIA
Corporation assumes no responsibility for the consequences of use of such
information or for any infringement of patents or other rights of third parties
that may result from its use. No license is granted by implication of otherwise
under any patent rights of NVIDIA Corporation. Specifications mentioned in this
publication are subject to change without notice. This publication supersedes and
replaces all other information previously supplied. NVIDIA Corporation products
are not authorized as critical components in life support devices or systems
without express written approval of NVIDIA Corporation.
Trademarks
NVIDIA and the NVIDIA logo are trademarks or registered trademarks of NVIDIA
Corporation in the U.S. and other countries. Other company and product names
may be trademarks of the respective companies with which they are associated.
Copyright
© 2019-2024 NVIDIA Corporation and affiliates. All rights reserved.
This product includes software developed by the Syncro Soft SRL (http://
www.sync.ro/).
www.nvidia.com