context.hpp 1.42 KB
Newer Older
Paul's avatar
Paul committed
1
2
#ifndef MIGRAPHX_GUARD_CONTEXT_HPP
#define MIGRAPHX_GUARD_CONTEXT_HPP
Paul's avatar
Paul committed
3

Paul's avatar
Paul committed
4
#include <cassert>
Paul's avatar
Paul committed
5
6
7
8
9
#include <string>
#include <functional>
#include <memory>
#include <type_traits>
#include <utility>
Paul's avatar
Paul committed
10
#include <migraphx/config.hpp>
Shucai Xiao's avatar
Shucai Xiao committed
11
#include <migraphx/value.hpp>
12
#include <migraphx/any_ptr.hpp>
Paul's avatar
Paul committed
13

Paul's avatar
Paul committed
14
namespace migraphx {
Paul's avatar
Paul committed
15
inline namespace MIGRAPHX_INLINE_NS {
Paul's avatar
Paul committed
16

Paul's avatar
Paul committed
17
18
19
20
21
22
#ifdef DOXYGEN

/// A context is used to store internal data for a `target`. A context is
/// constructed by a target during compilation and passed to the operations
/// during `eval`.
struct context
Paul's avatar
Paul committed
23
{
Paul's avatar
Paul committed
24
25
    /// Wait for any tasks in the context to complete
    void finish() const;
Paul's avatar
Paul committed
26
};
Paul's avatar
Paul committed
27
28
29

#else

Shucai Xiao's avatar
Shucai Xiao committed
30
31
32
33
34
35
36
template <class T>
value to_value_context(const T&)
{
    return value{};
}

template <class T>
37
38
39
40
41
42
43
44
45
void from_value_context(T&, const value&)
{
}

template <class T>
any_ptr get_queue_context(T&)
{
    return {};
}
Shucai Xiao's avatar
Shucai Xiao committed
46

Paul's avatar
Paul committed
47
<%
Shucai Xiao's avatar
Shucai Xiao committed
48
49
50
 interface('context',
           virtual('to_value', returns = 'value', const = True, default = 'to_value_context'),
           virtual('from_value', v = 'const value&', default = 'from_value_context'),
51
           virtual('get_queue', returns = 'any_ptr', default = 'get_queue_context'),
Shucai Xiao's avatar
Shucai Xiao committed
52
53
54
55
56
57
58
           virtual('finish', returns = 'void', const = True)) %>

    inline void migraphx_to_value(value& v, const context& ctx)
{
    v = ctx.to_value();
}
inline void migraphx_from_value(const value& v, context& ctx) { ctx.from_value(v); }
Paul's avatar
Paul committed
59

Paul's avatar
Paul committed
60
61
#endif

Paul's avatar
Paul committed
62
} // namespace MIGRAPHX_INLINE_NS
Paul's avatar
Paul committed
63
} // namespace migraphx
Paul's avatar
Paul committed
64
65

#endif