-
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.
ADD: move the remaining functions to new format
- Loading branch information
Showing
14 changed files
with
108 additions
and
235 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
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,34 @@ | ||
|
||
#include "nn_elu.h" | ||
|
||
|
||
void NN_ELU(Tensor *y, Tensor *x, float alpha) { | ||
assert(y->ndim == x->ndim); | ||
assert(y->dtype == x->dtype); | ||
assert(y->size == x->size); | ||
|
||
switch (y->dtype) { | ||
case DTYPE_F32: | ||
for (size_t i = 0; i < y->shape[0] * y->shape[1]; i += 1) { | ||
if (((float *)x->data)[i] > 0) { | ||
((float *)y->data)[i] = ((float *)x->data)[i]; | ||
} | ||
else { | ||
((float *)y->data)[i] = alpha * (expf(((float *)x->data)[i]) - 1.f); | ||
} | ||
} | ||
// NN__elu_F32(y->size, (float *)y->data, (float *)x->data, 0.0f); | ||
return; | ||
|
||
default: | ||
break; | ||
} | ||
|
||
printf("[ERROR] Unsupported operation between tensor with dtype %s = ELU(%s)\n", | ||
NN_getDataTypeName(y->dtype), NN_getDataTypeName(x->dtype) | ||
); | ||
} | ||
|
||
void NN_ELUInplace(Tensor *x, float alpha) { | ||
NN_ELU(x, x, alpha); | ||
} |
File renamed without changes.
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 @@ | ||
|
||
#include "nn_matrixnorm.h" | ||
|
||
#ifdef RVV | ||
#include <riscv_vector.h> | ||
#endif | ||
|
||
void NN_matrixNorm(Tensor *scalar, Tensor *x) { | ||
assert(x->ndim == 2); | ||
assert(NN_isScalar(scalar)); | ||
assert(scalar->dtype == x->dtype); | ||
|
||
switch (x->dtype) { | ||
case DTYPE_F32: | ||
NN_matrixNorm_F32(scalar, x); | ||
return; | ||
|
||
default: | ||
break; | ||
} | ||
|
||
printf("[ERROR] Unsupported operation between tensor with dtype %s = ||%s||\n", | ||
NN_getDataTypeName(scalar->dtype), NN_getDataTypeName(x->dtype) | ||
); | ||
} | ||
|
||
void NN_matrixNorm_F32(Tensor *scalar, Tensor *x) { | ||
float sum = 0; | ||
#ifdef RVV | ||
float *ptr = x->data; | ||
|
||
size_t vlmax = __riscv_vsetvlmax_e32m1(); | ||
vfloat32m1_t vec_zero = __riscv_vfmv_v_f_f32m1(0, vlmax); | ||
vfloat32m1_t vec_accumulate = __riscv_vfmv_v_f_f32m1(0, vlmax); | ||
|
||
size_t n = x->shape[0] * x->shape[1]; | ||
while (n > 0) { | ||
size_t vl = __riscv_vsetvl_e32m1(n); | ||
vfloat32m1_t vec_a = __riscv_vle32_v_f32m1(ptr, vl); | ||
vec_accumulate = __riscv_vfmacc_vv_f32m1(vec_accumulate, vec_a, vec_a, vl); | ||
ptr += vl; | ||
n -= vl; | ||
} | ||
vfloat32m1_t vec_sum = __riscv_vfredusum_vs_f32m1_f32m1(vec_accumulate, vec_zero, vlmax); | ||
sum = __riscv_vfmv_f_s_f32m1_f32(vec_sum); | ||
#else | ||
for (size_t i = 0; i < x->shape[0]; i += 1) { | ||
for (size_t j = 0; j < x->shape[1]; j += 1) { | ||
sum += pow(((float *)x->data)[i * x->shape[1] + j], 2); | ||
} | ||
} | ||
#endif | ||
|
||
((float *)scalar->data)[0] = sqrt(sum); | ||
return; | ||
} |
File renamed without changes.