program.hpp 2.63 KB
Newer Older
Paul's avatar
Paul committed
1
2
#ifndef MIGRAPHX_GUARD_MIGRAPHLIB_PROGRAM_HPP
#define MIGRAPHX_GUARD_MIGRAPHLIB_PROGRAM_HPP
Paul's avatar
Paul committed
3

Paul's avatar
Paul committed
4
#include <list>
Paul's avatar
Paul committed
5
#include <unordered_map>
Paul's avatar
Paul committed
6
#include <migraphx/operation.hpp>
Shucai Xiao's avatar
Shucai Xiao committed
7
#include <migraphx/module.hpp>
Paul's avatar
Paul committed
8
9
10
11
#include <migraphx/literal.hpp>
#include <migraphx/builtin.hpp>
#include <migraphx/instruction_ref.hpp>
#include <migraphx/target.hpp>
12
#include <migraphx/compile_options.hpp>
Paul's avatar
Paul committed
13
#include <migraphx/env.hpp>
Paul's avatar
Paul committed
14
#include <migraphx/config.hpp>
Paul's avatar
Paul committed
15
#include <algorithm>
Paul's avatar
Paul committed
16
#include <iostream>
Paul's avatar
Paul committed
17

Paul's avatar
Paul committed
18
namespace migraphx {
Paul's avatar
Paul committed
19
inline namespace MIGRAPHX_INLINE_NS {
Paul's avatar
Paul committed
20

Paul's avatar
Paul committed
21
22
23
MIGRAPHX_DECLARE_ENV_VAR(MIGRAPHX_TRACE_COMPILE)
MIGRAPHX_DECLARE_ENV_VAR(MIGRAPHX_TRACE_EVAL)

Paul's avatar
Paul committed
24
25
struct program_impl;

mei-ye's avatar
mei-ye committed
26
/**
Paul's avatar
Paul committed
27
28
 * @brief Stores the instruction stream
 */
Paul's avatar
Paul committed
29
30
struct program
{
Paul's avatar
Paul committed
31
    program();
32
33

    // move constructor
Paul's avatar
Paul committed
34
    program(program&&) noexcept;
35
36

    // copy constructor
Shucai Xiao's avatar
Shucai Xiao committed
37
    program(const program&);
38
39

    // copy assignment operator
Shucai Xiao's avatar
Shucai Xiao committed
40
    program& operator=(program);
41

Paul's avatar
Paul committed
42
    ~program() noexcept;
Paul's avatar
Paul committed
43

44
45
    std::vector<std::string> get_parameter_names() const;

Paul's avatar
Paul committed
46
    shape get_parameter_shape(std::string name) const;
Paul's avatar
Paul committed
47

mei-ye's avatar
mei-ye committed
48
49
    instruction_ref get_parameter(std::string name) const;

Paul's avatar
Paul committed
50
51
    std::unordered_map<std::string, shape> get_parameter_shapes() const;

52
    std::vector<argument> eval(parameter_map params) const;
Paul's avatar
Paul committed
53

Paul's avatar
Paul committed
54
    std::size_t size() const;
55

56
    std::vector<shape> get_output_shapes() const;
Paul's avatar
Paul committed
57

Paul's avatar
Paul committed
58
59
    context& get_context() const;

Paul's avatar
Paul committed
60
61
    instruction_ref validate() const;

62
    void compile(const target& t, compile_options options = compile_options{});
Paul's avatar
Paul committed
63

64
65
    bool is_compiled() const;

Paul's avatar
Paul committed
66
    void finalize();
Paul's avatar
Paul committed
67

Paul's avatar
Paul committed
68
69
    void perf_report(std::ostream& os, std::size_t n, parameter_map params) const;

70
71
72
    value to_value() const;
    void from_value(const value& v);

Paul's avatar
Paul committed
73
74
    void debug_print() const;
    void debug_print(instruction_ref ins) const;
Shucai Xiao's avatar
Shucai Xiao committed
75
76
77
78
    void print(const std::function<void(instruction_ref,
                                        const std::unordered_map<instruction_ref, std::string>&)>&
                   print_func) const;

79
    void print_graph(std::ostream& os, bool brief = false) const;
80
    void print_cpp(std::ostream& os) const;
Paul's avatar
Paul committed
81

Paul's avatar
Paul committed
82
83
    void dry_run(parameter_map params) const;

Shucai Xiao's avatar
Shucai Xiao committed
84
    void annotate(std::ostream& os, const std::function<void(instruction_ref)>& a) const;
Paul's avatar
Paul committed
85

86
87
    program& sort();

Paul's avatar
Paul committed
88
89
    friend std::ostream& operator<<(std::ostream& os, const program& p);
    friend bool operator==(const program& x, const program& y);
Paul's avatar
Paul committed
90
    friend bool operator!=(const program& x, const program& y) { return !(x == y); }
Paul's avatar
Paul committed
91

Shucai Xiao's avatar
Shucai Xiao committed
92
93
    module* get_main_module();
    const module* get_main_module() const;
Shucai Xiao's avatar
Shucai Xiao committed
94

95
    private:
Shucai Xiao's avatar
Shucai Xiao committed
96
    void assign(const program& p);
Paul's avatar
Paul committed
97
    std::unique_ptr<program_impl> impl;
Paul's avatar
Paul committed
98
};
Paul's avatar
Paul committed
99

Paul's avatar
Paul committed
100
} // namespace MIGRAPHX_INLINE_NS
Paul's avatar
Paul committed
101
} // namespace migraphx
Paul's avatar
Paul committed
102
103

#endif