-
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
19 changed files
with
416 additions
and
52 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 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,22 @@ | ||
#ifndef __NN_MAX_H | ||
#define __NN_MAX_H | ||
|
||
#include <assert.h> | ||
#include <float.h> | ||
|
||
#include "nn_tensor.h" | ||
|
||
|
||
/** | ||
* Returns the maximum value of all elements in the input tensor. | ||
* | ||
* @param t: input tensor | ||
*/ | ||
float NN_max(Tensor *t); | ||
|
||
float NN_max_F32(Tensor *t); | ||
|
||
float NN_max_F32_RVV(Tensor *t); | ||
|
||
|
||
#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,22 @@ | ||
#ifndef __NN_MIN_H | ||
#define __NN_MIN_H | ||
|
||
#include <assert.h> | ||
#include <float.h> | ||
|
||
#include "nn_tensor.h" | ||
|
||
|
||
/** | ||
* Returns the minimum value of all elements in the input tensor. | ||
* | ||
* @param t: input tensor | ||
*/ | ||
float NN_min(Tensor *t); | ||
|
||
float NN_min_F32(Tensor *t); | ||
|
||
float NN_min_F32_RVV(Tensor *t); | ||
|
||
|
||
#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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/** | ||
* @file rv_common.h | ||
* @brief RISC-V Definitions | ||
* | ||
* This header file provides common definitions and operations for RISC-V core programming. | ||
* It includes memory register attributes, bit operation definitions, RISC-V specific definitions, | ||
* and common enumerations for state and status values. | ||
* | ||
* The memory register attributes define volatile permissions for read-only, write-only, and read/write access. | ||
* The bit operation definitions provide macros for setting, clearing, reading, and writing specific bits in a register. | ||
* The RISC-V specific definitions include macros for reading and writing control and status registers (CSRs), | ||
* as well as operations to swap, set, and clear specific bits in a CSR. | ||
* The common definitions include enumerations for state values (such as RESET and SET), and status values (such as OK and ERROR). | ||
* | ||
* @note This file should be included to access RISC-V core-specific definitions and perform common operations. | ||
* | ||
* @author -T.K.- | ||
* @date 2023-05-20 | ||
*/ | ||
|
||
#ifndef __RV_H | ||
#define __RV_H | ||
|
||
#include <stdint.h> | ||
#include <stddef.h> | ||
|
||
|
||
/* ================ Memory register attributes ================ */ | ||
#ifdef __cplusplus | ||
#define __I volatile /** Defines "read only" permissions */ | ||
#else | ||
#define __I volatile const /** Defines "read only" permissions */ | ||
#endif | ||
#define __O volatile /** Defines "write only" permissions */ | ||
#define __IO volatile /** Defines "read / write" permissions */ | ||
|
||
/* following defines should be used for structure members */ | ||
#define __IM volatile const /** Defines "read only" structure member permissions */ | ||
#define __OM volatile /** Defines "write only" structure member permissions */ | ||
#define __IOM volatile /** Defines "read / write" structure member permissions */ | ||
|
||
|
||
/* ================ Bit Operation definitions ================ */ | ||
#define SET_BITS(REG, BIT) ((REG) |= (BIT)) | ||
#define CLEAR_BITS(REG, BIT) ((REG) &= ~(BIT)) | ||
#define READ_BITS(REG, BIT) ((REG) & (BIT)) | ||
#define WRITE_BITS(REG, CLEARMASK, SETMASK) ((REG) = (((REG) & (~(CLEARMASK))) | (SETMASK))) | ||
|
||
|
||
/* ================ RISC-V specific definitions ================ */ | ||
#define READ_CSR(REG) ({ \ | ||
unsigned long __tmp; \ | ||
asm volatile ("csrr %0, " REG : "=r"(__tmp)); \ | ||
__tmp; }) | ||
|
||
#define WRITE_CSR(REG, VAL) ({ \ | ||
asm volatile ("csrw " REG ", %0" :: "rK"(VAL)); }) | ||
|
||
#define SWAP_CSR(REG, VAL) ({ \ | ||
unsigned long __tmp; \ | ||
asm volatile ("csrrw %0, " REG ", %1" : "=r"(__tmp) : "rK"(VAL)); \ | ||
__tmp; }) | ||
|
||
#define SET_CSR_BITS(REG, BIT) ({ \ | ||
unsigned long __tmp; \ | ||
asm volatile ("csrrs %0, " REG ", %1" : "=r"(__tmp) : "rK"(BIT)); \ | ||
__tmp; }) | ||
|
||
#define CLEAR_CSR_BITS(REG, BIT) ({ \ | ||
unsigned long __tmp; \ | ||
asm volatile ("csrrc %0, " REG ", %1" : "=r"(__tmp) : "rK"(BIT)); \ | ||
__tmp; }) | ||
|
||
|
||
/* ================ Common definitions ================ */ | ||
typedef enum { | ||
RESET = 0UL, | ||
SET = !RESET, | ||
|
||
DISABLE = RESET, | ||
ENABLE = SET, | ||
|
||
LOW = RESET, | ||
HIGH = SET, | ||
} State; | ||
|
||
typedef enum { | ||
OK = 0U, | ||
ERROR, | ||
BUSY, | ||
TIMEOUT | ||
} Status; | ||
|
||
#endif /* __RV_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
#include "nn_matmul.h" | ||
|
||
void NN_matmul_I8_I8_I32_EAGLEX(Tensor *out, Tensor *a, Tensor *b) { | ||
// TODO: port to here | ||
} | ||
|
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,20 @@ | ||
|
||
#include "nn_max.h" | ||
|
||
|
||
float NN_max_F32(Tensor *t) { | ||
assert(t->dtype == DTYPE_F32); | ||
|
||
float max = -FLT_MAX; | ||
float *t_data = (float *)t->data; | ||
|
||
for (size_t i = 0; i < t->shape[0]; i += 1) { | ||
for (size_t j = 0; j < t->shape[1]; j += 1) { | ||
if (t_data[i * t->shape[1] + j] > max) { | ||
max = t_data[i * t->shape[1] + j]; | ||
} | ||
} | ||
} | ||
|
||
return max; | ||
} |
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,22 @@ | ||
|
||
#include "nn_max.h" | ||
#include "riscv_vector.h" | ||
|
||
float NN_max_F32_RVV(Tensor *t) { | ||
assert(t->dtype == DTYPE_F32); | ||
|
||
float max = -FLT_MAX; | ||
float *t_data = (float *)t->data; | ||
|
||
vfloat32m1_t vec_max = __riscv_vfmv_s_f_f32m1(max, 1); | ||
size_t i = 0; | ||
size_t vl = 0; | ||
for (size_t k = t->shape[0] * t->shape[1]; k > 0; k -= vl, i += vl) { | ||
vl = __riscv_vsetvl_e32m1(k); | ||
vfloat32m1_t vec_t = __riscv_vle32_v_f32m1(t_data + i, vl); | ||
vec_max = __riscv_vfredmax_vs_f32m1_f32m1(vec_t, vec_max, vl); | ||
} | ||
max = __riscv_vfmv_f_s_f32m1_f32(vec_max); | ||
return max; | ||
} | ||
|
Oops, something went wrong.