Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
gdeflate_cpu.h111 linesDownload Raw Back to native
1/*
2 * SPDX-FileCopyrightText: Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES.
3 * All rights reserved. SPDX-License-Identifier: LicenseRef-NvidiaProprietary
4 *
5 * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
6 * property and proprietary rights in and to this material, related
7 * documentation and any modifications thereto. Any use, reproduction,
8 * disclosure or distribution of this material and related documentation
9 * without an express license agreement from NVIDIA CORPORATION or
10 * its affiliates is strictly prohibited.
11*/
12
13#pragma once
14
15#include <cstdint>
16#include <cstddef>
17
18#include <nvcomp_export.h>
19
20namespace gdeflate {
21
22/**
23 * @brief The maximum supported uncompressed chunk size in bytes for the Gdeflate CPU compressor.
24 */
25static constexpr size_t nvcompGdeflateCPUCompressionMaxAllowedChunkSize = 1u << 16;
26
27/**
28 * @brief The minimum and maximum compression level allowed for the Gdeflate CPU compressor.
29 */
30static constexpr int nvcompGdeflateCPUMinCompressionLevel = 0;
31static constexpr int nvcompGdeflateCPUMaxCompressionLevel = 12;
32
33/**
34 * @brief The most restrictive of the minimum alignment requirements for void-type memory buffers
35 * used for input and output, passed to compression functions.
36 *
37 * @note In all cases, typed memory buffers must still be aligned to their type's size,
38 * e.g., 4 bytes for `int`.
39 */
40static constexpr size_t nvcompGdeflateCPURequiredCompressionAlignment = 1;
41
42/**
43 * @brief Get the maximum size that a chunk of size at most max_uncompressed_chunk_bytes
44 * could compress to. That is, the minimum amount of output memory required to be given
45 * \ref compressCPU for each chunk.
46 *
47 * @throw nvcomp::NVCompException on error.
48 *
49 * @param[in] max_uncompressed_chunk_bytes The maximum size of a chunk before compression.
50 * @param[out] max_compressed_chunk_bytes The maximum possible compressed size of the chunk.
51 */
52NVCOMP_EXPORT
53void compressCPUGetMaxOutputChunkSize(
54    size_t max_uncompressed_chunk_bytes,
55    size_t* max_compressed_chunk_bytes);
56
57/**
58 * @brief Perform compression on the CPU.
59 *
60 * @throw nvcomp::NVCompException on error.
61 *
62 * @param[in] in_ptr Pointers on the CPU, to uncompressed batched items.
63 * @param[in] in_bytes The size of each uncompressed batch item on the CPU.
64 * @param[in] max_uncompressed_chunk_bytes The maximum size of an uncompressed chunk in bytes.
65 * @param[in] batch_size The number of batch items.
66 * @param[out] out_ptr Pointers on the CPU, to the output location for each compressed batch item (output).
67 * @param[out] out_bytes The compressed size of each chunk on the CPU (output).
68 * @param[in] level The selected compression level (between 0 and 12, both inclusive).
69 */
70NVCOMP_EXPORT
71void compressCPU(
72    const void* const* in_ptr,
73    const size_t* in_bytes,
74    const size_t max_uncompressed_chunk_bytes,
75    size_t batch_size,
76    void* const* out_ptr,
77    size_t* out_bytes,
78    int level = 12);
79
80/**
81 * @brief The most restrictive of the minimum alignment requirements for void-type memory buffers
82 * used for input and output, passed to decompression functions.
83 *
84 * @note In all cases, typed memory buffers must still be aligned to their type's size,
85 * e.g., 4 bytes for `int`.
86 */
87static constexpr size_t nvcompGdeflateCPURequiredDecompressionAlignment = 1;
88
89/**
90 * @brief Perform decompression on the CPU.
91 *
92 * @throw nvcomp::NVCompException on error.
93 *
94 * @param[in] in_ptr Pointers on the CPU, to the compressed chunks.
95 * @param[in] in_bytes The size of each compressed batch item on the CPU in bytes.
96 * @param[in] batch_size The number of batch items.
97 * @param[out] out_ptr Pointers on the CPU, indicating where to decompress each chunk (output).
98 * @param[in] out_buffer_bytes The size of each output chunk buffer in bytes.
99 * @param[out] out_bytes The size of each decompressed batch item on the CPU in bytes. (output).
100 */
101NVCOMP_EXPORT
102void decompressCPU(
103    const void* const* in_ptr,
104    const size_t* in_bytes,
105    size_t batch_size,
106    void* const* out_ptr,
107    size_t* out_buffer_bytes,
108    size_t* out_bytes);
109
110} // namespace gdeflate
111 
codekingpro/portable-devtools · Team Ai