1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
#include "Halide.h"
#include <iostream>
#include "halide_benchmark.h"
using namespace Halide;
using namespace Halide::Tools;
int global_to_prevent_opt;
int null_call() {
return global_to_prevent_opt;
}
int main(int argc, char **argv) {
Target target = get_jit_target_from_environment();
if (target.arch == Target::WebAssembly) {
printf("[SKIP] Performance tests are meaningless and/or misleading under WebAssembly interpreter.\n");
return 0;
}
{
global_to_prevent_opt = argc;
double t = benchmark([&]() { null_call(); });
std::cout << "No argument native call time " << t * 1e6 << "us.\n";
}
{
Func f;
f() = 42;
f.compile_jit();
double t = benchmark([&]() { f.realize(); });
std::cout << "No argument Func realize time " << t * 1e6 << "us.\n";
}
{
Func f;
f() = 42;
Pipeline p(f);
p.compile_jit();
double t = benchmark([&]() { p.realize(); });
std::cout << "No argument Pipeline realize time " << t * 1e6 << "us.\n";
}
{
Func f;
f() = 42;
Pipeline p(f);
p.compile_jit();
auto buf = Buffer<int32_t>::make_scalar();
Realization r(buf);
Target target;
double t = benchmark([&]() { p.realize(r, target); });
std::cout << "No argument Pipeline realize reusing Realization/Target time " << t * 1e6 << "us.\n";
}
{
Func f;
f() = 42;
Pipeline p(f);
p.compile_jit();
auto buf = Buffer<int32_t>::make_scalar();
Target target;
double t = benchmark([&]() { p.realize(buf, target); });
std::cout << "No argument Pipeline realize reusing Buffer/Target time " << t * 1e6 << "us.\n";
}
{
Func f;
f() = 42;
Pipeline p(f);
p.compile_jit();
// This is probably the most common case
auto buf = Buffer<int32_t>::make_scalar();
double t = benchmark([&]() { p.realize(buf); });
std::cout << "No argument Pipeline realize reusing Buffer only time " << t * 1e6 << "us.\n";
}
{
Func f;
f() = 42;
Pipeline p(f);
p.compile_jit();
auto buf = Buffer<int32_t>::make_scalar();
Realization r(buf);
Target target("host-no_asserts-no_bounds_query");
double t = benchmark([&]() { p.realize(r, target); });
std::cout << "No argument Pipeline realize reusing Realization/Target with no_asserts and no_bounds_query time " << t * 1e6 << "us.\n";
}
{
Func f;
Param<int> in;
f() = in + 42;
f.compile_jit();
in.set(0);
auto buf = Buffer<int32_t>::make_scalar();
double t = benchmark([&]() { f.realize(buf); });
std::cout << "One argument Func realize to Buffer time " << t * 1e6 << "us.\n";
}
{
Func f;
Param<int> in;
f() = in + 42;
in.set(0);
Pipeline p(f);
p.compile_jit();
auto buf = Buffer<int32_t>::make_scalar();
Realization r(buf);
Target target;
double t = benchmark([&]() { p.realize(r, target); });
std::cout << "One argument Pipeline realize reusing Realization/Target time " << t * 1e6 << "us.\n";
}
for (int i = 10; i < 100; i += 10) {
Func f;
std::vector<Param<int>> params(i);
Expr e = 0;
for (auto &p : params) {
p.set(1);
e += p;
}
f() = e;
f.compile_jit();
auto buf = Buffer<int32_t>::make_scalar();
double t = benchmark([&]() { f.realize(buf); });
std::cout << std::to_string(i) << "-argument Func realize to Buffer time " << t * 1e6 << "us.\n";
}
std::cout << "Success!\n";
return 0;
}
|