File size: 2,901 Bytes
f62b46d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*

 * SPDX-FileCopyrightText: Copyright (c) 2020-2025 NVIDIA CORPORATION & AFFILIATES.

 * All rights reserved. SPDX-License-Identifier: LicenseRef-NvidiaProprietary

 *

 * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual

 * property and proprietary rights in and to this material, related

 * documentation and any modifications thereto. Any use, reproduction,

 * disclosure or distribution of this material and related documentation

 * without an express license agreement from NVIDIA CORPORATION or

 * its affiliates is strictly prohibited.

*/

#pragma once

#include <cstdint>
#include <stdexcept>
#include <string>

#include "nvcomp.h"

namespace nvcomp {

/**

 * @brief nvCOMP supported compression formats.

*/
enum class nvcompFormatType_t : uint8_t {
  LZ4 = 0,
  Snappy = 1,
  ANS = 2,
  GDeflate = 3,
  Cascaded = 4,
  Bitcomp = 5,
  Zstd = 6,
  Deflate = 7,
  Gzip = 8,
  NotSupportedError = 255
};

/**

 * @brief The top-level exception thrown by nvcomp C++ methods.

 */
class NVCompException : public std::runtime_error
{
public:
  /**

   * @brief Create a new NVCompException.

   *

   * @param[in] err The error associated with the exception.

   * @param[in] msg The error message.

   */
  NVCompException(nvcompStatus_t err, const std::string& msg) :
      std::runtime_error(msg + " : code=" + std::to_string(err) + "."),
      m_err(err)
  {}

  nvcompStatus_t get_error() const noexcept

  {
    return m_err;
  }

private:
  nvcompStatus_t m_err;
};

#ifndef DOXYGEN_SHOULD_SKIP_THIS

/**

 * @brief Retrieve the applicable nvCOMP type for a standard type.

 *

 * @tparam T A standard C/C++ type.

 *

 * @return The applicable nvCOMP type.

 */
template <typename T>
__device__ __host__ constexpr nvcompType_t TypeOfConst() noexcept

{
  return std::is_same<T, int8_t>::value ?
    NVCOMP_TYPE_CHAR : (
  std::is_same<T, uint8_t>::value ?
    NVCOMP_TYPE_UCHAR : (
  std::is_same<T, int16_t>::value ?
    NVCOMP_TYPE_SHORT : (
  std::is_same<T, uint16_t>::value ?
    NVCOMP_TYPE_USHORT : (
  std::is_same<T, int32_t>::value ?
    NVCOMP_TYPE_INT : (
  std::is_same<T, uint32_t>::value ?
    NVCOMP_TYPE_UINT : (
  std::is_same<T, int64_t>::value ?
    NVCOMP_TYPE_LONGLONG : (
  std::is_same<T, uint64_t>::value ?
    NVCOMP_TYPE_ULONGLONG : (
    NVCOMP_TYPE_BITS
  ))))))));
}

/**

 * @brief Retrieve the applicable nvCOMP type for a standard type with checks.

 *

 * @tparam T A standard C/C++ type.

 *

 * @return The applicable nvCOMP type.

 */
template <typename T>
inline nvcompType_t TypeOf()

{
  auto type = TypeOfConst<T>();
  if (type != NVCOMP_TYPE_BITS) {
    return type;
  }
  throw NVCompException(
      nvcompErrorNotSupported, "nvCOMP does not support the given type.");
}

#endif // DOXYGEN_SHOULD_SKIP_THIS

} // namespace nvcomp