Skip to content

Commit

Permalink
instruction debug print
Browse files Browse the repository at this point in the history
  • Loading branch information
Snektron committed Nov 9, 2021
1 parent ce062eb commit 6f1ff74
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
7 changes: 7 additions & 0 deletions include/pareas/compiler/futhark_interop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <string>
#include <stdexcept>
#include <utility>
#include <vector>
#include <cstdint>
#include <cassert>
#include <cstdio>
Expand Down Expand Up @@ -166,6 +167,12 @@ namespace futhark {
const int64_t* shape() const {
return ArrayTraits<T, N>::shape_fn(this->handle.ctx, this->handle.data);
}

std::vector<T> download() const {
auto out = std::vector<T>(this->shape()[0]);
this->values(out.data());
return out;
}
};

template <>
Expand Down
17 changes: 15 additions & 2 deletions src/compiler/backend.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#include "pareas/compiler/backend.hpp"
#include "pareas/compiler/futhark_interop.hpp"

#include <fmt/format.h>
#include <fmt/ostream.h>
#include <iostream>

namespace backend {
DeviceModule compile(futhark_context* ctx, DeviceAst& ast, pareas::Profiler& p) {
auto tree = futhark::UniqueTree(ctx);
Expand Down Expand Up @@ -87,16 +91,25 @@ namespace backend {
auto instr_gen_rs1 = futhark::UniqueArray<int64_t, 1>(ctx);
auto instr_gen_rs2 = futhark::UniqueArray<int64_t, 1>(ctx);
auto instr_gen_jt = futhark::UniqueArray<uint32_t, 1>(ctx);
int err = futhark_entry_backend_split_instr(
futhark_entry_backend_split_instr(
ctx,
&instr_gen_opcodes,
&instr_gen_rd,
&instr_gen_rs1,
&instr_gen_rs2,
&instr_gen_jt,
instr
);
);

auto h_opcodes = instr_gen_opcodes.download();
auto h_rd = instr_gen_rd.download();
auto h_rs1 = instr_gen_rs1.download();
auto h_rs2 = instr_gen_rs2.download();
auto h_jt = instr_gen_jt.download();

for (size_t i = 0; i < h_opcodes.size(); ++i) {
fmt::print(std::cerr, "{:0>32b} {} {} {} {}\n", h_opcodes[i], h_rd[i], h_rs1[i], h_rs2[i], h_jt[i]);
}

// Stage 4, optimizer
auto optimize = futhark::UniqueArray<bool, 1>(ctx);
Expand Down

0 comments on commit 6f1ff74

Please sign in to comment.