forked from NVIDIA/CUDALibrarySamples
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbenchmark_cascaded_chunked.cu
141 lines (134 loc) · 4.19 KB
/
benchmark_cascaded_chunked.cu
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
* SPDX-FileCopyrightText: Copyright (c) 2020-2024 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.
*/
#include "benchmark_template_chunked.cuh"
#include "nvcomp/cascaded.h"
#include <iostream>
#include <vector>
static nvcompBatchedCascadedOpts_t nvcompBatchedCascadedTestOpts
= {4096, NVCOMP_TYPE_UINT, 2, 1, 1};
static bool handleCommandLineArgument(
const std::string& arg,
const char* const* additionalArgs,
size_t& additionalArgsUsed)
{
if (arg == "--type" || arg == "-t") {
const char* const typeArg = *additionalArgs;
additionalArgsUsed = 1;
bool valid;
nvcompBatchedCascadedTestOpts.type = string_to_data_type(typeArg, valid);
return valid;
}
if (arg == "--num_rles" || arg == "-r") {
int n = atoi(*additionalArgs);
additionalArgsUsed = 1;
if (n < 0) {
std::cerr << "ERROR: num_rles can't be negative, but it is " << n
<< std::endl;
return false;
}
nvcompBatchedCascadedTestOpts.num_RLEs = n;
return true;
}
if (arg == "--num_deltas" || arg == "-d") {
int n = atoi(*additionalArgs);
additionalArgsUsed = 1;
if (n < 0) {
std::cerr << "ERROR: num_deltas can't be negative, but it is " << n
<< std::endl;
return false;
}
nvcompBatchedCascadedTestOpts.num_deltas = n;
return true;
}
if (arg == "--num_bps" || arg == "-b") {
int n = atoi(*additionalArgs);
additionalArgsUsed = 1;
if (n < 0 || n > 1) {
std::cerr << "ERROR: num_bps can only be 0 or 1, but it is " << n
<< std::endl;
return false;
}
nvcompBatchedCascadedTestOpts.use_bp = n;
return true;
}
return false;
}
static bool isCascadedInputValid(const std::vector<std::vector<char>>& data)
{
// Find the type size, to check that all chunk sizes are a multiple of it.
size_t typeSize = 1;
auto type = nvcompBatchedCascadedTestOpts.type;
switch (type) {
case NVCOMP_TYPE_CHAR:
case NVCOMP_TYPE_UCHAR:
// Type size is 1 byte, so chunk sizes are always a multiple of it.
return true;
case NVCOMP_TYPE_SHORT:
case NVCOMP_TYPE_USHORT:
typeSize = sizeof(uint16_t);
break;
case NVCOMP_TYPE_INT:
case NVCOMP_TYPE_UINT:
typeSize = sizeof(uint32_t);
break;
case NVCOMP_TYPE_LONGLONG:
case NVCOMP_TYPE_ULONGLONG:
typeSize = sizeof(uint64_t);
break;
default:
std::cerr << "ERROR: Cascaded data type must be 0-7 (CHAR, UCHAR, SHORT, "
"USHORT, INT, UINT, LONGLONG, or ULONGLONG), "
"but it is "
<< int(type) << std::endl;
return false;
}
for (const auto& chunk : data) {
if ((chunk.size() % typeSize) != 0) {
std::cerr << "ERROR: Input data must have a length and chunk size that "
"are a multiple of "
<< typeSize << ", the size of the specified data type."
<< std::endl;
return false;
}
}
return true;
}
void run_benchmark(
const std::vector<std::vector<char>>& data,
const bool warmup,
const size_t count,
const bool csv_output,
const bool tab_separator,
const size_t duplicate_count,
const size_t num_files,
const bool compressed_inputs,
const bool single_output_buffer)
{
run_benchmark_template(
nvcompBatchedCascadedCompressGetTempSize,
nvcompBatchedCascadedCompressGetMaxOutputChunkSize,
nvcompBatchedCascadedCompressAsync,
nvcompBatchedCascadedDecompressGetTempSize,
nvcompBatchedCascadedDecompressAsync,
nvcompBatchedCascadedGetDecompressSizeAsync,
isCascadedInputValid,
nvcompBatchedCascadedTestOpts,
data,
warmup,
count,
csv_output,
tab_separator,
duplicate_count,
num_files,
compressed_inputs,
single_output_buffer);
}