Skip to content

Commit cc69cce

Browse files
authored
FPGA: Reduce the decompress test file sizes when running simulation to make the runtime faster (#1351)
1 parent 6819ab9 commit cc69cce

File tree

5 files changed

+61
-19
lines changed

5 files changed

+61
-19
lines changed

DirectProgramming/C++SYCL_FPGA/ReferenceDesigns/decompress/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ Snappy is compression format that aims for high throughput compression and decom
195195

196196
Unlike many compression encodings, like DEFLATE, Snappy encoding is byte oriented. The Snappy format does not use entropy encoding, such as Huffman or range encoding.
197197

198-
Snappy encoding is like LZ77 encoding, which replaces portions of the byte stream with {length, distance} pairs. For more information on the Snappy format, see the [Snappy](https://en.wikipedia.org/wiki/Snappy_(compression)) Wikipedia article and the [Google Snappy](https://github.com/google/snappy) GitHub repository.
198+
Snappy encoding is like LZ77 encoding, which replaces portions of the byte stream with {length, distance} pairs. For more information on the Snappy format, see the [Snappy](https://en.wikipedia.org/wiki/Snappy_(compression)) Wikipedia article and the [Google Snappy](https://github.com/google/snappy) GitHub repository. The files being decompressed in this tutorial have been compressed using [python-snappy](https://github.com/andrix/python-snappy) which is a python library for the snappy compression library from Google.
199199

200200
The basic Snappy format is a *preamble* followed by the *compressed data stream*.
201201

Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
3+
4+
5+
ALICE'S ADVENTURES IN WONDERLAND
6+
7+
Lewis Carroll
8+
9+
THE MILLENNIUM FULCRUM EDITION 2.9
10+
11+
12+
13+
14+
CHAPTER I
15+
16+
Down the Rabbit-Hole
17+
18+
19+
Alice was beginning to get very tired of sitting by her sister
20+
on the bank, and of having nothing to do: once or twice she had
21+
peeped into the book her sister was reading, but it had no
22+
pictures or conversations in it, `and what is the use of a book,'
23+
thought Alice `without pictures or conversation?'

DirectProgramming/C++SYCL_FPGA/ReferenceDesigns/decompress/src/main.cpp

+37-18
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,26 @@ void PrintTestResults(std::string test_name, bool passed) {
184184
#if defined(GZIP)
185185
bool RunGzipTest(sycl::queue& q, GzipDecompressorT decompressor,
186186
const std::string test_dir) {
187+
188+
189+
#ifdef FPGA_SIMULATOR
190+
// the name of the file for the simulator is fixed
191+
std::string small_filename = test_dir + "/small.gz";
192+
193+
std::cout << ">>>>> Small File Test <<<<<" << std::endl;
194+
bool small_test_pass = decompressor.DecompressFile(
195+
q, small_filename, "", 1, false, false);
196+
PrintTestResults("Small File Test", small_test_pass);
197+
std::cout << std::endl;
198+
199+
return small_test_pass;
200+
#else
187201
// the name of the files for the default test are fixed
188202
std::string uncompressed_filename = test_dir + "/uncompressed.gz";
189203
std::string static_compress_filename = test_dir + "/static_compressed.gz";
190204
std::string dynamic_compress_filename = test_dir + "/dynamic_compressed.gz";
191205
std::string tp_test_filename = test_dir + "/tp_test.gz";
192206

193-
#ifndef FPGA_SIMULATOR
194207
std::cout << ">>>>> Uncompressed File Test <<<<<" << std::endl;
195208
bool uncompressed_test_pass = decompressor.DecompressFile(
196209
q, uncompressed_filename, "", 1, false, false);
@@ -202,53 +215,61 @@ bool RunGzipTest(sycl::queue& q, GzipDecompressorT decompressor,
202215
q, static_compress_filename, "", 1, false, false);
203216
PrintTestResults("Statically Compressed File Test", static_test_pass);
204217
std::cout << std::endl;
205-
#else
206-
std::cout << "Only running the Dynamically Compressed File Test when using "
207-
"the simulator flow to reduce execution time." << std::endl;
208-
bool uncompressed_test_pass = true;
209-
bool static_test_pass = true;
210-
#endif
211218

212219
std::cout << ">>>>> Dynamically Compressed File Test <<<<<" << std::endl;
213220
bool dynamic_test_pass = decompressor.DecompressFile(
214221
q, dynamic_compress_filename, "", 1, false, false);
215222
PrintTestResults("Dynamically Compressed File Test", dynamic_test_pass);
216223
std::cout << std::endl;
217224

218-
219-
#ifndef FPGA_SIMULATOR
220225
std::cout << ">>>>> Throughput Test <<<<<" << std::endl;
221226
constexpr int kTPTestRuns = 5;
222227
bool tp_test_pass = decompressor.DecompressFile(q, tp_test_filename, "",
223228
kTPTestRuns, true, false);
224229
PrintTestResults("Throughput Test", tp_test_pass);
225230
std::cout << std::endl;
226-
#else
227-
bool tp_test_pass = true;
228-
#endif
229231

230232
return uncompressed_test_pass && static_test_pass && dynamic_test_pass &&
231-
tp_test_pass;
233+
tp_test_pass;
234+
#endif
235+
232236
}
233237
#endif
234238

235239
#if defined(SNAPPY)
236240
bool RunSnappyTest(sycl::queue& q, SnappyDecompressorT decompressor,
237241
const std::string test_dir) {
242+
243+
244+
#ifdef FPGA_SIMULATOR
245+
std::cout << ">>>>> Small Alice In Wonderland Test <<<<<" << std::endl;
246+
std::string alice_in_file = test_dir + "/alice29_small.txt.sz";
247+
auto in_bytes = ReadInputFile(alice_in_file);
248+
auto result = decompressor.DecompressBytes(q, in_bytes, 1, false);
249+
250+
std::string alice_ref_file = test_dir + "/alice29_small.ref.txt";
251+
auto ref_bytes = ReadInputFile(alice_ref_file);
252+
bool alice_test_pass =
253+
(result != std::nullopt) && (result.value() == ref_bytes);
254+
255+
PrintTestResults("Small Alice In Wonderland Test", alice_test_pass);
256+
std::cout << std::endl;
257+
return alice_test_pass;
258+
259+
#else
238260
std::cout << ">>>>> Alice In Wonderland Test <<<<<" << std::endl;
239-
std::string alice_in_file = test_dir + "/alice29.txt.sz";
261+
std::string alice_in_file = test_dir + "/alice29_small.txt.sz";
240262
auto in_bytes = ReadInputFile(alice_in_file);
241263
auto result = decompressor.DecompressBytes(q, in_bytes, 1, false);
242264

243-
std::string alice_ref_file = test_dir + "/alice29.ref.txt";
265+
std::string alice_ref_file = test_dir + "/alice29_small.ref.txt";
244266
auto ref_bytes = ReadInputFile(alice_ref_file);
245267
bool alice_test_pass =
246268
(result != std::nullopt) && (result.value() == ref_bytes);
247269

248270
PrintTestResults("Alice In Wonderland Test", alice_test_pass);
249271
std::cout << std::endl;
250272

251-
#ifndef FPGA_SIMULATOR
252273
std::cout << ">>>>> Only Literal Strings Test <<<<<" << std::endl;
253274
auto test1_bytes = GenerateSnappyCompressedData(333, 3, 0, 0, 3);
254275
auto test1_ret = decompressor.DecompressBytes(q, test1_bytes, 1, false);
@@ -285,8 +306,6 @@ bool RunSnappyTest(sycl::queue& q, SnappyDecompressorT decompressor,
285306

286307
return alice_test_pass && test1_pass && test2_pass && test3_pass &&
287308
test_tp_pass;
288-
#else
289-
return alice_test_pass;
290309
#endif
291310

292311
}

0 commit comments

Comments
 (0)