1 #ifndef CHECK_CALL_GRAPHS_H
2 #define CHECK_CALL_GRAPHS_H
14 typedef std::map<std::string, std::vector<std::string>>
CallGraphs;
43 if (std::find(callees.begin(), callees.end(), op->
name) == callees.end()) {
44 callees.push_back(op->
name);
52 if (result.size() != expected.size()) {
53 printf(
"Expect %d callers instead of %d\n", (
int)expected.size(), (
int)result.size());
56 for (
auto &iter : expected) {
57 if (result.count(iter.first) == 0) {
58 printf(
"Expect %s to be in the call graphs\n", iter.first.c_str());
61 std::vector<std::string> &expected_callees = iter.second;
62 std::vector<std::string> &result_callees = result[iter.first];
63 std::sort(expected_callees.begin(), expected_callees.end());
64 std::sort(result_callees.begin(), result_callees.end());
65 if (expected_callees != result_callees) {
66 std::string expected_str = std::accumulate(
67 expected_callees.begin(), expected_callees.end(), std::string{},
68 [](
const std::string &a,
const std::string &b) {
69 return a.empty() ? b : a +
", " + b;
71 std::string result_str = std::accumulate(
72 result_callees.begin(), result_callees.end(), std::string{},
73 [](
const std::string &a,
const std::string &b) {
74 return a.empty() ? b : a +
", " + b;
77 printf(
"Expect calless of %s to be (%s); got (%s) instead\n",
78 iter.first.c_str(), expected_str.c_str(), result_str.c_str());
85 template<
typename T,
typename F>
87 for (
int y = 0; y < im.height(); y++) {
88 for (
int x = 0; x < im.width(); x++) {
89 T correct = func(x, y);
90 if (im(x, y) != correct) {
91 std::cout <<
"im(" << x <<
", " << y <<
") = " << im(x, y)
92 <<
" instead of " << correct <<
"\n";
100 template<
typename T,
typename F>
102 for (
int z = 0; z < im.channels(); z++) {
103 for (
int y = 0; y < im.height(); y++) {
104 for (
int x = 0; x < im.width(); x++) {
105 T correct = func(x, y, z);
106 if (im(x, y, z) != correct) {
107 std::cout <<
"im(" << x <<
", " << y <<
", " << z <<
") = "
108 << im(x, y, z) <<
" instead of " << correct <<
"\n";
117 template<
typename T,
typename F>
123 template<
typename T,
typename F>
int check_image2(const Halide::Buffer< T > &im, const F &func)
int check_call_graphs(CallGraphs &result, CallGraphs &expected)
auto check_image(const Halide::Buffer< T > &im, const F &func) -> decltype(std::declval< F >()(0, 0), int())
int check_image3(const Halide::Buffer< T > &im, const F &func)
std::map< std::string, std::vector< std::string > > CallGraphs
A Halide::Buffer is a named shared reference to a Halide::Runtime::Buffer.
A base class for algorithms that need to recursively walk over the IR.
virtual void visit(const IntImm *)
void accept(IRVisitor *v) const
Dispatch to the correct visitor method for this node.
Load a value from a named symbol if predicate is true.
This node is a helpful annotation to do with permissions.