SyterKit
0.4.0.x
SyterKit is a bare-metal framework
Loading...
Searching...
No Matches
board
longanpi-3h
tinymaix
tm_port.h
Go to the documentation of this file.
1
/* Copyright 2022 Sipeed Technology Co., Ltd. All Rights Reserved.
2
Licensed under the Apache License, Version 2.0 (the "License");
3
you may not use this file except in compliance with the License.
4
You may obtain a copy of the License at
5
http://www.apache.org/licenses/LICENSE-2.0
6
Unless required by applicable law or agreed to in writing, software
7
distributed under the License is distributed on an "AS IS" BASIS,
8
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9
See the License for the specific language governing permissions and
10
limitations under the License.
11
==============================================================================*/
12
13
#ifndef __TM_PORT_H
14
#define __TM_PORT_H
15
16
#include <
log.h
>
17
#include <timer.h>
18
19
#define TM_ARCH_CPU (0)
//default, pure cpu compute
20
#define TM_ARCH_ARM_SIMD (1)
//ARM Cortex M4/M7, etc.
21
#define TM_ARCH_ARM_NEON (2)
//ARM Cortex A7, etc.
22
#define TM_ARCH_ARM_MVEI (3)
//ARMv8.1: M55, etc.
23
#define TM_ARCH_RV32P (4)
//T-head E907, etc.
24
#define TM_ARCH_RV64V (5)
//T-head C906,C910, etc.
25
#define TM_ARCH_CSKYV2 (6)
//cskyv2 with dsp core
26
#define TM_ARCH_X86_SSE2 (7)
//x86 sse2
27
28
#define TM_OPT0 (0)
//default, least code and buf
29
#define TM_OPT1 (1)
//opt for speed, need more code and buf
30
#define TM_OPT2 (2)
//TODO
31
32
33
#define TM_ARCH TM_ARCH_CPU
34
#define TM_OPT_LEVEL TM_OPT0
35
#define TM_MDL_TYPE TM_MDL_INT8
36
#define TM_FASTSCALE (0)
//enable if your chip don't have FPU, may speed up 1/3, but decrease accuracy
37
#define TM_LOCAL_MATH (1)
//use local math func (like exp()) to avoid libm
38
#define TM_ENABLE_STAT (1)
//enable mdl stat functions
39
#define TM_MAX_CSIZE (1000)
//max channel num //used if INT8 mdl //cost TM_MAX_CSIZE*4 Byte
40
#define TM_MAX_KSIZE (5 * 5)
//max kernel_size //cost TM_MAX_KSIZE*4 Byte
41
#define TM_MAX_KCSIZE (3 * 3 * 256)
//max kernel_size*channels //cost TM_MAX_KSIZE*sizeof(mtype_t) Byte
42
43
#define TM_INLINE __attribute__((always_inline)) static inline
44
#define TM_WEAK __attribute__((weak))
45
46
#define tm_malloc(x) smalloc(x)
47
#define tm_free(x) sfree(x)
48
49
50
#define TM_PRINTF(...) printk(LOG_LEVEL_MUTE, __VA_ARGS__)
51
#define TM_DBG(...) \
52
TM_PRINTF("###L%d: ", __LINE__); \
53
TM_PRINTF(__VA_ARGS__);
54
#define TM_DBGL() TM_PRINTF("###L%d\n", __LINE__);
55
56
57
#include <timer.h>
58
#define TM_GET_US() time_us();
59
60
#define TM_DBGT_INIT() \
61
uint32_t _start, _finish; \
62
float _time; \
63
_start = TM_GET_US();
64
#define TM_DBGT_START() _start = TM_GET_US();
65
#define TM_DBGT(x) \
66
{ \
67
_finish = TM_GET_US(); \
68
_time = (float) (_finish - _start) / 1000.0; \
69
TM_PRINTF("===%s use %.3f ms\n", (x), _time); \
70
_start = TM_GET_US(); \
71
}
72
73
74
//need clock tick to make accurate statistics
75
#define TM_EN_PERF 0
76
77
#if TM_EN_PERF
78
#define TM_GET_TICK(x) __ASM volatile("csrr %0, mcycle" \
79
: "=r"(x));
//edit your self
80
81
#define TM_TICK_PERUS (380)
//sysconf(_SC_CLK_TCK)/1000000)
82
#define TM_PERF_REG(x) uint64_t x = 0;
83
#define TM_PERF_EXTREG(x) extern uint64_t x;
84
#define TM_PERF_INIT(x) uint64_t _##x##_t0, _##x##_t1;
85
#define TM_PERF_START(x) TM_GET_TICK(_##x##_t0);
86
#define TM_PERF_ADD(x) \
87
{ \
88
TM_GET_TICK(_##x##_t1); \
89
(x) += (_##x##_t1 - _##x##_t0); \
90
TM_GET_TICK(_##x##_t0); \
91
};
92
#define TM_PERF_PRINT(x) TM_PRINTF("PERF " #x ": %ld us\r\n", (x) / TM_TICK_PERUS)
93
#else
94
#define TM_GET_TICK(x)
95
#define TM_TICK_PERUS
96
#define TM_PERF_REG(x)
97
#define TM_PERF_EXTREG(x)
98
#define TM_PERF_INIT(x)
99
#define TM_PERF_START(x)
100
#define TM_PERF_ADD(x)
101
#define TM_PERF_PRINT(x)
102
#endif
103
104
105
108
#endif
log.h
Generated by
1.9.8