Skip to content
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

RS NF4: support encoding/decoding using packets #215

Merged
merged 12 commits into from
Aug 24, 2018
Merged

Conversation

lamphamsy
Copy link
Contributor

RS over gf::NF4 can encode/decode using packets now

@@ -379,7 +379,7 @@ void RingModN<T>::mul_coef_to_buf(T a, T* src, T* dest, size_t len) const
DoubleSizeVal<T> coef = DoubleSizeVal<T>(a);
for (i = 0; i < len; i++) {
// perform multiplication
dest[i] = T((coef * src[i]) % this->_card);
dest[i] = mul(coef, src[i]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having a method mul, could we overload the * operator? That would make the code more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of changes would be in a separated PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you don't need to handle it here, I'll do it in #208

@@ -404,7 +404,7 @@ void RingModN<T>::add_two_bufs(T* src, T* dest, size_t len) const
size_t i;
for (i = 0; i < len; i++) {
// perform addition
dest[i] = (src[i] + dest[i]) % this->_card;
dest[i] = add(src[i], dest[i]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having a method add, could we overload the + operator? That would make the code more readable.

result = this->_card - (bufb[i] - bufa[i]);
}
res[i] = result;
res[i] = sub(bufa[i], bufb[i]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having a method sub, could we overload the - operator? That would make the code more readable.

If these operations are the one from RingModN, you could replace:

virtual T neg(T a) const;
virtual T add(T a, T b) const;
virtual T sub(T a, T b) const;
virtual T mul(T a, T b) const;
virtual T div(T a, T b) const;

by

virtual T operator-() const;
virtual T operator+(T lhs, T rhs) const;
virtual T operator-(T lhs, T rhs) const;
virtual T operator*(T lhs, T rhs) const;
virtual T operator/(T lhs, T rhs) const;

(replace T by const T& if the type are not limited to built-in integers, to avoid useless copy)

src/simd_nf4.h Outdated
@@ -128,7 +128,7 @@ inline void unpack(__uint128_t a, GroupedValues<__uint128_t>& b, int n)
_mm_store_si128((m128i*)&values, val);

b.flag = flag;
b.values = values;
b.values = values; // NOLINT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

You should explain what are you disabling here (with a comment/in the commit msg), or at least disable a single lint instead of all of them.

src/simd_nf4.h Outdated
ai[7] = _mm_extract_epi16(_a, 7);

flag = ai[1];
flag += (ai[3] > 0) ? 2 : 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could avoid the branches (but I expect the compiler to be smart enough to remove them anyway) by writting the code as flag = ai[1] | (!!ai[3] << 1u) | (!!ai[5] << 2u) | (!!ai[7] << 3u);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forgot this one (but did it for inline GroupedValues<__uint128_t> unpack(__uint128_t a, int n)

@@ -360,7 +360,8 @@ template <typename T>
void run_fec_rs_nf4(int word_size, int n_data, int n_parities, int rflag)
{
quad::fec::RsNf4<T>* fec;
fec = new quad::fec::RsNf4<T>(word_size, n_data, n_parities);
size_t pkt_size = 1024;
fec = new quad::fec::RsNf4<T>(word_size, n_data, n_parities, pkt_size);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a std::unique_ptr

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of enhancement will be in a separated PR

@@ -49,7 +49,7 @@ static inline aint128 m128i_to_uint128(m128i v)
}
#endif // #ifdef QUADIRON_USE_AVX2

inline aint128 expand16(aint16* arr, int n)
inline aint128 expand16(uint16_t* arr, int n)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change?

It should be explained in the commit message.

@@ -171,7 +171,7 @@ int Benchmark<T>::init()
fec = new quad::fec::RsGfpFft<T>(word_size, k, m);
break;
case EC_TYPE_RS_NF4:
fec = new quad::fec::RsNf4<T>(word_size, k, m);
fec = new quad::fec::RsNf4<T>(word_size, k, m, pkt_size);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should probably use std::unique_ptr instead of raw new in order to have auto-delete

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of enhancement will be in a separated PR

src/simd_nf4.h Outdated
@@ -102,6 +102,35 @@ inline GroupedValues<__uint128_t> unpack(__uint128_t a, int n)
return b;
}

inline void unpack(__uint128_t a, GroupedValues<__uint128_t>& b, int n)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comments on inline GroupedValues<__uint128_t> unpack(__uint128_t a, int n)

src/fec_rs_nf4.h Outdated
std::vector<size_t> packed_symbs;
// pack marked symbols
for (auto const& data : props[frag_id].get_map()) {
off_t loc_offset = data.first.get_offset();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const

@lamphamsy lamphamsy force-pushed the ft/nf4_packet branch 2 times, most recently from 6879e22 to 4091482 Compare August 7, 2018 10:25
@lamphamsy lamphamsy changed the base branch from ft/decode_buffers to master August 7, 2018 10:26
@lamphamsy
Copy link
Contributor Author

@slaperche-scality : it's ready for next reviews. Thanks :)

Copy link
Contributor

@slaperche-scality slaperche-scality left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost good, next iteration should be good for merge 🙂

src/simd_nf4.h Outdated
ai[7] = _mm_extract_epi16(_a, 7);

flag = ai[1];
flag += (ai[3] > 0) ? 2 : 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forgot this one (but did it for inline GroupedValues<__uint128_t> unpack(__uint128_t a, int n)

@lamphamsy lamphamsy merged commit 73766c8 into master Aug 24, 2018
@lamphamsy lamphamsy deleted the ft/nf4_packet branch August 31, 2018 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants