Halide
19.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) << "Type mismatch for argument " << n << " to extern function " << #name << ". Type expected is " << t << " but the argument " << e << " has type " << e.type() << ".\n";
16
17
#define HalideExtern_1(rt, name, t1) \
18
Halide::Expr name(const Halide::Expr &a1) { \
19
_halide_check_arg_type(Halide::type_of<t1>(), name, a1, 1); \
20
return Halide::Internal::Call::make(Halide::type_of<rt>(), #name, {a1}, Halide::Internal::Call::Extern); \
21
}
22
23
#define HalideExtern_2(rt, name, t1, t2) \
24
Halide::Expr name(const Halide::Expr &a1, const Halide::Expr &a2) { \
25
_halide_check_arg_type(Halide::type_of<t1>(), name, a1, 1); \
26
_halide_check_arg_type(Halide::type_of<t2>(), name, a2, 2); \
27
return Halide::Internal::Call::make(Halide::type_of<rt>(), #name, {a1, a2}, Halide::Internal::Call::Extern); \
28
}
29
30
#define HalideExtern_3(rt, name, t1, t2, t3) \
31
Halide::Expr name(const Halide::Expr &a1, const Halide::Expr &a2, const Halide::Expr &a3) { \
32
_halide_check_arg_type(Halide::type_of<t1>(), name, a1, 1); \
33
_halide_check_arg_type(Halide::type_of<t2>(), name, a2, 2); \
34
_halide_check_arg_type(Halide::type_of<t3>(), name, a3, 3); \
35
return Halide::Internal::Call::make(Halide::type_of<rt>(), #name, {a1, a2, a3}, Halide::Internal::Call::Extern); \
36
}
37
38
#define HalideExtern_4(rt, name, t1, t2, t3, t4) \
39
Halide::Expr name(const Halide::Expr &a1, const Halide::Expr &a2, const Halide::Expr &a3, const Halide::Expr &a4) { \
40
_halide_check_arg_type(Halide::type_of<t1>(), name, a1, 1); \
41
_halide_check_arg_type(Halide::type_of<t2>(), name, a2, 2); \
42
_halide_check_arg_type(Halide::type_of<t3>(), name, a3, 3); \
43
_halide_check_arg_type(Halide::type_of<t4>(), name, a4, 4); \
44
return Halide::Internal::Call::make(Halide::type_of<rt>(), #name, {a1, a2, a3, a4}, Halide::Internal::Call::Extern); \
45
}
46
47
#define HalideExtern_5(rt, name, t1, t2, t3, t4, t5) \
48
Halide::Expr name(const Halide::Expr &a1, const Halide::Expr &a2, const Halide::Expr &a3, const Halide::Expr &a4, const Halide::Expr &a5) { \
49
_halide_check_arg_type(Halide::type_of<t1>(), name, a1, 1); \
50
_halide_check_arg_type(Halide::type_of<t2>(), name, a2, 2); \
51
_halide_check_arg_type(Halide::type_of<t3>(), name, a3, 3); \
52
_halide_check_arg_type(Halide::type_of<t4>(), name, a4, 4); \
53
_halide_check_arg_type(Halide::type_of<t5>(), name, a5, 5); \
54
return Halide::Internal::Call::make(Halide::type_of<rt>(), #name, {a1, a2, a3, a4, a5}, Halide::Internal::Call::Extern); \
55
}
56
57
#define HalidePureExtern_1(rt, name, t1) \
58
Halide::Expr name(const Halide::Expr &a1) { \
59
_halide_check_arg_type(Halide::type_of<t1>(), name, a1, 1); \
60
return Halide::Internal::Call::make(Halide::type_of<rt>(), #name, {a1}, Halide::Internal::Call::PureExtern); \
61
}
62
63
#define HalidePureExtern_2(rt, name, t1, t2) \
64
Halide::Expr name(const Halide::Expr &a1, const Halide::Expr &a2) { \
65
_halide_check_arg_type(Halide::type_of<t1>(), name, a1, 1); \
66
_halide_check_arg_type(Halide::type_of<t2>(), name, a2, 2); \
67
return Halide::Internal::Call::make(Halide::type_of<rt>(), #name, {a1, a2}, Halide::Internal::Call::PureExtern); \
68
}
69
70
#define HalidePureExtern_3(rt, name, t1, t2, t3) \
71
Halide::Expr name(const Halide::Expr &a1, const Halide::Expr &a2, const Halide::Expr &a3) { \
72
_halide_check_arg_type(Halide::type_of<t1>(), name, a1, 1); \
73
_halide_check_arg_type(Halide::type_of<t2>(), name, a2, 2); \
74
_halide_check_arg_type(Halide::type_of<t3>(), name, a3, 3); \
75
return Halide::Internal::Call::make(Halide::type_of<rt>(), #name, {a1, a2, a3}, Halide::Internal::Call::PureExtern); \
76
}
77
78
#define HalidePureExtern_4(rt, name, t1, t2, t3, t4) \
79
Halide::Expr name(const Halide::Expr &a1, const Halide::Expr &a2, const Halide::Expr &a3, const Halide::Expr &a4) { \
80
_halide_check_arg_type(Halide::type_of<t1>(), name, a1, 1); \
81
_halide_check_arg_type(Halide::type_of<t2>(), name, a2, 2); \
82
_halide_check_arg_type(Halide::type_of<t3>(), name, a3, 3); \
83
_halide_check_arg_type(Halide::type_of<t4>(), name, a4, 4); \
84
return Halide::Internal::Call::make(Halide::type_of<rt>(), #name, {a1, a2, a3, a4}, Halide::Internal::Call::PureExtern); \
85
}
86
87
#define HalidePureExtern_5(rt, name, t1, t2, t3, t4, t5) \
88
Halide::Expr name(const Halide::Expr &a1, const Halide::Expr &a2, const Halide::Expr &a3, const Halide::Expr &a4, const Halide::Expr &a5) { \
89
_halide_check_arg_type(Halide::type_of<t1>(), name, a1, 1); \
90
_halide_check_arg_type(Halide::type_of<t2>(), name, a2, 2); \
91
_halide_check_arg_type(Halide::type_of<t3>(), name, a3, 3); \
92
_halide_check_arg_type(Halide::type_of<t4>(), name, a4, 4); \
93
_halide_check_arg_type(Halide::type_of<t5>(), name, a5, 5); \
94
return Halide::Internal::Call::make(Halide::type_of<rt>(), #name, {a1, a2, a3, a4, a5}, Halide::Internal::Call::PureExtern); \
95
}
96
#endif
Debug.h
Defines functions for debug logging during code generation.
src
Extern.h
Generated by
1.12.0