SyterKit 0.4.0.x
SyterKit is a bare-metal framework
Loading...
Searching...
No Matches
Classes | Macros | Typedefs | Enumerations | Functions
tinymaix.h File Reference
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "tm_port.h"
Include dependency graph for tinymaix.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  tm_mdlbin_t
 
struct  tm_mdl_t
 
struct  tm_mat_t
 
struct  tml_head_t
 
struct  tml_conv2d_dw_t
 
struct  tml_gap_t
 
struct  tml_fc_t
 
struct  tml_softmax_t
 
struct  tml_reshape_t
 
struct  tml_dwconv2d_t
 
struct  tml_add_t
 

Macros

#define TM_MDL_INT8   0
 
#define TM_MDL_INT16   1
 
#define TM_MDL_FP32   2
 
#define TM_MDL_FP16   3
 
#define TM_MDL_FP8_143   4
 
#define TM_MDL_FP8_152   5
 
#define TM_MDL_MAGIC   0x5849414d
 
#define TM_ALIGN_SIZE   (8)
 
#define TM_ALIGN(addr)   ((((size_t) (addr)) + (TM_ALIGN_SIZE - 1)) / TM_ALIGN_SIZE * TM_ALIGN_SIZE)
 
#define TM_MATP(mat, y, x, ch)   ((mat)->data + ((y) * (mat)->w + (x)) * (mat)->c + (ch))
 
#define UINT2INT_SHIFT   (0)
 
#define TM_FASTSCALE_SHIFT   (8)
 
#define TML_GET_INPUT(mdl, lh)   ((mtype_t *) ((mdl)->buf + (lh)->in_oft))
 
#define TML_GET_OUTPUT(mdl, lh)   ((mtype_t *) ((mdl)->buf + (lh)->out_oft))
 
#define TML_DEQUANT(lh, x)   (((sumtype_t) (x) - ((lh)->out_zp)) * ((lh)->out_s))
 
#define TM_DEQUANT(i8, s, zp)   (((sumtype_t) (i8) - (zp)) * (s))
 
#define TM_QUANT(fp32, s, zp)   ((mtype_t) ((fp32) / (s) + zp))
 
#define tm_exp   _exp
 

Typedefs

typedef int8_t mtype_t
 
typedef int8_t wtype_t
 
typedef int32_t btype_t
 
typedef int32_t sumtype_t
 
typedef int32_t zptype_t
 
typedef float sctype_t
 
typedef tm_err_t(* tml_stat_t) (tml_head_t *layer, tm_mat_t *in, tm_mat_t *out)
 
typedef tm_err_t(* tm_cb_t) (tm_mdl_t *mdl, tml_head_t *lh)
 

Enumerations

enum  tm_err_t {
  TM_OK = 0 , TM_ERR = 1 , TM_ERR_MAGIC = 2 , TM_ERR_UNSUPPORT = 3 ,
  TM_ERR_OOM = 4 , TM_ERR_LAYERTYPE = 5 , TM_ERR_DIMS = 6 , TM_ERR_TODO = 7 ,
  TM_ERR_MDLTYPE = 8 , TM_ERR_KSIZE = 9
}
 
enum  tm_layer_type_t {
  TML_CONV2D = 0 , TML_GAP = 1 , TML_FC = 2 , TML_SOFTMAX = 3 ,
  TML_RESHAPE = 4 , TML_DWCONV2D = 5 , TML_ADD = 6 , TML_MAXCNT
}
 
enum  tm_pad_type_t { TM_PAD_VALID = 0 , TM_PAD_SAME = 1 }
 
enum  tm_act_type_t {
  TM_ACT_NONE = 0 , TM_ACT_RELU = 1 , TM_ACT_RELU1 = 2 , TM_ACT_RELU6 = 3 ,
  TM_ACT_TANH = 4 , TM_ACT_SIGNBIT = 5 , TM_ACT_MAXCNT
}
 
enum  tm_pp_t {
  TMPP_NONE = 0 , TMPP_FP2INT = 1 , TMPP_UINT2INT = 2 , TMPP_UINT2FP01 = 3 ,
  TMPP_UINT2FPN11 = 4 , TMPP_UINT2DTYPE = 5 , TMPP_MAXCNT
}
 

Functions

tm_err_t tm_load (tm_mdl_t *mdl, const uint8_t *bin, uint8_t *buf, tm_cb_t cb, tm_mat_t *in)
 
void tm_unload (tm_mdl_t *mdl)
 
tm_err_t tm_preprocess (tm_mdl_t *mdl, tm_pp_t pp_type, tm_mat_t *in, tm_mat_t *out)
 
tm_err_t tm_run (tm_mdl_t *mdl, tm_mat_t *in, tm_mat_t *out)
 
tm_err_t tml_conv2d_dwconv2d (tm_mat_t *in, tm_mat_t *out, wtype_t *w, btype_t *b, int kw, int kh, int sx, int sy, int dx, int dy, int act, int pad_top, int pad_bottom, int pad_left, int pad_right, int dmul, sctype_t *ws, sctype_t in_s, zptype_t in_zp, sctype_t out_s, zptype_t out_zp)
 
tm_err_t tml_gap (tm_mat_t *in, tm_mat_t *out, sctype_t in_s, zptype_t in_zp, sctype_t out_s, zptype_t out_zp)
 
tm_err_t tml_fc (tm_mat_t *in, tm_mat_t *out, wtype_t *w, btype_t *b, sctype_t *ws, sctype_t in_s, zptype_t in_zp, sctype_t out_s, zptype_t out_zp)
 
tm_err_t tml_softmax (tm_mat_t *in, tm_mat_t *out, sctype_t in_s, zptype_t in_zp, sctype_t out_s, zptype_t out_zp)
 
tm_err_t tml_reshape (tm_mat_t *in, tm_mat_t *out, sctype_t in_s, zptype_t in_zp, sctype_t out_s, zptype_t out_zp)
 
tm_err_t tml_add (tm_mat_t *in0, tm_mat_t *in1, tm_mat_t *out, sctype_t in_s0, zptype_t in_zp0, sctype_t in_s1, zptype_t in_zp1, sctype_t out_s, zptype_t out_zp)
 
tm_err_t tm_stat (tm_mdlbin_t *mdl)
 
uint8_t TM_WEAK tm_fp32to8 (float fp32)
 
float TM_WEAK tm_fp8to32 (uint8_t fp8)
 
static float _exp (float x)
 

Macro Definition Documentation

◆ TM_ALIGN

#define TM_ALIGN (   addr)    ((((size_t) (addr)) + (TM_ALIGN_SIZE - 1)) / TM_ALIGN_SIZE * TM_ALIGN_SIZE)

◆ TM_ALIGN_SIZE

#define TM_ALIGN_SIZE   (8)

◆ TM_DEQUANT

#define TM_DEQUANT (   i8,
  s,
  zp 
)    (((sumtype_t) (i8) - (zp)) * (s))

◆ tm_exp

#define tm_exp   _exp

◆ TM_FASTSCALE_SHIFT

#define TM_FASTSCALE_SHIFT   (8)

◆ TM_MATP

#define TM_MATP (   mat,
  y,
  x,
  ch 
)    ((mat)->data + ((y) * (mat)->w + (x)) * (mat)->c + (ch))

◆ TM_MDL_FP16

#define TM_MDL_FP16   3

◆ TM_MDL_FP32

#define TM_MDL_FP32   2

◆ TM_MDL_FP8_143

#define TM_MDL_FP8_143   4

◆ TM_MDL_FP8_152

#define TM_MDL_FP8_152   5

◆ TM_MDL_INT16

#define TM_MDL_INT16   1

◆ TM_MDL_INT8

#define TM_MDL_INT8   0

◆ TM_MDL_MAGIC

#define TM_MDL_MAGIC   0x5849414d

◆ TM_QUANT

#define TM_QUANT (   fp32,
  s,
  zp 
)    ((mtype_t) ((fp32) / (s) + zp))

◆ TML_DEQUANT

#define TML_DEQUANT (   lh,
 
)    (((sumtype_t) (x) - ((lh)->out_zp)) * ((lh)->out_s))

◆ TML_GET_INPUT

#define TML_GET_INPUT (   mdl,
  lh 
)    ((mtype_t *) ((mdl)->buf + (lh)->in_oft))

◆ TML_GET_OUTPUT

#define TML_GET_OUTPUT (   mdl,
  lh 
)    ((mtype_t *) ((mdl)->buf + (lh)->out_oft))

◆ UINT2INT_SHIFT

#define UINT2INT_SHIFT   (0)

Typedef Documentation

◆ btype_t

typedef int32_t btype_t

◆ mtype_t

typedef int8_t mtype_t

◆ sctype_t

typedef float sctype_t

◆ sumtype_t

typedef int32_t sumtype_t

◆ tm_cb_t

typedef tm_err_t(* tm_cb_t) (tm_mdl_t *mdl, tml_head_t *lh)

◆ tml_stat_t

typedef tm_err_t(* tml_stat_t) (tml_head_t *layer, tm_mat_t *in, tm_mat_t *out)

◆ wtype_t

typedef int8_t wtype_t

◆ zptype_t

typedef int32_t zptype_t

Enumeration Type Documentation

◆ tm_act_type_t

Enumerator
TM_ACT_NONE 
TM_ACT_RELU 
TM_ACT_RELU1 
TM_ACT_RELU6 
TM_ACT_TANH 
TM_ACT_SIGNBIT 
TM_ACT_MAXCNT 

◆ tm_err_t

enum tm_err_t
Enumerator
TM_OK 
TM_ERR 
TM_ERR_MAGIC 
TM_ERR_UNSUPPORT 
TM_ERR_OOM 
TM_ERR_LAYERTYPE 
TM_ERR_DIMS 
TM_ERR_TODO 
TM_ERR_MDLTYPE 
TM_ERR_KSIZE 

◆ tm_layer_type_t

Enumerator
TML_CONV2D 
TML_GAP 
TML_FC 
TML_SOFTMAX 
TML_RESHAPE 
TML_DWCONV2D 
TML_ADD 
TML_MAXCNT 

◆ tm_pad_type_t

Enumerator
TM_PAD_VALID 
TM_PAD_SAME 

◆ tm_pp_t

enum tm_pp_t
Enumerator
TMPP_NONE 
TMPP_FP2INT 
TMPP_UINT2INT 
TMPP_UINT2FP01 
TMPP_UINT2FPN11 
TMPP_UINT2DTYPE 
TMPP_MAXCNT 

Function Documentation

◆ _exp()

static float _exp ( float  x)
inlinestatic

◆ tm_fp32to8()

uint8_t TM_WEAK tm_fp32to8 ( float  fp32)

◆ tm_fp8to32()

float TM_WEAK tm_fp8to32 ( uint8_t  fp8)

◆ tm_load()

tm_err_t tm_load ( tm_mdl_t mdl,
const uint8_t bin,
uint8_t buf,
tm_cb_t  cb,
tm_mat_t in 
)

◆ tm_preprocess()

tm_err_t tm_preprocess ( tm_mdl_t mdl,
tm_pp_t  pp_type,
tm_mat_t in,
tm_mat_t out 
)

◆ tm_run()

tm_err_t tm_run ( tm_mdl_t mdl,
tm_mat_t in,
tm_mat_t out 
)

◆ tm_stat()

tm_err_t tm_stat ( tm_mdlbin_t mdl)

◆ tm_unload()

void tm_unload ( tm_mdl_t mdl)

◆ tml_add()

tm_err_t tml_add ( tm_mat_t in0,
tm_mat_t in1,
tm_mat_t out,
sctype_t  in_s0,
zptype_t  in_zp0,
sctype_t  in_s1,
zptype_t  in_zp1,
sctype_t  out_s,
zptype_t  out_zp 
)

◆ tml_conv2d_dwconv2d()

tm_err_t tml_conv2d_dwconv2d ( tm_mat_t in,
tm_mat_t out,
wtype_t w,
btype_t b,
int  kw,
int  kh,
int  sx,
int  sy,
int  dx,
int  dy,
int  act,
int  pad_top,
int  pad_bottom,
int  pad_left,
int  pad_right,
int  dmul,
sctype_t ws,
sctype_t  in_s,
zptype_t  in_zp,
sctype_t  out_s,
zptype_t  out_zp 
)

◆ tml_fc()

tm_err_t tml_fc ( tm_mat_t in,
tm_mat_t out,
wtype_t w,
btype_t b,
sctype_t ws,
sctype_t  in_s,
zptype_t  in_zp,
sctype_t  out_s,
zptype_t  out_zp 
)

◆ tml_gap()

tm_err_t tml_gap ( tm_mat_t in,
tm_mat_t out,
sctype_t  in_s,
zptype_t  in_zp,
sctype_t  out_s,
zptype_t  out_zp 
)

◆ tml_reshape()

tm_err_t tml_reshape ( tm_mat_t in,
tm_mat_t out,
sctype_t  in_s,
zptype_t  in_zp,
sctype_t  out_s,
zptype_t  out_zp 
)

◆ tml_softmax()

tm_err_t tml_softmax ( tm_mat_t in,
tm_mat_t out,
sctype_t  in_s,
zptype_t  in_zp,
sctype_t  out_s,
zptype_t  out_zp 
)