"src/targets/gpu/vscode:/vscode.git/clone" did not exist on "633199a1ff95685dd5a861e827bf71f37c7ccf54"
argument.hpp 956 Bytes
Newer Older
Paul's avatar
Paul committed
1
#ifndef RTG_GUARD_RTGLIB_ARGUMENT_HPP
Paul's avatar
Paul committed
2
#define RTG_GUARD_RTGLIB_ARGUMENT_HPP
Paul's avatar
Paul committed
3
4

#include <rtg/shape.hpp>
Paul's avatar
Paul committed
5
#include <rtg/raw_data.hpp>
Paul's avatar
Paul committed
6
7
8
9
#include <functional>

namespace rtg {

Paul's avatar
Paul committed
10
11
/**
 * @brief Arguments passed to instructions
Paul's avatar
Paul committed
12
13
14
15
 *
 * An `argument` can represent a raw buffer of data that either be referenced from another element
 * or it can be owned by the argument.
 *
Paul's avatar
Paul committed
16
 */
Paul's avatar
Paul committed
17
struct argument : raw_data<argument>
Paul's avatar
Paul committed
18
{
Paul's avatar
Paul committed
19
    argument() {}
Paul's avatar
Paul committed
20

Paul's avatar
Paul committed
21
    argument(shape s) : m_shape(s)
Paul's avatar
Paul committed
22
23
24
25
26
    {
        std::vector<char> buffer(s.bytes());
        // TODO: Move vector
        data = [=]() mutable { return buffer.data(); };
    }
Paul's avatar
Paul committed
27

Paul's avatar
Paul committed
28
    argument(shape s, std::function<char*()> d) : data(d), m_shape(s) {}
Paul's avatar
Paul committed
29

Paul's avatar
Paul committed
30
    /// Provides a raw pointer to the data
Paul's avatar
Paul committed
31
    std::function<char*()> data;
Paul's avatar
Paul committed
32

Paul's avatar
Paul committed
33
    /// Whether data is available
Paul's avatar
Paul committed
34
    bool empty() const { return not data; }
Paul's avatar
Paul committed
35

Paul's avatar
Paul committed
36
    const shape& get_shape() const { return this->m_shape; }
Paul's avatar
Paul committed
37
38

    private:
Paul's avatar
Paul committed
39
    shape m_shape;
Paul's avatar
Paul committed
40
41
};

Paul's avatar
Paul committed
42
} // namespace rtg
Paul's avatar
Paul committed
43
44

#endif