Skip to content

FPGA: make the decompress design use shared memory allocations in IPA flow #1396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ class GzipDecompressor : public DecompressorBase {
bool passed = true;

try {
#if defined (IS_BSP)
// allocate memory on the device
if ((in = sycl::malloc_device<unsigned char>(in_count, q)) == nullptr) {
std::cerr << "ERROR: could not allocate space for 'in'\n";
Expand All @@ -179,6 +180,30 @@ class GzipDecompressor : public DecompressorBase {
std::cerr << "ERROR: could not allocate space for 'count'\n";
std::terminate();
}
#else
// allocate shared memory
if ((in = sycl::malloc_shared<unsigned char>(in_count, q)) == nullptr) {
std::cerr << "ERROR: could not allocate space for 'in'\n";
std::terminate();
}
if ((out = sycl::malloc_shared<unsigned char>(out_count_padded, q)) ==
nullptr) {
std::cerr << "ERROR: could not allocate space for 'out'\n";
std::terminate();
}
if ((hdr_data = sycl::malloc_shared<GzipHeaderData>(1, q)) == nullptr) {
std::cerr << "ERROR: could not allocate space for 'hdr_data'\n";
std::terminate();
}
if ((crc = sycl::malloc_shared<int>(1, q)) == nullptr) {
std::cerr << "ERROR: could not allocate space for 'crc'\n";
std::terminate();
}
if ((count = sycl::malloc_shared<int>(1, q)) == nullptr) {
std::cerr << "ERROR: could not allocate space for 'count'\n";
std::terminate();
}
#endif

// copy the input data to the device memory and wait for the copy to
// finish
Expand Down Expand Up @@ -297,4 +322,4 @@ class GzipDecompressor : public DecompressorBase {
}
};

#endif /* __GZIP_DECOMPRESSOR_HPP__ */
#endif /* __GZIP_DECOMPRESSOR_HPP__ */
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "common/common.hpp"
#include "exception_handler.hpp"

using namespace sycl;

// ensure only one of GZIP and SNAPPY is defined
#if defined(GZIP) and defined(SNAPPY)
static_assert(false, "Only one of GZIP and SNAPPY can be defined!");
Expand Down Expand Up @@ -67,8 +69,6 @@ bool RunSnappyTest(sycl::queue& q, SnappyDecompressorT decompressor,
std::string decompressor_name = "SNAPPY";
#endif

using namespace sycl;

// Prints the usage for the executable command line args
void PrintUsage(std::string exe_name) {
std::cerr << "USAGE: \n"
Expand Down Expand Up @@ -240,23 +240,6 @@ bool RunGzipTest(sycl::queue& q, GzipDecompressorT decompressor,
bool RunSnappyTest(sycl::queue& q, SnappyDecompressorT decompressor,
const std::string test_dir) {


#ifdef FPGA_SIMULATOR
std::cout << ">>>>> Small Alice In Wonderland Test <<<<<" << std::endl;
std::string alice_in_file = test_dir + "/alice29_small.txt.sz";
auto in_bytes = ReadInputFile(alice_in_file);
auto result = decompressor.DecompressBytes(q, in_bytes, 1, false);

std::string alice_ref_file = test_dir + "/alice29_small.ref.txt";
auto ref_bytes = ReadInputFile(alice_ref_file);
bool alice_test_pass =
(result != std::nullopt) && (result.value() == ref_bytes);

PrintTestResults("Small Alice In Wonderland Test", alice_test_pass);
std::cout << std::endl;
return alice_test_pass;

#else
std::cout << ">>>>> Alice In Wonderland Test <<<<<" << std::endl;
std::string alice_in_file = test_dir + "/alice29.txt.sz";
auto in_bytes = ReadInputFile(alice_in_file);
Expand All @@ -270,6 +253,10 @@ bool RunSnappyTest(sycl::queue& q, SnappyDecompressorT decompressor,
PrintTestResults("Alice In Wonderland Test", alice_test_pass);
std::cout << std::endl;

#ifdef FPGA_SIMULATOR
return alice_test_pass;
#else

std::cout << ">>>>> Only Literal Strings Test <<<<<" << std::endl;
auto test1_bytes = GenerateSnappyCompressedData(333, 3, 0, 0, 3);
auto test1_ret = decompressor.DecompressBytes(q, test1_bytes, 1, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ class SnappyDecompressor : public DecompressorBase {
unsigned* preamble_count;

try {
#if defined (IS_BSP)
// allocate memory on the device for the input and output
if ((in = sycl::malloc_device<unsigned char>(in_count_padded, q)) ==
nullptr) {
Expand All @@ -165,6 +166,23 @@ class SnappyDecompressor : public DecompressorBase {
std::cerr << "ERROR: could not allocate space for 'preamble_count'\n";
std::terminate();
}
#else
// allocate shared memory
if ((in = sycl::malloc_shared<unsigned char>(in_count_padded, q)) ==
nullptr) {
std::cerr << "ERROR: could not allocate space for 'in'\n";
std::terminate();
}
if ((out = sycl::malloc_shared<unsigned char>(out_count_padded, q)) ==
nullptr) {
std::cerr << "ERROR: could not allocate space for 'out'\n";
std::terminate();
}
if ((preamble_count = sycl::malloc_shared<unsigned>(1, q)) == nullptr) {
std::cerr << "ERROR: could not allocate space for 'preamble_count'\n";
std::terminate();
}
#endif

// copy the input data to the device memory and wait for the copy to
// finish
Expand Down Expand Up @@ -260,4 +278,4 @@ class SnappyDecompressor : public DecompressorBase {
}
};

#endif /* __SNAPPY_DECOMPRESSOR_HPP__ */
#endif /* __SNAPPY_DECOMPRESSOR_HPP__ */