Halide 22.0.0 Halide compiler and libraries

mini_qurt.h
Go to the documentation of this file.
1#include "HalideRuntime.h"
2#include "printer.h"
3#include "runtime_internal.h"
4
5namespace Halide {
6namespace Runtime {
7namespace Internal {
8 namespace Qurt {
9
10 enum { QURT_EOK = 0 };
11
12}
13} // namespace Internal
14} // namespace Runtime
15} // namespace Halide
16
17extern "C" {
18 typedef unsigned int qurt_thread_t;
19
20/*
21 Macros for QuRT thread attributes.
22 */
23
24/**
25 * \defgroup qurt_thread_macros QURT threading macros
26 * @{
27 */
28#define QURT_HTHREAD_L1I_PREFETCH 0x1 /**< Enables hardware L1 instruction cache prefetching. */
29#define QURT_HTHREAD_L1D_PREFETCH 0x2 /**< Enables hardware L1 data cache prefetching. */
30#define QURT_HTHREAD_L2I_PREFETCH 0x4 /**< Enables hardware L2 instruction cache prefetching. */
31#define QURT_HTHREAD_L2D_PREFETCH 0x8 /**< Enables hardware L2 data cache prefetching. */
32#define QURT_HTHREAD_DCFETCH 0x10 /**< Enables DC fetch to the provided virtual address. \
33 DC fetch instructs the hardware that a data memory access is likely. \
34 Instructions are dropped in the case of high bus utilization. */
35
36#define QURT_THREAD_ATTR_NAME_MAXLEN 16 /**< */
37#define QURT_THREAD_ATTR_TCB_PARTITION_RAM 0 /**< Creates threads in RAM/DDR. */
38#define QURT_THREAD_ATTR_TCB_PARTITION_TCM 1 /**< Creates threads in TCM. */
39#define QURT_THREAD_ATTR_TCB_PARTITION_DEFAULT QURT_THREAD_ATTR_TCB_PARTITION_RAM /**< Backward compatibility. */
40#define QURT_THREAD_ATTR_PRIORITY_DEFAULT 255 /**< */
41#define QURT_THREAD_ATTR_ASID_DEFAULT 0 /**< */
42#define QURT_THREAD_ATTR_AFFINITY_DEFAULT (-1) /**< */
43#define QURT_THREAD_ATTR_BUS_PRIO_DEFAULT 255 /**< */
44#define QURT_THREAD_ATTR_TIMETEST_ID_DEFAULT (-2) /**< */
45/** @} */
46
47/** Thread attributes */
48 typedef struct _qurt_thread_attr {
49 /** @cond */
50 char name[QURT_THREAD_ATTR_NAME_MAXLEN]; /**< Thread name. */
51 unsigned char tcb_partition; /**< Should the thread TCB reside in RAM or
52 on chip memory (i.e. TCM). */
53 unsigned char affinity; /**< Hardware bitmask indicating the threads it
54 can run on. */
55 unsigned short priority; /**< Thread priority. */
56 unsigned char asid; /**< Address space ID. */
57 unsigned char bus_priority; /**< internal bus priority. */
58 unsigned short timetest_id; /**< Timetest ID. */
59 unsigned int stack_size; /**< Thread stack size. */
60 void *stack_addr; /**< Stack address base, the range of the stack is
61 (stack_addr, stack_addr+stack_size-1). */
62 /** @endcond */
63} qurt_thread_attr_t;
64
65/*=============================================================================
66 FUNCTIONS
67=============================================================================*/
68/**
69 Initializes the structure used to set the thread attributes when a thread is created.
70 After an attribute structure is initialized, the individual attributes in the structure can be
71 explicitly set using the thread attribute operations.
72
73 The default attribute values set the by the initialize operation are the following: \n
74 - Name -- Null string \n
75 - Timetest ID -- QURT_THREAD_ATTR_TIMETEST_ID_DEFAULT \n
76 - Priority -- QURT_THREAD_ATTR_PRIORITY_DEFAULT \n
77 - Affinity -- QURT_THREAD_ATTR_AFFINITY_DEFAULT \n
78 - Bus priority -- QURT_THREAD_ATTR_BUS_PRIO_DEFAULT \n
79 - TCB partition -- QURT_THREAD_ATTR_TCB_PARTITION_DEFAULT
80 - stack_size -- zero
81 - stack_addr -- zero
82
83 @datatypes
84 #qurt_thread_attr_t
85
86 @param[in,out] attr Thread attribute structure.
87
88 @return
89 None.
90*/
91// extern void qurt_thread_attr_init(qurt_thread_attr_t *attr); //pdb remove
92static inline void qurt_thread_attr_init(qurt_thread_attr_t *attr) {
93
94 attr->name[0] = 0;
95 attr->tcb_partition = QURT_THREAD_ATTR_TCB_PARTITION_DEFAULT;
96 attr->priority = QURT_THREAD_ATTR_PRIORITY_DEFAULT;
97 attr->asid = QURT_THREAD_ATTR_ASID_DEFAULT;
98 attr->affinity = QURT_THREAD_ATTR_AFFINITY_DEFAULT;
99 attr->bus_priority = QURT_THREAD_ATTR_BUS_PRIO_DEFAULT;
100 attr->timetest_id = QURT_THREAD_ATTR_TIMETEST_ID_DEFAULT;
101 attr->stack_size = 0;
102 attr->stack_addr = nullptr;
103}
104
105/**
106 Sets the thread stack size attribute.\n
107 Specifies the size of the memory area to be used for a thread's call stack.
108
109 The thread stack address (Section \ref qurt_thread_attr_set_stack_addr ) and stack size specify the memory area used as a
110 call stack for the thread. The user is responsible for allocating the memory area used for
111 the stack.
112
113 @datatypes
114 #qurt_thread_attr_t
115
116 @param[in,out] attr Thread attribute structure.
117 @param[in] stack_size Size (in bytes) of the thread stack.
118
119 @return
120 None.
121*/
122// extern void qurt_thread_attr_set_stack_size(qurt_thread_attr_t *attr, unsigned int stack_size); // pdb remove
123static inline void qurt_thread_attr_set_stack_size(qurt_thread_attr_t *attr, unsigned int stack_size) {
124 attr->stack_size = stack_size;
125}
126
127/**
128 Sets the thread stack address attribute. \n
129 Specifies the base address of the memory area to be used for a thread's call stack.
130
131 stack_addr must contain an address value that is 8-byte aligned.
132
133 The thread stack address and stack size (Section \ref qurt_thread_attr_set_stack_size ) specify the memory area used as a
134 call stack for the thread. \n
135 @note The user is responsible for allocating the memory area used for the thread
136 stack. The memory area must be large enough to contain the stack that is
137 created by the thread.
138
139 @datatypes
140 #qurt_thread_attr_t
141
142 @param[in,out] attr Thread attribute structure.
143 @param[in] stack_addr 8-byte aligned address of the thread stack.
144
145 @return
146 None.
147*/
148static inline void qurt_thread_attr_set_stack_addr(qurt_thread_attr_t *attr, void *stack_addr) {
149 attr->stack_addr = stack_addr;
150}
151
152/**
153 Sets the thread priority to be assigned to a thread.
154 Thread priorities are specified as numeric values in the range 1-255, with 1 representing
155 the highest priority.
156
157 @datatypes
158 #qurt_thread_attr_t
159
160 @param[in,out] attr Thread attribute structure.
161 @param[in] priority Thread priority.
162
163 @return
164 None.
165*/
166static inline void qurt_thread_attr_set_priority(qurt_thread_attr_t *attr, unsigned short priority) {
167 attr->priority = priority;
168}
169
170 extern int qurt_thread_set_priority(qurt_thread_t threadid, unsigned short newprio);
171 extern int qurt_thread_create(qurt_thread_t *thread_id, qurt_thread_attr_t *attr, void (*entrypoint)(void *), void *arg);
172/**
173 Waits for a specified thread to finish.
174 The specified thread should be another thread within the same process.
175 The caller thread is suspended until the specified thread exits. When this happens the
176 caller thread is awakened. \n
177 @note If the specified thread has already exited, this function returns immediately
178 with the result value QURT_ENOTHREAD. \par
179 @note Two threads cannot call qurt_thread_join to wait for the same thread to finish.
180 If this happens QuRT generates an exception.
181
182 @param[in] tid Thread identifier.
183 @param[out] status Destination variable for thread exit status. Returns an application-defined
184 value indicating the termination status of the specified thread.
185
186 @return
187 QURT_ENOTHREAD -- Thread has already exited. \n
188 QURT_EOK -- Thread successfully joined with valid status value.
189 */
190 extern int qurt_thread_join(unsigned int tid, int *status);
191
192/** QuRT mutex type.
193
194 Both non-recursive mutex lock/unlock and recursive
195 mutex lock/unlock can be applied to this type.
196 */
197 typedef union qurt_mutex_aligned8 {
198 /** @cond */
199 struct {
200 unsigned int holder;
201 unsigned int count;
202 unsigned int queue;
203 unsigned int wait_count;
204 };
205 unsigned long long int raw;
206 /** @endcond */
207} qurt_mutex_t;
208
209/** QuRT condition variable type. */
210 typedef union {
211 /** @cond */
212 unsigned long long raw;
213 struct {
214 unsigned int count;
215 unsigned int n_waiting;
216 unsigned int queue;
217 unsigned int reserved;
218 } X;
219 /** @endcond */
220} qurt_cond_t;
221
222 extern void qurt_mutex_init(qurt_mutex_t *lock);
223 extern void qurt_mutex_destroy(qurt_mutex_t *lock);
224 extern void qurt_mutex_lock(qurt_mutex_t *lock); /* blocking */
225 extern void qurt_mutex_unlock(qurt_mutex_t *lock); /* unlock */
226
227 extern void qurt_cond_init(qurt_cond_t *cond);
228 extern void qurt_cond_destroy(qurt_cond_t *cond);
229 extern void qurt_cond_signal(qurt_cond_t *cond);
230 extern void qurt_cond_wait(qurt_cond_t *cond, qurt_mutex_t *mutex);
231
232 typedef enum {
233 QURT_HVX_MODE_64B = 0, /**< HVX mode of 64 bytes */
234 QURT_HVX_MODE_128B = 1 /**< HVX mode of 128 bytes */
235} qurt_hvx_mode_t;
236
237 extern int qurt_hvx_lock(qurt_hvx_mode_t lock_mode);
238 extern int qurt_hvx_unlock(void);
239 extern int qurt_hvx_get_mode(void);
240
241 typedef unsigned int qurt_size_t;
242 typedef unsigned int qurt_mem_pool_t;
243}
HalideRuntime.h
This file declares the routines used by Halide internally in its runtime.
QURT_THREAD_ATTR_BUS_PRIO_DEFAULT
#define QURT_THREAD_ATTR_BUS_PRIO_DEFAULT
Definition: mini_qurt.h:43
QURT_THREAD_ATTR_TIMETEST_ID_DEFAULT
#define QURT_THREAD_ATTR_TIMETEST_ID_DEFAULT
Definition: mini_qurt.h:44
QURT_THREAD_ATTR_ASID_DEFAULT
#define QURT_THREAD_ATTR_ASID_DEFAULT
Definition: mini_qurt.h:41
QURT_THREAD_ATTR_NAME_MAXLEN
#define QURT_THREAD_ATTR_NAME_MAXLEN
Definition: mini_qurt.h:36
QURT_THREAD_ATTR_TCB_PARTITION_DEFAULT
#define QURT_THREAD_ATTR_TCB_PARTITION_DEFAULT
Backward compatibility.
Definition: mini_qurt.h:39
QURT_THREAD_ATTR_AFFINITY_DEFAULT
#define QURT_THREAD_ATTR_AFFINITY_DEFAULT
Definition: mini_qurt.h:42
QURT_THREAD_ATTR_PRIORITY_DEFAULT
#define QURT_THREAD_ATTR_PRIORITY_DEFAULT
Definition: mini_qurt.h:40
qurt_hvx_get_mode
int qurt_hvx_get_mode(void)
qurt_mutex_unlock
void qurt_mutex_unlock(qurt_mutex_t *lock)
qurt_cond_init
void qurt_cond_init(qurt_cond_t *cond)
qurt_cond_wait
void qurt_cond_wait(qurt_cond_t *cond, qurt_mutex_t *mutex)
qurt_mem_pool_t
unsigned int qurt_mem_pool_t
Definition: mini_qurt.h:242
qurt_mutex_destroy
void qurt_mutex_destroy(qurt_mutex_t *lock)
qurt_mutex_lock
void qurt_mutex_lock(qurt_mutex_t *lock)
qurt_size_t
unsigned int qurt_size_t
Definition: mini_qurt.h:241
qurt_cond_signal
void qurt_cond_signal(qurt_cond_t *cond)
qurt_thread_set_priority
int qurt_thread_set_priority(qurt_thread_t threadid, unsigned short newprio)
qurt_thread_create
int qurt_thread_create(qurt_thread_t *thread_id, qurt_thread_attr_t *attr, void(*entrypoint)(void *), void *arg)
qurt_mutex_init
void qurt_mutex_init(qurt_mutex_t *lock)
qurt_mutex_t
union qurt_mutex_aligned8 qurt_mutex_t
QuRT mutex type.
qurt_cond_destroy
void qurt_cond_destroy(qurt_cond_t *cond)
qurt_hvx_mode_t
qurt_hvx_mode_t
Definition: mini_qurt.h:232
QURT_HVX_MODE_64B
@ QURT_HVX_MODE_64B
HVX mode of 64 bytes.
Definition: mini_qurt.h:233
QURT_HVX_MODE_128B
@ QURT_HVX_MODE_128B
HVX mode of 128 bytes.
Definition: mini_qurt.h:234
qurt_hvx_unlock
int qurt_hvx_unlock(void)
qurt_thread_join
int qurt_thread_join(unsigned int tid, int *status)
Waits for a specified thread to finish.
qurt_thread_t
unsigned int qurt_thread_t
Definition: mini_qurt.h:18
qurt_hvx_lock
int qurt_hvx_lock(qurt_hvx_mode_t lock_mode)
qurt_thread_attr_t
struct _qurt_thread_attr qurt_thread_attr_t
Thread attributes.
Halide::Runtime::Internal::Qurt::QURT_EOK
@ QURT_EOK
Definition: mini_qurt.h:10
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition: AbstractGenerator.h:19
Halide::LinkageType::Internal
@ Internal
Not visible externally, similar to 'static' linkage in C.
printer.h
runtime_internal.h
_qurt_thread_attr
Thread attributes.
Definition: mini_qurt.h:48
qurt_cond_t
QuRT condition variable type.
Definition: mini_qurt.h:210
qurt_mutex_aligned8
QuRT mutex type.
Definition: mini_qurt.h:197