-
Notifications
You must be signed in to change notification settings - Fork 8
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
add some basic structure for quantizer, io and simd operators #25
base: main
Are you sure you want to change the base?
Conversation
LHT129
commented
Sep 12, 2024
- only header for quantizer and io
- fp32 quantizer as example
d41db02
to
36309db
Compare
src/io/memory_io.h
Outdated
|
||
private: | ||
[[nodiscard]] inline bool | ||
CheckValidOffset(uint64_t size) const { |
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.
unify the naming convention; our private methods generally use the underscore naming style. (check_valid_offset)
src/simd/fp32_simd_test.cpp
Outdated
#include "fixtures.h" | ||
using namespace vsag; | ||
|
||
#define TEST_RECALL(Func) \ |
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.
Renaming it to TEST_ACCURACY would be more accurate.
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.
done
auto val = query[i] - codes[i]; | ||
result += val * val; | ||
} | ||
return result; |
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.
There is no sqrt in the result. So, it is better to rename it to "FP32ComputeL2".
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.
L2Sqr is the Square of L2 norm
private: | ||
uint64_t dim_{0}; | ||
|
||
uint64_t codeSize_{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.
unify the code style.
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.
codeSize -> code_size_
f1ae5ea
to
ca3eda5
Compare
eb24b83
to
414ce55
Compare
auto* outVec = new float[dim]; | ||
quant.DecodeOne(codes, outVec); | ||
for (int i = 0; i < dim; ++i) { | ||
REQUIRE(std::abs(vecs[idx * dim + i] - outVec[i]) < error); |
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.
should replace abs with fabs?
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.
For integral arguments, the integral overloads of std::abs are likely better matches.
reference: https://en.cppreference.com/w/cpp/numeric/math/fabs
sum = _mm256_add_ps(sum, _mm256_mul_ps(a, b)); // accumulate the product | ||
} | ||
alignas(32) float result[8]; | ||
_mm256_store_ps(result, sum); // store the accumulated result into an array |
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.
When n == 0, the store instruction (e.g. _mm256_store_ps) still occur in the avx512, avx2, and sse operators that may be harmful to the performance. Is it possible to add a judgment to skip these store instructions?
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, I have fixed it
} else if (metric == vsag::MetricType::METRIC_TYPE_L2SQR) { | ||
gt = L2Sqr(data + idx1 * dim, query + i * dim, &dim); | ||
} | ||
REQUIRE(std::abs(gt - value) < 1e-4); |
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.
fabs?
60ae2ae
to
f421f5f
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.
LGTM
24002ac
to
d5e42ef
Compare
Signed-off-by: LHT129 <[email protected]>
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.
lgtm
|
||
namespace vsag { | ||
|
||
template <typename IOTmpl> |
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.
IOTmpl
need any interface limit ?
return ret; | ||
} | ||
void | ||
MemoryIO::PrefetchImpl(uint64_t offset, uint64_t cacheLine) { |
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.
explicit mark cacheLine
to unused ?
cacheLine -> cache_line
|
||
namespace vsag { | ||
|
||
template <MetricType Metric = MetricType::METRIC_TYPE_L2SQR> |
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.
Metric -> metric
} | ||
|
||
inline void | ||
Prefetch(uint64_t offset, uint64_t cacheLine = 64) { |
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.
cacheLine -> cache_line
MultiReadImpl(uint8_t* datas, uint64_t* sizes, uint64_t* offsets, uint64_t count) const; | ||
|
||
inline void | ||
PrefetchImpl(uint64_t offset, uint64_t cacheLine = 64); |
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.
cacheLine -> cache_line
|
||
uint64_t codeSize_{0}; | ||
|
||
bool isTrained_{false}; |
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.
isTrained_ -> is_trained_
private: | ||
uint64_t dim_{0}; | ||
|
||
uint64_t codeSize_{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.
codeSize -> code_size_
} else if (Metric == MetricType::METRIC_TYPE_COSINE) { | ||
return InnerProduct(codes1, codes2, &this->dim_); // TODO | ||
} else { | ||
return 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.
0.0 ?