Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Xinyu Li authored and Xinyu Li committed Jun 10, 2024
1 parent fb3a905 commit a5af0dd
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions test/dynamic_binding.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#include <exception>

#include "ion/ion.h"

#include "test-bb.h"
#include "test-rt.h"

using namespace std;
using namespace ion;

int main() {
try {

{
constexpr size_t h = 4, w = 4;

Halide::Buffer<int32_t> in(w, h);
in.fill(42);

Halide::Buffer<int32_t> out(w, h);
out.fill(0);

Builder b;

b.set_target(Halide::get_host_target());
Graph g = b.add_graph("graph0");
auto n = g.add("test_inc_by_offset")(in);
n["output"].bind(out);

Halide::Buffer<int32_t> out_buf = Halide::Buffer<int32_t>::make_scalar();
out_buf.fill(0);
for (auto& [pn, port] : n.dynamic_iports()) {
port.bind(out_buf.data());
}

for (auto& [pn, port] : n.dynamic_oports()) {
port.bind(out_buf);
}

for(int i = 0;i < 9;i++){
g.run();
if (out(0,0) != in(0,0)+ i) {
throw runtime_error("Unexpected out value");
}
}
}
{
constexpr size_t h = 4, w = 4;

Halide::Buffer<int32_t> in(w, h);
in.fill(42);

Halide::Buffer<int32_t> out(w, h);
out.fill(0);

Builder b;
b.set_target(Halide::get_host_target());
auto n = b.add("test_inc_by_offset")(in);
n["output"].bind(out);

Halide::Buffer<int32_t> out_buf = Halide::Buffer<int32_t>::make_scalar();
out_buf.fill(0);
for (auto& [pn, port] : n.dynamic_iports()) {
port.bind(out_buf.data());
}

for (auto& [pn, port] : n.dynamic_oports()) {
port.bind(out_buf);
}

for(int i = 0;i < 9;i++){
b.run();
if (out(0,0) != in(0,0)+ i) {
throw runtime_error("Unexpected out value");
}
}
}


} catch (const Halide::Error& e) {
std::cerr << e.what() << std::endl;
return 1;
} catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
return 1;
}

std::cout << "Passed" << std::endl;

return 0;
}

0 comments on commit a5af0dd

Please sign in to comment.