Debian Codegraph @

src/c-blosc2/blosc/context.h

raw
1 /*********************************************************************
2 Blosc - Blocked Shuffling and Compression Library
3
4 Copyright (c) 2021 Blosc Development Team <[email protected]>
5 https://blosc.org
6 License: BSD 3-Clause (see LICENSE.txt)
7
8 See LICENSE.txt for details about copyright and rights to use.
9 **********************************************************************/
10
11 #ifndef BLOSC_CONTEXT_H
12 #define BLOSC_CONTEXT_H
13
14 #include "b2nd.h"
15 #include "blosc2.h"
16
17 #if defined(HAVE_ZSTD)
18 #include "zstd.h"
19 #endif
20
21 #ifdef HAVE_IPP
22 #include <ipps.h>
23 #endif
24
25 #if defined(_WIN32) && !defined(__GNUC__)
26 #include "win32/pthread.h"
27 #else
28 #include <pthread.h>
29 #endif
30
31 #include <stddef.h>
32 #include <stdint.h>
33
34 /* Have problems using posix barriers when symbol value is 200112L */
35 /* Requires more investigation, but this will work for the moment */
36 #if defined(_POSIX_BARRIERS) && ( (_POSIX_BARRIERS - 20012L) >= 0 && _POSIX_BARRIERS != 200112L)
37 #define BLOSC_POSIX_BARRIERS
38 #endif
39
40 struct blosc2_context_s {
41 const uint8_t* src; /* The source buffer */
42 uint8_t* dest; /* The destination buffer */
43 uint8_t header_flags; /* Flags for header */
44 uint8_t blosc2_flags; /* Flags specific for blosc2 */
45 int32_t sourcesize; /* Number of bytes in source buffer */
46 int32_t header_overhead; /* The number of bytes in chunk header */
47 int32_t nblocks; /* Number of total blocks in buffer */
48 int32_t leftover; /* Extra bytes at end of buffer */
49 int32_t blocksize; /* Length of the block in bytes */
50 int32_t splitmode; /* Whether the blocks should be split or not */
51 int32_t output_bytes; /* Counter for the number of input bytes */
52 int32_t srcsize; /* Counter for the number of output bytes */
53 int32_t destsize; /* Maximum size for destination buffer */
54 int32_t typesize; /* Type size */
55 int32_t* bstarts; /* Starts for every block inside the compressed buffer */
56 int32_t special_type; /* Special type for chunk. 0 if not special. */
57 int compcode; /* Compressor code to use */
58 uint8_t compcode_meta; /* The metainfo for the compressor code */
59 int clevel; /* Compression level (1-9) */
60 int use_dict; /* Whether to use dicts or not */
61 void* dict_buffer; /* The buffer to keep the trained dictionary */
62 int32_t dict_size; /* The size of the trained dictionary */
63 void* dict_cdict; /* The dictionary in digested form for compression */
64 void* dict_ddict; /* The dictionary in digested form for decompression */
65 uint8_t filter_flags; /* The filter flags in the filter pipeline */
66 uint8_t filters[BLOSC2_MAX_FILTERS]; /* The (sequence of) filters */
67 uint8_t filters_meta[BLOSC2_MAX_FILTERS]; /* The metainfo for filters */
68 blosc2_filter urfilters[BLOSC2_MAX_UDFILTERS]; /* The user-defined filters */
69 blosc2_prefilter_fn prefilter; /* prefilter function */
70 blosc2_postfilter_fn postfilter; /* postfilter function */
71 blosc2_prefilter_params *preparams; /* prefilter params */
72 blosc2_postfilter_params *postparams; /* postfilter params */
73 bool* block_maskout; /* The blocks that are not meant to be decompressed.
74 * If NULL (default), all blocks in a chunk should be read. */
75 int block_maskout_nitems; /* The number of items in block_maskout array (must match
76 * the number of blocks in chunk) */
77 blosc2_schunk* schunk; /* Associated super-chunk (if available) */
78 struct thread_context* serial_context; /* Cache for temporaries for serial operation */
79 int do_compress; /* 1 if we are compressing, 0 if decompressing */
80 void *tuner_params; /* Entry point for tuner persistence between runs */
81 int tuner_id; /* User-defined tuner id */
82 void *codec_params; /* User defined parameters for the codec */
83 void *filter_params[BLOSC2_MAX_FILTERS]; /* User defined parameters for the filters */
84 /* Threading */
85 int16_t nthreads;
86 int16_t new_nthreads;
87 int16_t threads_started;
88 int16_t end_threads;
89 pthread_t *threads;
90 struct thread_context *thread_contexts; /* Only for user-managed threads */
91 pthread_mutex_t count_mutex;
92 pthread_mutex_t nchunk_mutex;
93 #ifdef BLOSC_POSIX_BARRIERS
94 pthread_barrier_t barr_init;
95 pthread_barrier_t barr_finish;
96 #else
97 int count_threads;
98 pthread_mutex_t count_threads_mutex;
99 pthread_cond_t count_threads_cv;
100 #endif
101 #if !defined(_WIN32)
102 pthread_attr_t ct_attr; /* creation time attrs for threads */
103 #endif
104 int thread_giveup_code; /* error code when give up */
105 int thread_nblock; /* block counter */
106 int dref_not_init; /* data ref in delta not initialized */
107 pthread_mutex_t delta_mutex;
108 pthread_cond_t delta_cv;
109 // Add new fields here to avoid breaking the ABI.
110 };
111
112 struct b2nd_context_s {
113 int8_t ndim;
114 //!< The array dimensions.
115 int64_t shape[B2ND_MAX_DIM];
116 //!< The array shape.
117 int32_t chunkshape[B2ND_MAX_DIM];
118 //!< The shape of each chunk of Blosc.
119 int32_t blockshape[B2ND_MAX_DIM];
120 //!< The shape of each block of Blosc.
121 char *dtype;
122 //!< Data type. Different formats can be supported (see dtype_format).
123 int8_t dtype_format;
124 //!< The format of the data type. Default is 0 (NumPy).
125 blosc2_storage *b2_storage;
126 //!< The Blosc storage properties
127 blosc2_metalayer metalayers[B2ND_MAX_METALAYERS];
128 //!< List with the metalayers desired.
129 int32_t nmetalayers;
130 //!< The number of metalayers.
131 };
132
133 struct thread_context {
134 blosc2_context* parent_context;
135 int tid;
136 uint8_t* tmp;
137 uint8_t* tmp2;
138 uint8_t* tmp3;
139 uint8_t* tmp4;
140 int32_t tmp_blocksize; /* the blocksize for different temporaries */
141 size_t tmp_nbytes; /* keep track of how big the temporary buffers are */
142 int32_t zfp_cell_start; /* cell starter index for ZFP fixed-rate mode */
143 int32_t zfp_cell_nitems; /* number of items to get for ZFP fixed-rate mode */
144 #if defined(HAVE_ZSTD)
145 /* The contexts for ZSTD */
146 ZSTD_CCtx* zstd_cctx;
147 ZSTD_DCtx* zstd_dctx;
148 #endif /* HAVE_ZSTD */
149 #ifdef HAVE_IPP
150 Ipp8u* lz4_hash_table;
151 #endif
152 };
153
154 #endif /* BLOSC_CONTEXT_H */