Back to Mnn

MNN: include/HalideRuntime.h 源文件

doc/API/html/_halide_runtime_8h_source.html

3.5.027.2 KB
Original Source

| MNN 1.0 |

HalideRuntime.h

浏览该文件的文档.

1 #ifndef HALIDE_HALIDERUNTIME_H

2 #define HALIDE_HALIDERUNTIME_H

3

4 #include <stddef.h>

5 #include <stdint.h>

6 #include <stdbool.h>

7

8 #ifdef __cplusplus

9 extern "C" {

10 #endif

11

12 // Note that you should not use "inline" along with HALIDE_ALWAYS_INLINE;

13 // it is not necessary, and may produce warnings for some build configurations.

14 #ifdef _MSC_VER

15 #define HALIDE_ALWAYS_INLINE __forceinline

16 #define HALIDE_NEVER_INLINE __declspec(noinline)

17 #else

18 #define HALIDE_ALWAYS_INLINE __attribute__((always_inline)) inline

19 #define HALIDE_NEVER_INLINE __attribute__((noinline))

20 #endif

21

51 // Forward-declare to suppress warnings if compiling as C.

52 struct [halide_buffer_t](structhalide buffer t.html);

53

59 typedef enum halide_type_code_t

60 {

61halide_type_int = 0,

62halide_type_uint = 1,

63halide_type_float = 2,

64halide_type_handle = 3

65 } halide_type_code_t;

66

67 // Note that while __attribute__ can go before or after the declaration,

68 // __declspec apparently is only allowed before.

69 #ifndef HALIDE_ATTRIBUTE_ALIGN

70 #ifdef _MSC_VER

71 #define HALIDE_ATTRIBUTE_ALIGN(x) __declspec(align(x))

72 #else

73 #define HALIDE_ATTRIBUTE_ALIGN(x) __attribute__((aligned(x)))

74 #endif

75 #endif

76

[82](structhalide type t.html) struct [halide_type_t](structhalide type t.html) {

84 #if __cplusplus >= 201103L

85[HALIDE_ATTRIBUTE_ALIGN](structhalide type t.html#aab2af12cfbc140041449489b96e09846)(1) halide_type_code_t code; // halide_type_code_t

86 #else

87[HALIDE_ATTRIBUTE_ALIGN](structhalide type t.html#aab2af12cfbc140041449489b96e09846)(1) uint8_t code; // halide_type_code_t

88 #endif

89

91[HALIDE_ATTRIBUTE_ALIGN](structhalide type t.html#aab2af12cfbc140041449489b96e09846)(1) uint8_t bits;

92

94[HALIDE_ATTRIBUTE_ALIGN](structhalide type t.html#aab2af12cfbc140041449489b96e09846)(2) uint16_t lanes;

95

96 #ifdef __cplusplus

97

101HALIDE_ALWAYS_INLINE [halide_type_t](structhalide type t.html)(halide_type_code_t code, uint8_t bits, uint16_t lanes = 1)

102 : code(code), bits(bits), lanes(lanes) {

103 }

104

107HALIDE_ALWAYS_INLINE [halide_type_t](structhalide type t.html)() : code((halide_type_code_t)0), bits(0), lanes(0) {}

108

110HALIDE_ALWAYS_INLINE bool operator==(const [halide_type_t](structhalide type t.html) &other) const {

111return (code == other.code &&

112 bits == other.bits &&

113 lanes == other.lanes);

114 }

115

116HALIDE_ALWAYS_INLINE bool operator!=(const [halide_type_t](structhalide type t.html) &other) const {

117return !(*this == other);

118 }

119

121HALIDE_ALWAYS_INLINE int bytes() const { return (bits + 7) / 8; }

122 #endif

123 };

124

127 struct halide_device_interface_impl_t;

128

[143](structhalide device interface__t.html) struct [halide_device_interface_t](structhalide__device interface t.html) {

[144](structhalide device interface__t.html#aefe045212c1c0cc8993ad77b4c7d793b) int (*[device_malloc](structhalide__device interface t.html#aefe045212c1c0cc8993ad77b4c7d793b))(void *user_context, struct [halide_buffer_t](structhalide buffer t.html) *buf,

145const struct [halide_device_interface_t](structhalide device interface__t.html) *device_interface);

[146](structhalide device interface__t.html#ab0bd6619c5acb90929eefa8c94488ebe) int (*[device_free](structhalide__device interface t.html#ab0bd6619c5acb90929eefa8c94488ebe))(void *user_context, struct [halide_buffer_t](structhalide buffer t.html) *buf);

[147](structhalide device interface__t.html#ac7e27bf4acf3d42a41bca1ca15088170) int (*[device_sync](structhalide__device interface t.html#ac7e27bf4acf3d42a41bca1ca15088170))(void *user_context, struct [halide_buffer_t](structhalide buffer t.html) *buf);

[148](structhalide device interface__t.html#a8d54f5cfdce5abfe5079e746ec6e9a32) void (*[device_release](structhalide__device interface t.html#a8d54f5cfdce5abfe5079e746ec6e9a32))(void *user_context,

149const struct [halide_device_interface_t](structhalide device interface__t.html) *device_interface);

[150](structhalide device interface__t.html#a94496f4e1181af69213ee72ad4e2664a) int (*[copy_to_host](structhalide__device interface t.html#a94496f4e1181af69213ee72ad4e2664a))(void *user_context, struct [halide_buffer_t](structhalide buffer t.html) *buf);

[151](structhalide device interface__t.html#aa7ec93c5a376610e3e7100e8b389591f) int (*[copy_to_device](structhalide__device interface t.html#aa7ec93c5a376610e3e7100e8b389591f))(void *user_context, struct [halide_buffer_t](structhalide buffer t.html) *buf,

152const struct [halide_device_interface_t](structhalide device interface__t.html) *device_interface);

[153](structhalide device interface__t.html#a0caa167abc636a7c7af4c602496e61cd) int (*[device_and_host_malloc](structhalide__device interface t.html#a0caa167abc636a7c7af4c602496e61cd))(void *user_context, struct [halide_buffer_t](structhalide buffer t.html) *buf,

154const struct [halide_device_interface_t](structhalide device interface__t.html) *device_interface);

[155](structhalide device interface__t.html#adfe1bff4d8a864c6450bfe10adbed304) int (*[device_and_host_free](structhalide__device interface t.html#adfe1bff4d8a864c6450bfe10adbed304))(void *user_context, struct [halide_buffer_t](structhalide buffer t.html) *buf);

[156](structhalide device interface__t.html#af8cf3a57fb9d7b7e5906e5f5a5d87145) int (*[buffer_copy](structhalide__device interface t.html#af8cf3a57fb9d7b7e5906e5f5a5d87145))(void *user_context, struct [halide_buffer_t](structhalide buffer t.html) *src,

157const struct [halide_device_interface_t](structhalide device interface__t.html) *dst_device_interface, struct halide_buffer_t *dst);

[158](structhalide device interface__t.html#a8a091d3679d588771f88172b8a867bd2) int (*[device_crop](structhalide__device interface t.html#a8a091d3679d588771f88172b8a867bd2))(void *user_context, const struct [halide_buffer_t](structhalide buffer t.html) *src,

159struct [halide_buffer_t](structhalide buffer t.html) *dst);

[160](structhalide device interface__t.html#a3a61cbd45258f14821c95f9b62d38d29) int (*[device_release_crop](structhalide__device interface t.html#a3a61cbd45258f14821c95f9b62d38d29))(void *user_context, struct [halide_buffer_t](structhalide buffer t.html) *buf);

[161](structhalide device interface__t.html#a165c8b301ca4f0013af7767a63afd753) int (*[wrap_native](structhalide__device interface t.html#a165c8b301ca4f0013af7767a63afd753))(void *user_context, struct [halide_buffer_t](structhalide buffer t.html) *buf, uint64_t handle,

162const struct [halide_device_interface_t](structhalide device interface__t.html) *device_interface);

[163](structhalide device interface__t.html#ad22c6f186583b56c91652261e905038f) int (*[detach_native](structhalide__device interface t.html#ad22c6f186583b56c91652261e905038f))(void *user_context, struct [halide_buffer_t](structhalide buffer t.html) *buf);

[164](structhalide device interface__t.html#a0fd396e5aa336a352d86cff51e6099dd)const struct halide_device_interface_impl_t *[impl](structhalide__device interface t.html#a0fd396e5aa336a352d86cff51e6099dd);

165 };

166

[167](structhalide dimension t.html) typedef struct [halide_dimension_t](structhalide dimension t.html) {

[168](structhalide dimension t.html#a80516014224196a33fc560fa023c4363) int32_t [min](structhalide dimension t.html#a49c3d005ce7759e05105763f98112b87), [extent](structhalide dimension t.html#a6c808a6b5accb9fc952917fa671fb9e8), [stride](structhalide dimension t.html#a80516014224196a33fc560fa023c4363);

169

170// Per-dimension flags. None are defined yet (This is reserved for future use).

[171](structhalide dimension t.html#a6a8348375b0afd8e981e712726ac212c) uint32_t [flags](structhalide dimension t.html#a6a8348375b0afd8e981e712726ac212c);

172

173 #ifdef __cplusplus

174HALIDE_ALWAYS_INLINE halide_dimension_t() : [min](structhalide dimension t.html#a49c3d005ce7759e05105763f98112b87)(0), [extent](structhalide dimension t.html#a6c808a6b5accb9fc952917fa671fb9e8)(0), [stride](structhalide dimension t.html#a80516014224196a33fc560fa023c4363)(0), [flags](structhalide dimension t.html#a6a8348375b0afd8e981e712726ac212c)(0) {}

175HALIDE_ALWAYS_INLINE halide_dimension_t(int32_t m, int32_t e, int32_t s, uint32_t f = 0) :

176[min](structhalide dimension t.html#a49c3d005ce7759e05105763f98112b87)(m), [extent](structhalide dimension t.html#a6c808a6b5accb9fc952917fa671fb9e8)(e), [stride](structhalide dimension t.html#a80516014224196a33fc560fa023c4363)(s), [flags](structhalide dimension t.html#a6a8348375b0afd8e981e712726ac212c)(f) {}

177

178HALIDE_ALWAYS_INLINE bool operator==(const [halide_dimension_t](structhalide dimension t.html) &other) const {

179return ([min](structhalide dimension t.html#a49c3d005ce7759e05105763f98112b87) == other.[min](structhalide dimension t.html#a49c3d005ce7759e05105763f98112b87)) &&

180 ([extent](structhalide dimension t.html#a6c808a6b5accb9fc952917fa671fb9e8) == other.[extent](structhalide dimension t.html#a6c808a6b5accb9fc952917fa671fb9e8)) &&

181 ([stride](structhalide dimension t.html#a80516014224196a33fc560fa023c4363) == other.[stride](structhalide dimension t.html#a80516014224196a33fc560fa023c4363)) &&

182 ([flags](structhalide dimension t.html#a6a8348375b0afd8e981e712726ac212c) == other.[flags](structhalide dimension t.html#a6a8348375b0afd8e981e712726ac212c));

183 }

184

185HALIDE_ALWAYS_INLINE bool operator!=(const [halide_dimension_t](structhalide dimension t.html) &other) const {

186return !(*this == other);

187 }

188 #endif

189 } halide_dimension_t;

190

191 #ifdef __cplusplus

192 } // extern "C"

193 #endif

194

195 typedef enum {halide_buffer_flag_host_dirty = 1,

196halide_buffer_flag_device_dirty = 2} halide_buffer_flags;

197

[203](structhalide buffer t.html) typedef struct [halide_buffer_t](structhalide buffer t.html) {

[205](structhalide buffer t.html#a51aa231b39c37cb777369dda8825030f) uint64_t [device](structhalide buffer t.html#a51aa231b39c37cb777369dda8825030f);

206

[208](structhalide buffer t.html#ab449476b5d2b9a6eddb7bd813b7c8f6c)const struct [halide_device_interface_t](structhalide device interface__t.html) *device_interface;

209

[213](structhalide buffer t.html#a6e3420b357ead1398489ea508f3ac4a9) uint8_t* [host](structhalide buffer t.html#a6e3420b357ead1398489ea508f3ac4a9);

214

[216](structhalide buffer t.html#acbee1a8a419c5ba3dcaedfabb3817c8c) uint64_t [flags](structhalide buffer t.html#acbee1a8a419c5ba3dcaedfabb3817c8c);

217

[219](structhalide buffer t.html#a7aa90af2694ee99f6a097eaecbd7dcc2)struct [halide_type_t](structhalide type t.html) [type](structhalide buffer t.html#a7aa90af2694ee99f6a097eaecbd7dcc2);

220

[222](structhalide buffer t.html#a15a026342a3f8402f06d8b0f9f1391dc) int32_t [dimensions](structhalide buffer t.html#a15a026342a3f8402f06d8b0f9f1391dc);

223

[226](structhalide buffer t.html#a36ad75ba5fff094906f338aa48722bbe)[halide_dimension_t](structhalide dimension t.html) *[dim](structhalide buffer t.html#a36ad75ba5fff094906f338aa48722bbe);

227

[229](structhalide buffer t.html#a0a1207bdde5e92c5b367a92c118a76c3)void *[padding](structhalide buffer t.html#a0a1207bdde5e92c5b367a92c118a76c3);

230 } halide_buffer_t;

231

232

233 #ifdef __cplusplus

234

235 namespace {

236 template<typename T> struct check_is_pointer;

237 template<typename T> struct check_is_pointer<T *> {};

238 }

239

241 template<typename T>

242 HALIDE_ALWAYS_INLINE [halide_type_t](structhalide type t.html) halide_type_of() {

243// Create a compile-time error if T is not a pointer (without

244// using any includes - this code goes into the runtime).

245 check_is_pointer<T> check;

246 (void)check;

247return [halide_type_t](structhalide type t.html)(halide_type_handle, 64);

248 }

249

250 template<>

251 HALIDE_ALWAYS_INLINE [halide_type_t](structhalide type t.html) halide_type_of<float>() {

252return [halide_type_t](structhalide type t.html)(halide_type_float, 32);

253 }

254

255 template<>

256 HALIDE_ALWAYS_INLINE [halide_type_t](structhalide type t.html) halide_type_of<double>() {

257return [halide_type_t](structhalide type t.html)(halide_type_float, 64);

258 }

259

260 template<>

261 HALIDE_ALWAYS_INLINE [halide_type_t](structhalide type t.html) halide_type_of<bool>() {

262return [halide_type_t](structhalide type t.html)(halide_type_uint, 1);

263 }

264

265 template<>

266 HALIDE_ALWAYS_INLINE [halide_type_t](structhalide type t.html) halide_type_of<uint8_t>() {

267return [halide_type_t](structhalide type t.html)(halide_type_uint, 8);

268 }

269

270 template<>

271 HALIDE_ALWAYS_INLINE [halide_type_t](structhalide type t.html) halide_type_of<uint16_t>() {

272return [halide_type_t](structhalide type t.html)(halide_type_uint, 16);

273 }

274

275 template<>

276 HALIDE_ALWAYS_INLINE [halide_type_t](structhalide type t.html) halide_type_of<uint32_t>() {

277return [halide_type_t](structhalide type t.html)(halide_type_uint, 32);

278 }

279

280 template<>

281 HALIDE_ALWAYS_INLINE [halide_type_t](structhalide type t.html) halide_type_of<uint64_t>() {

282return [halide_type_t](structhalide type t.html)(halide_type_uint, 64);

283 }

284

285 template<>

286 HALIDE_ALWAYS_INLINE [halide_type_t](structhalide type t.html) halide_type_of<int8_t>() {

287return [halide_type_t](structhalide type t.html)(halide_type_int, 8);

288 }

289

290 template<>

291 HALIDE_ALWAYS_INLINE [halide_type_t](structhalide type t.html) halide_type_of<int16_t>() {

292return [halide_type_t](structhalide type t.html)(halide_type_int, 16);

293 }

294

295 template<>

296 HALIDE_ALWAYS_INLINE [halide_type_t](structhalide type t.html) halide_type_of<int32_t>() {

297return [halide_type_t](structhalide type t.html)(halide_type_int, 32);

298 }

299

300 template<>

301 HALIDE_ALWAYS_INLINE [halide_type_t](structhalide type t.html) halide_type_of<int64_t>() {

302return [halide_type_t](structhalide type t.html)(halide_type_int, 64);

303 }

304

305 #endif

306

307 #endif // HALIDE_HALIDERUNTIME_H

[halide_dimension_t](structhalide dimension t.html)

Definition: HalideRuntime.h:167

halide_buffer_flag_host_dirty

Definition: HalideRuntime.h:195

[halide_device_interface_t::device_and_host_malloc](structhalide device interface__t.html#a0caa167abc636a7c7af4c602496e61cd)

int(* device_and_host_malloc)(void *user_context, struct halide_buffer_t *buf, const struct halide_device_interface_t *device_interface)

Definition: HalideRuntime.h:153

halide_dimension_t

struct halide_dimension_t halide_dimension_t

[halide_device_interface_t::detach_native](structhalide device interface__t.html#ad22c6f186583b56c91652261e905038f)

int(* detach_native)(void *user_context, struct halide_buffer_t *buf)

Definition: HalideRuntime.h:163

[halide_device_interface_t::wrap_native](structhalide device interface__t.html#a165c8b301ca4f0013af7767a63afd753)

int(* wrap_native)(void *user_context, struct halide_buffer_t *buf, uint64_t handle, const struct halide_device_interface_t *device_interface)

Definition: HalideRuntime.h:161

[halide_buffer_t::type](structhalide buffer t.html#a7aa90af2694ee99f6a097eaecbd7dcc2)

struct halide_type_t type

Definition: HalideRuntime.h:219

[halide_device_interface_t::device_and_host_free](structhalide device interface__t.html#adfe1bff4d8a864c6450bfe10adbed304)

int(* device_and_host_free)(void *user_context, struct halide_buffer_t *buf)

Definition: HalideRuntime.h:155

halide_type_float

floating point numbers

Definition: HalideRuntime.h:63

[halide_device_interface_t::device_malloc](structhalide device interface__t.html#aefe045212c1c0cc8993ad77b4c7d793b)

int(* device_malloc)(void *user_context, struct halide_buffer_t *buf, const struct halide_device_interface_t *device_interface)

Definition: HalideRuntime.h:144

[halide_device_interface_t::device_release](structhalide device interface__t.html#a8d54f5cfdce5abfe5079e746ec6e9a32)

void(* device_release)(void *user_context, const struct halide_device_interface_t *device_interface)

Definition: HalideRuntime.h:148

[halide_dimension_t::extent](structhalide dimension t.html#a6c808a6b5accb9fc952917fa671fb9e8)

int32_t extent

Definition: HalideRuntime.h:168

[halide_buffer_t::flags](structhalide buffer t.html#acbee1a8a419c5ba3dcaedfabb3817c8c)

uint64_t flags

Definition: HalideRuntime.h:216

[halide_dimension_t::flags](structhalide dimension t.html#a6a8348375b0afd8e981e712726ac212c)

uint32_t flags

Definition: HalideRuntime.h:171

[halide_buffer_t::dim](structhalide buffer t.html#a36ad75ba5fff094906f338aa48722bbe)

halide_dimension_t * dim

Definition: HalideRuntime.h:226

halide_buffer_flag_device_dirty

Definition: HalideRuntime.h:196

halide_type_uint

unsigned integers

Definition: HalideRuntime.h:62

[halide_device_interface_t::device_sync](structhalide device interface__t.html#ac7e27bf4acf3d42a41bca1ca15088170)

int(* device_sync)(void *user_context, struct halide_buffer_t *buf)

Definition: HalideRuntime.h:147

[halide_device_interface_t::copy_to_device](structhalide device interface__t.html#aa7ec93c5a376610e3e7100e8b389591f)

int(* copy_to_device)(void *user_context, struct halide_buffer_t *buf, const struct halide_device_interface_t *device_interface)

Definition: HalideRuntime.h:151

[halide_device_interface_t::device_release_crop](structhalide device interface__t.html#a3a61cbd45258f14821c95f9b62d38d29)

int(* device_release_crop)(void *user_context, struct halide_buffer_t *buf)

Definition: HalideRuntime.h:160

halide_buffer_t

struct halide_buffer_t halide_buffer_t

[halide_device_interface_t](structhalide device interface__t.html)

Definition: HalideRuntime.h:143

halide_type_handle

opaque pointer type (void *)

Definition: HalideRuntime.h:64

[halide_buffer_t::dimensions](structhalide buffer t.html#a15a026342a3f8402f06d8b0f9f1391dc)

int32_t dimensions

Definition: HalideRuntime.h:222

[halide_dimension_t::stride](structhalide dimension t.html#a80516014224196a33fc560fa023c4363)

int32_t stride

Definition: HalideRuntime.h:168

HALIDE_ALWAYS_INLINE

#define HALIDE_ALWAYS_INLINE

Definition: HalideRuntime.h:18

[halide_type_t](structhalide type t.html)

Definition: HalideRuntime.h:82

[halide_buffer_t::device_interface](structhalide buffer t.html#ab449476b5d2b9a6eddb7bd813b7c8f6c)

const struct halide_device_interface_t * device_interface

Definition: HalideRuntime.h:208

[halide_buffer_t::host](structhalide buffer t.html#a6e3420b357ead1398489ea508f3ac4a9)

uint8_t * host

Definition: HalideRuntime.h:213

[halide_device_interface_t::impl](structhalide device interface__t.html#a0fd396e5aa336a352d86cff51e6099dd)

const struct halide_device_interface_impl_t * impl

Definition: HalideRuntime.h:164

[halide_dimension_t::min](structhalide dimension t.html#a49c3d005ce7759e05105763f98112b87)

int32_t min

Definition: HalideRuntime.h:168

[halide_buffer_t::padding](structhalide buffer t.html#a0a1207bdde5e92c5b367a92c118a76c3)

void * padding

Definition: HalideRuntime.h:229

halide_type_code_t

halide_type_code_t

Definition: HalideRuntime.h:59

[halide_device_interface_t::copy_to_host](structhalide device interface__t.html#a94496f4e1181af69213ee72ad4e2664a)

int(* copy_to_host)(void *user_context, struct halide_buffer_t *buf)

Definition: HalideRuntime.h:150

[halide_buffer_t::device](structhalide buffer t.html#a51aa231b39c37cb777369dda8825030f)

uint64_t device

Definition: HalideRuntime.h:205

[halide_device_interface_t::buffer_copy](structhalide device interface__t.html#af8cf3a57fb9d7b7e5906e5f5a5d87145)

int(* buffer_copy)(void *user_context, struct halide_buffer_t *src, const struct halide_device_interface_t *dst_device_interface, struct halide_buffer_t *dst)

Definition: HalideRuntime.h:156

[halide_buffer_t](structhalide buffer t.html)

Definition: HalideRuntime.h:203

[halide_type_t::HALIDE_ATTRIBUTE_ALIGN](structhalide type t.html#aab2af12cfbc140041449489b96e09846)

HALIDE_ATTRIBUTE_ALIGN(1) uint8_t code

halide_buffer_flags

halide_buffer_flags

Definition: HalideRuntime.h:195

[halide_device_interface_t::device_crop](structhalide device interface__t.html#a8a091d3679d588771f88172b8a867bd2)

int(* device_crop)(void *user_context, const struct halide_buffer_t *src, struct halide_buffer_t *dst)

Definition: HalideRuntime.h:158

halide_type_int

signed integers

Definition: HalideRuntime.h:61

[halide_device_interface_t::device_free](structhalide device interface__t.html#ab0bd6619c5acb90929eefa8c94488ebe)

int(* device_free)(void *user_context, struct halide_buffer_t *buf)

Definition: HalideRuntime.h:146


制作者 1.8.15