Skip to content

Commit

Permalink
Profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
Snektron committed Jul 8, 2021
1 parent 4b6d766 commit 55fee79
Show file tree
Hide file tree
Showing 5 changed files with 723 additions and 201 deletions.
76 changes: 76 additions & 0 deletions include/pareas/compiler/frontend.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,82 @@
#ifndef _PAREAS_COMPILER_FRONTEND_HPP
#define _PAREAS_COMPILER_FRONTEND_HPP

#include "futhark_generated.h"

#include "pareas/compiler/ast.hpp"

#include <chrono>
#include <stdexcept>
#include <iosfwd>

namespace frontend {
// Keep in sync with src/compiler/frontend.fut
enum class Status : uint8_t {
OK = 0,
PARSE_ERROR = 1,
STRAY_ELSE_ERROR = 2,
INVALID_DECL = 3,
INVALID_PARAMS = 4,
INVALID_ASSIGN = 5,
INVALID_FN_PROTO = 6,
DUPLICATE_FN_OR_INVALID_CALL = 7,
INVALID_VARIABLE = 8,
INVALID_ARG_COUNT = 9,
TYPE_ERROR = 10,
INVALID_RETURN = 11,
MISSING_RETURN = 12,
};

const char* status_name(Status s);

struct CompileError: std::runtime_error {
CompileError(Status status):
std::runtime_error(status_name(status)) {}
};

struct CombinedStatistics {
std::chrono::microseconds table_upload;
std::chrono::microseconds input_upload;
std::chrono::microseconds compile;
std::chrono::microseconds total;

void dump(std::ostream& os) const;
};

DeviceAst compile_combined(futhark_context* ctx, const std::string& input, CombinedStatistics& stats);

struct SeparateStatistics {
std::chrono::microseconds table_upload;
std::chrono::microseconds input_upload;
std::chrono::microseconds tokenize;
std::chrono::microseconds parse;
std::chrono::microseconds build_parse_tree;
std::chrono::microseconds fix_bin_ops;
std::chrono::microseconds fix_if_else;
std::chrono::microseconds flatten_lists;
std::chrono::microseconds fix_names;
std::chrono::microseconds fix_ascriptions;
std::chrono::microseconds fix_fn_decls;
std::chrono::microseconds fix_args_and_params;
std::chrono::microseconds fix_decls;
std::chrono::microseconds remove_marker_nodes;
std::chrono::microseconds compute_prev_siblings;
std::chrono::microseconds check_assignments;
std::chrono::microseconds insert_derefs;
std::chrono::microseconds extract_lexemes;
std::chrono::microseconds resolve_vars;
std::chrono::microseconds resolve_fns;
std::chrono::microseconds resolve_args;
std::chrono::microseconds resolve_data_types;
std::chrono::microseconds check_return_types;
std::chrono::microseconds check_convergence;
std::chrono::microseconds build_ast;
std::chrono::microseconds total;

void dump(std::ostream& os) const;
};

DeviceAst compile_separate(futhark_context* ctx, const std::string& input, SeparateStatistics& stats);
}

#endif
28 changes: 17 additions & 11 deletions include/pareas/compiler/futhark_interop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ namespace futhark {
}

struct Error: std::runtime_error {
Error(Context& ctx):
std::runtime_error(get_error_str(ctx.get())) {}

Error(futhark_context* ctx):
std::runtime_error(get_error_str(ctx)) {}
};
Expand All @@ -50,12 +47,12 @@ namespace futhark {
futhark_context* ctx;
Array* data;

UniqueOpaqueArray(Context& ctx, Array* data):
ctx(ctx.get()), data(data) {
UniqueOpaqueArray(futhark_context* ctx, Array* data):
ctx(ctx), data(data) {
}

explicit UniqueOpaqueArray(Context& ctx):
ctx(ctx.get()), data(nullptr) {
explicit UniqueOpaqueArray(futhark_context* ctx):
ctx(ctx), data(nullptr) {
}

UniqueOpaqueArray(UniqueOpaqueArray&& other):
Expand Down Expand Up @@ -87,11 +84,16 @@ namespace futhark {
Array** operator&() {
return &this->data;
}

Array* exchange(Array* other) {
return std::exchange(this->data, other);
}
};

using UniqueLexTable = UniqueOpaqueArray<futhark_opaque_lex_table, futhark_free_opaque_lex_table>;
using UniqueParseTable = UniqueOpaqueArray<futhark_opaque_parse_table, futhark_free_opaque_parse_table>;
using UniqueStackChangeTable = UniqueOpaqueArray<futhark_opaque_stack_change_table, futhark_free_opaque_stack_change_table>;
using UniqueTokenArray = UniqueOpaqueArray<futhark_opaque_arr_token_1d, futhark_free_opaque_arr_token_1d>;

template <typename T, size_t N>
struct ArrayTraits;
Expand All @@ -102,17 +104,17 @@ namespace futhark {

UniqueOpaqueArray<Array, ArrayTraits<T, N>::free_fn> handle;

UniqueArray(Context& ctx, Array* data):
UniqueArray(futhark_context* ctx, Array* data):
handle(ctx, data) {
}

explicit UniqueArray(Context& ctx):
explicit UniqueArray(futhark_context* ctx):
handle(ctx, nullptr) {
}

template <typename... Sizes>
UniqueArray(Context& ctx, const T* data, Sizes... dims):
handle(ctx, ArrayTraits<T, N>::new_fn(ctx.get(), data, dims...)) {
UniqueArray(futhark_context* ctx, const T* data, Sizes... dims):
handle(ctx, ArrayTraits<T, N>::new_fn(ctx, data, dims...)) {
if (!this->handle.data)
throw Error(this->handle.ctx);
}
Expand All @@ -129,6 +131,10 @@ namespace futhark {
return &this->handle;
}

Array* exchange(Array* other) {
return this->handle.exchange(other);
}

void values(T* out) const {
int err = ArrayTraits<T, N>::values_fn(this->handle.ctx, this->handle.data, out);
if (err != 0)
Expand Down
Loading

0 comments on commit 55fee79

Please sign in to comment.