Sanitizer Api - v2019.1 (older) - Last updated January 01, 2019 - Send Feedback -

## 1. Modules

Here is a list of all modules:

- Sanitizer Callback API
- Sanitizer Memory API
- Sanitizer Patching API
- Sanitizer Result Codes

### 1.1. Sanitizer Callback API

Functions, types, and enums that implement the Sanitizer Callback API.

#### Classes

struct
Sanitizer_BatchMemopData
  Data passed into a batch memop callback function.
struct
Sanitizer_CallbackData
  Data passed into a runtime or driver API callback function.
struct
Sanitizer_LaunchData
  Data passed into a launch callback function.
struct
Sanitizer_MemcpyData
  Data passed into a memcpy callback function.
struct
Sanitizer_MemsetData
  Data passed into a memset callback function.
struct
Sanitizer_ResourceContextData
  Data passed into a context resource callback function.
struct
Sanitizer_ResourceMemoryData
  Data passed into a memory resource callback function.
struct
Sanitizer_ResourceModuleData
  Data passed into a module resource callback function.
struct
Sanitizer_ResourceStreamData
  Data passed into a stream resource callback function.
struct
Sanitizer_SynchronizeData
  Data passed into a synchronization callback function.

#### Typedefs

typedef void(SANITIZERAPI* Sanitizer_CallbackFunc )( void* userdata, Sanitizer_CallbackDomain domain, Sanitizer_CallbackId cbid, const void* cbdata )
  Function type for a callback.
typedef uint32_t Sanitizer_CallbackId
  Callback ID.
typedef Sanitizer_Subscriber_st * Sanitizer_SubscriberHandle
  A callback subscriber.

#### Enumerations

enum Sanitizer_ApiCallbackSite
  Specifies the point in an API call that a callback is issued.
enum Sanitizer_BatchMemopType
  Specifies the type of batch memory operation.
enum Sanitizer_CallackIdSync
  Callback IDs for synchronization domain.
enum Sanitizer_CallbackDomain
  Callback domains.
enum Sanitizer_CallbackIdBatchMemop
  Callback IDs for batch memop domain.
enum Sanitizer_CallbackIdLaunch
  Callback IDs for launch domain.
enum Sanitizer_CallbackIdMemcpy
  Callback IDs for memcpy domain.
enum Sanitizer_CallbackIdMemset
  Callback IDs for memset domain.
enum Sanitizer_CallbackIdResource
  Callback IDs for resource domain.
enum Sanitizer_ResourceMemoryFlags
  Flags describing a memory allocation.

#### Functions

SanitizerResult sanitizerEnableAllDomains ( uint32_t enable, Sanitizer_SubscriberHandle subscriber )
  Enable or disable all callbacks in all domains.
SanitizerResult sanitizerEnableCallback ( uint32_t enable, Sanitizer_SubscriberHandle subscriber, Sanitizer_CallbackDomain domain, Sanitizer_CallbackId cbid )
  Enable or disable callbacks for a specific domain and callback ID.
SanitizerResult sanitizerEnableDomain ( uint32_t enable, Sanitizer_SubscriberHandle subscriber, Sanitizer_CallbackDomain domain )
  Enable or disable all callbacks for a specific domain.
SanitizerResult sanitizerGetCallbackState ( uint32_t* enable, Sanitizer_SubscriberHandle subscriber, Sanitizer_CallbackDomain domain, Sanitizer_CallbackId cbid )
  Get the current enabled/disabled state of a callback for a specific domain and function ID.
SanitizerResult sanitizerSubscribe ( Sanitizer_SubscriberHandle* subscriber, Sanitizer_CallbackFunc callback, void* userdata )
  Initialize a callback subscriber with a callback function and user data.
SanitizerResult sanitizerUnsubscribe ( Sanitizer_SubscriberHandle subscriber )
  Unregister a callback subscriber.

#### Variables

uint64_t Sanitizer_BatchMemopData::address
CUstream Sanitizer_BatchMemopData::stream
Sanitizer_BatchMemopType Sanitizer_BatchMemopData::type
uint64_t Sanitizer_BatchMemopData::value
CUcontext Sanitizer_CallbackData::context
const char * Sanitizer_CallbackData::functionName
const void * Sanitizer_CallbackData::functionParams
const void * Sanitizer_CallbackData::functionReturnValue
const char * Sanitizer_CallbackData::symbolName
CUfunction Sanitizer_LaunchData::function
const char * Sanitizer_LaunchData::functionName
uint32_t Sanitizer_LaunchData::gridDim_x
uint64_t Sanitizer_LaunchData::gridId
CUmodule Sanitizer_LaunchData::module
CUstream Sanitizer_LaunchData::stream
uint64_t Sanitizer_MemcpyData::dstAddress
CUcontext Sanitizer_MemcpyData::dstContext
uint32_t Sanitizer_MemcpyData::isAsync
uint64_t Sanitizer_MemcpyData::size
uint64_t Sanitizer_MemcpyData::srcAddress
uint64_t Sanitizer_MemsetData::address
uint32_t Sanitizer_MemsetData::isAsync
uint32_t Sanitizer_MemsetData::value
uint64_t Sanitizer_MemsetData::width
CUdevice Sanitizer_ResourceContextData::device
CUcontext Sanitizer_ResourceMemoryData::context
uint64_t Sanitizer_ResourceMemoryData::flags
uint64_t Sanitizer_ResourceMemoryData::size
size_t Sanitizer_ResourceModuleData::cubinSize
CUmodule Sanitizer_ResourceModuleData::module
const char * Sanitizer_ResourceModuleData::pCubin
CUstream Sanitizer_ResourceStreamData::stream
CUstream Sanitizer_SynchronizeData::stream

#### Typedefs

void(SANITIZERAPI* Sanitizer_CallbackFunc )( void* userdata, Sanitizer_CallbackDomain domain, Sanitizer_CallbackId cbid, const void* cbdata )

  Function type for a callback. Function type for a callback. The type of the data passed to the callback in `cbdata` depends on the domain. If `domain` is SANITIZER_CB_DOMAIN_DRIVER_API or SANITIZER_CB_DOMAIN_RUNTIME_API the type of `cbdata` will be Sanitizer_CallbackData. If `domain` is SANITIZER_CB_DOMAIN_RESOURCE the type of `cbdata` will be dependent on cbid. Refer to Sanitizer_ResourceContextData, Sanitizer_ResourceStreamData, Sanitizer_ResourceModuleData and Sanitizer_ResourceMemoryFlags documentations. If `domain` is SANITIZER_CB_DOMAIN_SYNCHRONIZE the type of `cbdata` will be Sanitizer_SynchronizeData. If `domain` is SANITIZER_CB_DOMAIN_LAUNCH the typf of `cbdata` will be Sanitizer_LaunchData. If `domain` is SANITIZER_CB_DOMAIN_MEMCPY the type of `cbdata` will be Sanitizer_MemcpyData. If `domain` is SANITIZER_CB_DOMAIN_MEMSET the type of `cbdata` will be Sanitizer_MemsetData. If `domain` is SANITIZER_CB_DOMAIN_BATCH_MEMOP the type of `cbdata` will be Sanitizer_BatchMemopData.

typedef uint32_t Sanitizer_CallbackId

  Callback ID.

typedef Sanitizer_Subscriber_st * Sanitizer_SubscriberHandle

  A callback subscriber.

#### Enumerations

enum Sanitizer_ApiCallbackSite

  Specifies the point in an API that a callback is issued. This value is communicated to the callback function via Sanitizer_CallbackData::CallbackSize.

  ###### Values

  SANITIZER_API_ENTER = 0
    This callback is at API entry.
  SANITIZER_API_EXIT = 1
    This callback is at API exit.
  SANITIZER_API_CBSITE_FORCE_INT = 0x7fffffff
enum Sanitizer_BatchMemopType

  Specifies the type of batch memory operation reported by a callback in domain SANITIZER_CB_DOMAIN_BATCH_MEMOP. This value is communicated to the callback function via Sanitizer_BatchMemopData::type.

  ###### Values

  SANITIZER_BATCH_MEMOP_TYPE_32B = 0
    Batch memory operation size is 32 bits.
  SANITIZER_BATCH_MEMOP_TYPE_64B = 1
    Batch memory operation size is 64 bits.
  SANITIZER_BATCH_MEMOP_TYPE_FORCE_INT = 0x7fffffff
enum Sanitizer_CallackIdSync

  Callback IDs for resource domain SANITIZER_CB_DOMAIN_SYNCHRONIZE. This value is communicated to the callback function via the `cbid` parameter.

  ###### Values

  SANITIZER_CBID_SYNCHRONIZE_INVALID = 0
    Invalid synchronize callback ID.
  SANITIZER_CBID_SYNCHRONIZE_STREAM_SYNCHRONIZED = 1
    Stream synchronization has completed for a given stream.
  SANITIZER_CBID_SYNCHRONIZE_CONTEXT_SYNCHRONIZED = 2
    Context synchronization has completed for a given context.
  SANITIZER_CBID_SYNCHRONIZE_SIZE
  SANITIZER_CBID_SYNCHRONIZE_FORCE_INT = 0x7fffffff
enum Sanitizer_CallbackDomain

  Callback domain. Each domain represents callback points for a group of related API functions or CUDA driver activity.

  ###### Values

  SANITIZER_CB_DOMAIN_INVALID = 0
    Invalid domain.
  SANITIZER_CB_DOMAIN_DRIVER_API = 1
    Domain containing callback points for all driver API functions.
  SANITIZER_CB_DOMAIN_RUNTIME_API = 2
    Domain containing callback points for all runtime API functions.
  SANITIZER_CB_DOMAIN_RESOURCE = 3
    Domain containing callback points for CUDA resource tracking.
  SANITIZER_CB_DOMAIN_SYNCHRONIZE = 4
    Domain containing callback points for CUDA synchronization.
  SANITIZER_CB_DOMAIN_LAUNCH = 5
    Domain containing callback points for CUDA grid launches.
  SANITIZER_CB_DOMAIN_MEMCPY = 6
    Domain containing callback points for CUDA memcpy operations.
  SANITIZER_CB_DOMAIN_MEMSET = 7
    Domain containing callback points for CUDA memset operations.
  SANITIZER_CB_DOMAIN_BATCH_MEMOP = 8
    Domain containing callback points for CUDA batch memop operations.
  SANITIZER_CB_DOMAIN_SIZE
  SANITIZER_CB_DOMAIN_FORCE_INT = 0x7fffffff
enum Sanitizer_CallbackIdBatchMemop

  Callback IDs for resource domain SANITIZER_CB_DOMAIN_BATCH_MEMOP. This value is communicated to the callback function via the `cbid` parameter.

  ###### Values

  SANITIZER_CBID_BATCH_MEMOP_INVALID = 0
    Invalid batch memop callback ID.
  SANITIZER_CBID_BATCH_MEMOP_WRITE = 1
    A batch memory operation was initiated.
  SANITIZER_CBID_BATCH_MEMOP_SIZE
  SANITIZER_CBID_BATCH_MEMOP_FORCE_INT = 0x7fffffff
enum Sanitizer_CallbackIdLaunch

  Callback IDs for resource domain SANITIZER_CB_DOMAIN_LAUNCH. This value is communicated to the callback function via the `cbid` parameter.

  ###### Values

  SANITIZER_CBID_LAUNCH_INVALID = 0
    Invalid launch callback ID.
  SANITIZER_CBID_LAUNCH_BEGIN = 1
    A grid launch was initiated.
  SANITIZER_CBID_LAUNCH_END = 2
    The grid launch is complete.
  SANITIZER_CBID_LAUNCH_SIZE
  SANITIZER_CBID_LAUNCH_FORCE_INT = 0x7fffffff
enum Sanitizer_CallbackIdMemcpy

  Callback IDs for resource domain SANITIZER_CB_DOMAIN_MEMCPY. This value is communicated to the callback function via the `cbid` parameter.

  ###### Values

  SANITIZER_CBID_MEMCPY_INVALID = 0
    Invalid memcpy callback ID.
  SANITIZER_CBID_MEMCPY_STARTING = 1
    A memcpy operation was initiated.
  SANITIZER_CBID_MEMCPY_SIZE
  SANITIZER_CBID_MEMCPY_FORCE_INT = 0x7fffffff
enum Sanitizer_CallbackIdMemset

  Callback IDs for resource domain SANITIZER_CB_DOMAIN_MEMSET. This value is communicated to the callback function via the `cbid` parameter.

  ###### Values

  SANITIZER_CBID_MEMSET_INVALID = 0
    Invalid memset callback ID.
  SANITIZER_CBID_MEMSET_STARTING = 1
    A memset operation was initiated.
  SANITIZER_CBID_MEMSET_SIZE
  SANITIZER_CBID_MEMSET_FORCE_INT = 0x7fffffff
enum Sanitizer_CallbackIdResource

  Callback IDs for resource domain SANITIZER_CB_DOMAIN_RESOURCE. This value is communicated to the callback function via the `cbid` parameter.

  ###### Values

  SANITIZER_CBID_RESOURCE_INVALID = 0
    Invalid resource callback ID.
  SANITIZER_CBID_RESOURCE_INIT_FINISHED = 1
    Driver initialization is finished.
  SANITIZER_CBID_RESOURCE_CONTEXT_CREATION_STARTING = 2
    A new context is about to be created.
  SANITIZER_CBID_RESOURCE_CONTEXT_CREATION_FINISHED = 3
    A new context was created.
  SANITIZER_CBID_RESOURCE_CONTEXT_DESTROY_STARTING = 4
    A context is about to be destroyed.
  SANITIZER_CBID_RESOURCE_CONTEXT_DESTROY_FINISHED = 5
    A context was destroyed.
  SANITIZER_CBID_RESOURCE_STREAM_CREATED = 6
    A new stream was created.
  SANITIZER_CBID_RESOURCE_STREAM_DESTROY_STARTING = 7
    A stream is about to be destroyed.
  SANITIZER_CBID_RESOURCE_MODULE_LOADED = 8
    A module was loaded.
  SANITIZER_CBID_RESOURCE_MODULE_UNLOAD_STARTING = 9
    A module is about to be unloaded.
  SANITIZER_CBID_RESOURCE_DEVICE_MEMORY_ALLOC = 10
    Device memory was allocated.
  SANITIZER_CBID_RESOURCE_DEVICE_MEMORY_FREE = 11
    Device memory was freed.
  SANITIZER_CBID_RESOURCE_HOST_MEMORY_ALLOC = 12
    Pinned host memory was allocated.
  SANITIZER_CBID_RESOURCE_HOST_MEMORY_FREE = 13
    Pinned host memory was freed.
  SANITIZER_CBID_RESOURCE_SIZE
  SANITIZER_CBID_RESOURCE_FORCE_INT = 0x7fffffff
enum Sanitizer_ResourceMemoryFlags

  Flags describing a memory allocation. These values are to be used in order to interpret the value of Sanitizer_ResourceMemoryData::flags

  ###### Values

  SANITIZER_MEMORY_FLAG_NONE = 0
    Empty flag.
  SANITIZER_MEMORY_FLAG_MODULE = 0x1
    Specifies that the allocation is static scoped to a module.
  SANITIZER_MEMORY_FLAG_MANAGED = 0x2
    Specifies that the allocation is managed memory.
  SANITIZER_MEMORY_FLAG_HOST_MAPPED = 0x4
    Species that the allocation accessible from the host.
  SANITIZER_MEMORY_FLAG_HOST_PINNED = 0x8
    Specifies that the allocation is pinned on the host.
  SANITIZER_MEMORY_FLAG_PEER = 0x10
    Specifies that the allocation is located on a peer GPU.
  SANITIZER_MEMORY_FLAG_PEER_ATOMIC = 0x20
    Specifies that the allocation is located on a peer GPU supporting native atomics. This implies that SANITIZER_MEMORY_FLAG_PEER is set as well.
  SANITIZER_MEMORY_FLAG_FORCE_INT = 0x7fffffff

#### Functions

SanitizerResult sanitizerEnableAllDomains ( uint32_t enable, Sanitizer_SubscriberHandle subscriber )
  Enable or disable all callbacks in all domains.

  ###### Parameters

  `enable`
    New enable state for all callbacks in all domains. Zero disables all callbacks, non-zero enables all callbacks.
  `subscriber`
    - Handle of the initialized subscriber

  ###### Returns

  - SANITIZER_SUCCESS

    on success

  - SANITIZER_ERROR_NOT_INITIALIZED

    if unable to initialize the sanitizer

  - SANITIZER_ERROR_INVALID_PARAMETER

    if `subscriber` is invalid

  ###### Description

  Enable or disable all callbacks in all domains.

  Note:

  Thread-safety: a subscriber must serialize access to sanitizerGetCallbackState, sanitizerEnableCallback, sanitizerEnableDomain, and sanitizerEnableAllDomains. For example, if sanitizerGetCallbackState(sub, d, *) and sanitizerEnableAllDomains(sub) are called concurrently, the results are undefined.

SanitizerResult sanitizerEnableCallback ( uint32_t enable, Sanitizer_SubscriberHandle subscriber, Sanitizer_CallbackDomain domain, Sanitizer_CallbackId cbid )
  Enable or disable callbacks for a specific domain and callback ID.

  ###### Parameters

  `enable`
    New enable state for the callback. Zero disables the callback, non-zero enables the callback
  `subscriber`
    - Handle of the initialized subscriber
  `domain`
    The domain of the callback
  `cbid`
    The ID of the callback

  ###### Returns

  - SANITIZER_SUCCESS

    on success

  - SANITIZER_ERROR_NOT_INITIALIZED

    if unable to initialize the sanitizer

  - SANITIZER_ERROR_INVALID_PARAMETER

    if `subscriber`, `domain` or `cbid` is invalid

  ###### Description

  Enable or disable callbacks for a subscriber for a specific domain and callback ID.

  Note:

  Thread-safety: a subscriber must serialize access to sanitizerGetCallbackState, sanitizerEnableCallback, sanitizerEnableDomain, and sanitizerEnableAllDomains. For example, if sanitizerGetCallbackState(sub, d, c) and sanitizerEnableCallback(sub, d, c) are called concurrently, the results are undefined.

SanitizerResult sanitizerEnableDomain ( uint32_t enable, Sanitizer_SubscriberHandle subscriber, Sanitizer_CallbackDomain domain )
  Enable or disable all callbacks for a specific domain.

  ###### Parameters

  `enable`
    New enable state for all callbacks in the domain. Zero disables all callbacks, non-zero enables all callbacks
  `subscriber`
    - Handle of the initialized subscriber
  `domain`
    The domain of the callback

  ###### Returns

  - SANITIZER_SUCCESS

    on success

  - SANITIZER_ERROR_NOT_INITIALIZED

    if unable to initialize the sanitizer

  - SANITIZER_ERROR_INVALID_PARAMETER

    if `subscriber` or `domain` is invalid

  ###### Description

  Enable or disable all callbacks for a specific domain.

  Note:

  Thread-safety: a subscriber must serialize access to sanitizerGetCallbackState, sanitizerEnableCallback, sanitizerEnableDomain, and sanitizerEnableAllDomains. For example, if sanitizerGetCallbackEnabled(sub, d, *) and sanitizerEnableDomain(sub, d) are called concurrently, the results are undefined.

SanitizerResult sanitizerGetCallbackState ( uint32_t* enable, Sanitizer_SubscriberHandle subscriber, Sanitizer_CallbackDomain domain, Sanitizer_CallbackId cbid )
  Get the current enabled/disabled state of a callback for a specific domain and function ID.

  ###### Parameters

  `enable`
    Returns non-zero if callback enabled, zero if not enabled
  `subscriber`
    Handle to the initialized subscriber
  `domain`
    The domain of the callback
  `cbid`
    The ID of the callback

  ###### Returns

  - SANITIZER_SUCCESS

    on success

  - SANITIZER_ERROR_NOT_INITIALIZED

    if unable to initialize the sanitizer

  - SANITIZER_ERROR_INVALID_PARAMETER

    if `enabled` is NULL, or if `subscriber`, `domain` or `cbid` is invalid.

  ###### Description

  Returns non-zero in `*enable` if the callback for a domain and callback ID is enabled, and zero if not enabled.

  Note:

  Thread-safety: a subscriber must serialize access to sanitizerGetCallbackState, sanitizerEnableCallback, sanitizerEnableDomain, and sanitizerEnableAllDomains. For example, if sanitizerGetCallbackState(sub, d, c) and sanitizerEnableCallback(sub, d, c) are called concurrently, the results are undefined.

SanitizerResult sanitizerSubscribe ( Sanitizer_SubscriberHandle* subscriber, Sanitizer_CallbackFunc callback, void* userdata )
  Initialize a callback subscriber with a callback function and user data.

  ###### Parameters

  `subscriber`
    Returns handle to initialize subscriber
  `callback`
    The callback function
  `userdata`
    A pointer to user data. This data will be passed to the callback function via the `userdata` parameter

  ###### Returns

  - SANITIZER_SUCCESS

    on success

  - SANITIZER_ERROR_NOT_INITIALIZED

    if unable to initialize the sanitizer

  - SANITIZER_ERROR_MAX_LIMIT_RACHED

    if there is already a sanitizer subscriber

  - SANITIZER_ERROR_INVALID_PARAMETER

    if `subscriber` is NULL

  ###### Description

  Initialize a callback subscriber with a callback function and (optionally) a pointer to user data. The returned subscriber handle can be used to enable and disable the callback for specific domains and callback IDs.

  Note:

  - Only one subscriber can be registered at a time.

  - This function does not enable any callbacks.

  - Thread-safety: this function is thread safe.

SanitizerResult sanitizerUnsubscribe ( Sanitizer_SubscriberHandle subscriber )
  Unregister a callback subscriber.

  ###### Parameters

  `subscriber`
    Handle to the initialized subscriber

  ###### Returns

  - SANITIZER_SUCCESS

    on success

  - SANITIZER_ERROR_NOT_INITIALIZED

    if unable to initialize the sanitizer

  - SANITIZER_ERROR_INVALID_PARAMETER

    if `subscriber` is NULL or not initialized

  ###### Description

  Removes a callback subscriber so that no future callback will be issued to that subscriber.

  Note:

  Thread-safety: this function is thread safe.

#### Variables

uint64_t Sanitizer_BatchMemopData::address

  The address to be written.

CUstream Sanitizer_BatchMemopData::stream

  The stream where the batch memop is executed.

Sanitizer_BatchMemopType Sanitizer_BatchMemopData::type

  Type of batch memory operation.

uint64_t Sanitizer_BatchMemopData::value

  The value to be written.

CUcontext Sanitizer_CallbackData::context

  Driver context current to the thread, or null if no context is current. This value can change from the entry to exit callback of a runtime API function if the runtime initialized a context.

const char * Sanitizer_CallbackData::functionName

  Name of the runtime or driver API function which issued the callback. This string is a global constant and so may be accessed outside of the callback.

const void * Sanitizer_CallbackData::functionParams

  Pointer to the arguments passed to the runtime or driver API call. See generated_cuda_runtime_api_meta.h and generated_cuda_meta.h for structure definitions for the parameters for each runtime and driver API function.

const void * Sanitizer_CallbackData::functionReturnValue

  Pointer to the return value of the runtime or driver API call. This field is only valid within the SANITIZER_API_EXIT callback. For a runtime API `functionReturnValue` points to a `cudaError_t`. For a driver API `functionReturnValue` points to a `CUresult`.

const char * Sanitizer_CallbackData::symbolName

  Name of the symbol operated on by the runtime or driver API function which issued the callback. This entry is valid only for driver and runtime launch callbacks, where it returns the name of the kernel.

CUfunction Sanitizer_LaunchData::function

  The function of the grid launch.

const char * Sanitizer_LaunchData::functionName

  The name of the launched function.

uint32_t Sanitizer_LaunchData::gridDim_x

  Launch properties of the grid. These values are only valid for SANITIZER_CBID_LAUNCH_BEGIN callback

uint64_t Sanitizer_LaunchData::gridId

  Unique identifier of the grid launch.

CUmodule Sanitizer_LaunchData::module

  The module containing the grid code.

CUstream Sanitizer_LaunchData::stream

  The stream where the grid is launched.

uint64_t Sanitizer_MemcpyData::dstAddress

  The destination allocation address.

CUcontext Sanitizer_MemcpyData::dstContext

  The context where the destination allocation is located

uint32_t Sanitizer_MemcpyData::isAsync

  Boolean value indicating if the transfer is asynchronous.

uint64_t Sanitizer_MemcpyData::size

  Size of the transfer in bytes.

uint64_t Sanitizer_MemcpyData::srcAddress

  The source allocation address.

uint64_t Sanitizer_MemsetData::address

  The address of the memset start.

uint32_t Sanitizer_MemsetData::isAsync

  Boolean value indicating if the transfer is asynchronous.

uint32_t Sanitizer_MemsetData::value

  Value to be written.

uint64_t Sanitizer_MemsetData::width

  Memset size configuration.

CUdevice Sanitizer_ResourceContextData::device

  The device on which the context is being created or destroyed. This field is only valid for SANITIZER_CBID_RESOURCE_CONTEXT_CREATION_* callbacks

CUcontext Sanitizer_ResourceMemoryData::context

  Context containing the allocation being created or destroyed.

uint64_t Sanitizer_ResourceMemoryData::flags

  Allocation details: use Sanitizer_ResourceMemoryFlags to interpret this field.

uint64_t Sanitizer_ResourceMemoryData::size

  Size of the allocation being created or destroyed.

size_t Sanitizer_ResourceModuleData::cubinSize

  The size of the cubin.

CUmodule Sanitizer_ResourceModuleData::module

  The module being loaded or unloaded.

const char * Sanitizer_ResourceModuleData::pCubin

  Pointer to the associated cubin.

CUstream Sanitizer_ResourceStreamData::stream

  The stream being created or destroyed.

CUstream Sanitizer_SynchronizeData::stream

  This field is only valid for SANITIZER_CBID_SYNCHRONIZE_STREAM_SYNCHRONIZED. This is the stream being synchronized.

### 1.2. Sanitizer Memory API

Functions, types, and enums that implement the Sanitizer Memory API.

#### Functions

SanitizerResult sanitizerAlloc ( void** devPtr, size_t size )
  Allocate memory on the device.
SanitizerResult sanitizerFree ( void* devPtr )
  Frees memory on the device.
SanitizerResult sanitizerMemcpyDeviceToHost ( void* dst, void* src, size_t count, CUstream stream )
  Copies data from device to host.
SanitizerResult sanitizerMemcpyHostToDeviceAsync ( void* dst, void* src, size_t count, CUstream stream )
  Copies data from host to device.
SanitizerResult sanitizerMemset ( void* devPtr, int value, size_t count, CUstream stream )
  Initializes or sets device memory to a value.

#### Functions

SanitizerResult sanitizerAlloc ( void** devPtr, size_t size )
  Allocate memory on the device.

  ###### Parameters

  `devPtr`
    Pointer to allocated device memory
  `size`
    Allocation size in bytes

  ###### Description

  Equivalent of cudaMalloc that can be called within a callback function.

  Note:

  Thread-safety: this function is thread safe.

SanitizerResult sanitizerFree ( void* devPtr )
  Frees memory on the device.

  ###### Parameters

  `devPtr`
    Device pointer to memory to free

  ###### Description

  Equivalent of cudaFree that can be called within a callback function.

  Note:

  Thread-safety: this function is thread safe.

SanitizerResult sanitizerMemcpyDeviceToHost ( void* dst, void* src, size_t count, CUstream stream )
  Copies data from device to host.

  ###### Parameters

  `dst`
    Destination memory address
  `src`
    Source memory address
  `count`
    Size in bytes to copy
  `stream`
    Stream identifier

  ###### Description

  Equivalent of cudaMemcpy that can be called within a callback function. The function will return once the copy has completed.

  Note:

  Thread-safety: this function is thread safe.

SanitizerResult sanitizerMemcpyHostToDeviceAsync ( void* dst, void* src, size_t count, CUstream stream )
  Copies data from host to device.

  ###### Parameters

  `dst`
    Destination memory address
  `src`
    Source memory address
  `count`
    Size in bytes to copy
  `stream`
    Stream identifier

  ###### Description

  Equivalent of cudaMemcpyAsync that can be called within a callback function. The function will return once the pageable buffer has been copied to the staging memory for DMA transfer to device memory, but the DMA to final destination may not have completed.

  Note:

  Thread-safety: this function is thread safe.

SanitizerResult sanitizerMemset ( void* devPtr, int value, size_t count, CUstream stream )
  Initializes or sets device memory to a value.

  ###### Parameters

  `devPtr`
    Pointer to device memory
  `value`
    value to set for each byte of specified memory
  `count`
    Size in bytes to set
  `stream`
    Stream identifier

  ###### Description

  Equivalent of cudaMemset that can be called within a callback function.

  Note:

  Thread-safety: this function is thread safe.

### 1.3. Sanitizer Patching API

Functions, types, and enums that implement the Sanitizer Patching API.

#### Typedefs

typedef SanitizerPatchResult* ( *SanitizerCallbackBarrier )( void* userdata, uint64_t pc, uint32_t barIndex )
  Function type for a barrier callback.
typedef SanitizerPatchResult* ( *SanitizerCallbackBlockEnter )( void* userdata )
  Function type for a CUDA block enter callback.
typedef SanitizerPatchResult* ( *SanitizerCallbackBlockExit )( void* userdata, uint64_t pc )
  Function type for a CUDA block exit callback.
typedef SanitizerPatchResult* ( *SanitizerCallbackCall )( void* userdata, uint64_t pc, uint64_t targetPc )
  Function type for a function call callback.
typedef SanitizerPatchResult* ( *SanitizerCallbackDeviceSideFree )( void* userdata, uint64_t pc, void* ptr )
  Function type for a device-side free call.
typedef SanitizerPatchResult* ( *SanitizerCallbackDeviceSideMalloc )( void* userdata, uint64_t pc, void* allocatedPtr, uint64_t allocatedSize )
  Function type for a device-side malloc call.
typedef SanitizerPatchResult* ( *SanitizerCallbackMemoryAccess )( void* userdata, uint64_t pc, void* ptr, uint32_t accessSize, uint32_t flags )
  Function type for a memory access callback.
typedef SanitizerPatchResult* ( *SanitizerCallbackRet )( void* userdata, uint64_t pc )
  Function type for a function return callback.
typedef SanitizerPatchResult* ( *SanitizerCallbackShfl )( void* userdata, uint64_t pc )
  Function type for a shfl callback.
typedef SanitizerPatchResult* ( *SanitizerCallbackSyncwarp )( void* userdata, uint64_t pc, uint32_t mask )
  Function type for a syncwarp callback.

#### Enumerations

enum SanitizerPatchResult
  Sanitizer patch result codes.
enum Sanitizer_DeviceMemoryFlags
  Flags describing a memory access.
enum Sanitizer_InstructionId
  Instrumentation.

#### Functions

SanitizerResult sanitizerAddPatches ( const void* image, CUcontext ctx )
  Load a module containing patches that can be used by the patching API.
SanitizerResult sanitizerAddPatchesFromFile ( const char* filename, CUcontext ctx )
  Load a module containing patches that can be used by the patching API.
SanitizerResult sanitizerPatchInstructions ( const Sanitizer_InstructionId instructionId, CUmodule module, const char* deviceCallbackName )
  Set instrumentation points and patches to be applied in a module.
SanitizerResult sanitizerPatchModule ( CUmodule module )
  Perform the actual instrumentation of a module.
SanitizerResult sanitizerSetCallbackData ( CUstream stream, const void* userdata )
  Specifies the user data pointer for callbacks.
SanitizerResult sanitizerUnpatchModule ( CUmodule module )
  Remove existing instrumentation of a module.

#### Typedefs

SanitizerPatchResult* ( *SanitizerCallbackBarrier )( void* userdata, uint64_t pc, uint32_t barIndex )

  Function type for a barrier callback. `userdata` is a pointer to user data. See sanitizerPatchModule `pc` is the program counter of the patched instruction `barIndex` is the barrier index.

SanitizerPatchResult* ( *SanitizerCallbackBlockEnter )( void* userdata )

  Function type for a CUDA block enter callback. `userdata` is a pointer to user data. See sanitizerPatchModule

SanitizerPatchResult* ( *SanitizerCallbackBlockExit )( void* userdata, uint64_t pc )

  Function type for a CUDA block exit callback. `userdata` is a pointer to user data. See sanitizerPatchModule `pc` is the program counter of the patched instruction

SanitizerPatchResult* ( *SanitizerCallbackCall )( void* userdata, uint64_t pc, uint64_t targetPc )

  Function type for a function call callback. `userdata` is a pointer to user data. See sanitizerPatchModule `pc` is the program counter of the patched instruction `targetPc` is the PC where the called function is located.

SanitizerPatchResult* ( *SanitizerCallbackDeviceSideFree )( void* userdata, uint64_t pc, void* ptr )

  Function type for a device-side free call.

  Note:

  This is called prior to the actual call.

  `userdata` is a pointer to user data. See sanitizerPatchModule `pc` is the program counter of the patched instruction `ptr` is the pointer passed to device-side free.

SanitizerPatchResult* ( *SanitizerCallbackDeviceSideMalloc )( void* userdata, uint64_t pc, void* allocatedPtr, uint64_t allocatedSize )

  Function type for a device-side malloc call.

  Note:

  This is called after the call has completed.

  `userdata` is a pointer to user data. See sanitizerPatchModule `pc` is the program counter of the patched instruction `allocatedPtr` is the pointer returned by device-side malloc `allocatedSize` is the size requested by the user to device-side malloc.

SanitizerPatchResult* ( *SanitizerCallbackMemoryAccess )( void* userdata, uint64_t pc, void* ptr, uint32_t accessSize, uint32_t flags )

  Function type for a memory access callback. `userdata` is a pointer to user data. See sanitizerPatchModule `pc` is the program counter of the patched instruction `ptr` is the address of the memory being accessed `accessSize` is the size of the access in bytes. Valid values are 1, 2, 4, 8, and 16. `flags` contains information about the type of access. See Sanitizer_DeviceMemoryFlags to interpret this value.

SanitizerPatchResult* ( *SanitizerCallbackRet )( void* userdata, uint64_t pc )

  Function type for a function return callback. `userdata` is a pointer to user data. See sanitizerPatchModule `pc` is the program counter of the patched instruction

SanitizerPatchResult* ( *SanitizerCallbackShfl )( void* userdata, uint64_t pc )

  Function type for a shfl callback. `userdata` is a pointer to user data. See sanitizerPatchModule `pc` is the program counter of the patched instruction

SanitizerPatchResult* ( *SanitizerCallbackSyncwarp )( void* userdata, uint64_t pc, uint32_t mask )

  Function type for a syncwarp callback. `userdata` is a pointer to user data. See sanitizerPatchModule `pc` is the program counter of the patched instruction `mask` is the thread mask passed to __syncwarp().

#### Enumerations

enum SanitizerPatchResult

  Error and result codes returned by Sanitizer patches. If a patch returns with an error code different than SANITIZER_PATCH_SUCCESS, the thread will be exited.

  ###### Values

  SANITIZER_PATCH_SUCCESS = 0
    No error.
  SANITIZER_PATCH_INVALID_MEMORY_ACCESS = 1
    An invalid memory access was performed.
  SANITIZER_PATCH_INVALID_SYNCHRONIZATION = 2
    An invalid synchronization operation was performed.
  SANITIZER_PATCH_FORCE_INT = 0x7fffffff
enum Sanitizer_DeviceMemoryFlags

  Flags describing a memory access. These values are to be used in order to interpret the value of flags for a SanitizerCallbackMemoryAccess callback.

  If neither LOCAL or SHARED flag is set, the access is made to global memory.

  ###### Values

  SANITIZER_MEMORY_DEVICE_FLAG_NONE = 0
    Empty flag.
  SANITIZER_MEMORY_DEVICE_FLAG_READ = 0x1
    Specifies that the access is a read.
  SANITIZER_MEMORY_DEVICE_FLAG_WRITE = 0x2
    Specifies that the access is a write.
  SANITIZER_MEMORY_DEVICE_FLAG_ATOMSYS = 0x4
    Specifies that the access is a system-scoped atomic.
  SANITIZER_MEMORY_DEVICE_FLAG_LOCAL = 0x8
    Specifies that the memory accessed is local memory.
  SANITIZER_MEMORY_DEVICE_FLAG_SHARED = 0x10
    Specifies that the memory accessed is shared memory.
  SANITIZER_MEMORY_DEVICE_FLAG_FORCE_INT = 0x7fffffff
enum Sanitizer_InstructionId

  Instrumentation. Every entry represent an instruction type or a function call where a callback patch can be inserted.

  ###### Values

  SANITIZER_INSTRUCTION_INVALID = 0
    Invalid instruction ID.
  SANITIZER_INSTRUCTION_BLOCK_ENTER = 1
    CUDA block enter. This is called prior to any user code. The type of the callback must be SanitizerCallbackBlockEnter.
  SANITIZER_INSTRUCTION_BLOCK_EXIT = 2
    CUDA block exit. This is called after all user code has executed. The type of the callback must be SanitizerCallbackBlockExit.
  SANITIZER_INSTRUCTION_MEMORY_ACCESS = 3
    Memory Access. This can be a store, load or atomic operation. The type of the callback must be SanitizerCallbackMemoryAccess.
  SANITIZER_INSTRUCTION_BARRIER = 4
    Barrier. The type of the callback must be SanitizerCallbackBarrier.
  SANITIZER_INSTRUCTION_SYNCWARP = 5
    Syncwarp. The type of the callback must be SanitizerCallbackSyncwarp.
  SANITIZER_INSTRUCTION_SHFL = 6
    Shfl. The type of the callback must be SanitizerCallbackShfl.
  SANITIZER_INSTRUCTION_CALL = 7
    Function call. The type of the callback must be SanitizerCallbackCall.
  SANITIZER_INSTRUCTION_RET = 8
    Function return. The type of the callback must be SanitizerCallbackRet.
  SANITIZER_INSTRUCTION_DEVICE_SIDE_MALLOC = 9
    Device-side malloc. The type of the callback must be SanitizerCallbackDeviceSideMalloc.
  SANITIZER_INSTRUCTION_DEVICE_SIDE_FREE = 10
    Device-side free. The type of the callback must be SanitizerCallbackDeviceSideFree.
  SANITIZER_INSTRUCTION_FORCE_INT = 0x7fffffff

#### Functions

SanitizerResult sanitizerAddPatches ( const void* image, CUcontext ctx )
  Load a module containing patches that can be used by the patching API.

  ###### Parameters

  `image`
    Pointer to module data to load. This API supports the same module formats as the cuModuleLoadData and cuModuleLoadFatBinary functions from the CUDA driver API.
  `ctx`
    CUDA context in which to load the patches. If ctx is NULL, the current context will be used.

  ###### Returns

  - SANITIZER_SUCCESS

    on success

  - SANITIZER_ERROR_NOT_INITIALIZED

    if unable to initialize the sanitizer

  - SANITIZER_ERROR_INVALID_PARAMETER

    if `image` does not point to a valid CUDA module.

  ###### Description

  Note:

  - Thread-safety: an API user must serialize access to sanitizerAddPatchesFromFile, sanitizerAddPatches, sanitizerPatchInstructions, and sanitizerPatchModule. For example if sanitizerAddPatches(image) and sanitizerPatchInstruction(*, *, cbName) are called concurrently and cbName is intended to be found in the loaded image, the results are undefined.

  - The patches loaded are only valid for the specified CUDA context.

SanitizerResult sanitizerAddPatchesFromFile ( const char* filename, CUcontext ctx )
  Load a module containing patches that can be used by the patching API.

  ###### Parameters

  `filename`
    Path to the module file. This API supports the same module formats as the cuModuleLoad function from the CUDA driver API.
  `ctx`
    CUDA context in which to load the patches. If ctx is NULL, the current context will be used.

  ###### Returns

  - SANITIZER_SUCCESS

    on success

  - SANITIZER_ERROR_NOT_INITIALIZED

    if unable to initialize the sanitizer

  - SANITIZER_ERROR_INVALID_PARAMETER

    if `filename` is not a path to a valid CUDA module.

  ###### Description

  Note:

  - Thread-safety: an API user must serialize access to sanitizerAddPatchesFromFile, sanitizerAddPatches, sanitizerPatchInstructions, and sanitizerPatchModule. For example if sanitizerAddPatchesFromFile(filename) and sanitizerPatchInstruction(*, *, cbName) are called concurrently and cbName is intended to be found in the loaded module, the results are undefined.

  - The patches loaded are only valid for the specified CUDA context.

SanitizerResult sanitizerPatchInstructions ( const Sanitizer_InstructionId instructionId, CUmodule module, const char* deviceCallbackName )
  Set instrumentation points and patches to be applied in a module.

  ###### Parameters

  `instructionId`
    Instrumentation point for which to insert patches
  `module`
    CUDA module to instrument
  `deviceCallbackName`
    Name of the device function callback that the inserted patch will call at the instrumented points. This function is expected to be found in code previously loaded by sanitizerAddPatchesFromFile or sanitizerAddPatches.

  ###### Returns

  - SANITIZER_SUCCESS

    on success

  - SANITIZER_ERROR_NOT_INITIALIZED

    if unable to initialize the sanitizer

  - SANITIZER_ERROR_INVALID_PARAMETER

    if `module` is not a CUDA module or if `deviceCallbackName` function cannot be located.

  ###### Description

  Mark that all instrumentation points matching instructionId are to be patched in order to call the device function identified by deviceCallbackName. It is up to the API client to ensure that this device callback exists and match the correct callback format for this instrumentation point.

  Note:

  Thread-safety: an API user must serialize access to sanitizerAddPatchesFromFile, sanitizerAddPatches, sanitizerPatchInstructions, and sanitizerPatchModule. For example if sanitizerAddPatches(fileName) and sanitizerPatchInstruction(*, *, cbName) are called concurrently and cbName is intended to be found in the loaded module, the results are undefined.

SanitizerResult sanitizerPatchModule ( CUmodule module )
  Perform the actual instrumentation of a module.

  ###### Parameters

  `module`
    CUDA module to instrument

  ###### Returns

  - SANITIZER_SUCCESS

    on success

  - SANITIZER_ERROR_INVALID_PARAMETER

    if `module` is not a CUDA module

  ###### Description

  Perform the instrumentation of a CUDA module based on previous calls to sanitizerPatchInstructions. This function also specifies the device memory buffer to be passed in as userdata to all callback functions.

  Note:

  Thread-safety: an API user must serialize access to sanitizerAddPatchesFromFile, sanitizerAddPatches, sanitizerPatchInstructions, and sanitizerPatchModule. For example if sanitizerPatchModule(mod, *) and sanitizerPatchInstruction(*, mod, *) are called concurrently, the results are undefined.

SanitizerResult sanitizerSetCallbackData ( CUstream stream, const void* userdata )
  Specifies the user data pointer for callbacks.

  ###### Parameters

  `stream`
    CUDA stream to link to user data. Callbacks in subsequent launches on this stream will use `userdata` as callback data. Can be 0 to specify the NULL stream.
  `userdata`
    Device memory buffer. This data will be passed to callback functions via the `userdata` parameter.

  ###### Returns

  - SANITIZER_SUCCESS

    on success

  - SANITIZER_ERROR_INVALID_PARAMETER

    if `stream` is not a CUDA stream

  ###### Description

  Mark all subsequent launches on `stream` to use `userdata` pointer as the device memory buffer to pass in to callback functions.

  Note:

  Thread-safety: an API user must serialize access to sanitizerSetCallbackData and kernel launches on the same stream.

SanitizerResult sanitizerUnpatchModule ( CUmodule module )
  Remove existing instrumentation of a module.

  ###### Parameters

  `module`
    CUDA module on which to remove instrumentation

  ###### Returns

  - SANITIZER_SUCCESS

    on success

  ###### Description

  Remove any instrumentation of a CUDA module performed by previous calls to sanitizerPatchModule.

  Note:

  Thread-safety: an API user must serialize access to sanitizerPatchModule and sanitizerUnpatchModule on the same module. For example, if sanitizerPatchModule(mod) and sanitizerUnpatchModule(mod) are called concurrently, the results are undefined.

### 1.4. Sanitizer Result Codes

Error and result codes returned by Sanitizer functions.

#### Enumerations

enum SanitizerResult
  Sanitizer result codes.

#### Functions

SanitizerResult sanitizerGetResultString ( SanitizerResult result, const char** str )

#### Enumerations

enum SanitizerResult

  Error and result codes returned by Sanitizer functions.

  ###### Values

  SANITIZER_SUCCESS = 0
    No error.
  SANITIZER_ERROR_INVALID_PARAMETER = 1
    One or more of the parameters is invalid.
  SANITIZER_ERROR_INVALID_DEVICE = 2
    The device does not correspond to a valid CUDA device.
  SANITIZER_ERROR_INVALID_CONTEXT = 3
    The context is NULL or not valid.
  SANITIZER_ERROR_INVALID_DOMAIN_ID = 4
    The domain ID is invalid.
  SANITIZER_ERROR_INVALID_CALLBACK_ID = 5
    The callback ID is invalid.
  SANITIZER_ERROR_INVALID_OPERATION = 6
    The current operation cannot be performed due to dependency on other factors.
  SANITIZER_ERROR_OUT_OF_MEMORY = 7
    Unable to allocate enough memory to perform the requested operation.
  SANITIZER_ERROR_PARAMETER_SIZE_NOT_SUFFICIENT = 8
    The output buffer size is not sufficient to return all requested data.
  SANITIZER_ERROR_API_NOT_IMPLEMENTED = 9
    API is not implemented.
  SANITIZER_ERROR_MAX_LIMIT_REACHED = 10
    The maximum limit is reached.
  SANITIZER_ERROR_NOT_READY = 11
    The object is not ready to perform the requested operation.
  SANITIZER_ERROR_NOT_COMPATIBLE = 12
    The current operation is not compatible with the current state of the object.
  SANITIZER_ERROR_NOT_INITIALIZED = 13
    Sanitizer is unable to initialize its connection to the CUDA driver.
  SANITIZER_ERROR_NOT_SUPPORTED = 14
    The attempted operation is not supported on the current system or device
  SANITIZER_ERROR_UNKNOWN = 999
    An unknown internal error has occurred.
  SANITIZER_ERROR_FORCE_INT = 0x7fffffff

#### Functions

SanitizerResult sanitizerGetResultString ( SanitizerResult result, const char** str )

  ###### Parameters

  `result`
    The result to get the string for
  `str`
    Returns the string

  ###### Returns

  - SANITIZER_SUCCESS

    on success

  - SANITIZER_ERROR_INVALID_PARAMETER

    if `str` is NULL or `result` is not a valid SanitizerResult.

  ###### Description

  Get the descriptive string for a SanitizerResult.

  Return the descriptive string for a SanitizerResult in `*str`.

  Note:

  Thread-safety: this function is thread-safe.