Halide 22.0.0 Halide compiler and libraries

Loading...
Searching...
No Matches
Extern.h
Go to the documentation of this file.
1#ifndef HALIDE_EXTERN_H
2#define HALIDE_EXTERN_H
3
4/** \file
5 *
6 * Convenience macros that lift functions that take C types into
7 * functions that take and return exprs, and call the original
8 * function at runtime under the hood. See test/c_function.cpp for
9 * example usage.
10 */
11
12#include "Debug.h"
13
14#define _halide_check_arg_type(t, name, e, n) \
15 _halide_user_assert((e).type() == (t)) \
16 << "Type mismatch for argument " << (n) << " to extern function " << #name \
17 << ". Type expected is " << (t) << " but the argument " << (e) \
18 << " has type " << (e).type() << ".\n";
19
20#define HalideExtern_1(rt, name, t1) \
21 Halide::Expr name(const Halide::Expr &a1) { \
22 _halide_check_arg_type(Halide::type_of<t1>(), name, a1, 1); \
23 return Halide::Internal::Call::make(Halide::type_of<rt>(), #name, {a1}, Halide::Internal::Call::Extern); \
24 }
25
26#define HalideExtern_2(rt, name, t1, t2) \
27 Halide::Expr name(const Halide::Expr &a1, const Halide::Expr &a2) { \
28 _halide_check_arg_type(Halide::type_of<t1>(), name, a1, 1); \
29 _halide_check_arg_type(Halide::type_of<t2>(), name, a2, 2); \
30 return Halide::Internal::Call::make(Halide::type_of<rt>(), #name, {a1, a2}, Halide::Internal::Call::Extern); \
31 }
32
33#define HalideExtern_3(rt, name, t1, t2, t3) \
34 Halide::Expr name(const Halide::Expr &a1, const Halide::Expr &a2, const Halide::Expr &a3) { \
35 _halide_check_arg_type(Halide::type_of<t1>(), name, a1, 1); \
36 _halide_check_arg_type(Halide::type_of<t2>(), name, a2, 2); \
37 _halide_check_arg_type(Halide::type_of<t3>(), name, a3, 3); \
38 return Halide::Internal::Call::make(Halide::type_of<rt>(), #name, {a1, a2, a3}, Halide::Internal::Call::Extern); \
39 }
40
41#define HalideExtern_4(rt, name, t1, t2, t3, t4) \
42 Halide::Expr name(const Halide::Expr &a1, const Halide::Expr &a2, const Halide::Expr &a3, const Halide::Expr &a4) { \
43 _halide_check_arg_type(Halide::type_of<t1>(), name, a1, 1); \
44 _halide_check_arg_type(Halide::type_of<t2>(), name, a2, 2); \
45 _halide_check_arg_type(Halide::type_of<t3>(), name, a3, 3); \
46 _halide_check_arg_type(Halide::type_of<t4>(), name, a4, 4); \
47 return Halide::Internal::Call::make(Halide::type_of<rt>(), #name, {a1, a2, a3, a4}, Halide::Internal::Call::Extern); \
48 }
49
50#define HalideExtern_5(rt, name, t1, t2, t3, t4, t5) \
51 Halide::Expr name(const Halide::Expr &a1, const Halide::Expr &a2, const Halide::Expr &a3, const Halide::Expr &a4, const Halide::Expr &a5) { \
52 _halide_check_arg_type(Halide::type_of<t1>(), name, a1, 1); \
53 _halide_check_arg_type(Halide::type_of<t2>(), name, a2, 2); \
54 _halide_check_arg_type(Halide::type_of<t3>(), name, a3, 3); \
55 _halide_check_arg_type(Halide::type_of<t4>(), name, a4, 4); \
56 _halide_check_arg_type(Halide::type_of<t5>(), name, a5, 5); \
57 return Halide::Internal::Call::make(Halide::type_of<rt>(), #name, {a1, a2, a3, a4, a5}, Halide::Internal::Call::Extern); \
58 }
59
60#define HalidePureExtern_1(rt, name, t1) \
61 Halide::Expr name(const Halide::Expr &a1) { \
62 _halide_check_arg_type(Halide::type_of<t1>(), name, a1, 1); \
63 return Halide::Internal::Call::make(Halide::type_of<rt>(), #name, {a1}, Halide::Internal::Call::PureExtern); \
64 }
65
66#define HalidePureExtern_2(rt, name, t1, t2) \
67 Halide::Expr name(const Halide::Expr &a1, const Halide::Expr &a2) { \
68 _halide_check_arg_type(Halide::type_of<t1>(), name, a1, 1); \
69 _halide_check_arg_type(Halide::type_of<t2>(), name, a2, 2); \
70 return Halide::Internal::Call::make(Halide::type_of<rt>(), #name, {a1, a2}, Halide::Internal::Call::PureExtern); \
71 }
72
73#define HalidePureExtern_3(rt, name, t1, t2, t3) \
74 Halide::Expr name(const Halide::Expr &a1, const Halide::Expr &a2, const Halide::Expr &a3) { \
75 _halide_check_arg_type(Halide::type_of<t1>(), name, a1, 1); \
76 _halide_check_arg_type(Halide::type_of<t2>(), name, a2, 2); \
77 _halide_check_arg_type(Halide::type_of<t3>(), name, a3, 3); \
78 return Halide::Internal::Call::make(Halide::type_of<rt>(), #name, {a1, a2, a3}, Halide::Internal::Call::PureExtern); \
79 }
80
81#define HalidePureExtern_4(rt, name, t1, t2, t3, t4) \
82 Halide::Expr name(const Halide::Expr &a1, const Halide::Expr &a2, const Halide::Expr &a3, const Halide::Expr &a4) { \
83 _halide_check_arg_type(Halide::type_of<t1>(), name, a1, 1); \
84 _halide_check_arg_type(Halide::type_of<t2>(), name, a2, 2); \
85 _halide_check_arg_type(Halide::type_of<t3>(), name, a3, 3); \
86 _halide_check_arg_type(Halide::type_of<t4>(), name, a4, 4); \
87 return Halide::Internal::Call::make(Halide::type_of<rt>(), #name, {a1, a2, a3, a4}, Halide::Internal::Call::PureExtern); \
88 }
89
90#define HalidePureExtern_5(rt, name, t1, t2, t3, t4, t5) \
91 Halide::Expr name(const Halide::Expr &a1, const Halide::Expr &a2, const Halide::Expr &a3, const Halide::Expr &a4, const Halide::Expr &a5) { \
92 _halide_check_arg_type(Halide::type_of<t1>(), name, a1, 1); \
93 _halide_check_arg_type(Halide::type_of<t2>(), name, a2, 2); \
94 _halide_check_arg_type(Halide::type_of<t3>(), name, a3, 3); \
95 _halide_check_arg_type(Halide::type_of<t4>(), name, a4, 4); \
96 _halide_check_arg_type(Halide::type_of<t5>(), name, a5, 5); \
97 return Halide::Internal::Call::make(Halide::type_of<rt>(), #name, {a1, a2, a3, a4, a5}, Halide::Internal::Call::PureExtern); \
98 }
99#endif
Debug.h
Defines functions for debug logging during code generation.