-
-
Notifications
You must be signed in to change notification settings - Fork 85
/
btune.c
164 lines (146 loc) · 4.04 KB
/
btune.c
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*********************************************************************
Blosc - Blocked Shuffling and Compression Library
Author: Francesc Alted <[email protected]>
Creation date: 2017-08-29
See LICENSE.txt for details about copyright and rights to use.
**********************************************************************/
#include <stdbool.h>
#include <stdio.h>
#include "btune.h"
/* Whether a codec is meant for High Compression Ratios
Includes LZ4 + BITSHUFFLE here, but not BloscLZ + BITSHUFFLE because,
for some reason, the latter does not work too well */
static bool is_HCR(blosc2_context * context) {
switch (context->compcode) {
case BLOSC_BLOSCLZ :
return false;
case BLOSC_LZ4 :
return (context->filter_flags & BLOSC_DOBITSHUFFLE) ? true : false;
case BLOSC_LZ4HC :
return true;
case BLOSC_LIZARD :
return true;
case BLOSC_ZLIB :
return true;
case BLOSC_ZSTD :
return true;
default :
fprintf(stderr, "Error in is_COMP_HCR: codec %d not handled\n",
context->compcode);
}
return false;
}
// Set the automatic blocksize 0 to its real value
void btune_next_blocksize(blosc2_context *context) {
int32_t clevel = context->clevel;
int32_t typesize = context->typesize;
int32_t nbytes = context->sourcesize;
int32_t user_blocksize = context->blocksize;
int32_t blocksize = nbytes;
// Protection against very small buffers
if (nbytes < typesize) {
context->blocksize = 1;
return;
}
if (user_blocksize) {
blocksize = user_blocksize;
goto last;
}
if (nbytes >= L1) {
blocksize = L1;
/* For HCR codecs, increase the block sizes by a factor of 2 because they
are meant for compressing large blocks (i.e. they show a big overhead
when compressing small ones). */
if (is_HCR(context)) {
blocksize *= 2;
}
// Choose a different blocksize depending on the compression level
switch (clevel) {
case 0:
// Case of plain copy
blocksize /= 4;
break;
case 1:
blocksize /= 2;
break;
case 2:
blocksize *= 1;
break;
case 3:
blocksize *= 2;
break;
case 4:
case 5:
blocksize *= 4;
break;
case 6:
case 7:
case 8:
blocksize *= 8;
break;
case 9:
// Do not exceed 256 KB for non HCR codecs
blocksize *= 8;
if (is_HCR(context)) {
blocksize *= 2;
}
break;
default:
break;
}
}
/* Now the blocksize for splittable codecs */
if (clevel > 0 && split_block(context, typesize, blocksize, true)) {
// For performance reasons, do not exceed 256 KB (in must fit in L2 cache)
switch (clevel) {
case 1:
blocksize = 8 * 1024;
break;
case 2:
case 3:
blocksize = 16 * 1024;
break;
case 4:
case 5:
case 6:
case 7:
case 8:
blocksize = 128 * 1024;
break;
case 9:
default:
blocksize = 256 * 1024;
break;
}
// Multiply by typesize so as to get proper split sizes
blocksize *= typesize;
// But do not exceed 1 MB per thread (having this capacity in L3 is normal in modern CPUs)
if (blocksize > 1024 * 1024) {
blocksize = 1024 * 1024;
}
if (blocksize < 32 * 1024) {
/* Do not use a too small blocksize (< 32 KB) when typesize is small */
blocksize = 32 * 1024;
}
}
last:
/* Check that blocksize is not too large */
if (blocksize > nbytes) {
blocksize = nbytes;
}
// blocksize *must absolutely* be a multiple of the typesize
if (blocksize > typesize) {
blocksize = blocksize / typesize * typesize;
}
context->blocksize = blocksize;
}
void btune_next_cparams(blosc2_context * context) {
BLOSC_UNUSED_PARAM(context);
}
void btune_update(blosc2_context * context, double ctime) {
BLOSC_UNUSED_PARAM(context);
BLOSC_UNUSED_PARAM(ctime);
}
void btune_free(blosc2_context * context) {
BLOSC_UNUSED_PARAM(context);
}