pool2d_fwd_fp32.cpp 4.08 KB
Newer Older
Chao Liu's avatar
Chao Liu committed
1
// SPDX-License-Identifier: MIT
Illia Silin's avatar
Illia Silin committed
2
// Copyright (c) 2018-2023, Advanced Micro Devices, Inc. All rights reserved.
Chao Liu's avatar
Chao Liu committed
3

Qianfeng's avatar
Qianfeng committed
4
5
#include <iostream>

Chao Liu's avatar
Chao Liu committed
6
7
8
#include "ck/ck.hpp"
#include "ck/utility/reduction_enums.hpp"
#include "ck/tensor_operation/gpu/device/tensor_layout.hpp"
Qianfeng's avatar
Qianfeng committed
9
10
11

#include "pool2d_fwd_common.hpp"

rocking's avatar
rocking committed
12
13
14
using InDataType      = float;
using OutDataType     = float;
using ComputeDataType = float;
Qianfeng's avatar
Qianfeng committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

using IndexDataType = int32_t;

using InLayout  = ck::tensor_layout::convolution::NHWC;
using OutLayout = ck::tensor_layout::convolution::NHWC;

#if 1
static constexpr auto ReduceOpId = ck::ReduceTensorOp::MAX;
#else
static constexpr auto ReduceOpId = ck::ReduceTensorOp::AVG;
#endif

static constexpr bool OutputIndex  = false;
static constexpr bool PropagateNan = false;

int main(int argc, char* argv[])
{
    bool do_verification;
    int init_method;
    bool time_kernel;

    // Pool shape
rocking's avatar
rocking committed
37
38
39
40
41
42
43
44
45
46
47
48
49
50
    ck::index_t N                 = 128;
    ck::index_t C                 = 192;
    ck::index_t Y                 = 3;
    ck::index_t X                 = 3;
    ck::index_t Hi                = 71;
    ck::index_t Wi                = 71;
    ck::index_t window_stride_h   = 2;
    ck::index_t window_stride_w   = 2;
    ck::index_t window_dilation_h = 1;
    ck::index_t window_dilation_w = 1;
    ck::index_t in_left_pad_h     = 1;
    ck::index_t in_left_pad_w     = 1;
    ck::index_t in_right_pad_h    = 1;
    ck::index_t in_right_pad_w    = 1;
Qianfeng's avatar
Qianfeng committed
51
52
53
54
55
56
57
58
59
60
61
62
63

    if(argc == 1)
    {
        do_verification = true;
        init_method     = 1;
        time_kernel     = true;
    }
    else if(argc == 4)
    {
        do_verification = std::stoi(argv[1]);
        init_method     = std::stoi(argv[2]);
        time_kernel     = static_cast<bool>(std::stoi(argv[3]));
    }
rocking's avatar
rocking committed
64
    else if(argc == 18)
Qianfeng's avatar
Qianfeng committed
65
66
67
68
69
    {
        do_verification = std::stoi(argv[1]);
        init_method     = std::stoi(argv[2]);
        time_kernel     = static_cast<bool>(std::stoi(argv[3]));

rocking's avatar
rocking committed
70
71
72
73
74
75
76
77
78
79
80
81
82
83
        N                 = std::stoi(argv[4]);
        C                 = std::stoi(argv[5]);
        Y                 = std::stoi(argv[6]);
        X                 = std::stoi(argv[7]);
        Hi                = std::stoi(argv[8]);
        Wi                = std::stoi(argv[9]);
        window_stride_h   = std::stoi(argv[10]);
        window_stride_w   = std::stoi(argv[11]);
        window_dilation_h = std::stoi(argv[12]);
        window_dilation_w = std::stoi(argv[13]);
        in_left_pad_h     = std::stoi(argv[14]);
        in_left_pad_w     = std::stoi(argv[15]);
        in_right_pad_h    = std::stoi(argv[16]);
        in_right_pad_w    = std::stoi(argv[17]);
Qianfeng's avatar
Qianfeng committed
84
85
86
87
88
89
    }
    else
    {
        printf("arg1: verification (0=no, 1=yes)\n");
        printf("arg2: initialization (0=no init, 1=integer value, 2=decimal value)\n");
        printf("arg3: time kernel (0=no, 1=yes)\n");
rocking's avatar
rocking committed
90
        printf("arg4 to 15: N, C, Y, X, Hi, Wi, Sy, Sx, Dy, Dx, LeftPy, LeftPx, RightPy, "
Qianfeng's avatar
Qianfeng committed
91
92
93
94
95
96
               "RightPx\n");
        exit(0);
    }

    bool pass = pool_test<InDataType,
                          OutDataType,
rocking's avatar
rocking committed
97
                          ComputeDataType,
Qianfeng's avatar
Qianfeng committed
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
                          IndexDataType,
                          InLayout,
                          OutLayout,
                          ReduceOpId,
                          PropagateNan,
                          OutputIndex>(do_verification,
                                       init_method,
                                       time_kernel,
                                       N,
                                       C,
                                       Y,
                                       X,
                                       Hi,
                                       Wi,
                                       window_stride_h,
                                       window_stride_w,
rocking's avatar
rocking committed
114
115
                                       window_dilation_h,
                                       window_dilation_w,
Qianfeng's avatar
Qianfeng committed
116
117
118
119
120
121
122
                                       in_left_pad_h,
                                       in_left_pad_w,
                                       in_right_pad_h,
                                       in_right_pad_w);

    return (pass ? 0 : 1);
}