Skip to content

Commit ac61e95

Browse files
committed
[API] explicitly specify malloc
- name: `psz_(de)compress_init` - implicit free in `psz_release` - forward declaration of `pszctx` in type.h - massive change in `pszctx` occurrence - [TODO] see if ergonomically good
1 parent 4033fda commit ac61e95

File tree

8 files changed

+600
-526
lines changed

8 files changed

+600
-526
lines changed

example/src/demo_capi_cxx.cc

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ void f(std::string fname)
2525
uint8_t* compressed_buf;
2626
size_t compressed_len;
2727

28-
T *d_ori, *h_ori;
29-
T *d_reconst, *h_reconst;
28+
T *d_uncomp, *h_uncomp;
29+
T *d_decomp, *h_decomp;
3030

3131
auto oribytes = sizeof(T) * len;
32-
cudaMalloc(&d_ori, oribytes), cudaMallocHost(&h_ori, oribytes);
33-
cudaMalloc(&d_reconst, oribytes), cudaMallocHost(&h_reconst, oribytes);
32+
cudaMalloc(&d_uncomp, oribytes), cudaMallocHost(&h_uncomp, oribytes);
33+
cudaMalloc(&d_decomp, oribytes), cudaMallocHost(&h_decomp, oribytes);
3434

3535
/* User handles loading from filesystem & transferring to device. */
36-
io::read_binary_to_array(fname, h_ori, len);
37-
cudaMemcpy(d_ori, h_ori, oribytes, cudaMemcpyHostToDevice);
36+
io::read_binary_to_array(fname, h_uncomp, len);
37+
cudaMemcpy(d_uncomp, h_uncomp, oribytes, cudaMemcpyHostToDevice);
3838

3939
cudaStream_t stream;
4040
cudaStreamCreate(&stream);
@@ -59,13 +59,14 @@ void f(std::string fname)
5959
cusz::TimeRecord decompress_timerecord;
6060

6161
{
62-
cusz_compress(
63-
comp, config, d_ori, uncomp_len, &ptr_compressed, &compressed_len,
64-
&header, (void*)&compress_timerecord, stream);
62+
psz_compress_init(comp, uncomp_len, config);
63+
psz_compress(
64+
comp, d_uncomp, uncomp_len, &ptr_compressed, &compressed_len, &header,
65+
(void*)&compress_timerecord, stream);
6566

6667
/* User can interpret the collected time information in other ways. */
6768
cusz::TimeRecordViewer::view_compression(
68-
&compress_timerecord, len * sizeof(T), compressed_len);
69+
&compress_timerecord, oribytes, compressed_len);
6970

7071
/* verify header */
7172
printf("header.%-*s : %x\n", 12, "(addr)", &header);
@@ -84,22 +85,23 @@ void f(std::string fname)
8485
cudaMemcpyDeviceToDevice);
8586

8687
{
87-
cusz_decompress(
88-
comp, &header, ptr_compressed, compressed_len, d_reconst, decomp_len,
88+
psz_decompress_init(comp, &header);
89+
psz_decompress(
90+
comp, ptr_compressed, compressed_len, d_decomp, decomp_len,
8991
(void*)&decompress_timerecord, stream);
9092

91-
cusz::TimeRecordViewer::view_decompression(&decompress_timerecord, len *
92-
sizeof(T));
93+
cusz::TimeRecordViewer::view_decompression(
94+
&decompress_timerecord, oribytes);
9395
}
9496

9597
/* demo: offline checking (de)compression quality. */
96-
psz::eval_dataquality_gpu(d_reconst, d_ori, len, compressed_len);
98+
psz::eval_dataquality_gpu(d_decomp, d_uncomp, len, compressed_len);
9799

98100
cusz_release(comp);
99101

100102
cudaFree(compressed_buf);
101-
cudaFree(d_ori), cudaFreeHost(h_ori);
102-
cudaFree(d_reconst), cudaFreeHost(h_reconst);
103+
cudaFree(d_uncomp), cudaFreeHost(h_uncomp);
104+
cudaFree(d_decomp), cudaFreeHost(h_decomp);
103105

104106
cudaStreamDestroy(stream);
105107
}

example/src/demo_capi_nvcc.cu

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,20 @@ void f(std::string fname)
2525
uint8_t* compressed;
2626
size_t compressed_len;
2727

28-
T *d_uncompressed, *h_uncompressed;
29-
T *d_decompressed, *h_decompressed;
28+
T *d_uncomp, *h_uncomp;
29+
T *d_decomp, *h_decomp;
3030

31-
cudaMalloc(&d_uncompressed, sizeof(T) * len),
32-
cudaMallocHost(&h_uncompressed, sizeof(T) * len);
33-
cudaMalloc(&d_decompressed, sizeof(T) * len),
34-
cudaMallocHost(&h_decompressed, sizeof(T) * len);
31+
auto oribytes = sizeof(T) * len;
32+
cudaMalloc(&d_uncomp, oribytes), cudaMallocHost(&h_uncomp, oribytes);
33+
cudaMalloc(&d_decomp, oribytes), cudaMallocHost(&h_decomp, oribytes);
3534

3635
/* User handles loading from filesystem & transferring to device. */
37-
io::read_binary_to_array(fname, h_uncompressed, len);
38-
cudaMemcpy(
39-
d_uncompressed, h_uncompressed, sizeof(T) * len, cudaMemcpyHostToDevice);
36+
io::read_binary_to_array(fname, h_uncomp, len);
37+
cudaMemcpy(d_uncomp, h_uncomp, oribytes, cudaMemcpyHostToDevice);
4038

4139
/* a casual peek */
4240
printf("peeking uncompressed data, 20 elements\n");
43-
psz::peek_device_data(d_uncompressed, 20);
41+
psz::peek_device_data(d_uncomp, 20);
4442

4543
cudaStream_t stream;
4644
cudaStreamCreate(&stream);
@@ -72,13 +70,14 @@ void f(std::string fname)
7270
cusz::TimeRecord decompress_timerecord;
7371

7472
{
75-
cusz_compress(
76-
comp, config, d_uncompressed, uncomp_len, &exposed_compressed,
77-
&compressed_len, &header, (void*)&compress_timerecord, stream);
73+
psz_compress_init(comp, uncomp_len, config);
74+
psz_compress(
75+
comp, d_uncomp, uncomp_len, &exposed_compressed, &compressed_len,
76+
&header, (void*)&compress_timerecord, stream);
7877

7978
/* User can interpret the collected time information in other ways. */
8079
cusz::TimeRecordViewer::view_compression(
81-
&compress_timerecord, len * sizeof(T), compressed_len);
80+
&compress_timerecord, oribytes, compressed_len);
8281

8382
/* verify header */
8483
printf("header.%-*s : %x\n", 12, "(addr)", &header);
@@ -97,21 +96,21 @@ void f(std::string fname)
9796
cudaMemcpyDeviceToDevice);
9897

9998
{
100-
cusz_decompress(
101-
comp, &header, exposed_compressed, compressed_len, d_decompressed,
102-
decomp_len, (void*)&decompress_timerecord, stream);
99+
psz_decompress_init(comp, &header);
100+
psz_decompress(
101+
comp, exposed_compressed, compressed_len, d_decomp, decomp_len,
102+
(void*)&decompress_timerecord, stream);
103103

104104
cusz::TimeRecordViewer::view_decompression(
105-
&decompress_timerecord, len * sizeof(T));
105+
&decompress_timerecord, oribytes);
106106
}
107107

108108
/* a casual peek */
109109
printf("peeking decompressed data, 20 elements\n");
110-
psz::peek_device_data(d_decompressed, 20);
110+
psz::peek_device_data(d_decomp, 20);
111111

112112
/* demo: offline checking (de)compression quality. */
113-
psz::eval_dataquality_gpu(
114-
d_decompressed, d_uncompressed, len, compressed_len);
113+
psz::eval_dataquality_gpu(d_decomp, d_uncomp, len, compressed_len);
115114

116115
cusz_release(comp);
117116

include/context.h

Lines changed: 69 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* @date 2020-09-20
88
* Created on: 20-04-24
99
*
10-
* @copyright (C) 2020 by Washington State University, The University of Alabama, Argonne National Laboratory
11-
* See LICENSE in top-level directory
10+
* @copyright (C) 2020 by Washington State University, The University of
11+
* Alabama, Argonne National Laboratory See LICENSE in top-level directory
1212
*
1313
*/
1414

@@ -23,82 +23,77 @@ extern "C" {
2323
#include "stdint.h"
2424

2525
struct cusz_context {
26-
bool task_construct{false};
27-
bool task_reconstruct{false};
28-
bool task_dryrun{false};
29-
bool task_experiment{false};
30-
31-
bool prep_binning{false};
32-
bool prep_logtransform{false};
33-
bool prep_prescan{false};
34-
35-
bool use_demodata{false};
36-
bool use_release_input{false};
37-
bool use_anchor{false};
38-
bool use_autotune_hf{true};
39-
bool use_gpu_verify{false};
40-
41-
bool export_book{false};
42-
bool export_errctrl{false};
43-
44-
bool skip_tofile{false};
45-
bool skip_hf{false};
46-
47-
bool report_time{false};
48-
bool report_cr{false};
49-
bool report_cr_est{false};
50-
bool verbose{false};
51-
52-
// sizes
53-
uint32_t x{1}, y{1}, z{1}, w{1};
54-
size_t data_len{1};
55-
int ndim{-1};
56-
57-
// filenames
58-
char demodata_name[40];
59-
char infile[500];
60-
char original_file[500];
61-
char opath[200];
62-
63-
// pipeline config
64-
cusz_dtype dtype{F4};
65-
cusz_mode mode{Rel};
66-
double eb{0.0};
67-
int dict_size{1024}, radius{512};
68-
int quant_bytewidth{2}, huff_bytewidth{4};
69-
70-
// spv gather-scatter config, tmp. unused
71-
float nz_density{0.2};
72-
float nz_density_factor{5};
73-
74-
// codec config
75-
uint32_t codecs_in_use{0b01};
76-
int vle_sublen{512}, vle_pardeg{-1};
26+
bool task_construct{false};
27+
bool task_reconstruct{false};
28+
bool task_dryrun{false};
29+
bool task_experiment{false};
30+
31+
bool prep_binning{false};
32+
bool prep_logtransform{false};
33+
bool prep_prescan{false};
34+
35+
bool use_demodata{false};
36+
bool use_release_input{false};
37+
bool use_anchor{false};
38+
bool use_autotune_hf{true};
39+
bool use_gpu_verify{false};
40+
41+
bool export_book{false};
42+
bool export_errctrl{false};
43+
44+
bool skip_tofile{false};
45+
bool skip_hf{false};
46+
47+
bool report_time{false};
48+
bool report_cr{false};
49+
bool report_cr_est{false};
50+
bool verbose{false};
51+
52+
// sizes
53+
uint32_t x{1}, y{1}, z{1}, w{1};
54+
size_t data_len{1};
55+
int ndim{-1};
56+
57+
// filenames
58+
char demodata_name[40];
59+
char infile[500];
60+
char original_file[500];
61+
char opath[200];
62+
63+
// pipeline config
64+
cusz_dtype dtype{F4};
65+
cusz_mode mode{Rel};
66+
double eb{0.0};
67+
int dict_size{1024}, radius{512};
68+
int quant_bytewidth{2}, huff_bytewidth{4};
69+
70+
// spv gather-scatter config, tmp. unused
71+
float nz_density{0.2};
72+
float nz_density_factor{5};
73+
74+
// codec config
75+
uint32_t codecs_in_use{0b01};
76+
int vle_sublen{512}, vle_pardeg{-1};
7777
};
78-
7978
typedef struct cusz_context cusz_context;
80-
typedef cusz_context CuszCtx;
81-
typedef cusz_context PszCtx;
79+
typedef cusz_context pszctx;
8280

8381
void pszctx_print_document(bool full_document);
84-
85-
void pszctx_parse_argv(cusz_context* ctx, int const argc, char** const argv);
86-
void pszctx_parse_length(cusz_context* ctx, const char* lenstr);
87-
void pszctx_parse_control_string(cusz_context* ctx, const char* in_str, bool dbg_print);
88-
void pszctx_validate(cusz_context* ctx);
89-
void pszctx_load_demo_datasize(cusz_context* ctx, void* demodata_name);
90-
91-
void pszctx_set_rawlen(cusz_context* ctx, size_t _x, size_t _y, size_t _z, size_t _w);
92-
void pszctx_set_len(cusz_context* ctx, pszlen len);
93-
void pszctx_set_report(cusz_context* ctx, const char* in_str);
94-
void pszctx_set_config(cusz_context* ctx, pszrc* config);
95-
void pszctx_set_radius(cusz_context* ctx, int _);
96-
void pszctx_set_huffbyte(cusz_context* ctx, int _);
97-
void pszctx_set_huffchunk(cusz_context* ctx, int _);
98-
void pszctx_set_densityfactor(cusz_context* ctx, int _);
99-
100-
void pszctx_create_from_argv(cusz_context* ctx, int const argc, char** const argv);
101-
void pszctx_create_from_string(cusz_context* ctx, const char* in_str, bool dbg_print);
82+
void pszctx_parse_argv(pszctx* ctx, int const argc, char** const argv);
83+
void pszctx_parse_length(pszctx* ctx, const char* lenstr);
84+
void pszctx_parse_control_string(pszctx* ctx, const char* in_str, bool dbg_print);
85+
void pszctx_validate(pszctx* ctx);
86+
void pszctx_load_demo_datasize(pszctx* ctx, void* demodata_name);
87+
void pszctx_set_rawlen(pszctx* ctx, size_t _x, size_t _y, size_t _z, size_t _w);
88+
void pszctx_set_len(pszctx* ctx, pszlen len);
89+
void pszctx_set_report(pszctx* ctx, const char* in_str);
90+
void pszctx_set_config(pszctx* ctx, pszrc* config);
91+
void pszctx_set_radius(pszctx* ctx, int _);
92+
void pszctx_set_huffbyte(pszctx* ctx, int _);
93+
void pszctx_set_huffchunk(pszctx* ctx, int _);
94+
void pszctx_set_densityfactor(pszctx* ctx, int _);
95+
void pszctx_create_from_argv(pszctx* ctx, int const argc, char** const argv);
96+
void pszctx_create_from_string(pszctx* ctx, const char* in_str, bool dbg_print);
10297

10398
#ifdef __cplusplus
10499
}

include/cusz.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,20 @@ pszcompressor* psz_create(pszframe* framework, pszdtype const type);
3838

3939
pszerror psz_release(pszcompressor* comp);
4040

41+
pszerror psz_compress_init(
42+
pszcompressor* comp, pszlen const uncomp_len, pszrc* config);
43+
4144
pszerror psz_compress(
42-
pszcompressor* comp, pszrc* config, void* uncompressed,
43-
pszlen const uncomp_len, ptr_pszout compressed, size_t* comp_bytes,
44-
pszheader* header, void* record, cudaStream_t stream);
45+
pszcompressor* comp, void* uncompressed, pszlen const uncomp_len,
46+
ptr_pszout compressed, size_t* comp_bytes, pszheader* header, void* record,
47+
cudaStream_t stream);
48+
49+
pszerror psz_decompress_init(pszcompressor* comp, pszheader* header);
4550

4651
pszerror psz_decompress(
47-
pszcompressor* comp, pszheader* header, pszout compressed,
48-
size_t const comp_len, void* decompressed, pszlen const decomp_len,
49-
void* record, cudaStream_t stream);
52+
pszcompressor* comp, pszout compressed, size_t const comp_len,
53+
void* decompressed, pszlen const decomp_len, void* record,
54+
cudaStream_t stream);
5055

5156
#endif
5257

include/cusz/type.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,16 @@ typedef struct cusz_framework {
172172
typedef cusz_framework pszframework;
173173
typedef cusz_framework pszframe;
174174

175+
struct cusz_context;
176+
typedef struct cusz_context pszctx;
177+
178+
struct cusz_header;
179+
typedef struct cusz_header pszheader;
180+
175181
typedef struct cusz_compressor {
176182
void* compressor;
183+
pszctx* ctx;
184+
pszheader* header;
177185
pszframe* framework;
178186
pszdtype type;
179187
} cusz_compressor;

0 commit comments

Comments
 (0)