Skip to content

Commit

Permalink
Draft
Browse files Browse the repository at this point in the history
  • Loading branch information
lamphamsy committed Aug 31, 2018
1 parent 6248116 commit 127c10d
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 12 deletions.
34 changes: 31 additions & 3 deletions src/fec_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class FecCode {
std::vector<Properties>& props,
off_t offset){};
virtual void encode(
const DecodeContext<T>& context,
vec::Buffers<T>& output,
std::vector<Properties>& props,
off_t offset,
Expand Down Expand Up @@ -498,6 +499,15 @@ void FecCode<T>::encode_packet(
vec::Buffers<uint8_t> output_char(output_len, buf_size);
const std::vector<uint8_t*> output_mem_char = output_char.get_mem();

// ids of received fragments, from 0 to codelen-1
vec::Vector<T> fragments_ids(*(this->gf), n_data);
for (unsigned i = 0; i < n_data; i++) {
fragments_ids.set(i, i);
}
vec::Buffers<T> inter_words(n_data, pkt_size);
std::unique_ptr<DecodeContext<T>> context =
init_context_dec(fragments_ids, pkt_size, &inter_words);

reset_stats_enc();

while (true) {
Expand All @@ -517,7 +527,7 @@ void FecCode<T>::encode_packet(

timeval t1 = tick();
uint64_t start = hw_timer();
encode(output, output_parities_props, offset, words);
encode(*context, output, output_parities_props, offset, words);
uint64_t end = hw_timer();
uint64_t t2 = hrtime_usec(t1);

Expand Down Expand Up @@ -918,7 +928,6 @@ bool FecCode<T>::decode_packet(
if (fragment_index == n_data)
return true;
}
fragments_ids.sort();

vec::Vector<T> avail_parity_ids(*(this->gf), n_data - avail_data_nb);

Expand All @@ -941,6 +950,8 @@ bool FecCode<T>::decode_packet(
if (fragment_index < n_data)
return false;
}
fragments_ids.sort();
std::cout << "fragments_ids:"; fragments_ids.dump();

decode_build();

Expand Down Expand Up @@ -994,6 +1005,8 @@ bool FecCode<T>::decode_packet(
vec::pack<uint8_t, T>(
words_mem_char, words_mem_T, n_data, pkt_size, word_size);

std::cout << "received:"; words.dump();

timeval t1 = tick();
uint64_t start = hw_timer();
decode(*context, output, input_parities_props, offset, words);
Expand All @@ -1007,6 +1020,8 @@ bool FecCode<T>::decode_packet(
vec::unpack<T, uint8_t>(
output_mem_T, output_mem_char, output_len, pkt_size, word_size);

std::cout << "decoded:"; output.dump();

for (unsigned i = 0; i < n_data; i++) {
if (output_data_bufs[i] != nullptr) {
write_pkt(
Expand Down Expand Up @@ -1039,11 +1054,18 @@ void FecCode<T>::decode(
off_t offset,
vec::Buffers<T>& words)
{
std::cout << "decode_prepare..\n";
// prepare for decoding
decode_prepare(context, props, offset, words);

std::cout << "done. decode_apply..\n";
// Lagrange interpolation
decode_apply(context, output, words);
std::cout << "decode_apply done.\n";

if (type == FecType::SYSTEMATIC) {
this->fft->fft(output, output);
}
}

/* Prepare for decoding
Expand All @@ -1063,8 +1085,14 @@ void FecCode<T>::decode_prepare(

T thres = (this->gf->card() - 1);
for (unsigned i = 0; i < this->n_data; i++) {
const int frag_id = fragments_ids.get(i);
int frag_id = fragments_ids.get(i);
if (type == FecType::SYSTEMATIC && frag_id < this->n_data) {
continue;
}
T* chunk = words.get(i);
if (type == FecType::SYSTEMATIC) {
frag_id -= this->n_data;
}
// loop over marked symbols
for (auto const& data : props[frag_id].get_map()) {
off_t loc_offset = data.first;
Expand Down
2 changes: 2 additions & 0 deletions src/fec_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class DecodeContext {
this->max_n_2k = (this->n > this->len_2k) ? this->n : this->len_2k;

this->fragments_ids = &fragments_ids;
this->output = output;

A = std::unique_ptr<vec::Poly<T>>(new vec::Poly<T>(gf, n));
A_fft_2k =
Expand Down Expand Up @@ -274,6 +275,7 @@ class DecodeContext {

public:
int vx_zero;
vec::Buffers<T>* output = nullptr;

private:
unsigned k;
Expand Down
35 changes: 29 additions & 6 deletions src/fec_rs_fnt.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ namespace fec {
*/
template <typename T>
class RsFnt : public FecCode<T> {
private:
std::unique_ptr<vec::Buffers<T>> inter_bufs_1;
std::unique_ptr<vec::Buffers<T>> inter_bufs_2;
std::unique_ptr<vec::Vector<T>> inter_vecs;

public:
RsFnt(
FecType type,
Expand Down Expand Up @@ -113,11 +118,20 @@ class RsFnt : public FecCode<T> {
for (unsigned i = 0; i < this->n; i++) {
this->r_powers->set(i, this->gf->exp(this->r, i));
}

if (this->type == FecType::SYSTEMATIC) {
inter_vecs = std::unique_ptr<vec::Vector<T>>(
new vec::Vector<T>(*(this->gf), this->n_data));
inter_bufs_1 = std::unique_ptr<vec::Buffers<T>>(
new vec::Buffers<T>(this->n_data, this->pkt_size));
inter_bufs_2 = std::unique_ptr<vec::Buffers<T>>(
new vec::Buffers<T>(this->n - this->n_data - this->n_outputs, this->pkt_size));
}
}

int get_n_outputs() override
{
return this->n;
return (this->type == FecType::SYSTEMATIC) ? this->n_parities : this->n;
}

/**
Expand Down Expand Up @@ -146,7 +160,7 @@ class RsFnt : public FecCode<T> {
// max_value = 2^x
T thres = this->gf->card() - 1;
// check for out of range value in output
for (unsigned i = 0; i < this->code_len; i++) {
for (unsigned i = 0; i < this->n_outputs; i++) {
if (output.get(i) & thres) {
props[i].add(offset, OOR_MARK);
output.set(i, 0);
Expand All @@ -155,12 +169,23 @@ class RsFnt : public FecCode<T> {
}

void encode(
const DecodeContext<T>& context,
vec::Buffers<T>& output,
std::vector<Properties>& props,
off_t offset,
vec::Buffers<T>& words) override
{
this->fft->fft(output, words);
if (this->type == FecType::SYSTEMATIC) {
std::cout << "words"; words.dump();
this->decode_apply(context, *(context.output), words);
std::cout << "intermediate"; context.output->dump();
vec::Buffers<T> _tmp(*inter_bufs_1, output);
vec::Buffers<T> _output(_tmp, *inter_bufs_2);
this->fft->fft(_output, *(context.output));
std::cout << "encoded"; output.dump();
} else {
this->fft->fft(output, words);
}
encode_post_process(output, props, offset);
}

Expand All @@ -172,7 +197,7 @@ class RsFnt : public FecCode<T> {
// check for out of range value in output
unsigned size = output.get_size();
T thres = (this->gf->card() - 1);
for (unsigned i = 0; i < this->code_len; ++i) {
for (unsigned i = 0; i < this->n_outputs; ++i) {
T* chunk = output.get(i);
for (unsigned j = 0; j < size; ++j) {
if (chunk[j] & thres) {
Expand All @@ -184,8 +209,6 @@ class RsFnt : public FecCode<T> {

void decode_add_data(int fragment_index, int row) override
{
// not applicable
assert(false);
}

void decode_add_parities(int fragment_index, int row) override
Expand Down
1 change: 1 addition & 0 deletions src/fec_rs_nf4.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ class RsNf4 : public FecCode<T> {
/********** Encoding & Decoding using Buffers **********/

void encode(
const DecodeContext<T>& context,
vec::Buffers<T>& output,
std::vector<Properties>& props,
off_t offset,
Expand Down
9 changes: 8 additions & 1 deletion src/fft_2n.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ void Radix2<T>::fft_inv(vec::Buffers<T>& output, vec::Buffers<T>& input)
{
const unsigned size = this->pkt_size;
const unsigned len = this->n;
const unsigned input_len = input.get_n();

// 1st reversion of elements of output
for (unsigned i = 0; i < len; i++) {
Expand All @@ -328,7 +329,13 @@ void Radix2<T>::fft_inv(vec::Buffers<T>& output, vec::Buffers<T>& input)
}

// copy input to output
output.copy(input);
unsigned i;
for (i = 0; i < input_len; ++i) {
output.copy(i, input.get(i));
}
for (; i < len; ++i) {
output.fill(i, 0);
}

for (unsigned m = len / 2; m >= 1; m /= 2) {
unsigned doubled_m = 2 * m;
Expand Down
2 changes: 1 addition & 1 deletion test/ec_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ char* prefix = nullptr;
void xusage()
{
std::cerr << std::string("Usage: ") +
"ec [-e rs-gf2n-v|rs-gf2n-c|rs-gf2n-fft|rs-gf2n-fft-add|rs-gfp-fft|rs-fnt|rs-nf4]" +
"ec [-e rs-gf2n-v|rs-gf2n-c|rs-gf2n-fft|rs-gf2n-fft-add|rs-gfp-fft|rs-fnt|rs-fnt-sys|rs-nf4]" +
"[-w word_size][-n n_data][-m n_parities][-p prefix][-v (verbose)]" +
" -c (encode) | -r (repair)\n";
exit(1);
Expand Down
2 changes: 1 addition & 1 deletion test/fec_utest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class FecTestCommon : public ::testing::Test {
}
};

using AllTypes = ::testing::Types<uint32_t, uint64_t, __uint128_t>;
using AllTypes = ::testing::Types<uint32_t, uint64_t>;
TYPED_TEST_CASE(FecTestCommon, AllTypes);

TYPED_TEST(FecTestCommon, TestNf4) // NOLINT
Expand Down

0 comments on commit 127c10d

Please sign in to comment.