-
Notifications
You must be signed in to change notification settings - Fork 5
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
Conversation
20e26a4
to
f362e7b
Compare
@@ -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]); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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]); |
There was a problem hiding this comment.
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]); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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)
test/ec_driver.cpp
Outdated
@@ -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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
benchmark/benchmark.cpp
Outdated
@@ -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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const
6879e22
to
4091482
Compare
4091482
to
63e74e8
Compare
@slaperche-scality : it's ready for next reviews. Thanks :) |
63e74e8
to
6239754
Compare
There was a problem hiding this 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; |
There was a problem hiding this comment.
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)
6239754
to
455fa8c
Compare
Use virtualized basic operations instead of implementing directly for prime fields
It removes align attributes that are not necessary.
455fa8c
to
d78fe68
Compare
RS over gf::NF4 can encode/decode using packets now