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

[ neon ] Implement neon kernel for copy_s16_f32 #2881

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions nntrainer/tensor/blas_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -979,13 +979,18 @@ void scopy_int8_to_float32(const unsigned int N, const int8_t *X,
}
}

static inline void copy_s16_fp32_fallback(const unsigned int N,
const int16_t *X, float *Y) {
for (unsigned int idx = 0; idx < N; ++idx) {
Y[idx] = (float)X[idx];
}
}

void copy_s16_fp32(const unsigned int N, const int16_t *X, float *Y) {
#ifdef USE_NEON
nntrainer::neon::copy_s16_fp32(N, X, Y);
#endif
for (unsigned int idx = 0; idx < N; ++idx) {
Y[idx] = (float)X[idx];
}
copy_s16_fp32_fallback(N, X, Y);
}

float snrm2(const int N, const float *X, const int incX) {
Expand Down
17 changes: 16 additions & 1 deletion nntrainer/tensor/blas_neon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1598,8 +1598,23 @@ void copy_int8_to_fp32(const unsigned int N, const int8_t *X, float *Y) {
}

void copy_s16_fp32(const unsigned int N, const int16_t *X, float *Y) {
/// @todo implement int16_t to fp32
unsigned int idx = 0;
for (; (N - idx) >= 8; idx += 8) {
int16x8_t batch = vld1q_s16(&X[idx]);
int16x4_t low = vget_low_s16(batch);
int16x4_t high = vget_high_s16(batch);

// widen to s32
int32x4_t low_s32 = vmovl_s16(low);
int32x4_t high_s32 = vmovl_s16(high);

// convert to f32
float32x4_t low_f32 = vcvtq_f32_s32(low_s32);
float32x4_t high_f32 = vcvtq_f32_s32(high_s32);

vst1q_f32(&Y[idx], low_f32);
vst1q_f32(&Y[idx + 4], high_f32);
}
for (; (N - idx) >= 1; ++idx) {
Y[idx] = X[idx];
}
Expand Down
Loading