Macros
Utility_error

Macros

#define CUDA_DRIVER_TRY(...)
 Error checking macro for CUDA driver API functions. More...
 
#define CUFILE_TRY(...)
 Error checking macro for cuFile API functions. More...
 
#define KVIKIO_EXPECT(...)    GET_KVIKIO_EXPECT_MACRO(__VA_ARGS__, KVIKIO_EXPECT_3, KVIKIO_EXPECT_2)(__VA_ARGS__)
 Macro for checking pre-conditions or conditions that throws an exception when a condition is violated. More...
 
#define KVIKIO_FAIL(...)    GET_KVIKIO_FAIL_MACRO(__VA_ARGS__, KVIKIO_FAIL_2, KVIKIO_FAIL_1)(__VA_ARGS__)
 Indicates that an erroneous code path has been taken. More...
 
#define SYSCALL_CHECK(...)
 Error checking macro for Linux system call. More...
 

Detailed Description

Macro Definition Documentation

◆ CUDA_DRIVER_TRY

#define CUDA_DRIVER_TRY (   ...)
Value:
GET_CUDA_DRIVER_TRY_MACRO(__VA_ARGS__, CUDA_DRIVER_TRY_2, CUDA_DRIVER_TRY_1) \
(__VA_ARGS__)

Error checking macro for CUDA driver API functions.

Invoke a CUDA driver API function call. If the call does not return CUDA_SUCCESS, throw an exception detailing the CUDA error that occurred.

Example:

// Throws kvikio::CUfileException
CUDA_DRIVER_TRY(cudaAPI::instance().StreamSynchronize(_stream));
// Throws std::runtime_error
CUDA_DRIVER_TRY(cudaAPI::instance().StreamSynchronize(_stream), std::runtime_error);
#define CUDA_DRIVER_TRY(...)
Error checking macro for CUDA driver API functions.
Definition: error.hpp:68
Parameters
...This macro accepts either one or two arguments:
  • The first argument must be a CUDA driver API error code.
  • When given, the second argument is the exception to be thrown. When not specified, defaults to kvikio::CUfileException.

Definition at line 68 of file error.hpp.

◆ CUFILE_TRY

#define CUFILE_TRY (   ...)
Value:
GET_CUFILE_TRY_MACRO(__VA_ARGS__, CUFILE_TRY_2, CUFILE_TRY_1) \
(__VA_ARGS__)

Error checking macro for cuFile API functions.

Invoke a cuFile API function call. If the call does not return CU_FILE_SUCCESS, throw an exception detailing the cuFile error that occurred.

Example:

// Throws kvikio::CUfileException
CUFILE_TRY(cuFileAPI::instance().ReadAsync(...));
// Throws std::runtime_error
CUFILE_TRY(cuFileAPI::instance().ReadAsync(...), std::runtime_error);
#define CUFILE_TRY(...)
Error checking macro for cuFile API functions.
Definition: error.hpp:107
Parameters
...This macro accepts either one or two arguments:
  • The first argument must be a cuFile API error code.
  • When given, the second argument is the exception to be thrown. When not specified, defaults to kvikio::CUfileException.

Definition at line 107 of file error.hpp.

◆ KVIKIO_EXPECT

#define KVIKIO_EXPECT (   ...)     GET_KVIKIO_EXPECT_MACRO(__VA_ARGS__, KVIKIO_EXPECT_3, KVIKIO_EXPECT_2)(__VA_ARGS__)

Macro for checking pre-conditions or conditions that throws an exception when a condition is violated.

Defaults to throwing kvikio::CUfileException, but a custom exception may also be specified.

Example:

// Throws kvikio::CUfileException
KVIKIO_EXPECT(p != nullptr, "Unexpected null pointer");
// Throws std::runtime_error
KVIKIO_EXPECT(p != nullptr, "Unexpected nullptr", std::runtime_error);
#define KVIKIO_EXPECT(...)
Macro for checking pre-conditions or conditions that throws an exception when a condition is violated...
Definition: error.hpp:216
Parameters
...This macro accepts either two or three arguments:
  • The first argument must be an expression that evaluates to true or false, and is the condition being checked.
  • The second argument is a string literal used to construct the what of the exception.
  • When given, the third argument is the exception to be thrown. When not specified, defaults to kvikio::CUfileException.

Definition at line 216 of file error.hpp.

◆ KVIKIO_FAIL

#define KVIKIO_FAIL (   ...)     GET_KVIKIO_FAIL_MACRO(__VA_ARGS__, KVIKIO_FAIL_2, KVIKIO_FAIL_1)(__VA_ARGS__)

Indicates that an erroneous code path has been taken.

Example usage:

// Throws kvikio::CUfileException
KVIKIO_FAIL("Unsupported code path");
// Throws std::runtime_error
KVIKIO_FAIL("Unsupported code path", std::runtime_error);
#define KVIKIO_FAIL(...)
Indicates that an erroneous code path has been taken.
Definition: error.hpp:252
Parameters
...This macro accepts either one or two arguments:
  • The first argument is a string literal used to construct the what of the exception.
  • When given, the second argument is the exception to be thrown. When not specified, defaults to kvikio::CUfileException.

Definition at line 252 of file error.hpp.

◆ SYSCALL_CHECK

#define SYSCALL_CHECK (   ...)
Value:
GET_SYSCALL_CHECK_MACRO(__VA_ARGS__, SYSCALL_CHECK_3, SYSCALL_CHECK_2, SYSCALL_CHECK_1) \
(__VA_ARGS__)

Error checking macro for Linux system call.

Error checking for a Linux system call typically involves:

  • Check the return value of the system call. A value of -1 indicates failure for the overwhelming majority of system calls.
  • If failure, check the global error number errno. Use Linux utility functions to obtain detailed error information.

This macro is used to perform the steps above. A simple SYSCALL_CHECK(ret) is designed for the common cases where an integer of -1 indicates a failure, whereas a more complex SYSCALL_CHECK(ret, "extra msg", error_value) for the remaining rare cases, such as (void*)-1 for mmap. At any rate, if a failure occurs, this macro throws an exception (kvikio::GenericSystemError) with detailed error information.

Example:

// Common case: (int)-1 indicates an error.
SYSCALL_CHECK(open(file_name, flags, mode));
// Rare case: (void*)-1 indicates an error.
SYSCALL_CHECK(mmap(addr, length,prot, flags, fd, offset), "mmap failed",
reinterpret_cast<void*>(-1));
#define SYSCALL_CHECK(...)
Error checking macro for Linux system call.
Definition: error.hpp:326
Parameters
...This macro accepts the following arguments:
  • The first argument must be the return value of a Linux system call.
  • When given, the second argument is the extra message for the exception. When not specified, defaults to empty.
  • When given, the third argument is the error code value used to indicate an error. When not specified, defaults to -1.

Definition at line 326 of file error.hpp.