-
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
27 changed files
with
635 additions
and
45 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,26 @@ | ||
#ifndef __NN_ABS_H | ||
#define __NN_ABS_H | ||
|
||
#include <assert.h> | ||
#include <math.h> | ||
|
||
#include "nn_tensor.h" | ||
|
||
|
||
/** | ||
* Computes the absolute value of each element in input. | ||
* | ||
* out_i = |input_i| | ||
* | ||
* @param out: the output tensor | ||
* @param input: the input tensor | ||
*/ | ||
void NN_abs(Tensor *out, Tensor *input); | ||
|
||
void NN_abs_F32(Tensor *out, Tensor *input); | ||
|
||
|
||
void NN_abs_F32_RVV(Tensor *out, Tensor *input); | ||
|
||
|
||
#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,21 @@ | ||
#ifndef __NN_MATRIXNORM_H | ||
#define __NN_MATRIXNORM_H | ||
|
||
#include <assert.h> | ||
#include <math.h> | ||
|
||
#include "nn_tensor.h" | ||
|
||
|
||
/** | ||
* Computes the Frobenius norm of a matrix. | ||
* | ||
* @param tensor: the input tensor of shape (m, n) | ||
*/ | ||
float NN_matrixNorm_F32(Tensor *tensor); | ||
|
||
|
||
float NN_matrixNorm_F32_RVV(Tensor *tensor); | ||
|
||
|
||
#endif // __NN_MATRIXNORM_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,25 @@ | ||
#ifndef __NN_MAXIMUM_H | ||
#define __NN_MAXIMUM_H | ||
|
||
#include <assert.h> | ||
#include <float.h> | ||
|
||
#include "nn_tensor.h" | ||
|
||
|
||
/** | ||
* Computes the element-wise maximum of two tensors. | ||
* | ||
* @param out: the output tensor | ||
* @param a: the input tensor | ||
* @param b: the input tensor | ||
*/ | ||
void NN_maximum(Tensor *out, Tensor *a, Tensor *b); | ||
|
||
void NN_maximum_F32(Tensor *out, Tensor *a, Tensor *b); | ||
|
||
|
||
void NN_maximum_F32_RVV(Tensor *out, Tensor *a, Tensor *b); | ||
|
||
|
||
#endif // __NN_MAXIMUM_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#ifndef __NN_MINIMUM_H | ||
#define __NN_MINIMUM_H | ||
|
||
#include <assert.h> | ||
|
||
#include "nn_tensor.h" | ||
|
||
|
||
/** | ||
* Computes the element-wise minimum of two tensors. | ||
* | ||
* @param out: the output tensor | ||
* @param a: the input tensor | ||
* @param b: the input tensor | ||
*/ | ||
void NN_minimum(Tensor *out, Tensor *a, Tensor *b); | ||
|
||
void NN_minimum_F32(Tensor *out, Tensor *a, Tensor *b); | ||
|
||
|
||
void NN_minimum_F32_RVV(Tensor *out, Tensor *a, Tensor *b); | ||
|
||
|
||
#endif // __NN_MINIMUM_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#ifndef __NN_MULTIPLY_H | ||
#define __NN_MULTIPLY_H | ||
|
||
#include <assert.h> | ||
#include <float.h> | ||
|
||
#include "nn_tensor.h" | ||
|
||
|
||
/** | ||
* Returns the element-wise multiplication of the input tensor with a scalar. | ||
* | ||
* @param out: the output tensor | ||
* @param in: the input tensor | ||
* @param scalar: scalar value | ||
*/ | ||
void NN_multiply(Tensor *out, Tensor *in, float scalar); | ||
|
||
void NN_multiply_F32(Tensor *out, Tensor *in, float scalar); | ||
|
||
void NN_multiply_F32_RVV(Tensor *out, Tensor *in, float scalar); | ||
|
||
|
||
#endif // __NN_MULTIPLY_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,25 @@ | ||
#ifndef __NN_NEG_H | ||
#define __NN_NEG_H | ||
|
||
#include <assert.h> | ||
|
||
#include "nn_tensor.h" | ||
|
||
|
||
/** | ||
* Returns a tensor with the negative of the elements of input. | ||
* | ||
* out = -1 x input | ||
* | ||
* @param out: the output tensor | ||
* @param input: the input tensor | ||
*/ | ||
void NN_neg(Tensor *out, Tensor *input); | ||
|
||
void NN_neg_F32(Tensor *out, Tensor *input); | ||
|
||
|
||
void NN_neg_F32_RVV(Tensor *out, Tensor *input); | ||
|
||
|
||
#endif // __NN_NEG_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
#include "nn_abs.h" | ||
|
||
|
||
void NN_abs_F32(Tensor *out, Tensor *input) { | ||
assert(out->ndim == input->ndim); | ||
assert(input->dtype == DTYPE_F32); | ||
assert(out->dtype == DTYPE_F32); | ||
assert(out->size == input->size); | ||
|
||
for (size_t i = 0; i < out->size; i += 1) { | ||
((float *)out->data)[i] = fabs(((float *)input->data)[i]); | ||
} | ||
} |
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,25 @@ | ||
|
||
#include "nn_abs.h" | ||
#include "riscv_vector.h" | ||
|
||
void NN_abs_F32_RVV(Tensor *out, Tensor *input) { | ||
assert(out->ndim == input->ndim); | ||
assert(input->dtype == DTYPE_F32); | ||
assert(out->dtype == DTYPE_F32); | ||
assert(out->size == input->size); | ||
|
||
float *ptr_out = out->data; | ||
float *ptr_in = input->data; | ||
|
||
size_t n = out->shape[0] * out->shape[1]; | ||
while (n > 0) { | ||
size_t vl = __riscv_vsetvl_e32m1(n); | ||
vfloat32m1_t vec_in = __riscv_vle32_v_f32m1(ptr_in, vl); | ||
vfloat32m1_t vec_out = __riscv_vfabs_v_f32m1(vec_in, vl); | ||
__riscv_vse32_v_f32m1(ptr_out, vec_out, vl); | ||
ptr_in += vl; | ||
ptr_out += vl; | ||
n -= vl; | ||
} | ||
} | ||
|
Oops, something went wrong.