miopen_target.cpp 1.41 KB
Newer Older
Paul's avatar
Paul committed
1
2
3
4
5
#include <rtg/miopen/miopen_target.hpp>
#include <rtg/manage_ptr.hpp>

#include <miopen/miopen.h>

Paul's avatar
Paul committed
6
7
namespace rtg {
namespace miopen {
Paul's avatar
Paul committed
8

Paul's avatar
Paul committed
9
using miopen_handle     = RTG_MANAGE_PTR(miopenHandle_t, miopenDestroy);
Paul's avatar
Paul committed
10
using tensor_descriptor = RTG_MANAGE_PTR(miopenTensorDescriptor_t, miopenDestroyTensorDescriptor);
Paul's avatar
Paul committed
11
12
13
14
using convolution_descriptor = RTG_MANAGE_PTR(miopenConvolutionDescriptor_t,
                                              miopenDestroyConvolutionDescriptor);
using activation_descriptor  = RTG_MANAGE_PTR(miopenActivationDescriptor_t,
                                             miopenDestroyActivationDescriptor);
Paul's avatar
Paul committed
15
16
17

struct miopen_apply
{
Paul's avatar
Paul committed
18
    program* prog;
Paul's avatar
Paul committed
19
20
21

    void apply()
    {
Paul's avatar
Paul committed
22
23
24
25
        for(auto it = prog->begin(); it != prog->end(); it++)
        {
            if(it->op.name() == "convolution")
            {
Paul's avatar
Paul committed
26
                apply_convolution(it);
Paul's avatar
Paul committed
27
28
29
            }
            else if(it->op.name() == "activation")
            {
Paul's avatar
Paul committed
30
31
32
33
34
35
36
37
38
39
40
                apply_activation(it);
            }
        }
    }

    void apply_convolution(instruction_ref ins)
    {
        // auto&& op = any_cast<convolution>(ins->op);
        // prog->replace_instruction(ins, miopen_convolution{op}, ins->arguments);
    }

Paul's avatar
Paul committed
41
    void apply_activation(instruction_ref ins) {}
Paul's avatar
Paul committed
42
43
};

Paul's avatar
Paul committed
44
std::string miopen_target::name() const { return "miopen"; }
Paul's avatar
Paul committed
45

Paul's avatar
Paul committed
46
void miopen_target::apply(program& p) const { miopen_apply{&p}.apply(); }
Paul's avatar
Paul committed
47
48
49
50

} // namespace miopen

} // namespace rtg