FZGPUModules 2.0
GPU-accelerated modular compression pipelines
Loading...
Searching...
No Matches
cuda_check.h File Reference

GPU backend API error-checking macros. More...

#include <stdexcept>
#include <string>
#include "backend/types.h"
#include "log.h"

Go to the source code of this file.

Detailed Description

GPU backend API error-checking macros.

Despite the "CUDA" name (kept for call-site stability — this macro is used at ~30 call sites across the codebase), the implementation is backend-neutral: it checks against fz::error_t/fz::kBackendSuccess, which alias to the active backend's native error type (see include/backend/types.h).

FZ_CUDA_CHECK(call) Evaluates a CUDA API call and throws std::runtime_error on failure. Use on every CUDA API call in normal code paths — the overhead is a single integer comparison, which the CPU branch predictor predicts correctly 100% of the time in the success case.

Example: FZ_CUDA_CHECK(cudaMalloc(&ptr, size)); FZ_CUDA_CHECK(cudaStreamSynchronize(stream));

FZ_CUDA_CHECK_WARN(call) Evaluates a CUDA API call and emits a FZ_LOG(WARN) on failure. Does NOT throw. Use in destructors, cleanup/teardown paths, and resource-release calls where throwing would cause additional harm (e.g. cudaEventDestroy, cudaStreamDestroy, cudaFreeAsync in reset()).

Example: FZ_CUDA_CHECK_WARN(cudaEventDestroy(event)); FZ_CUDA_CHECK_WARN(cudaFreeAsync(ptr, stream));