cuda::experimental::stf::cuda_try#

Overloads#

cuda_try(status, loc=::cuda::std::source_location::current())#

template<typename Status>
void cuda::experimental::stf::cuda_try(
Status status,
const ::cuda::std::source_location loc = ::cuda::std::source_location::current(),
)

Throws a cuda_exception if the given status is an error code.

The typical usage is to place a CUDA function call inside cuda_try, i.e. cuda_try(cudaFunc(args)) (the same way cuda_safe_call would be called). For example, cuda_try(cudaCreateStream(&stream)) is equivalent to cudaCreateStream(&stream), with the note that the former call throws an exception in case of error.

Template Parameters:

Status – CUDA error code type, such as cudaError_t, cublasStatus_t, or cusolverStatus_t

Parameters:
  • status – CUDA error code value, usually the result of a CUDA API call

  • loc – location of the call, defaulted

cuda_try(ps)#

template<auto fun, typename ...Ps>
auto cuda::experimental::stf::cuda_try(
Ps&&... ps,
)

Calls a CUDA function and throws a cuda_exception in case of failure.

In this overload of cuda_try, the function name is passed explicitly as a template argument and also the first argument is omitted, as in cuda_try<cudaCreateStream>(). cuda_try will create a temporary of the appropriate type internally, call the specified CUDA function with the address of that temporary, and then return the temporary. For example, in the call cuda_try<cudaCreateStream>(), the created stream object will be returned. That way you can write auto stream = cuda_try<cudaCreateStream>(); instead of cudaStream_t stream; cudaCreateStream(&stream);. This invocation mode relies on the convention used by many CUDA functions with output parameters of specifying them in the first parameter position.

Limitations: Does not work with overloaded functions.

Template Parameters:
  • fun – Name of the CUDA function to invoke, cannot be the name of an overloaded function

  • Ps – Parameter types to be forwarded

Parameters:

ps – Arguments to be forwarded

Returns:

auto (see below)