Skip to content

Commit

Permalink
fix using arm neon
Browse files Browse the repository at this point in the history
  • Loading branch information
maxilevi committed Jun 27, 2024
1 parent 0e0b08f commit 7fe36f3
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions test/bench_simd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ namespace HWY_NAMESPACE {
} // namespace HWY_NAMESPACE
HWY_AFTER_NAMESPACE();


template<class T> void DotProductStandard(const T* arr1, const T* arr2, T* result, size_t size) {
T accum = 0;
for (size_t i = 0; i < size; ++i) {
accum += arr1[i] * arr2[i];
}
*result = accum;
}

#if defined(__ARM_NEON)
#include <arm_neon.h>

void DotProductSIMD_NEON(const float* arr1, const float* arr2, float* result, size_t size) {
Expand All @@ -54,14 +64,15 @@ void DotProductSIMD_NEON(const float* arr1, const float* arr2, float* result, si
}
}

template<class T> void DotProductStandard(const T* arr1, const T* arr2, T* result, size_t size) {
T accum = 0;
for (size_t i = 0; i < size; ++i) {
accum += arr1[i] * arr2[i];
}
*result = accum;
#else

void DotProductSIMD_NEON(const float* arr1, const float* arr2, float* result, size_t size) {
printf("NEON not supported on this platform\n");
DotProductStandard(arr1, arr2, result, size);
}

#endif

template<typename T>
std::pair<T, T> calculateMeanAndStd(const std::vector<T>& data) {
T sum = std::accumulate(data.begin(), data.end(), T(0));
Expand Down

0 comments on commit 7fe36f3

Please sign in to comment.