CUDASafety-1.1

Do not use CUDA callbacks

Required inputs: IR

CUDA SAFETY 1.1 [safety.cuda.callback] Do not use CUDA callbacks

CUDA callbacks are not a part of the safety subset.

Scope: Host.
Audience: CUDA C++, CUDA Libraries.
Category: Mandatory.
Hardware Applicability: All Compute Capabilities.
Rationale

CUDA callbacks are not supported in the safety subset.

Example 1 (Bad)
# include <cassert>

__host__ void callback(void*) {
  assert(0);
}

int main() {
  // Adding a callback is not supported in the CUDA safety subset.
  cudaError_t const error0 = cudaLaunchHostFunc(nullptr, &callback, nullptr);
  assert(cudaSuccess == error0);
  cudaError_t const error1 = cudaDeviceSynchronize();
  assert(cudaSuccess == error1);
}
Excerpt from NVIDIA CUDA C++ Guidelines for robust and safety-critical programming, Version 3.0.1, Copyright (C) 2018-2023 NVIDIA Corporation.

Possible Messages

Key

Text

Severity

Disabled

cuda_callback

Do not use CUDA callbacks

None

False

Options

cuda_callback_registrations

cuda_callback_registrations

Type: dict[bauhaus.analysis.config.QualifiedName, int]

Default:

{
   'cuGraphAddHostNode': 4,
   'cuLaunchHostFunc': 1,
   'cuStreamAddCallback': 1,
   'cudaGraphAddHostNode': 4,
   'cudaLaunchHostFunc': 1,
   'cudaStreamAddCallback': 1
}
CUDA API functions taking callbacks as function pointer arguments. Maps the (qualified) function name to the index of the parameter used to pass in a function pointer or a (struct) object containing a function pointer (in a field).