-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
622 additions
and
425 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#ifndef __NN__ABS_H | ||
#define __NN__ABS_H | ||
|
||
#include <stddef.h> | ||
#include <stdint.h> | ||
#include <math.h> | ||
|
||
#ifdef AVX | ||
#include <immintrin.h> | ||
#endif | ||
|
||
#ifdef RVV | ||
#include <riscv_vector.h> | ||
#endif | ||
|
||
static inline void NN__abs_F32(size_t n, float *y, float *x) { | ||
#if defined(AVX) | ||
// Mask to clear the sign bit | ||
__m256 mask = _mm256_castsi256_ps(_mm256_set1_epi32(0x7FFFFFFF)); | ||
|
||
size_t vl = 8; | ||
|
||
while (n > 0) { | ||
size_t count = n < vl ? n : vl; | ||
|
||
// Load input values into an AVX register | ||
__m256 vec_x = _mm256_loadu_ps(x); | ||
|
||
// Compute the absolute values | ||
__m256 vec_y = _mm256_and_ps(vec_x, mask); | ||
|
||
// Store the result | ||
_mm256_storeu_ps(y, vec_y); | ||
|
||
x += count; | ||
y += count; | ||
n -= count; | ||
} | ||
#elif defined(RVV) | ||
while (n > 0) { | ||
size_t vl = __riscv_vsetvl_e32m1(n); | ||
vfloat32m1_t vec_x = __riscv_vle32_v_f32m1(x, vl); | ||
vfloat32m1_t vec_y = __riscv_vfabs_v_f32m1(vec_x, vl); | ||
__riscv_vse32_v_f32m1(y, vec_y, vl); | ||
x += vl; | ||
y += vl; | ||
n -= vl; | ||
} | ||
#else | ||
for (size_t i = 0; i < n; i += 1) { | ||
y[i] = fabsf(x[i]); | ||
} | ||
#endif | ||
} | ||
|
||
#endif // __NN__ABS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#ifndef __NN__MAX_H | ||
#define __NN__MAX_H | ||
|
||
#include <stddef.h> | ||
#include <stdint.h> | ||
#include <float.h> | ||
|
||
#ifdef RVV | ||
#include <riscv_vector.h> | ||
#endif | ||
|
||
static inline void NN__max_F32(size_t n, float *s, float *x) { | ||
float max = -FLT_MAX; | ||
|
||
#ifdef RVV | ||
vfloat32m1_t vec_max = __riscv_vfmv_s_f_f32m1(max, 1); | ||
while (n > 0) { | ||
size_t vl = __riscv_vsetvl_e32m1(n); | ||
vfloat32m1_t vec_x = __riscv_vle32_v_f32m1(x, vl); | ||
vec_max = __riscv_vfredmax_vs_f32m1_f32m1(vec_x, vec_max, vl); | ||
x += vl; | ||
n -= vl; | ||
} | ||
max = __riscv_vfmv_f_s_f32m1_f32(vec_max); | ||
#else | ||
for (size_t i = 0; i < n; i += 1) { | ||
float val = x[i]; | ||
max = val > max ? val : max; | ||
} | ||
#endif | ||
|
||
*s = max; | ||
} | ||
|
||
#endif // __NN__MAX_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#ifndef __NN__MIN_H | ||
#define __NN__MIN_H | ||
|
||
#include <stddef.h> | ||
#include <stdint.h> | ||
#include <float.h> | ||
|
||
#ifdef RVV | ||
#include <riscv_vector.h> | ||
#endif | ||
|
||
static inline void NN__min_F32(size_t n, float *s, float *x) { | ||
float min = FLT_MAX; | ||
|
||
#ifdef RVV | ||
vfloat32m1_t vec_min = __riscv_vfmv_s_f_f32m1(min, 1); | ||
while (n > 0) { | ||
size_t vl = __riscv_vsetvl_e32m1(n); | ||
vfloat32m1_t vec_x = __riscv_vle32_v_f32m1(x, vl); | ||
vec_min = __riscv_vfredmin_vs_f32m1_f32m1(vec_x, vec_min, vl); | ||
x += vl; | ||
n -= vl; | ||
} | ||
min = __riscv_vfmv_f_s_f32m1_f32(vec_min); | ||
#else | ||
for (size_t i = 0; i < n; i += 1) { | ||
float val = x[i]; | ||
min = val < min ? val : min; | ||
} | ||
#endif | ||
|
||
*s = min; | ||
} | ||
|
||
#endif // __NN__MIN_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
#ifndef __NN_PRINT_H | ||
#define __NN_PRINT_H | ||
|
||
#include <math.h> | ||
|
||
#include "nn_tensor.h" | ||
|
||
|
||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.