int8_conv_pack.cpp 1.59 KB
Newer Older
1
2
3
4
5
6
7
#include <migraphx/gpu/int8_conv_pack.hpp>
#include <migraphx/gpu/context.hpp>

namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {
namespace gpu {

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
shape pack_int8_shape(const shape& s)
{
    if(s.type() != shape::int8_type)
    {
        MIGRAPHX_THROW("PACK_INT8_ARGS: only process int8_type");
    }

    auto lens    = s.lens();
    auto strides = s.strides();
    lens[1]      = (lens[1] + 3) / 4 * 4;
    strides[0]   = strides[1] * lens[1];

    return {s.type(), lens, strides};
}

23
24
25
shape miopen_int8_conv_pack::compute_shape(const std::vector<shape>& inputs) const
{
    check_shapes{{inputs.at(0)}, *this}.has(1).standard();
26
    return pack_int8_shape(inputs.at(0));
27
28
}

Shucai Xiao's avatar
Shucai Xiao committed
29
30
argument
miopen_int8_conv_pack::compute(context& ctx, const shape&, const std::vector<argument>& args) const
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
{
    auto arg_desc      = make_tensor(args[0].get_shape());
    auto arg_desc_vec4 = make_tensor(args[0].get_shape(), true);

    float alpha = 1;
    float beta  = 0;
    // pack input to vec4 format
    auto status = miopenTransformTensor(ctx.get_stream().get_miopen(),
                                        &alpha,
                                        arg_desc.get(),
                                        args[0].implicit(),
                                        &beta,
                                        arg_desc_vec4.get(),
                                        args[1].implicit());
    if(status != miopenStatusSuccess)
    {
        MIGRAPHX_THROW("INT8_CONV_PACK: transform input tensor failed");
    }

    return args[1];
}

} // namespace gpu
} // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx