< Summary

Line coverage
28%
Covered lines: 75
Uncovered lines: 185
Coverable lines: 260
Total lines: 589
Line coverage: 28.8%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

File(s)

C:\Users\Kremenchuk\actions-runner\_work\Holoflow\Holoflow\src\curaii\src\cuda\cublas.cc

#LineLine coverage
 1// Copyright 2025 Digital Holography Foundation
 2//
 3// Licensed under the Apache License, Version 2.0 (the "License");
 4// you may not use this file except in compliance with the License.
 5// You may obtain a copy of the License at
 6//
 7//     http://www.apache.org/licenses/LICENSE-2.0
 8//
 9// Unless required by applicable law or agreed to in writing, software
 10// distributed under the License is distributed on an "AS IS" BASIS,
 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12// See the License for the specific language governing permissions and
 13// limitations under the License.
 14
 15#include "curaii/cublas.hh"
 16
 17#include <format>
 18
 19#include "logger.hh"
 20
 21namespace curaii {
 22
 23CublasError::CublasError(cublasStatus_t code, const char *what, const char *file, int line)
 024    : std::runtime_error(CublasError::make_message(code, what, file, line)), code_(code) {}
 25
 26std::string CublasError::make_message(cublasStatus_t code, const char *what, const char *file,
 027                                      int line) {
 028  return std::format("cuBLAS error: {} ({})\n  expression : {}\n  location   : {}:{}",
 29                     cublasGetStatusString(code), static_cast<int>(code), what, file, line);
 030}
 31
 032cublasStatus_t CublasError::code() const noexcept { return code_; }
 33
 134CublasHandle::CublasHandle() { CUBLAS_CHECK(cublasCreate(&handle_)); }
 35
 136CublasHandle::~CublasHandle() noexcept {
 137  if (handle_) {
 138    CUBLAS_CHECK_NT(cublasDestroy(handle_));
 39  }
 140}
 41
 042CublasHandle::CublasHandle(CublasHandle &&other) noexcept : handle_(other.handle_) {
 043  other.handle_ = nullptr;
 044}
 45
 046CublasHandle &CublasHandle::operator=(CublasHandle &&other) noexcept {
 047  if (this != &other) {
 048    reset();
 049    handle_       = other.handle_;
 050    other.handle_ = nullptr;
 51  }
 052  return *this;
 053}
 54
 155cublasHandle_t CublasHandle::get() const noexcept { return handle_; }
 56
 057cublasHandle_t CublasHandle::release() noexcept {
 058  cublasHandle_t tmp = handle_;
 059  handle_            = nullptr;
 060  return tmp;
 061}
 62
 063void CublasHandle::reset(cublasHandle_t handle) noexcept {
 064  if (handle_ != handle) {
 065    if (handle_) {
 066      CUBLAS_CHECK_NT(cublasDestroy(handle_));
 67    }
 068    handle_ = handle;
 69  }
 070}
 71
 072CublasHandle::operator bool() const noexcept { return handle_ != nullptr; }
 73
 74} // namespace curaii
 75
 76namespace curaii::detail {
 77void log_cublas_failure(spdlog::level::level_enum level, cublasStatus_t code, const char *what,
 078                        const char *file, int line) {
 079  logger()->log(level, "cuBLAS error: {} ({})\n  expression : {}\n  location   : {}:{}",
 80                cublasGetStatusString(code), static_cast<int>(code), what, file, line);
 081}
 82
 83} // namespace curaii::detail

C:\Users\Kremenchuk\actions-runner\_work\Holoflow\Holoflow\src\curaii\src\cuda\cuda.cc

#LineLine coverage
 1// Copyright 2025 Digital Holography Foundation
 2//
 3// Licensed under the Apache License, Version 2.0 (the "License");
 4// you may not use this file except in compliance with the License.
 5// You may obtain a copy of the License at
 6//
 7//     http://www.apache.org/licenses/LICENSE-2.0
 8//
 9// Unless required by applicable law or agreed to in writing, software
 10// distributed under the License is distributed on an "AS IS" BASIS,
 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12// See the License for the specific language governing permissions and
 13// limitations under the License.
 14
 15#include "curaii/cuda.hh"
 16
 17#include <format>
 18
 19#include "logger.hh"
 20
 21namespace curaii {
 22
 23CudaError::CudaError(cudaError_t code, const char *what, const char *file, int line)
 024    : std::runtime_error(CudaError::make_message(code, what, file, line)), code_(code) {}
 25
 26std::string CudaError::make_message(cudaError_t code, const char *what, const char *file,
 027                                    int line) {
 028  return std::format("CUDA error: {} ({})\n  expression : {}\n  location   : {}:{}",
 29                     cudaGetErrorString(code), static_cast<int>(code), what, file, line);
 030}
 31
 032cudaError_t CudaError::code() const noexcept { return code_; }
 33
 134void HostDeleter::operator()(void *ptr) const noexcept {
 135  if (ptr) {
 136    CUDA_CHECK_NT(cudaFreeHost(ptr));
 37  }
 138}
 39
 140void DeviceDeleter::operator()(void *ptr) const noexcept {
 141  if (ptr) {
 142    CUDA_CHECK_NT(cudaFree(ptr));
 43  }
 144}
 45
 146CudaStream::CudaStream(unsigned flags, int priority) {
 147  CUDA_CHECK(cudaStreamCreateWithPriority(&stream_, flags, priority));
 148}
 49
 150CudaStream::~CudaStream() noexcept {
 151  if (stream_) {
 152    CUDA_CHECK_NT(cudaStreamDestroy(stream_));
 53  }
 154}
 55
 156CudaStream::CudaStream(CudaStream &&other) noexcept : stream_(other.stream_) {
 157  other.stream_ = nullptr;
 158}
 59
 060CudaStream &CudaStream::operator=(CudaStream &&other) noexcept {
 061  if (this != &other) {
 062    reset();
 063    stream_       = other.stream_;
 064    other.stream_ = nullptr;
 65  }
 066  return *this;
 067}
 68
 169cudaStream_t CudaStream::get() const noexcept { return stream_; }
 70
 071cudaStream_t CudaStream::release() noexcept {
 072  auto tmp = stream_;
 073  stream_  = nullptr;
 074  return tmp;
 075}
 76
 077void CudaStream::reset(cudaStream_t s) noexcept {
 078  if (stream_ != s) {
 079    if (stream_) {
 080      CUDA_CHECK_NT(cudaStreamDestroy(stream_));
 81    }
 082    stream_ = s;
 83  }
 084}
 85
 086CudaStream::operator bool() const noexcept { return stream_ != nullptr; }
 87
 88} // namespace curaii
 89
 90namespace curaii::detail {
 91
 92void log_cuda_failure(spdlog::level::level_enum lvl, cudaError_t code, const char *expr,
 093                      const char *file, int line) {
 094  logger()->log(lvl, "CUDA error {} ({}): \"{}\"  [{}:{}]", cudaGetErrorString(code),
 95                static_cast<int>(code), expr, file, line);
 096}
 97
 98} // namespace curaii::detail

C:\Users\Kremenchuk\actions-runner\_work\Holoflow\Holoflow\src\curaii\src\cuda\cufft.cc

#LineLine coverage
 1// Copyright 2025 Digital Holography Foundation
 2//
 3// Licensed under the Apache License, Version 2.0 (the "License");
 4// you may not use this file except in compliance with the License.
 5// You may obtain a copy of the License at
 6//
 7//     http://www.apache.org/licenses/LICENSE-2.0
 8//
 9// Unless required by applicable law or agreed to in writing, software
 10// distributed under the License is distributed on an "AS IS" BASIS,
 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12// See the License for the specific language governing permissions and
 13// limitations under the License.
 14
 15#include "curaii/cufft.hh"
 16
 17#include <format>
 18
 19#include "logger.hh"
 20
 21namespace {
 22
 023const char *cufftGetErrorString(cufftResult result) {
 024  switch (result) {
 25  case CUFFT_SUCCESS:
 026    return "The cuFFT operation was successful";
 27  case CUFFT_INVALID_PLAN:
 028    return "cuFFT was passed an invalid plan handle";
 29  case CUFFT_ALLOC_FAILED:
 030    return "cuFFT failed to allocate GPU or CPU memory";
 31  case CUFFT_INVALID_TYPE:
 032    return "No longer used";
 33  case CUFFT_INVALID_VALUE:
 034    return "User specified an invalid pointer or parameter";
 35  case CUFFT_INTERNAL_ERROR:
 036    return "Driver or internal cuFFT library error";
 37  case CUFFT_EXEC_FAILED:
 038    return "Failed to execute an FFT on the GPU";
 39  case CUFFT_SETUP_FAILED:
 040    return "The cuFFT library failed to initialize";
 41  case CUFFT_INVALID_SIZE:
 042    return "User specified an invalid transform size";
 43  case CUFFT_UNALIGNED_DATA:
 044    return "No longer used";
 45  case CUFFT_INVALID_DEVICE:
 046    return "Execution of a plan was on different GPU than plan creation";
 47  case CUFFT_NO_WORKSPACE:
 048    return "No workspace has been provided prior to plan execution";
 49  case CUFFT_NOT_IMPLEMENTED:
 050    return "Function does not implement functionality for parameters given";
 51  case CUFFT_NOT_SUPPORTED:
 052    return "Operation is not supported for parameters given";
 53  default:
 054    return "Unknown error";
 55  }
 056}
 57
 58} // namespace
 59
 60namespace curaii {
 61
 62CufftError::CufftError(cufftResult code, const char *what, const char *file, int line)
 063    : std::runtime_error(CufftError::make_message(code, what, file, line)), code_(code) {}
 64
 65std::string CufftError::make_message(cufftResult code, const char *what, const char *file,
 066                                     int line) {
 067  return std::format("cuFFT error: {} ({})\n  expression : {}\n  location   : {}:{}",
 68                     cufftGetErrorString(code), static_cast<int>(code), what, file, line);
 069}
 70
 071cufftResult CufftError::code() const noexcept { return code_; }
 72
 173CufftHandle::CufftHandle() { CUFFT_CHECK(cufftCreate(&handle_)); }
 74
 175CufftHandle::~CufftHandle() noexcept {
 176  if (handle_ != 0) {
 177    CUFFT_CHECK_NT(cufftDestroy(handle_));
 78  }
 179}
 80
 181CufftHandle::CufftHandle(CufftHandle &&other) noexcept : handle_(other.handle_) {
 182  other.handle_ = 0;
 183}
 84
 185CufftHandle &CufftHandle::operator=(CufftHandle &&other) noexcept {
 186  if (this != &other) {
 187    reset();
 188    handle_       = other.handle_;
 189    other.handle_ = 0;
 90  }
 191  return *this;
 192}
 93
 194cufftHandle CufftHandle::get() const noexcept { return handle_; }
 95
 096cufftHandle CufftHandle::release() noexcept {
 097  cufftHandle tmp = handle_;
 098  handle_         = 0;
 099  return tmp;
 0100}
 101
 1102void CufftHandle::reset(cufftHandle handle) noexcept {
 1103  if (handle_ != handle) {
 1104    if (handle_ != 0) {
 1105      CUFFT_CHECK_NT(cufftDestroy(handle_));
 106    }
 1107    handle_ = handle;
 108  }
 1109}
 110
 0111CufftHandle::operator bool() const noexcept { return handle_ != 0; }
 112
 113} // namespace curaii
 114
 115namespace curaii::detail {
 116
 117void log_cufft_failure(spdlog::level::level_enum level, cufftResult code, const char *what,
 0118                       const char *file, int line) {
 0119  logger()->log(level, "cuFFT error: {} ({})\n  expression : {}\n  location   : {}:{}",
 120                cufftGetErrorString(code), static_cast<int>(code), what, file, line);
 0121}
 122
 123} // namespace curaii::detail

C:\Users\Kremenchuk\actions-runner\_work\Holoflow\Holoflow\src\curaii\src\cuda\cusolver.cc

#LineLine coverage
 1// Copyright 2025 Digital Holography Foundation
 2//
 3// Licensed under the Apache License, Version 2.0 (the "License");
 4// you may not use this file except in compliance with the License.
 5// You may obtain a copy of the License at
 6//
 7//     http://www.apache.org/licenses/LICENSE-2.0
 8//
 9// Unless required by applicable law or agreed to in writing, software
 10// distributed under the License is distributed on an "AS IS" BASIS,
 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12// See the License for the specific language governing permissions and
 13// limitations under the License.
 14
 15#include "curaii/cusolver.hh"
 16
 17#include <format>
 18
 19#include "logger.hh"
 20
 21namespace {
 22
 023const char *cusolverGetErrorString(cusolverStatus_t status) {
 024  switch (status) {
 25  case CUSOLVER_STATUS_SUCCESS:
 026    return "The operation completed successfully";
 27  case CUSOLVER_STATUS_NOT_INITIALIZED:
 028    return "Library not initialized";
 29  case CUSOLVER_STATUS_ALLOC_FAILED:
 030    return "Resource allocation failed";
 31  case CUSOLVER_STATUS_INVALID_VALUE:
 032    return "Invalid value";
 33  case CUSOLVER_STATUS_ARCH_MISMATCH:
 034    return "Architecture mismatch";
 35  case CUSOLVER_STATUS_EXECUTION_FAILED:
 036    return "Execution failed";
 37  case CUSOLVER_STATUS_INTERNAL_ERROR:
 038    return "Internal error";
 39  case CUSOLVER_STATUS_MATRIX_TYPE_NOT_SUPPORTED:
 040    return "Matrix type not supported";
 41  case CUSOLVER_STATUS_NOT_SUPPORTED:
 042    return "Operation not supported";
 43  case CUSOLVER_STATUS_ZERO_PIVOT:
 044    return "Zero pivot";
 45  case CUSOLVER_STATUS_INVALID_LICENSE:
 046    return "Invalid license";
 47  default:
 048    return "Unknown error";
 49  }
 050}
 51
 52} // namespace
 53
 54namespace curaii {
 55
 56CusolverError::CusolverError(cusolverStatus_t code, const char *what, const char *file, int line)
 057    : std::runtime_error(CusolverError::make_message(code, what, file, line)), code_(code) {}
 58
 59std::string CusolverError::make_message(cusolverStatus_t code, const char *what, const char *file,
 060                                        int line) {
 061  return std::format("cuSOLVER error: {} ({})\n  expression : {}\n  location   : {}:{}",
 62                     cusolverGetErrorString(code), static_cast<int>(code), what, file, line);
 063}
 64
 065cusolverStatus_t CusolverError::code() const noexcept { return code_; }
 66
 167CusolverDnHandle::CusolverDnHandle() { CUSOLVER_CHECK(cusolverDnCreate(&handle_)); }
 68
 169CusolverDnHandle::~CusolverDnHandle() noexcept {
 170  if (handle_) {
 171    CUSOLVER_CHECK_NT(cusolverDnDestroy(handle_));
 72  }
 173}
 74
 075CusolverDnHandle::CusolverDnHandle(CusolverDnHandle &&other) noexcept : handle_(other.handle_) {
 076  other.handle_ = nullptr;
 077}
 78
 079CusolverDnHandle &CusolverDnHandle::operator=(CusolverDnHandle &&other) noexcept {
 080  if (this != &other) {
 081    reset();
 082    handle_       = other.handle_;
 083    other.handle_ = nullptr;
 84  }
 085  return *this;
 086}
 87
 188cusolverDnHandle_t CusolverDnHandle::get() const noexcept { return handle_; }
 89
 090cusolverDnHandle_t CusolverDnHandle::release() noexcept {
 091  cusolverDnHandle_t tmp = handle_;
 092  handle_                = nullptr;
 093  return tmp;
 094}
 95
 096void CusolverDnHandle::reset(cusolverDnHandle_t handle) noexcept {
 097  if (handle_ != handle) {
 098    if (handle_) {
 099      CUSOLVER_CHECK_NT(cusolverDnDestroy(handle_));
 100    }
 0101    handle_ = handle;
 102  }
 0103}
 104
 0105CusolverDnHandle::operator bool() const noexcept { return handle_ != nullptr; }
 106
 1107CusolverDnParams::CusolverDnParams() { CUSOLVER_CHECK(cusolverDnCreateParams(&params_)); }
 108
 1109CusolverDnParams::~CusolverDnParams() noexcept {
 1110  if (params_) {
 1111    CUSOLVER_CHECK_NT(cusolverDnDestroyParams(params_));
 112  }
 1113}
 114
 0115CusolverDnParams::CusolverDnParams(CusolverDnParams &&other) noexcept : params_(other.params_) {
 0116  other.params_ = nullptr;
 0117}
 118
 0119CusolverDnParams &CusolverDnParams::operator=(CusolverDnParams &&other) noexcept {
 0120  if (this != &other) {
 0121    reset();
 0122    params_       = other.params_;
 0123    other.params_ = nullptr;
 124  }
 0125  return *this;
 0126}
 127
 1128cusolverDnParams_t CusolverDnParams::get() const noexcept { return params_; }
 129
 0130cusolverDnParams_t CusolverDnParams::release() noexcept {
 0131  cusolverDnParams_t tmp = params_;
 0132  params_                = nullptr;
 0133  return tmp;
 0134}
 135
 0136void CusolverDnParams::reset(cusolverDnParams_t params) noexcept {
 0137  if (params_ != params) {
 0138    if (params_) {
 0139      CUSOLVER_CHECK_NT(cusolverDnDestroyParams(params_));
 140    }
 0141    params_ = params;
 142  }
 0143}
 144
 0145CusolverDnParams::operator bool() const noexcept { return params_ != nullptr; }
 146
 147} // namespace curaii
 148
 149namespace curaii::detail {
 150
 151void log_cusolver_failure(spdlog::level::level_enum level, cusolverStatus_t code, const char *what,
 0152                          const char *file, int line) {
 0153  logger()->log(level, "cuSOLVER error: {} ({})\n  expression : {}\n  location   : {}:{}",
 154                cusolverGetErrorString(code), static_cast<int>(code), what, file, line);
 0155}
 156
 157} // namespace curaii::detail

C:\Users\Kremenchuk\actions-runner\_work\Holoflow\Holoflow\src\curaii\src\cuda\logger.cc

#LineLine coverage
 1// Copyright 2025 Digital Holography Foundation
 2//
 3// Licensed under the Apache License, Version 2.0 (the "License");
 4// you may not use this file except in compliance with the License.
 5// You may obtain a copy of the License at
 6//
 7//     http://www.apache.org/licenses/LICENSE-2.0
 8//
 9// Unless required by applicable law or agreed to in writing, software
 10// distributed under the License is distributed on an "AS IS" BASIS,
 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12// See the License for the specific language governing permissions and
 13// limitations under the License.
 14
 15#include "logger.hh"
 16
 17#include <spdlog/sinks/stdout_color_sinks.h>
 18#include <spdlog/spdlog.h>
 19
 20namespace curaii {
 21
 022std::shared_ptr<spdlog::logger> logger() {
 023  static std::shared_ptr<spdlog::logger> logger = [] {
 24    auto sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
 25    sink->set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%n] [thread %t] [%^%l%$] %v");
 26
 27    auto log = std::make_shared<spdlog::logger>("curaii", sink);
 28    log->set_level(spdlog::default_logger()->level());
 29    log->flush_on(spdlog::level::warn);
 30
 31    spdlog::register_logger(log);
 32
 33    return log;
 034  }();
 035  return logger;
 036}
 37
 38} // namespace curaii

C:\Users\Kremenchuk\actions-runner\_work\Holoflow\Holoflow\src\curaii\src\cuda\nvrtc.cc

#LineLine coverage
 1// Copyright 2025 Digital Holography Foundation
 2//
 3// Licensed under the Apache License, Version 2.0 (the "License");
 4// you may not use this file except in compliance with the License.
 5// You may obtain a copy of the License at
 6//
 7//     http://www.apache.org/licenses/LICENSE-2.0
 8//
 9// Unless required by applicable law or agreed to in writing, software
 10// distributed under the License is distributed on an "AS IS" BASIS,
 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12// See the License for the specific language governing permissions and
 13// limitations under the License.
 14
 15#include "curaii/nvrtc.hh"
 16
 17#include <format>
 18
 19#include "logger.hh"
 20
 21namespace curaii {
 22
 23NvrtcError::NvrtcError(nvrtcResult code, const char *what, const char *file, int line)
 024    : std::runtime_error(NvrtcError::make_message(code, what, file, line)), code_(code) {}
 25
 26std::string NvrtcError::make_message(nvrtcResult code, const char *what, const char *file,
 027                                     int line) {
 028  return std::format("NVRTC error: {} ({})\n  expression : {}\n  location   : {}:{}",
 29                     nvrtcGetErrorString(code), static_cast<int>(code), what, file, line);
 030}
 31
 032nvrtcResult NvrtcError::code() const noexcept { return code_; }
 33
 34NvrtcProgram::NvrtcProgram(const char *source, const char *name, int numHeaders,
 135                           const char *const *headers, const char *const *includeNames) {
 136  create(source, name, numHeaders, headers, includeNames);
 137}
 38
 139NvrtcProgram::~NvrtcProgram() noexcept { reset(); }
 40
 041NvrtcProgram::NvrtcProgram(NvrtcProgram &&other) noexcept : program_(other.program_) {
 042  other.program_ = nullptr;
 043}
 44
 045NvrtcProgram &NvrtcProgram::operator=(NvrtcProgram &&other) noexcept {
 046  if (this != &other) {
 047    reset();
 048    program_       = other.program_;
 049    other.program_ = nullptr;
 50  }
 051  return *this;
 052}
 53
 54void NvrtcProgram::create(const char *source, const char *name, int numHeaders,
 155                          const char *const *headers, const char *const *includeNames) {
 156  reset();
 157  NVRTC_CHECK(nvrtcCreateProgram(&program_, source, name, numHeaders, headers, includeNames));
 158}
 59
 160nvrtcProgram NvrtcProgram::get() const noexcept { return program_; }
 61
 062nvrtcProgram NvrtcProgram::release() noexcept {
 063  nvrtcProgram tmp = program_;
 064  program_         = nullptr;
 065  return tmp;
 066}
 67
 168void NvrtcProgram::reset(nvrtcProgram program) noexcept {
 169  if (program_ != program) {
 170    if (program_) {
 171      nvrtcProgram tmp = program_;
 172      NVRTC_CHECK_NT(nvrtcDestroyProgram(&tmp));
 73    }
 174    program_ = program;
 75  }
 176}
 77
 078NvrtcProgram::operator bool() const noexcept { return program_ != nullptr; }
 79
 80} // namespace curaii
 81
 82namespace curaii::detail {
 83
 84void log_nvrtc_failure(spdlog::level::level_enum level, nvrtcResult code, const char *what,
 085                       const char *file, int line) {
 086  logger()->log(level, "NVRTC error: {} ({})\n  expression : {}\n  location   : {}:{}",
 87                nvrtcGetErrorString(code), static_cast<int>(code), what, file, line);
 088}
 89
 90} // namespace curaii::detail

Methods/Properties