Improve readability

This commit is contained in:
Andrzej Janik 2025-09-11 01:21:01 +00:00
commit d58d9053fa

View file

@ -531,44 +531,45 @@ pub(crate) unsafe fn get_error_string(
error: cuda_types::cuda::CUresult,
error_string: &mut *const ::core::ffi::c_char,
) -> CUresult {
// Map known error codes to error strings
*error_string = match error {
CUresult::SUCCESS => b"no error\0".as_ptr() as *const i8,
CUresult::ERROR_INVALID_VALUE => b"invalid value\0".as_ptr() as *const i8,
CUresult::ERROR_OUT_OF_MEMORY => b"out of memory\0".as_ptr() as *const i8,
CUresult::ERROR_NOT_INITIALIZED => b"driver not initialized\0".as_ptr() as *const i8,
CUresult::ERROR_DEINITIALIZED => b"driver deinitialized\0".as_ptr() as *const i8,
CUresult::ERROR_NO_DEVICE => b"no CUDA-capable device is detected\0".as_ptr() as *const i8,
CUresult::ERROR_INVALID_DEVICE => b"invalid device\0".as_ptr() as *const i8,
CUresult::ERROR_INVALID_IMAGE => b"invalid kernel image\0".as_ptr() as *const i8,
CUresult::ERROR_INVALID_CONTEXT => b"invalid context\0".as_ptr() as *const i8,
CUresult::ERROR_CONTEXT_ALREADY_CURRENT => b"context already current\0".as_ptr() as *const i8,
CUresult::ERROR_MAP_FAILED => b"map failed\0".as_ptr() as *const i8,
CUresult::ERROR_UNMAP_FAILED => b"unmap failed\0".as_ptr() as *const i8,
CUresult::ERROR_ARRAY_IS_MAPPED => b"array is mapped\0".as_ptr() as *const i8,
CUresult::ERROR_ALREADY_MAPPED => b"already mapped\0".as_ptr() as *const i8,
CUresult::ERROR_NO_BINARY_FOR_GPU => b"no binary for GPU\0".as_ptr() as *const i8,
CUresult::ERROR_ALREADY_ACQUIRED => b"already acquired\0".as_ptr() as *const i8,
CUresult::ERROR_NOT_MAPPED => b"not mapped\0".as_ptr() as *const i8,
CUresult::ERROR_NOT_SUPPORTED => b"operation not supported\0".as_ptr() as *const i8,
CUresult::ERROR_INVALID_SOURCE => b"invalid source\0".as_ptr() as *const i8,
CUresult::ERROR_FILE_NOT_FOUND => b"file not found\0".as_ptr() as *const i8,
CUresult::ERROR_INVALID_HANDLE => b"invalid handle\0".as_ptr() as *const i8,
CUresult::ERROR_NOT_READY => b"not ready\0".as_ptr() as *const i8,
CUresult::ERROR_ILLEGAL_ADDRESS => b"illegal address\0".as_ptr() as *const i8,
CUresult::ERROR_LAUNCH_OUT_OF_RESOURCES => b"launch out of resources\0".as_ptr() as *const i8,
CUresult::ERROR_LAUNCH_TIMEOUT => b"launch timeout\0".as_ptr() as *const i8,
CUresult::ERROR_LAUNCH_INCOMPATIBLE_TEXTURING => b"launch incompatible texturing\0".as_ptr() as *const i8,
CUresult::ERROR_PEER_ACCESS_ALREADY_ENABLED => b"peer access already enabled\0".as_ptr() as *const i8,
CUresult::ERROR_PEER_ACCESS_NOT_ENABLED => b"peer access not enabled\0".as_ptr() as *const i8,
CUresult::ERROR_PRIMARY_CONTEXT_ACTIVE => b"primary context active\0".as_ptr() as *const i8,
CUresult::ERROR_CONTEXT_IS_DESTROYED => b"context is destroyed\0".as_ptr() as *const i8,
CUresult::ERROR_ASSERT => b"device-side assert triggered\0".as_ptr() as *const i8,
CUresult::ERROR_TOO_MANY_PEERS => b"too many peers\0".as_ptr() as *const i8,
CUresult::ERROR_HOST_MEMORY_ALREADY_REGISTERED => b"host memory already registered\0".as_ptr() as *const i8,
CUresult::ERROR_HOST_MEMORY_NOT_REGISTERED => b"host memory not registered\0".as_ptr() as *const i8,
CUresult::ERROR_UNKNOWN => b"unknown error\0".as_ptr() as *const i8,
_ => b"unknown error\0".as_ptr() as *const i8,
CUresult::SUCCESS => c"no error".as_ptr(),
CUresult::ERROR_INVALID_VALUE => c"invalid value".as_ptr(),
CUresult::ERROR_OUT_OF_MEMORY => c"out of memory".as_ptr(),
CUresult::ERROR_NOT_INITIALIZED => c"driver not initialized".as_ptr(),
CUresult::ERROR_DEINITIALIZED => c"driver deinitialized".as_ptr(),
CUresult::ERROR_NO_DEVICE => c"no CUDA-capable device is detected".as_ptr(),
CUresult::ERROR_INVALID_DEVICE => c"invalid device".as_ptr(),
CUresult::ERROR_INVALID_IMAGE => c"invalid kernel image".as_ptr(),
CUresult::ERROR_INVALID_CONTEXT => c"invalid context".as_ptr(),
CUresult::ERROR_CONTEXT_ALREADY_CURRENT => c"context already current".as_ptr(),
CUresult::ERROR_MAP_FAILED => c"map failed".as_ptr(),
CUresult::ERROR_UNMAP_FAILED => c"unmap failed".as_ptr(),
CUresult::ERROR_ARRAY_IS_MAPPED => c"array is mapped".as_ptr(),
CUresult::ERROR_ALREADY_MAPPED => c"already mapped".as_ptr(),
CUresult::ERROR_NO_BINARY_FOR_GPU => c"no binary for GPU".as_ptr(),
CUresult::ERROR_ALREADY_ACQUIRED => c"already acquired".as_ptr(),
CUresult::ERROR_NOT_MAPPED => c"not mapped".as_ptr(),
CUresult::ERROR_NOT_SUPPORTED => c"operation not supported".as_ptr(),
CUresult::ERROR_INVALID_SOURCE => c"invalid source".as_ptr(),
CUresult::ERROR_FILE_NOT_FOUND => c"file not found".as_ptr(),
CUresult::ERROR_INVALID_HANDLE => c"invalid handle".as_ptr(),
CUresult::ERROR_NOT_READY => c"not ready".as_ptr(),
CUresult::ERROR_ILLEGAL_ADDRESS => c"illegal address".as_ptr(),
CUresult::ERROR_LAUNCH_OUT_OF_RESOURCES => c"launch out of resources".as_ptr(),
CUresult::ERROR_LAUNCH_TIMEOUT => c"launch timeout".as_ptr(),
CUresult::ERROR_LAUNCH_INCOMPATIBLE_TEXTURING => c"launch incompatible texturing".as_ptr(),
CUresult::ERROR_PEER_ACCESS_ALREADY_ENABLED => c"peer access already enabled".as_ptr(),
CUresult::ERROR_PEER_ACCESS_NOT_ENABLED => c"peer access not enabled".as_ptr(),
CUresult::ERROR_PRIMARY_CONTEXT_ACTIVE => c"primary context active".as_ptr(),
CUresult::ERROR_CONTEXT_IS_DESTROYED => c"context is destroyed".as_ptr(),
CUresult::ERROR_ASSERT => c"device-side assert triggered".as_ptr(),
CUresult::ERROR_TOO_MANY_PEERS => c"too many peers".as_ptr(),
CUresult::ERROR_HOST_MEMORY_ALREADY_REGISTERED => {
c"host memory already registered".as_ptr()
}
CUresult::ERROR_HOST_MEMORY_NOT_REGISTERED => c"host memory not registered".as_ptr(),
CUresult::ERROR_UNKNOWN => c"unknown error".as_ptr(),
_ => c"error".as_ptr(),
};
Ok(())
}