Loading...
Searching...
No Matches
CompilerLogger.h
Go to the documentation of this file.
#ifndef HALIDE_COMPILER_LOGGER_H_
#define HALIDE_COMPILER_LOGGER_H_
/** \file
* Defines an interface used to gather and log compile-time information, stats, etc
* for use in evaluating internal Halide compilation rules and efficiency.
*
* The 'standard' implementation simply logs all gathered data to
* a local file (in JSON form), but the entire implementation can be
* replaced by custom definitions if you have unusual logging needs.
*/
#include <iostream>
#include <map>
#include <memory>
#include <string>
#include <utility>
#include "Expr.h"
#include "Target.h"
namespace Halide {
namespace Internal {
class CompilerLogger {
public:
/** The "Phase" of compilation, used for some calls */
enum class Phase {
HalideLowering,
LLVM,
};
CompilerLogger() = default;
virtual ~CompilerLogger() = default;
/** Record when a particular simplifier rule matches.
*/
virtual void record_matched_simplifier_rule(const std::string &rulename, Expr expr) = 0;
/** Record when an expression is non-monotonic in a loop variable.
*/
virtual void record_non_monotonic_loop_var(const std::string &loop_var, Expr expr) = 0;
/** Record when can_prove() fails, but cannot find a counterexample.
*/
virtual void record_failed_to_prove(Expr failed_to_prove, Expr original_expr) = 0;
/** Record total size (in bytes) of final generated object code (e.g., file size of .o output).
*/
virtual void record_object_code_size(uint64_t bytes) = 0;
/** Record the compilation time (in seconds) for a given phase.
*/
virtual void record_compilation_time(Phase phase, double duration) = 0;
/**
* Emit all the gathered data to the given stream. This may be called multiple times.
*/
virtual std::ostream &emit_to_stream(std::ostream &o) = 0;
};
/** Set the active CompilerLogger object, replacing any existing one.
* It is legal to pass in a nullptr (which means "don't do any compiler logging").
* Returns the previous CompilerLogger (if any). */
std::unique_ptr<CompilerLogger> set_compiler_logger(std::unique_ptr<CompilerLogger> compiler_logger);
/** Return the currently active CompilerLogger object. If set_compiler_logger()
* has never been called, a nullptr implementation will be returned.
* Do not save the pointer returned! It is intended to be used for immediate
* calls only. */
CompilerLogger *get_compiler_logger();
/** JSONCompilerLogger is a basic implementation of the CompilerLogger interface
* that saves logged data, then logs it all in JSON format in emit_to_stream().
*/
class JSONCompilerLogger : public CompilerLogger {
public:
JSONCompilerLogger() = default;
JSONCompilerLogger(
const std::string &generator_name,
const std::string &function_name,
const std::string &autoscheduler_name,
const Target &target,
const std::string &generator_args,
bool obfuscate_exprs);
void record_matched_simplifier_rule(const std::string &rulename, Expr expr) override;
void record_non_monotonic_loop_var(const std::string &loop_var, Expr expr) override;
void record_failed_to_prove(Expr failed_to_prove, Expr original_expr) override;
void record_object_code_size(uint64_t bytes) override;
void record_compilation_time(Phase phase, double duration) override;
std::ostream &emit_to_stream(std::ostream &o) override;
protected:
const std::string generator_name;
const std::string function_name;
const std::string autoscheduler_name;
const Target target = Target();
const std::string generator_args;
const bool obfuscate_exprs{false};
// Maps from string representing rewrite rule -> list of Exprs that matched that rule
std::map<std::string, std::vector<Expr>> matched_simplifier_rules;
// Maps loop_var -> list of Exprs that were nonmonotonic for that loop_var
std::map<std::string, std::vector<Expr>> non_monotonic_loop_vars;
// List of (unprovable simplified Expr, original version of that Expr passed to can_prove()).
std::vector<std::pair<Expr, Expr>> failed_to_prove_exprs;
// Total code size generated, in bytes.
uint64_t object_code_size{0};
// Map of the time take for each phase of compilation.
std::map<Phase, double> compilation_time;
void obfuscate();
void emit();
};
} // namespace Internal
} // namespace Halide
#endif // HALIDE_COMPILER_LOGGER_H_
Expr.h
Base classes for Halide expressions (Halide::Expr) and statements (Halide::Internal::Stmt).
Target.h
Defines the structure that describes a Halide target.
Halide::Internal::CompilerLogger
Definition CompilerLogger.h:25
Halide::Internal::CompilerLogger::emit_to_stream
virtual std::ostream & emit_to_stream(std::ostream &o)=0
Emit all the gathered data to the given stream.
Halide::Internal::CompilerLogger::Phase
Phase
The "Phase" of compilation, used for some calls.
Definition CompilerLogger.h:28
Halide::Internal::CompilerLogger::Phase::LLVM
@ LLVM
Definition CompilerLogger.h:30
Halide::Internal::CompilerLogger::Phase::HalideLowering
@ HalideLowering
Definition CompilerLogger.h:29
Halide::Internal::CompilerLogger::record_matched_simplifier_rule
virtual void record_matched_simplifier_rule(const std::string &rulename, Expr expr)=0
Record when a particular simplifier rule matches.
Halide::Internal::CompilerLogger::record_non_monotonic_loop_var
virtual void record_non_monotonic_loop_var(const std::string &loop_var, Expr expr)=0
Record when an expression is non-monotonic in a loop variable.
Halide::Internal::CompilerLogger::record_object_code_size
virtual void record_object_code_size(uint64_t bytes)=0
Record total size (in bytes) of final generated object code (e.g., file size of .o output).
Halide::Internal::CompilerLogger::record_failed_to_prove
virtual void record_failed_to_prove(Expr failed_to_prove, Expr original_expr)=0
Record when can_prove() fails, but cannot find a counterexample.
Halide::Internal::CompilerLogger::CompilerLogger
CompilerLogger()=default
Halide::Internal::CompilerLogger::~CompilerLogger
virtual ~CompilerLogger()=default
Halide::Internal::CompilerLogger::record_compilation_time
virtual void record_compilation_time(Phase phase, double duration)=0
Record the compilation time (in seconds) for a given phase.
Halide::Internal::JSONCompilerLogger::autoscheduler_name
const std::string autoscheduler_name
Definition CompilerLogger.h:99
Halide::Internal::JSONCompilerLogger::record_matched_simplifier_rule
void record_matched_simplifier_rule(const std::string &rulename, Expr expr) override
Record when a particular simplifier rule matches.
Halide::Internal::JSONCompilerLogger::JSONCompilerLogger
JSONCompilerLogger()=default
Halide::Internal::JSONCompilerLogger::obfuscate
void obfuscate()
Halide::Internal::JSONCompilerLogger::record_object_code_size
void record_object_code_size(uint64_t bytes) override
Record total size (in bytes) of final generated object code (e.g., file size of .o output).
Halide::Internal::JSONCompilerLogger::matched_simplifier_rules
std::map< std::string, std::vector< Expr > > matched_simplifier_rules
Definition CompilerLogger.h:105
Halide::Internal::JSONCompilerLogger::object_code_size
uint64_t object_code_size
Definition CompilerLogger.h:114
Halide::Internal::JSONCompilerLogger::emit
void emit()
Halide::Internal::JSONCompilerLogger::record_non_monotonic_loop_var
void record_non_monotonic_loop_var(const std::string &loop_var, Expr expr) override
Record when an expression is non-monotonic in a loop variable.
Halide::Internal::JSONCompilerLogger::obfuscate_exprs
const bool obfuscate_exprs
Definition CompilerLogger.h:102
Halide::Internal::JSONCompilerLogger::non_monotonic_loop_vars
std::map< std::string, std::vector< Expr > > non_monotonic_loop_vars
Definition CompilerLogger.h:108
Halide::Internal::JSONCompilerLogger::compilation_time
std::map< Phase, double > compilation_time
Definition CompilerLogger.h:117
Halide::Internal::JSONCompilerLogger::generator_args
const std::string generator_args
Definition CompilerLogger.h:101
Halide::Internal::JSONCompilerLogger::function_name
const std::string function_name
Definition CompilerLogger.h:98
Halide::Internal::JSONCompilerLogger::JSONCompilerLogger
JSONCompilerLogger(const std::string &generator_name, const std::string &function_name, const std::string &autoscheduler_name, const Target &target, const std::string &generator_args, bool obfuscate_exprs)
Halide::Internal::JSONCompilerLogger::failed_to_prove_exprs
std::vector< std::pair< Expr, Expr > > failed_to_prove_exprs
Definition CompilerLogger.h:111
Halide::Internal::JSONCompilerLogger::emit_to_stream
std::ostream & emit_to_stream(std::ostream &o) override
Emit all the gathered data to the given stream.
Halide::Internal::JSONCompilerLogger::record_failed_to_prove
void record_failed_to_prove(Expr failed_to_prove, Expr original_expr) override
Record when can_prove() fails, but cannot find a counterexample.
Halide::Internal::JSONCompilerLogger::record_compilation_time
void record_compilation_time(Phase phase, double duration) override
Record the compilation time (in seconds) for a given phase.
Halide::Internal::JSONCompilerLogger::target
const Target target
Definition CompilerLogger.h:100
Halide::Internal::JSONCompilerLogger::generator_name
const std::string generator_name
Definition CompilerLogger.h:97
Halide::Internal
Definition AbstractGenerator.h:24
Halide::Internal::set_compiler_logger
std::unique_ptr< CompilerLogger > set_compiler_logger(std::unique_ptr< CompilerLogger > compiler_logger)
Set the active CompilerLogger object, replacing any existing one.
Halide::Internal::get_compiler_logger
CompilerLogger * get_compiler_logger()
Return the currently active CompilerLogger object.
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition AbstractGenerator.h:19
uint64_t
unsigned __INT64_TYPE__ uint64_t
Definition runtime_internal.h:23
Halide::Expr
A fragment of Halide syntax.
Definition Expr.h:258
Halide::Target
A struct representing a target machine and os to generate code for.
Definition Target.h:19