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_exceptionif the givenstatusis an error code.The typical usage is to place a CUDA function call inside
cuda_try, i.e.cuda_try(cudaFunc(args))(the same waycuda_safe_callwould be called). For example,cuda_try(cudaCreateStream(&stream))is equivalent tocudaCreateStream(&stream), with the note that the former call throws an exception in case of error.cuda_try(CUDA_SUCCESS); // no effect, returns CUDA_SUCCESS int dev; cuda_try(cudaGetDevice(&dev)); // equivalent to the line above try { cuda_try(CUDA_ERROR_INVALID_VALUE); // would abort application if called } catch (...) { // This point will be reached return; } EXPECT(false, "Should not get here.");
- Template Parameters:
Status – CUDA error code type, such as
cudaError_t,cublasStatus_t, orcusolverStatus_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_exceptionin 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 incuda_try<cudaCreateStream>().cuda_trywill 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 callcuda_try<cudaCreateStream>(), the created stream object will be returned. That way you can writeauto stream = cuda_try<cudaCreateStream>();instead ofcudaStream_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.
int dev = cuda_try<cudaGetDevice>(); // continue execution if the call is successful cuda_try(cudaGetDevice(&dev)); // equivalent to the line above
- 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)