Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
composable_kernel
Commits
07a673c6
"...resnet50_tensorflow.git" did not exist on "14f78b2cbd9424638d76e1c8ae09390e2213e637"
Commit
07a673c6
authored
Apr 14, 2022
by
carlushuang
Browse files
Merge remote-tracking branch 'origin/develop' into cpu_avx2
parents
c0f698d5
ac0d8066
Changes
307
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
797 additions
and
632 deletions
+797
-632
example/08_conv3d_fwd/CMakeLists.txt
example/08_conv3d_fwd/CMakeLists.txt
+0
-1
example/08_conv3d_fwd/README.md
example/08_conv3d_fwd/README.md
+0
-57
example/08_conv3d_fwd/conv3d_fwd_xdl.cpp
example/08_conv3d_fwd/conv3d_fwd_xdl.cpp
+0
-281
example/09_convnd_fwd/CMakeLists.txt
example/09_convnd_fwd/CMakeLists.txt
+2
-0
example/09_convnd_fwd/README.md
example/09_convnd_fwd/README.md
+3
-36
example/09_convnd_fwd/convnd_fwd_xdl.cpp
example/09_convnd_fwd/convnd_fwd_xdl.cpp
+32
-87
example/09_convnd_fwd/convnd_fwd_xdl_fp16.cpp
example/09_convnd_fwd/convnd_fwd_xdl_fp16.cpp
+341
-0
example/09_convnd_fwd/convnd_fwd_xdl_int8.cpp
example/09_convnd_fwd/convnd_fwd_xdl_int8.cpp
+343
-0
example/10_conv2d_bwd_data/README.md
example/10_conv2d_bwd_data/README.md
+3
-35
example/10_conv2d_bwd_data/conv2d_bwd_data_xdl.cpp
example/10_conv2d_bwd_data/conv2d_bwd_data_xdl.cpp
+5
-3
example/11_conv2d_bwd_weight/CMakeLists.txt
example/11_conv2d_bwd_weight/CMakeLists.txt
+1
-0
example/11_conv2d_bwd_weight/README.md
example/11_conv2d_bwd_weight/README.md
+25
-0
example/11_conv2d_bwd_weight/conv2d_bwd_weight_xdl.cpp
example/11_conv2d_bwd_weight/conv2d_bwd_weight_xdl.cpp
+9
-7
example/11_conv2d_bwd_wgt/CMakeLists.txt
example/11_conv2d_bwd_wgt/CMakeLists.txt
+0
-1
example/12_reduce/README.md
example/12_reduce/README.md
+4
-37
example/12_reduce/reduce_blockwise.cpp
example/12_reduce/reduce_blockwise.cpp
+13
-10
example/13_pool2d_fwd/README.md
example/13_pool2d_fwd/README.md
+3
-36
example/13_pool2d_fwd/pool2d_fwd.cpp
example/13_pool2d_fwd/pool2d_fwd.cpp
+8
-5
example/14_gemm_xdl_requant_relu_requant/gemm_xdl_requant_relu_requant_int8.cpp
...quant_relu_requant/gemm_xdl_requant_relu_requant_int8.cpp
+3
-1
example/15_grouped_gemm/README.md
example/15_grouped_gemm/README.md
+2
-35
No files found.
example/08_conv3d_fwd/CMakeLists.txt
deleted
100644 → 0
View file @
c0f698d5
add_example_executable
(
example_conv3d_fwd_xdl conv3d_fwd_xdl.cpp
)
example/08_conv3d_fwd/README.md
deleted
100644 → 0
View file @
c0f698d5
# Instructions for ```conv3d_fwd_xdl``` Example
## Docker script
```
bash
docker run
\
-it
\
--rm
\
--privileged
\
--group-add
sudo
\
-w
/root/workspace
\
-v
${
PATH_TO_LOCAL_WORKSPACE
}
:/root/workspace
\
rocm/tensorflow:rocm4.3.1-tf2.6-dev
\
/bin/bash
```
## Build ```conv3d_fwd_xdl```
```
bash
mkdir
build
&&
cd
build
```
```
bash
# Need to specify target ID, example below is gfx908
cmake
\
-D
BUILD_DEV
=
OFF
\
-D
CMAKE_BUILD_TYPE
=
Release
\
-D
CMAKE_CXX_FLAGS
=
"-DCK_AMD_GPU_GFX908 --amdgpu-target=gfx908 -O3 "
\
-D
CMAKE_CXX_COMPILER
=
/opt/rocm/bin/hipcc
\
-D
CMAKE_PREFIX_PATH
=
/opt/rocm
\
..
```
```
bash
make
-j
conv3d_fwd_xdl
```
## Run ```conv3d_fwd_xdl```
```
bash
#arg1: verification (0=no, 1=yes)
#arg2: initialization (0=no init, 1=integer value, 2=decimal value)
#arg3: run kernel # of times (>1)
#arg4 to 24: N, K, C, Z, Y, X, Di, Hi, Wi, Sz, Sy, Sx, Dz, Dy, Dx, leftPz, LeftPy, LeftPx, RightPz, RightPy, RightPx
./example/conv3d_fwd_xdl 0 1 5
```
Result (MI100 dynamic frequency)
```
in: dim 5, lengths {4, 71, 71, 71, 192}, strides {68718912, 967872, 13632, 192, 1}
wei: dim 5, lengths {256, 3, 3, 3, 192}, strides {5184, 1728, 576, 192, 1}
out: dim 5, lengths {4, 36, 36, 36, 256}, strides {11943936, 331776, 9216, 256, 1}
a_grid_desc_b_k0_m_k1{1, 648, 186624, 8}
b_grid_desc_b_k0_n_k1{1, 648, 256, 8}
launch_and_time_kernel: grid_dim {1458, 1, 1}, block_dim {256, 1, 1}
Warm up
Start running 5 times...
Perf: 4.49466 ms, 110.206 TFlops, 144.161 GB/s
```
example/08_conv3d_fwd/conv3d_fwd_xdl.cpp
deleted
100644 → 0
View file @
c0f698d5
#include <iostream>
#include <numeric>
#include <initializer_list>
#include <cstdlib>
#include <stdlib.h>
#include <half.hpp>
#include "config.hpp"
#include "print.hpp"
#include "device.hpp"
#include "host_tensor.hpp"
#include "host_tensor_generator.hpp"
#include "host_gemm.hpp"
#include "device_tensor.hpp"
#include "device_base.hpp"
#include "device_conv3d_fwd_xdl_ndhwc_kzyxc_ndhwk.hpp"
#include "device_conv3d_fwd_naive_ndhwc_kzyxc_ndhwk.hpp"
#include "convolution_utility.hpp"
// convolution data type
using
InDataType
=
ck
::
half_t
;
using
WeiDataType
=
ck
::
half_t
;
using
OutDataType
=
ck
::
half_t
;
using
AccDataType
=
float
;
using
InElementOp
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
using
WeiElementOp
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
using
OutElementOp
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
using
F16
=
ck
::
half_t
;
using
F32
=
float
;
template
<
ck
::
index_t
...
Is
>
using
S
=
ck
::
Sequence
<
Is
...
>
;
using
InLayout
=
ck
::
tensor_layout
::
convolution
::
NDHWC
;
using
WeiLayout
=
ck
::
tensor_layout
::
convolution
::
KZYXC
;
using
OutLayout
=
ck
::
tensor_layout
::
convolution
::
NDHWK
;
static
constexpr
auto
ConvFwdDefault
=
ck
::
tensor_operation
::
device
::
ConvolutionForwardSpecialization_t
::
Default
;
using
DeviceConv3dFwdInstance
=
ck
::
tensor_operation
::
device
::
DeviceConv3dFwdXdl_Input_N_Di_Hi_Wi_C_Weight_K_Z_Y_X_C_Output_N_Do_Ho_Wo_K
<
InDataType
,
// InData
WeiDataType
,
// WeiData
OutDataType
,
// OutData
AccDataType
,
// AccData
InElementOp
,
// InElementwise Operation
WeiElementOp
,
// WeiElementwise Operation
OutElementOp
,
// OutElementwise Operation
ConvFwdDefault
,
// ConvForwardSpecialization
256
,
// BlockSize
128
,
// MPerBlock
256
,
// NPerBlock
4
,
// K0PerBlock
8
,
// K1. K0PerBlock * K1 = KPerBlock
32
,
// MPerXDL
32
,
// NPerXDL. Each XDL computes a matrix of size (MPerXDL, NPerBlock)
2
,
// MXdlPerWave
4
,
// NXdlPerWave
S
<
4
,
64
,
1
>
,
// ABlockTransferThreadClusterLengths_K0_M_K1
S
<
1
,
0
,
2
>
,
// ABlockTransferThreadClusterArrangeOrder
S
<
1
,
0
,
2
>
,
// ABlockTransferSrcAccessOrder
2
,
// ABlockTransferSrcVectorDim
8
,
// ABlockTransferSrcScalarPerVector
8
,
// ABlockTransferDstScalarPerVector_K1
true
,
// ABlockLdsAddExtraM
S
<
4
,
64
,
1
>
,
// BBlockTransferThreadClusterLengths_K0_N_K1
S
<
1
,
0
,
2
>
,
// BBlockTransferThreadClusterArrangeOrder
S
<
1
,
0
,
2
>
,
// BBlockTransferSrcAccessOrder
2
,
// BBlockTransferSrcVectorDim
8
,
// BBlockTransferSrcScalarPerVector
8
,
// BBlockTransferDstScalarPerVector_K1
true
,
// BBlockLdsAddExtraN
7
,
// CThreadTransferSrcDstVectorDim
1
>
;
// CThreadTransferDstScalarPerVector
int
main
(
int
argc
,
char
*
argv
[])
{
bool
do_verification
=
false
;
int
init_method
=
0
;
int
nrepeat
=
5
;
// convolution shape
ck
::
index_t
N
=
4
;
ck
::
index_t
K
=
256
;
ck
::
index_t
C
=
192
;
std
::
vector
<
ck
::
index_t
>
in_spatial_lengths
=
{
71
,
71
,
71
};
std
::
vector
<
ck
::
index_t
>
filter_spatial_lengths
=
{
3
,
3
,
3
};
std
::
vector
<
ck
::
index_t
>
conv_filter_strides
=
{
2
,
2
,
2
};
std
::
vector
<
ck
::
index_t
>
conv_filter_dilations
=
{
1
,
1
,
1
};
std
::
vector
<
ck
::
index_t
>
in_left_pads
=
{
1
,
1
,
1
};
std
::
vector
<
ck
::
index_t
>
in_right_pads
=
{
1
,
1
,
1
};
if
(
argc
==
4
)
{
do_verification
=
std
::
stoi
(
argv
[
1
]);
init_method
=
std
::
stoi
(
argv
[
2
]);
nrepeat
=
std
::
stoi
(
argv
[
3
]);
}
else
if
(
argc
==
25
)
{
do_verification
=
std
::
stoi
(
argv
[
1
]);
init_method
=
std
::
stoi
(
argv
[
2
]);
nrepeat
=
std
::
stoi
(
argv
[
3
]);
N
=
std
::
stoi
(
argv
[
4
]);
K
=
std
::
stoi
(
argv
[
5
]);
C
=
std
::
stoi
(
argv
[
6
]);
filter_spatial_lengths
[
0
]
=
std
::
stoi
(
argv
[
7
]);
filter_spatial_lengths
[
1
]
=
std
::
stoi
(
argv
[
8
]);
filter_spatial_lengths
[
2
]
=
std
::
stoi
(
argv
[
9
]);
in_spatial_lengths
[
0
]
=
std
::
stoi
(
argv
[
10
]);
in_spatial_lengths
[
1
]
=
std
::
stoi
(
argv
[
11
]);
in_spatial_lengths
[
2
]
=
std
::
stoi
(
argv
[
12
]);
conv_filter_strides
[
0
]
=
std
::
stoi
(
argv
[
13
]);
conv_filter_strides
[
1
]
=
std
::
stoi
(
argv
[
14
]);
conv_filter_strides
[
2
]
=
std
::
stoi
(
argv
[
15
]);
conv_filter_dilations
[
0
]
=
std
::
stoi
(
argv
[
16
]);
conv_filter_dilations
[
1
]
=
std
::
stoi
(
argv
[
17
]);
conv_filter_dilations
[
2
]
=
std
::
stoi
(
argv
[
18
]);
in_left_pads
[
0
]
=
std
::
stoi
(
argv
[
19
]);
in_left_pads
[
1
]
=
std
::
stoi
(
argv
[
20
]);
in_left_pads
[
2
]
=
std
::
stoi
(
argv
[
21
]);
in_right_pads
[
0
]
=
std
::
stoi
(
argv
[
22
]);
in_right_pads
[
1
]
=
std
::
stoi
(
argv
[
23
]);
in_right_pads
[
2
]
=
std
::
stoi
(
argv
[
24
]);
}
else
{
printf
(
"Usage: 3 or 24 input arguments
\n
"
);
printf
(
" arg1: verification (0=no, 1=yes)
\n
"
);
printf
(
" arg2: initialization (0=no init, 1=integer value, 2=decimal value)
\n
"
);
printf
(
" arg3: run kernel # of times (>1)
\n
"
);
printf
(
" arg4 to 24: N, K, C, Z, Y, X, Di, Hi, Wi, Sz, Sy, Sz, Dz, Dy, Dx, LeftPz, LeftPy, "
"LeftPz, RightPz, RightPy, RightPx
\n
"
);
exit
(
0
);
}
auto
conv3d
=
DeviceConv3dFwdInstance
{};
const
auto
out_spatial_lengths
=
ck
::
tensor_operation
::
ConvolutionUtility
::
ComputeOutputSpatialLengths
(
in_spatial_lengths
,
filter_spatial_lengths
,
conv_filter_strides
,
conv_filter_dilations
,
in_left_pads
,
in_right_pads
);
Tensor
<
InDataType
>
in
(
{
N
,
in_spatial_lengths
[
0
],
in_spatial_lengths
[
1
],
in_spatial_lengths
[
2
],
C
});
Tensor
<
WeiDataType
>
wei
(
{
K
,
filter_spatial_lengths
[
0
],
filter_spatial_lengths
[
1
],
filter_spatial_lengths
[
2
],
C
});
Tensor
<
OutDataType
>
out
(
{
N
,
out_spatial_lengths
[
0
],
out_spatial_lengths
[
1
],
out_spatial_lengths
[
2
],
K
});
std
::
cout
<<
"in: "
<<
in
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"wei: "
<<
wei
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"out: "
<<
out
.
mDesc
<<
std
::
endl
;
switch
(
init_method
)
{
case
0
:
break
;
case
1
:
in
.
GenerateTensorValue
(
GeneratorTensor_2
<
InDataType
>
{
-
5
,
5
});
wei
.
GenerateTensorValue
(
GeneratorTensor_2
<
WeiDataType
>
{
-
5
,
5
});
break
;
default:
in
.
GenerateTensorValue
(
GeneratorTensor_3
<
InDataType
>
{
0.0
,
1.0
});
wei
.
GenerateTensorValue
(
GeneratorTensor_3
<
WeiDataType
>
{
-
0.5
,
0.5
});
}
DeviceMem
in_device_buf
(
sizeof
(
InDataType
)
*
in
.
mDesc
.
GetElementSpace
());
DeviceMem
wei_device_buf
(
sizeof
(
WeiDataType
)
*
wei
.
mDesc
.
GetElementSpace
());
DeviceMem
out_device_buf
(
sizeof
(
OutDataType
)
*
out
.
mDesc
.
GetElementSpace
());
in_device_buf
.
ToDevice
(
in
.
mData
.
data
());
wei_device_buf
.
ToDevice
(
wei
.
mData
.
data
());
// do Convolution
auto
invoker
=
conv3d
.
MakeInvoker
();
auto
argument
=
conv3d
.
MakeArgument
(
static_cast
<
InDataType
*>
(
in_device_buf
.
GetDeviceBuffer
()),
static_cast
<
WeiDataType
*>
(
wei_device_buf
.
GetDeviceBuffer
()),
static_cast
<
OutDataType
*>
(
out_device_buf
.
GetDeviceBuffer
()),
N
,
K
,
C
,
in_spatial_lengths
,
filter_spatial_lengths
,
out_spatial_lengths
,
conv_filter_strides
,
conv_filter_dilations
,
in_left_pads
,
in_right_pads
,
InElementOp
{},
WeiElementOp
{},
OutElementOp
{});
if
(
!
conv3d
.
IsSupportedArgument
(
argument
))
{
throw
std
::
runtime_error
(
"wrong! device_conv3d with the specified compilation parameters does "
"not support this GEMM problem"
);
}
float
ave_time
=
invoker
.
Run
(
argument
,
nrepeat
);
const
auto
Di
=
in_spatial_lengths
[
0
];
const
auto
Hi
=
in_spatial_lengths
[
1
];
const
auto
Wi
=
in_spatial_lengths
[
2
];
const
auto
Do
=
out_spatial_lengths
[
0
];
const
auto
Ho
=
out_spatial_lengths
[
1
];
const
auto
Wo
=
out_spatial_lengths
[
2
];
const
auto
Z
=
filter_spatial_lengths
[
0
];
const
auto
Y
=
filter_spatial_lengths
[
1
];
const
auto
X
=
filter_spatial_lengths
[
2
];
std
::
size_t
flop
=
std
::
size_t
(
2
)
*
N
*
K
*
Do
*
Ho
*
Wo
*
C
*
Z
*
Y
*
X
;
std
::
size_t
num_btype
=
sizeof
(
InDataType
)
*
N
*
Di
*
Hi
*
Wi
*
C
+
sizeof
(
WeiDataType
)
*
K
*
Z
*
Y
*
X
*
C
+
sizeof
(
OutDataType
)
*
N
*
Do
*
Ho
*
Wo
*
K
;
float
tflops
=
static_cast
<
float
>
(
flop
)
/
1.E9
/
ave_time
;
float
gb_per_sec
=
num_btype
/
1.E6
/
ave_time
;
std
::
cout
<<
"Perf: "
<<
ave_time
<<
" ms, "
<<
tflops
<<
" TFlops, "
<<
gb_per_sec
<<
" GB/s"
<<
std
::
endl
;
out_device_buf
.
FromDevice
(
out
.
mData
.
data
());
if
(
do_verification
)
{
DeviceMem
out_ref_device_buf
(
sizeof
(
OutDataType
)
*
N
*
Do
*
Ho
*
Wo
*
K
);
using
DeviceConv3dFwdNaive
=
ck
::
tensor_operation
::
device
::
DeviceConv3dFwdNaive_Input_N_Di_Hi_Wi_C_Weight_K_Z_Y_X_C_Output_N_Do_Ho_Wo_K
<
InDataType
,
WeiDataType
,
OutDataType
,
AccDataType
,
InElementOp
,
WeiElementOp
,
OutElementOp
>
;
auto
conv3d_naive
=
DeviceConv3dFwdNaive
{};
auto
invoker_naive
=
conv3d_naive
.
MakeInvoker
();
auto
argument_naive
=
conv3d_naive
.
MakeArgument
(
static_cast
<
InDataType
*>
(
in_device_buf
.
GetDeviceBuffer
()),
static_cast
<
WeiDataType
*>
(
wei_device_buf
.
GetDeviceBuffer
()),
static_cast
<
OutDataType
*>
(
out_ref_device_buf
.
GetDeviceBuffer
()),
N
,
K
,
C
,
in_spatial_lengths
,
filter_spatial_lengths
,
out_spatial_lengths
,
conv_filter_strides
,
conv_filter_dilations
,
in_left_pads
,
in_right_pads
,
InElementOp
{},
WeiElementOp
{},
OutElementOp
{});
if
(
!
conv3d_naive
.
IsSupportedArgument
(
argument_naive
))
{
throw
std
::
runtime_error
(
"wrong! device_conv3d_naive does NOT support the specified compilation parameters"
);
}
invoker_naive
.
Run
(
argument_naive
);
Tensor
<
OutDataType
>
out_ref
(
{
N
,
out_spatial_lengths
[
0
],
out_spatial_lengths
[
1
],
out_spatial_lengths
[
2
],
K
});
out_ref_device_buf
.
FromDevice
(
out_ref
.
mData
.
data
());
check_error
(
out_ref
,
out
);
}
return
0
;
}
example/09_convnd_fwd/CMakeLists.txt
View file @
07a673c6
add_example_executable
(
example_convnd_fwd_xdl convnd_fwd_xdl.cpp
)
add_example_executable
(
example_convnd_fwd_xdl convnd_fwd_xdl.cpp
)
add_example_executable
(
example_convnd_fwd_xdl_int8 convnd_fwd_xdl_int8.cpp
)
add_example_executable
(
example_convnd_fwd_xdl_fp16 convnd_fwd_xdl_fp16.cpp
)
example/09_convnd_fwd/README.md
View file @
07a673c6
# Instructions for ```convnd_fwd_xdl```
Example
# Instructions for ```
example_
convnd_fwd_xdl```
## Docker script
## Run ```example_convnd_fwd_xdl```
```
bash
docker run
\
-it
\
--rm
\
--privileged
\
--group-add
sudo
\
-w
/root/workspace
\
-v
${
PATH_TO_LOCAL_WORKSPACE
}
:/root/workspace
\
rocm/tensorflow:rocm4.3.1-tf2.6-dev
\
/bin/bash
```
## Build ```convnd_fwd_xdl```
```
bash
mkdir
build
&&
cd
build
```
```
bash
# Need to specify target ID, example below is gfx908
cmake
\
-D
BUILD_DEV
=
OFF
\
-D
CMAKE_BUILD_TYPE
=
Release
\
-D
CMAKE_CXX_FLAGS
=
"-DCK_AMD_GPU_GFX908 --amdgpu-target=gfx908 -O3 "
\
-D
CMAKE_CXX_COMPILER
=
/opt/rocm/bin/hipcc
\
-D
CMAKE_PREFIX_PATH
=
/opt/rocm
\
..
```
```
bash
make
-j
convnd_fwd_xdl
```
## Run ```convnd_fwd_xdl```
```
bash
```
bash
#arg1: verification (0=no, 1=yes)
#arg1: verification (0=no, 1=yes)
#arg2: initialization (0=no init, 1=integer value, 2=decimal value)
#arg2: initialization (0=no init, 1=integer value, 2=decimal value)
...
@@ -47,7 +14,7 @@ cmake \
...
@@ -47,7 +14,7 @@ cmake \
# <dilations>, (ie Dy, Dx for 2D)
# <dilations>, (ie Dy, Dx for 2D)
# <left padding>, (ie LeftPy, LeftPx for 2D)
# <left padding>, (ie LeftPy, LeftPx for 2D)
# <right padding>, (ie RightPy, RightPx for 2D)
# <right padding>, (ie RightPy, RightPx for 2D)
./example
/
convnd_fwd_xdl 0 1 100
./
bin/
example
_
convnd_fwd_xdl 0 1 100
```
```
Result (MI100 @ 1087Mhz, 33.4TFlops peak FP32)
Result (MI100 @ 1087Mhz, 33.4TFlops peak FP32)
...
...
example/09_convnd_fwd/convnd_fwd_xdl.cpp
View file @
07a673c6
...
@@ -2,8 +2,10 @@
...
@@ -2,8 +2,10 @@
#include <iostream>
#include <iostream>
#include <numeric>
#include <numeric>
#include <type_traits>
#include <type_traits>
#include "check_err.hpp"
#include "config.hpp"
#include "config.hpp"
#include "conv_util
s
.hpp"
#include "conv_
fwd_
util.hpp"
#include "device.hpp"
#include "device.hpp"
#include "device_tensor.hpp"
#include "device_tensor.hpp"
#include "device_convnd_fwd_xdl_nhwc_kyxc_nhwk.hpp"
#include "device_convnd_fwd_xdl_nhwc_kyxc_nhwk.hpp"
...
@@ -13,6 +15,8 @@
...
@@ -13,6 +15,8 @@
#include "reference_conv_fwd.hpp"
#include "reference_conv_fwd.hpp"
#include "tensor_layout.hpp"
#include "tensor_layout.hpp"
namespace
{
using
InDataType
=
float
;
using
InDataType
=
float
;
using
WeiDataType
=
float
;
using
WeiDataType
=
float
;
using
OutDataType
=
float
;
using
OutDataType
=
float
;
...
@@ -26,7 +30,7 @@ using WeiElementOp = ck::tensor_operation::element_wise::PassThrough;
...
@@ -26,7 +30,7 @@ using WeiElementOp = ck::tensor_operation::element_wise::PassThrough;
using
OutElementOp
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
using
OutElementOp
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
static
constexpr
auto
ConvFwdDefault
=
static
constexpr
auto
ConvFwdDefault
=
ck
::
tensor_operation
::
device
::
ConvolutionForwardSpecialization
_t
::
Default
;
ck
::
tensor_operation
::
device
::
ConvolutionForwardSpecialization
::
Default
;
using
DeviceConvFwdBasePtr
=
using
DeviceConvFwdBasePtr
=
ck
::
tensor_operation
::
device
::
DeviceConvFwdPtr
<
InElementOp
,
WeiElementOp
,
OutElementOp
>
;
ck
::
tensor_operation
::
device
::
DeviceConvFwdPtr
<
InElementOp
,
WeiElementOp
,
OutElementOp
>
;
...
@@ -80,7 +84,7 @@ using ReferenceConvNDFwdInstance = ck::tensor_operation::host::ReferenceConvFwd<
...
@@ -80,7 +84,7 @@ using ReferenceConvNDFwdInstance = ck::tensor_operation::host::ReferenceConvFwd<
OutElementOp
,
OutElementOp
,
NumDimSpatial
>
;
NumDimSpatial
>
;
DeviceConvFwdBasePtr
G
et
C
onv
I
nstance
(
int
num_dim_spatial
)
DeviceConvFwdBasePtr
g
et
_c
onv
_i
nstance
(
int
num_dim_spatial
)
{
{
switch
(
num_dim_spatial
)
switch
(
num_dim_spatial
)
{
{
...
@@ -99,7 +103,7 @@ DeviceConvFwdBasePtr GetConvInstance(int num_dim_spatial)
...
@@ -99,7 +103,7 @@ DeviceConvFwdBasePtr GetConvInstance(int num_dim_spatial)
}
}
}
}
void
P
rint
UseM
sg
()
void
p
rint
_use_m
sg
()
{
{
std
::
cout
<<
"arg1: verification (0=no, 1=yes)
\n
"
std
::
cout
<<
"arg1: verification (0=no, 1=yes)
\n
"
<<
"arg2: initialization (0=no init, 1=integer value, 2=decimal value)
\n
"
<<
"arg2: initialization (0=no init, 1=integer value, 2=decimal value)
\n
"
...
@@ -116,18 +120,18 @@ void PrintUseMsg()
...
@@ -116,18 +120,18 @@ void PrintUseMsg()
<<
std
::
endl
;
<<
std
::
endl
;
}
}
ck
::
conv_util
::
ConvParams
P
arse
C
onv
P
arams
(
int
num_dim_spatial
,
int
argc
,
char
*
argv
[])
ck
::
utils
::
conv
::
ConvParams
p
arse
_c
onv
_p
arams
(
int
num_dim_spatial
,
int
argc
,
char
*
argv
[])
{
{
// (N, K, C) + num_dim_spatial * 6 (filter, input, strides, dilations, pad left, pad right)
// (N, K, C) + num_dim_spatial * 6 (filter, input, strides, dilations, pad left, pad right)
int
conv_args
=
3
+
num_dim_spatial
*
6
;
int
conv_args
=
3
+
num_dim_spatial
*
6
;
int
cmdline_nargs
=
conv_args
+
5
;
int
cmdline_nargs
=
conv_args
+
5
;
if
(
cmdline_nargs
!=
argc
)
if
(
cmdline_nargs
!=
argc
)
{
{
P
rint
UseM
sg
();
p
rint
_use_m
sg
();
exit
(
0
);
exit
(
0
);
}
}
ck
::
conv_util
::
ConvParams
params
;
ck
::
utils
::
conv
::
ConvParams
params
;
int
arg_idx
=
5
;
int
arg_idx
=
5
;
params
.
num_dim_spatial
=
num_dim_spatial
;
params
.
num_dim_spatial
=
num_dim_spatial
;
...
@@ -169,80 +173,18 @@ ck::conv_util::ConvParams ParseConvParams(int num_dim_spatial, int argc, char* a
...
@@ -169,80 +173,18 @@ ck::conv_util::ConvParams ParseConvParams(int num_dim_spatial, int argc, char* a
return
params
;
return
params
;
}
}
HostTensorDescriptor
GetOutputHostTensorDescriptor
(
const
std
::
vector
<
std
::
size_t
>&
dims
,
}
// anonymous namespace
int
num_dim_spatial
=
2
)
{
namespace
tl
=
ck
::
tensor_layout
::
convolution
;
switch
(
num_dim_spatial
)
{
case
3
:
{
return
ck
::
conv_util
::
GetHostTensorDescriptor
(
dims
,
tl
::
NDHWK
{});
}
case
2
:
{
return
ck
::
conv_util
::
GetHostTensorDescriptor
(
dims
,
tl
::
NHWK
{});
}
case
1
:
{
return
ck
::
conv_util
::
GetHostTensorDescriptor
(
dims
,
tl
::
NWK
{});
}
default:
{
throw
std
::
runtime_error
(
"Unsupported number of spatial dimensions provided!"
);
}
}
}
HostTensorDescriptor
GetFiltersHostTensorDescriptor
(
const
std
::
vector
<
std
::
size_t
>&
dims
,
int
num_dim_spatial
=
2
)
{
namespace
tl
=
ck
::
tensor_layout
::
convolution
;
switch
(
num_dim_spatial
)
{
case
3
:
{
return
ck
::
conv_util
::
GetHostTensorDescriptor
(
dims
,
tl
::
KZYXC
{});
}
case
2
:
{
return
ck
::
conv_util
::
GetHostTensorDescriptor
(
dims
,
tl
::
KYXC
{});
}
case
1
:
{
return
ck
::
conv_util
::
GetHostTensorDescriptor
(
dims
,
tl
::
KXC
{});
}
default:
{
throw
std
::
runtime_error
(
"Unsupported number of spatial dimensions provided!"
);
}
}
}
HostTensorDescriptor
GetInputHostTensorDescriptor
(
const
std
::
vector
<
std
::
size_t
>&
dims
,
int
num_dim_spatial
=
2
)
{
namespace
tl
=
ck
::
tensor_layout
::
convolution
;
switch
(
num_dim_spatial
)
{
case
3
:
{
return
ck
::
conv_util
::
GetHostTensorDescriptor
(
dims
,
tl
::
NDHWC
{});
}
case
2
:
{
return
ck
::
conv_util
::
GetHostTensorDescriptor
(
dims
,
tl
::
NHWC
{});
}
case
1
:
{
return
ck
::
conv_util
::
GetHostTensorDescriptor
(
dims
,
tl
::
NWC
{});
}
default:
{
throw
std
::
runtime_error
(
"Unsupported number of spatial dimensions provided!"
);
}
}
}
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
using
namespace
ck
::
utils
::
conv
;
bool
do_verification
=
0
;
bool
do_verification
=
0
;
int
init_method
=
0
;
int
init_method
=
0
;
int
nrepeat
=
5
;
int
nrepeat
=
5
;
int
num_dim_spatial
=
2
;
int
num_dim_spatial
=
2
;
ck
::
conv_util
::
ConvParams
params
;
ck
::
utils
::
conv
::
ConvParams
params
;
if
(
argc
>=
5
)
if
(
argc
>=
5
)
{
{
...
@@ -254,7 +196,7 @@ int main(int argc, char* argv[])
...
@@ -254,7 +196,7 @@ int main(int argc, char* argv[])
if
(
argc
>=
6
)
if
(
argc
>=
6
)
{
{
params
=
P
arse
C
onv
P
arams
(
num_dim_spatial
,
argc
,
argv
);
params
=
p
arse
_c
onv
_p
arams
(
num_dim_spatial
,
argc
,
argv
);
}
}
std
::
vector
<
std
::
size_t
>
input_dims
{
static_cast
<
std
::
size_t
>
(
params
.
N
),
std
::
vector
<
std
::
size_t
>
input_dims
{
static_cast
<
std
::
size_t
>
(
params
.
N
),
...
@@ -276,10 +218,12 @@ int main(int argc, char* argv[])
...
@@ -276,10 +218,12 @@ int main(int argc, char* argv[])
std
::
begin
(
output_spatial_lengths
),
std
::
begin
(
output_spatial_lengths
),
std
::
end
(
output_spatial_lengths
));
std
::
end
(
output_spatial_lengths
));
Tensor
<
InDataType
>
input
(
GetInputHostTensorDescriptor
(
input_dims
,
num_dim_spatial
));
Tensor
<
InDataType
>
input
(
get_input_host_tensor_descriptor
(
input_dims
,
num_dim_spatial
));
Tensor
<
WeiDataType
>
weights
(
GetFiltersHostTensorDescriptor
(
filter_dims
,
num_dim_spatial
));
Tensor
<
WeiDataType
>
weights
(
get_filters_host_tensor_descriptor
(
filter_dims
,
num_dim_spatial
));
Tensor
<
OutDataType
>
host_output
(
GetOutputHostTensorDescriptor
(
output_dims
,
num_dim_spatial
));
Tensor
<
OutDataType
>
host_output
(
Tensor
<
OutDataType
>
device_output
(
GetOutputHostTensorDescriptor
(
output_dims
,
num_dim_spatial
));
get_output_host_tensor_descriptor
(
output_dims
,
num_dim_spatial
));
Tensor
<
OutDataType
>
device_output
(
get_output_host_tensor_descriptor
(
output_dims
,
num_dim_spatial
));
std
::
cout
<<
"input: "
<<
input
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"input: "
<<
input
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"weights: "
<<
weights
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"weights: "
<<
weights
.
mDesc
<<
std
::
endl
;
...
@@ -305,7 +249,7 @@ int main(int argc, char* argv[])
...
@@ -305,7 +249,7 @@ int main(int argc, char* argv[])
wei_device_buf
.
ToDevice
(
weights
.
mData
.
data
());
wei_device_buf
.
ToDevice
(
weights
.
mData
.
data
());
// do GEMM
// do GEMM
auto
conv
=
G
et
C
onv
I
nstance
(
num_dim_spatial
);
auto
conv
=
g
et
_c
onv
_i
nstance
(
num_dim_spatial
);
auto
invoker
=
conv
->
MakeInvokerPointer
();
auto
invoker
=
conv
->
MakeInvokerPointer
();
auto
argument
=
auto
argument
=
conv
->
MakeArgumentPointer
(
static_cast
<
InDataType
*>
(
in_device_buf
.
GetDeviceBuffer
()),
conv
->
MakeArgumentPointer
(
static_cast
<
InDataType
*>
(
in_device_buf
.
GetDeviceBuffer
()),
...
@@ -334,15 +278,15 @@ int main(int argc, char* argv[])
...
@@ -334,15 +278,15 @@ int main(int argc, char* argv[])
float
ave_time
=
invoker
->
Run
(
argument
.
get
(),
nrepeat
);
float
ave_time
=
invoker
->
Run
(
argument
.
get
(),
nrepeat
);
std
::
size_t
flop
=
ck
::
conv_util
::
GetF
lops
(
std
::
size_t
flop
=
get_f
lops
(
params
.
N
,
params
.
C
,
params
.
K
,
params
.
filter_spatial_lengths
,
output_spatial_lengths
);
params
.
N
,
params
.
C
,
params
.
K
,
params
.
filter_spatial_lengths
,
output_spatial_lengths
);
std
::
size_t
num_btype
=
std
::
size_t
num_btype
=
ck
::
conv_util
::
GetB
type
<
InDataType
,
WeiDataType
,
OutDataType
>
(
params
.
N
,
get_b
type
<
InDataType
,
WeiDataType
,
OutDataType
>
(
params
.
N
,
params
.
C
,
params
.
C
,
params
.
K
,
params
.
K
,
params
.
input_spatial_lengths
,
params
.
input_spatial_lengths
,
params
.
filter_spatial_lengths
,
params
.
filter_spatial_lengths
,
output_spatial_lengths
);
output_spatial_lengths
);
float
tflops
=
static_cast
<
float
>
(
flop
)
/
1.E9
/
ave_time
;
float
tflops
=
static_cast
<
float
>
(
flop
)
/
1.E9
/
ave_time
;
float
gb_per_sec
=
num_btype
/
1.E6
/
ave_time
;
float
gb_per_sec
=
num_btype
/
1.E6
/
ave_time
;
...
@@ -367,7 +311,8 @@ int main(int argc, char* argv[])
...
@@ -367,7 +311,8 @@ int main(int argc, char* argv[])
ref_invoker
.
Run
(
ref_argument
);
ref_invoker
.
Run
(
ref_argument
);
out_device_buf
.
FromDevice
(
device_output
.
mData
.
data
());
out_device_buf
.
FromDevice
(
device_output
.
mData
.
data
());
check_error
(
host_output
,
device_output
);
ck
::
utils
::
check_err
(
host_output
.
mData
,
device_output
.
mData
,
"Error: incorrect results!"
,
1e-5
f
,
1e-4
f
);
};
};
switch
(
num_dim_spatial
)
switch
(
num_dim_spatial
)
...
...
example/09_convnd_fwd/convnd_fwd_xdl_fp16.cpp
0 → 100644
View file @
07a673c6
#include <cstdlib>
#include <iostream>
#include <numeric>
#include <type_traits>
#include "check_err.hpp"
#include "config.hpp"
#include "conv_fwd_util.hpp"
#include "device.hpp"
#include "device_tensor.hpp"
#include "device_convnd_fwd_xdl_nhwc_kyxc_nhwk.hpp"
#include "element_wise_operation.hpp"
#include "host_tensor.hpp"
#include "host_tensor_generator.hpp"
#include "reference_conv_fwd.hpp"
#include "tensor_layout.hpp"
namespace
{
using
InDataType
=
ck
::
half_t
;
using
WeiDataType
=
ck
::
half_t
;
using
OutDataType
=
ck
::
half_t
;
using
AccDataType
=
float
;
template
<
ck
::
index_t
...
Is
>
using
S
=
ck
::
Sequence
<
Is
...
>
;
using
InLayout
=
ck
::
tensor_layout
::
convolution
::
NHWC
;
using
WeiLayout
=
ck
::
tensor_layout
::
convolution
::
KYXC
;
using
OutLayout
=
ck
::
tensor_layout
::
convolution
::
NHWK
;
using
InElementOp
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
using
WeiElementOp
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
using
OutElementOp
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
static
constexpr
auto
ConvFwdDefault
=
ck
::
tensor_operation
::
device
::
ConvolutionForwardSpecialization
::
Default
;
using
DeviceConvFwdBasePtr
=
ck
::
tensor_operation
::
device
::
DeviceConvFwdPtr
<
InElementOp
,
WeiElementOp
,
OutElementOp
>
;
template
<
ck
::
index_t
NumDimSpatial
>
using
DeviceConvNDFwdInstance
=
ck
::
tensor_operation
::
device
::
DeviceConvNDFwdXdl_Input_N_Hi_Wi_C_Weight_K_Y_X_C_Output_N_Ho_Wo_K
<
// clang-format off
InDataType
,
//
WeiDataType
,
//
OutDataType
,
//
AccDataType
,
//
InElementOp
,
// Input Elementwise Operation
WeiElementOp
,
// Weights Elementwise Operation
OutElementOp
,
// Output Elementwise Operation
ConvFwdDefault
,
// ConvForwardSpecialization
NumDimSpatial
,
// NumDimSpatial
256
,
// BlockSize
128
,
// MPerBlock
256
,
// NPerBlock
4
,
// K0PerBlock
8
,
// K1
32
,
// MPerXdl
32
,
// NPerXdl
2
,
// MXdlPerWave
4
,
// NXdlPerWave
S
<
4
,
64
,
1
>
,
// ABlockTransferThreadClusterLengths_K0_M_K1
S
<
1
,
0
,
2
>
,
// ABlockTransferThreadClusterArrangeOrder
S
<
1
,
0
,
2
>
,
// ABlockTransferSrcAccessOrder
2
,
// ABlockTransferSrcVectorDim
8
,
// ABlockTransferSrcScalarPerVector
8
,
// ABlockTransferDstScalarPerVector_K1
true
,
// ABlockLdsAddExtraM
S
<
4
,
64
,
1
>
,
// BBlockTransferThreadClusterLengths_K0_N_K1
S
<
1
,
0
,
2
>
,
// BBlockTransferThreadClusterArrangeOrder
S
<
1
,
0
,
2
>
,
// BBlockTransferSrcAccessOrder
2
,
// BBlockTransferSrcVectorDim
8
,
// BBlockTransferSrcScalarPerVector
8
,
// BBlockTransferDstScalarPerVector_K1
true
,
// BBlockLdsAddExtraN
7
,
// CThreadTransferSrcDstVectorDim
1
>
;
// CThreadTransferDstScalarPerVector
template
<
ck
::
index_t
NumDimSpatial
>
using
ReferenceConvNDFwdInstance
=
ck
::
tensor_operation
::
host
::
ReferenceConvFwd
<
InDataType
,
WeiDataType
,
OutDataType
,
InElementOp
,
WeiElementOp
,
OutElementOp
,
NumDimSpatial
>
;
DeviceConvFwdBasePtr
get_conv_instance
(
int
num_dim_spatial
)
{
switch
(
num_dim_spatial
)
{
case
3
:
{
return
std
::
make_unique
<
DeviceConvNDFwdInstance
<
3
>>
();
}
case
2
:
{
return
std
::
make_unique
<
DeviceConvNDFwdInstance
<
2
>>
();
}
case
1
:
{
return
std
::
make_unique
<
DeviceConvNDFwdInstance
<
1
>>
();
}
default:
{
throw
std
::
runtime_error
(
"Unsupported number of spatial dimensions provided!"
);
}
}
}
void
print_use_msg
()
{
std
::
cout
<<
"arg1: verification (0=no, 1=yes)
\n
"
<<
"arg2: initialization (0=no init, 1=integer value, 2=decimal value)
\n
"
<<
"arg3: run kernel # of times (>1)
\n
"
<<
"arg4: N spatial dimensions (default 2)
\n
"
<<
"Following arguments (depending on number of spatial dims):
\n
"
<<
" N, K, C,
\n
"
<<
" <filter spatial dimensions>, (ie Y, X for 2D)
\n
"
<<
" <input image spatial dimensions>, (ie Hi, Wi for 2D)
\n
"
<<
" <strides>, (ie Sy, Sx for 2D)
\n
"
<<
" <dilations>, (ie Dy, Dx for 2D)
\n
"
<<
" <left padding>, (ie LeftPy, LeftPx for 2D)
\n
"
<<
" <right padding>, (ie RightPy, RightPx for 2D)
\n
"
<<
std
::
endl
;
}
ck
::
utils
::
conv
::
ConvParams
parse_conv_params
(
int
num_dim_spatial
,
int
argc
,
char
*
argv
[])
{
// (N, K, C) + num_dim_spatial * 6 (filter, input, strides, dilations, pad left, pad right)
int
conv_args
=
3
+
num_dim_spatial
*
6
;
int
cmdline_nargs
=
conv_args
+
5
;
if
(
cmdline_nargs
!=
argc
)
{
print_use_msg
();
exit
(
0
);
}
ck
::
utils
::
conv
::
ConvParams
params
;
int
arg_idx
=
5
;
params
.
num_dim_spatial
=
num_dim_spatial
;
params
.
N
=
std
::
stoi
(
argv
[
arg_idx
++
]);
params
.
K
=
std
::
stoi
(
argv
[
arg_idx
++
]);
params
.
C
=
std
::
stoi
(
argv
[
arg_idx
++
]);
params
.
filter_spatial_lengths
.
resize
(
num_dim_spatial
);
for
(
int
i
=
0
;
i
<
num_dim_spatial
;
++
i
)
{
params
.
filter_spatial_lengths
[
i
]
=
std
::
stoi
(
argv
[
arg_idx
++
]);
}
params
.
input_spatial_lengths
.
resize
(
num_dim_spatial
);
for
(
int
i
=
0
;
i
<
num_dim_spatial
;
++
i
)
{
params
.
input_spatial_lengths
[
i
]
=
std
::
stoi
(
argv
[
arg_idx
++
]);
}
params
.
conv_filter_strides
.
resize
(
num_dim_spatial
);
for
(
int
i
=
0
;
i
<
num_dim_spatial
;
++
i
)
{
params
.
conv_filter_strides
[
i
]
=
std
::
stoi
(
argv
[
arg_idx
++
]);
}
params
.
conv_filter_dilations
.
resize
(
num_dim_spatial
);
for
(
int
i
=
0
;
i
<
num_dim_spatial
;
++
i
)
{
params
.
conv_filter_dilations
[
i
]
=
std
::
stoi
(
argv
[
arg_idx
++
]);
}
params
.
input_left_pads
.
resize
(
num_dim_spatial
);
for
(
int
i
=
0
;
i
<
num_dim_spatial
;
++
i
)
{
params
.
input_left_pads
[
i
]
=
std
::
stoi
(
argv
[
arg_idx
++
]);
}
params
.
input_right_pads
.
resize
(
num_dim_spatial
);
for
(
int
i
=
0
;
i
<
num_dim_spatial
;
++
i
)
{
params
.
input_right_pads
[
i
]
=
std
::
stoi
(
argv
[
arg_idx
++
]);
}
return
params
;
}
}
// anonymous namespace
int
main
(
int
argc
,
char
*
argv
[])
{
using
namespace
ck
::
utils
::
conv
;
bool
do_verification
=
0
;
int
init_method
=
0
;
int
nrepeat
=
5
;
int
num_dim_spatial
=
2
;
ck
::
utils
::
conv
::
ConvParams
params
;
if
(
argc
>=
5
)
{
do_verification
=
std
::
stoi
(
argv
[
1
]);
init_method
=
std
::
stoi
(
argv
[
2
]);
nrepeat
=
std
::
stoi
(
argv
[
3
]);
num_dim_spatial
=
std
::
stoi
(
argv
[
4
]);
}
if
(
argc
>=
6
)
{
params
=
parse_conv_params
(
num_dim_spatial
,
argc
,
argv
);
}
std
::
vector
<
std
::
size_t
>
input_dims
{
static_cast
<
std
::
size_t
>
(
params
.
N
),
static_cast
<
std
::
size_t
>
(
params
.
C
)};
input_dims
.
insert
(
std
::
end
(
input_dims
),
std
::
begin
(
params
.
input_spatial_lengths
),
std
::
end
(
params
.
input_spatial_lengths
));
std
::
vector
<
std
::
size_t
>
filter_dims
{
static_cast
<
std
::
size_t
>
(
params
.
K
),
static_cast
<
std
::
size_t
>
(
params
.
C
)};
filter_dims
.
insert
(
std
::
end
(
filter_dims
),
std
::
begin
(
params
.
filter_spatial_lengths
),
std
::
end
(
params
.
filter_spatial_lengths
));
const
std
::
vector
<
ck
::
index_t
>&
output_spatial_lengths
=
params
.
GetOutputSpatialLengths
();
std
::
vector
<
std
::
size_t
>
output_dims
{
static_cast
<
std
::
size_t
>
(
params
.
N
),
static_cast
<
std
::
size_t
>
(
params
.
K
)};
output_dims
.
insert
(
std
::
end
(
output_dims
),
std
::
begin
(
output_spatial_lengths
),
std
::
end
(
output_spatial_lengths
));
Tensor
<
InDataType
>
input
(
get_input_host_tensor_descriptor
(
input_dims
,
num_dim_spatial
));
Tensor
<
WeiDataType
>
weights
(
get_filters_host_tensor_descriptor
(
filter_dims
,
num_dim_spatial
));
Tensor
<
OutDataType
>
host_output
(
get_output_host_tensor_descriptor
(
output_dims
,
num_dim_spatial
));
Tensor
<
OutDataType
>
device_output
(
get_output_host_tensor_descriptor
(
output_dims
,
num_dim_spatial
));
std
::
cout
<<
"input: "
<<
input
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"weights: "
<<
weights
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"output: "
<<
host_output
.
mDesc
<<
std
::
endl
;
switch
(
init_method
)
{
case
0
:
break
;
case
1
:
input
.
GenerateTensorValue
(
GeneratorTensor_2
<
InDataType
>
{
-
5
,
5
});
weights
.
GenerateTensorValue
(
GeneratorTensor_2
<
WeiDataType
>
{
-
5
,
5
});
break
;
default:
input
.
GenerateTensorValue
(
GeneratorTensor_3
<
InDataType
>
{
0.0
,
1.0
});
weights
.
GenerateTensorValue
(
GeneratorTensor_3
<
WeiDataType
>
{
-
0.5
,
0.5
});
}
DeviceMem
in_device_buf
(
sizeof
(
InDataType
)
*
input
.
mDesc
.
GetElementSpace
());
DeviceMem
wei_device_buf
(
sizeof
(
WeiDataType
)
*
weights
.
mDesc
.
GetElementSpace
());
DeviceMem
out_device_buf
(
sizeof
(
OutDataType
)
*
device_output
.
mDesc
.
GetElementSpace
());
in_device_buf
.
ToDevice
(
input
.
mData
.
data
());
wei_device_buf
.
ToDevice
(
weights
.
mData
.
data
());
// do GEMM
auto
conv
=
get_conv_instance
(
num_dim_spatial
);
auto
invoker
=
conv
->
MakeInvokerPointer
();
auto
argument
=
conv
->
MakeArgumentPointer
(
static_cast
<
InDataType
*>
(
in_device_buf
.
GetDeviceBuffer
()),
static_cast
<
WeiDataType
*>
(
wei_device_buf
.
GetDeviceBuffer
()),
static_cast
<
OutDataType
*>
(
out_device_buf
.
GetDeviceBuffer
()),
params
.
N
,
params
.
K
,
params
.
C
,
params
.
input_spatial_lengths
,
params
.
filter_spatial_lengths
,
output_spatial_lengths
,
params
.
conv_filter_strides
,
params
.
conv_filter_dilations
,
params
.
input_left_pads
,
params
.
input_right_pads
,
InElementOp
{},
WeiElementOp
{},
OutElementOp
{});
if
(
!
conv
->
IsSupportedArgument
(
argument
.
get
()))
{
throw
std
::
runtime_error
(
"wrong! device_conv with the specified compilation parameters does "
"not support this Conv problem"
);
}
float
ave_time
=
invoker
->
Run
(
argument
.
get
(),
nrepeat
);
std
::
size_t
flop
=
get_flops
(
params
.
N
,
params
.
C
,
params
.
K
,
params
.
filter_spatial_lengths
,
output_spatial_lengths
);
std
::
size_t
num_btype
=
get_btype
<
InDataType
,
WeiDataType
,
OutDataType
>
(
params
.
N
,
params
.
C
,
params
.
K
,
params
.
input_spatial_lengths
,
params
.
filter_spatial_lengths
,
output_spatial_lengths
);
float
tflops
=
static_cast
<
float
>
(
flop
)
/
1.E9
/
ave_time
;
float
gb_per_sec
=
num_btype
/
1.E6
/
ave_time
;
std
::
cout
<<
"Perf: "
<<
ave_time
<<
" ms, "
<<
tflops
<<
" TFlops, "
<<
gb_per_sec
<<
" GB/s"
<<
std
::
endl
;
if
(
do_verification
)
{
auto
verify_f
=
[
&
input
,
&
weights
,
&
host_output
,
&
params
,
&
out_device_buf
,
&
device_output
](
const
auto
&
ref_conv
)
{
auto
ref_invoker
=
ref_conv
.
MakeInvoker
();
auto
ref_argument
=
ref_conv
.
MakeArgument
(
input
,
weights
,
host_output
,
params
.
conv_filter_strides
,
params
.
conv_filter_dilations
,
params
.
input_left_pads
,
params
.
input_right_pads
,
InElementOp
{},
WeiElementOp
{},
OutElementOp
{});
ref_invoker
.
Run
(
ref_argument
);
out_device_buf
.
FromDevice
(
device_output
.
mData
.
data
());
ck
::
utils
::
check_err
(
host_output
.
mData
,
device_output
.
mData
,
"Error: incorrect results!"
,
1e-5
f
,
1e-4
f
);
};
switch
(
num_dim_spatial
)
{
case
3
:
{
auto
ref_conv
=
ReferenceConvNDFwdInstance
<
3
>
();
verify_f
(
ref_conv
);
break
;
}
case
2
:
{
auto
ref_conv
=
ReferenceConvNDFwdInstance
<
2
>
();
verify_f
(
ref_conv
);
break
;
}
case
1
:
{
auto
ref_conv
=
ReferenceConvNDFwdInstance
<
1
>
();
verify_f
(
ref_conv
);
break
;
}
default:
{
throw
std
::
runtime_error
(
"Unsupported number of spatial dimensions provided!"
);
}
}
}
}
example/09_convnd_fwd/convnd_fwd_xdl_int8.cpp
0 → 100644
View file @
07a673c6
#include <cstdlib>
#include <iostream>
#include <numeric>
#include <type_traits>
#include "check_err.hpp"
#include "config.hpp"
#include "conv_fwd_util.hpp"
#include "device.hpp"
#include "device_tensor.hpp"
#include "device_convnd_fwd_xdl_nhwc_kyxc_nhwk.hpp"
#include "element_wise_operation.hpp"
#include "host_tensor.hpp"
#include "host_tensor_generator.hpp"
#include "reference_conv_fwd.hpp"
#include "tensor_layout.hpp"
namespace
{
using
InDataType
=
int8_t
;
using
WeiDataType
=
int8_t
;
using
OutDataType
=
int8_t
;
using
AccDataType
=
int32_t
;
template
<
ck
::
index_t
...
Is
>
using
S
=
ck
::
Sequence
<
Is
...
>
;
using
InLayout
=
ck
::
tensor_layout
::
convolution
::
NHWC
;
using
WeiLayout
=
ck
::
tensor_layout
::
convolution
::
KYXC
;
using
OutLayout
=
ck
::
tensor_layout
::
convolution
::
NHWK
;
using
InElementOp
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
using
WeiElementOp
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
using
OutElementOp
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
using
PassThrough
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
static
constexpr
auto
ConvFwdDefault
=
ck
::
tensor_operation
::
device
::
ConvolutionForwardSpecialization
::
Default
;
using
DeviceConvFwdBasePtr
=
ck
::
tensor_operation
::
device
::
DeviceConvFwdPtr
<
InElementOp
,
WeiElementOp
,
OutElementOp
>
;
template
<
ck
::
index_t
NumDimSpatial
>
using
DeviceConvNDFwdInstance
=
ck
::
tensor_operation
::
device
::
DeviceConvNDFwdXdl_Input_N_Hi_Wi_C_Weight_K_Y_X_C_Output_N_Ho_Wo_K
<
// clang-format off
InDataType
,
//
WeiDataType
,
//
OutDataType
,
//
AccDataType
,
//
InElementOp
,
// Input Elementwise Operation
WeiElementOp
,
// Weights Elementwise Operation
OutElementOp
,
// Output Elementwise Operation
ConvFwdDefault
,
// ConvForwardSpecialization
NumDimSpatial
,
// NumDimSpatial
256
,
// BlockSize
128
,
// MPerBlock
256
,
// NPerBlock
4
,
// K0PerBlock
16
,
// K1
32
,
// MPerXdl
32
,
// NPerXdl
2
,
// MXdlPerWave
4
,
// NXdlPerWave
S
<
4
,
64
,
1
>
,
// ABlockTransferThreadClusterLengths_K0_M_K1
S
<
1
,
0
,
2
>
,
// ABlockTransferThreadClusterArrangeOrder
S
<
1
,
0
,
2
>
,
// ABlockTransferSrcAccessOrder
2
,
// ABlockTransferSrcVectorDim
16
,
// ABlockTransferSrcScalarPerVector
16
,
// ABlockTransferDstScalarPerVector_K1
true
,
// ABlockLdsAddExtraM
S
<
4
,
64
,
1
>
,
// BBlockTransferThreadClusterLengths_K0_N_K1
S
<
1
,
0
,
2
>
,
// BBlockTransferThreadClusterArrangeOrder
S
<
1
,
0
,
2
>
,
// BBlockTransferSrcAccessOrder
2
,
// BBlockTransferSrcVectorDim
16
,
// BBlockTransferSrcScalarPerVector
16
,
// BBlockTransferDstScalarPerVector_K1
true
,
// BBlockLdsAddExtraN
7
,
// CThreadTransferSrcDstVectorDim
1
>
;
// CThreadTransferDstScalarPerVector
template
<
ck
::
index_t
NumDimSpatial
>
using
ReferenceConvNDFwdInstance
=
ck
::
tensor_operation
::
host
::
ReferenceConvFwd
<
InDataType
,
WeiDataType
,
OutDataType
,
InElementOp
,
WeiElementOp
,
OutElementOp
,
NumDimSpatial
>
;
DeviceConvFwdBasePtr
get_conv_instance
(
int
num_dim_spatial
)
{
switch
(
num_dim_spatial
)
{
case
3
:
{
return
std
::
make_unique
<
DeviceConvNDFwdInstance
<
3
>>
();
}
case
2
:
{
return
std
::
make_unique
<
DeviceConvNDFwdInstance
<
2
>>
();
}
case
1
:
{
return
std
::
make_unique
<
DeviceConvNDFwdInstance
<
1
>>
();
}
default:
{
throw
std
::
runtime_error
(
"Unsupported number of spatial dimensions provided!"
);
}
}
}
void
print_use_msg
()
{
std
::
cout
<<
"arg1: verification (0=no, 1=yes)
\n
"
<<
"arg2: initialization (0=no init, 1=integer value, 2=decimal value)
\n
"
<<
"arg3: run kernel # of times (>1)
\n
"
<<
"arg4: N spatial dimensions (default 2)
\n
"
<<
"Following arguments (depending on number of spatial dims):
\n
"
<<
" N, K, C,
\n
"
<<
" <filter spatial dimensions>, (ie Y, X for 2D)
\n
"
<<
" <input image spatial dimensions>, (ie Hi, Wi for 2D)
\n
"
<<
" <strides>, (ie Sy, Sx for 2D)
\n
"
<<
" <dilations>, (ie Dy, Dx for 2D)
\n
"
<<
" <left padding>, (ie LeftPy, LeftPx for 2D)
\n
"
<<
" <right padding>, (ie RightPy, RightPx for 2D)
\n
"
<<
std
::
endl
;
}
ck
::
utils
::
conv
::
ConvParams
parse_conv_params
(
int
num_dim_spatial
,
int
argc
,
char
*
argv
[])
{
// (N, K, C) + num_dim_spatial * 6 (filter, input, strides, dilations, pad left, pad right)
int
conv_args
=
3
+
num_dim_spatial
*
6
;
int
cmdline_nargs
=
conv_args
+
5
;
if
(
cmdline_nargs
!=
argc
)
{
print_use_msg
();
exit
(
0
);
}
ck
::
utils
::
conv
::
ConvParams
params
;
int
arg_idx
=
5
;
params
.
num_dim_spatial
=
num_dim_spatial
;
params
.
N
=
std
::
stoi
(
argv
[
arg_idx
++
]);
params
.
K
=
std
::
stoi
(
argv
[
arg_idx
++
]);
params
.
C
=
std
::
stoi
(
argv
[
arg_idx
++
]);
params
.
filter_spatial_lengths
.
resize
(
num_dim_spatial
);
for
(
int
i
=
0
;
i
<
num_dim_spatial
;
++
i
)
{
params
.
filter_spatial_lengths
[
i
]
=
std
::
stoi
(
argv
[
arg_idx
++
]);
}
params
.
input_spatial_lengths
.
resize
(
num_dim_spatial
);
for
(
int
i
=
0
;
i
<
num_dim_spatial
;
++
i
)
{
params
.
input_spatial_lengths
[
i
]
=
std
::
stoi
(
argv
[
arg_idx
++
]);
}
params
.
conv_filter_strides
.
resize
(
num_dim_spatial
);
for
(
int
i
=
0
;
i
<
num_dim_spatial
;
++
i
)
{
params
.
conv_filter_strides
[
i
]
=
std
::
stoi
(
argv
[
arg_idx
++
]);
}
params
.
conv_filter_dilations
.
resize
(
num_dim_spatial
);
for
(
int
i
=
0
;
i
<
num_dim_spatial
;
++
i
)
{
params
.
conv_filter_dilations
[
i
]
=
std
::
stoi
(
argv
[
arg_idx
++
]);
}
params
.
input_left_pads
.
resize
(
num_dim_spatial
);
for
(
int
i
=
0
;
i
<
num_dim_spatial
;
++
i
)
{
params
.
input_left_pads
[
i
]
=
std
::
stoi
(
argv
[
arg_idx
++
]);
}
params
.
input_right_pads
.
resize
(
num_dim_spatial
);
for
(
int
i
=
0
;
i
<
num_dim_spatial
;
++
i
)
{
params
.
input_right_pads
[
i
]
=
std
::
stoi
(
argv
[
arg_idx
++
]);
}
return
params
;
}
}
// anonymous namespace
int
main
(
int
argc
,
char
*
argv
[])
{
using
namespace
ck
::
utils
::
conv
;
bool
do_verification
=
0
;
int
init_method
=
0
;
int
nrepeat
=
5
;
int
num_dim_spatial
=
2
;
ck
::
utils
::
conv
::
ConvParams
params
;
if
(
argc
>=
5
)
{
do_verification
=
std
::
stoi
(
argv
[
1
]);
init_method
=
std
::
stoi
(
argv
[
2
]);
nrepeat
=
std
::
stoi
(
argv
[
3
]);
num_dim_spatial
=
std
::
stoi
(
argv
[
4
]);
}
if
(
argc
>=
6
)
{
params
=
parse_conv_params
(
num_dim_spatial
,
argc
,
argv
);
}
std
::
vector
<
std
::
size_t
>
input_dims
{
static_cast
<
std
::
size_t
>
(
params
.
N
),
static_cast
<
std
::
size_t
>
(
params
.
C
)};
input_dims
.
insert
(
std
::
end
(
input_dims
),
std
::
begin
(
params
.
input_spatial_lengths
),
std
::
end
(
params
.
input_spatial_lengths
));
std
::
vector
<
std
::
size_t
>
filter_dims
{
static_cast
<
std
::
size_t
>
(
params
.
K
),
static_cast
<
std
::
size_t
>
(
params
.
C
)};
filter_dims
.
insert
(
std
::
end
(
filter_dims
),
std
::
begin
(
params
.
filter_spatial_lengths
),
std
::
end
(
params
.
filter_spatial_lengths
));
const
std
::
vector
<
ck
::
index_t
>&
output_spatial_lengths
=
params
.
GetOutputSpatialLengths
();
std
::
vector
<
std
::
size_t
>
output_dims
{
static_cast
<
std
::
size_t
>
(
params
.
N
),
static_cast
<
std
::
size_t
>
(
params
.
K
)};
output_dims
.
insert
(
std
::
end
(
output_dims
),
std
::
begin
(
output_spatial_lengths
),
std
::
end
(
output_spatial_lengths
));
Tensor
<
InDataType
>
input
(
get_input_host_tensor_descriptor
(
input_dims
,
num_dim_spatial
));
Tensor
<
WeiDataType
>
weights
(
get_filters_host_tensor_descriptor
(
filter_dims
,
num_dim_spatial
));
Tensor
<
OutDataType
>
host_output
(
get_output_host_tensor_descriptor
(
output_dims
,
num_dim_spatial
));
Tensor
<
OutDataType
>
device_output
(
get_output_host_tensor_descriptor
(
output_dims
,
num_dim_spatial
));
std
::
cout
<<
"input: "
<<
input
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"weights: "
<<
weights
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"output: "
<<
host_output
.
mDesc
<<
std
::
endl
;
switch
(
init_method
)
{
case
0
:
break
;
case
1
:
input
.
GenerateTensorValue
(
GeneratorTensor_2
<
InDataType
>
{
-
5
,
5
});
weights
.
GenerateTensorValue
(
GeneratorTensor_2
<
WeiDataType
>
{
-
5
,
5
});
break
;
default:
input
.
GenerateTensorValue
(
GeneratorTensor_3
<
InDataType
>
{
0.0
,
1.0
});
weights
.
GenerateTensorValue
(
GeneratorTensor_3
<
WeiDataType
>
{
-
0.5
,
0.5
});
}
DeviceMem
in_device_buf
(
sizeof
(
InDataType
)
*
input
.
mDesc
.
GetElementSpace
());
DeviceMem
wei_device_buf
(
sizeof
(
WeiDataType
)
*
weights
.
mDesc
.
GetElementSpace
());
DeviceMem
out_device_buf
(
sizeof
(
OutDataType
)
*
device_output
.
mDesc
.
GetElementSpace
());
in_device_buf
.
ToDevice
(
input
.
mData
.
data
());
wei_device_buf
.
ToDevice
(
weights
.
mData
.
data
());
// do GEMM
auto
conv
=
get_conv_instance
(
num_dim_spatial
);
auto
invoker
=
conv
->
MakeInvokerPointer
();
auto
argument
=
conv
->
MakeArgumentPointer
(
static_cast
<
InDataType
*>
(
in_device_buf
.
GetDeviceBuffer
()),
static_cast
<
WeiDataType
*>
(
wei_device_buf
.
GetDeviceBuffer
()),
static_cast
<
OutDataType
*>
(
out_device_buf
.
GetDeviceBuffer
()),
params
.
N
,
params
.
K
,
params
.
C
,
params
.
input_spatial_lengths
,
params
.
filter_spatial_lengths
,
output_spatial_lengths
,
params
.
conv_filter_strides
,
params
.
conv_filter_dilations
,
params
.
input_left_pads
,
params
.
input_right_pads
,
InElementOp
{},
WeiElementOp
{},
OutElementOp
{});
if
(
!
conv
->
IsSupportedArgument
(
argument
.
get
()))
{
throw
std
::
runtime_error
(
"wrong! device_conv with the specified compilation parameters does "
"not support this Conv problem"
);
}
float
ave_time
=
invoker
->
Run
(
argument
.
get
(),
nrepeat
);
std
::
size_t
flop
=
get_flops
(
params
.
N
,
params
.
C
,
params
.
K
,
params
.
filter_spatial_lengths
,
output_spatial_lengths
);
std
::
size_t
num_btype
=
get_btype
<
InDataType
,
WeiDataType
,
OutDataType
>
(
params
.
N
,
params
.
C
,
params
.
K
,
params
.
input_spatial_lengths
,
params
.
filter_spatial_lengths
,
output_spatial_lengths
);
float
tflops
=
static_cast
<
float
>
(
flop
)
/
1.E9
/
ave_time
;
float
gb_per_sec
=
num_btype
/
1.E6
/
ave_time
;
std
::
cout
<<
"Perf: "
<<
ave_time
<<
" ms, "
<<
tflops
<<
" TFlops, "
<<
gb_per_sec
<<
" GB/s"
<<
std
::
endl
;
if
(
do_verification
)
{
auto
verify_f
=
[
&
input
,
&
weights
,
&
host_output
,
&
params
,
&
out_device_buf
,
&
device_output
](
const
auto
&
ref_conv
)
{
auto
ref_invoker
=
ref_conv
.
MakeInvoker
();
auto
ref_argument
=
ref_conv
.
MakeArgument
(
input
,
weights
,
host_output
,
params
.
conv_filter_strides
,
params
.
conv_filter_dilations
,
params
.
input_left_pads
,
params
.
input_right_pads
,
InElementOp
{},
WeiElementOp
{},
OutElementOp
{});
ref_invoker
.
Run
(
ref_argument
);
out_device_buf
.
FromDevice
(
device_output
.
mData
.
data
());
ck
::
utils
::
check_err
(
host_output
.
mData
,
device_output
.
mData
,
"Error: incorrect results!"
,
1e-5
f
,
1e-4
f
);
};
switch
(
num_dim_spatial
)
{
case
3
:
{
auto
ref_conv
=
ReferenceConvNDFwdInstance
<
3
>
();
verify_f
(
ref_conv
);
break
;
}
case
2
:
{
auto
ref_conv
=
ReferenceConvNDFwdInstance
<
2
>
();
verify_f
(
ref_conv
);
break
;
}
case
1
:
{
auto
ref_conv
=
ReferenceConvNDFwdInstance
<
1
>
();
verify_f
(
ref_conv
);
break
;
}
default:
{
throw
std
::
runtime_error
(
"Unsupported number of spatial dimensions provided!"
);
}
}
}
}
example/10_conv2d_bwd_data/README.md
View file @
07a673c6
# Instructions for ```conv2d_bwd_data_xdl``` Example
# Instructions for ```
example_
conv2d_bwd_data_xdl``` Example
## Docker script
```
bash
docker run
\
-it
\
--rm
\
--privileged
\
--group-add
sudo
\
-w
/root/workspace
\
-v
${
PATH_TO_LOCAL_WORKSPACE
}
:/root/workspace
\
rocm/tensorflow:rocm4.3.1-tf2.6-dev
\
/bin/bash
```
## Build ```conv2d_bwd_data_xdl```
```
bash
mkdir
build
&&
cd
build
```
```
bash
# Need to specify target ID, example below is gfx908
cmake
\
-D
BUILD_DEV
=
OFF
\
-D
CMAKE_BUILD_TYPE
=
Release
\
-D
CMAKE_CXX_FLAGS
=
"-DCK_AMD_GPU_GFX908 --amdgpu-target=gfx908 -O3 "
\
-D
CMAKE_CXX_COMPILER
=
/opt/rocm/bin/hipcc
\
-D
CMAKE_PREFIX_PATH
=
/opt/rocm
\
..
```
```
bash
make
-j
conv2d_bwd_data_xdl
```
## Run ```conv2d_bwd_data_xdl```
## Run ```
example_
conv2d_bwd_data_xdl```
```
bash
```
bash
#arg1: verification (0=no, 1=yes)
#arg1: verification (0=no, 1=yes)
#arg2: initialization (0=no init, 1=integer value, 2=decimal value)
#arg2: initialization (0=no init, 1=integer value, 2=decimal value)
#arg3: run kernel # of times (>1)
#arg3: run kernel # of times (>1)
#arg4 to 18: N, K, C, Y, X, Hi, Wi, Sy, Sx, Dy, Dx, LeftPy, LeftPx, RightPy, RightPx
#arg4 to 18: N, K, C, Y, X, Hi, Wi, Sy, Sx, Dy, Dx, LeftPy, LeftPx, RightPy, RightPx
./bin/conv2d_bwd_data_xdl 0 1 5
./bin/
example_
conv2d_bwd_data_xdl 0 1 5
```
```
Result
Result
...
...
example/10_conv2d_bwd_data/conv2d_bwd_data_xdl.cpp
View file @
07a673c6
...
@@ -4,6 +4,8 @@
...
@@ -4,6 +4,8 @@
#include <cstdlib>
#include <cstdlib>
#include <stdlib.h>
#include <stdlib.h>
#include <half.hpp>
#include <half.hpp>
#include "check_err.hpp"
#include "config.hpp"
#include "config.hpp"
#include "print.hpp"
#include "print.hpp"
#include "device.hpp"
#include "device.hpp"
...
@@ -27,7 +29,7 @@ using InElementOp = ck::tensor_operation::element_wise::PassThrough;
...
@@ -27,7 +29,7 @@ using InElementOp = ck::tensor_operation::element_wise::PassThrough;
using
WeiElementOp
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
using
WeiElementOp
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
using
OutElementOp
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
using
OutElementOp
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
static
constexpr
auto
ConvBwdDefault
=
static
constexpr
auto
ConvBwdDefault
=
ck
::
tensor_operation
::
device
::
ConvolutionBackwardDataSpecialization
_t
::
Default
;
ck
::
tensor_operation
::
device
::
ConvolutionBackwardDataSpecialization
::
Default
;
using
DeviceConvBwdDataInstance
=
ck
::
tensor_operation
::
device
::
using
DeviceConvBwdDataInstance
=
ck
::
tensor_operation
::
device
::
DeviceConv2dBwdDataXdl_Input_N_Hi_Wi_C_Weight_K_Y_X_C_Output_N_Ho_Wo_K
<
DeviceConv2dBwdDataXdl_Input_N_Hi_Wi_C_Weight_K_Y_X_C_Output_N_Ho_Wo_K
<
...
@@ -38,7 +40,7 @@ using DeviceConvBwdDataInstance = ck::tensor_operation::device::
...
@@ -38,7 +40,7 @@ using DeviceConvBwdDataInstance = ck::tensor_operation::device::
InElementOp
,
// InElementwiseOperation
InElementOp
,
// InElementwiseOperation
WeiElementOp
,
// WeiElementwiseOperation
WeiElementOp
,
// WeiElementwiseOperation
OutElementOp
,
// OutElementwiseOperation
OutElementOp
,
// OutElementwiseOperation
ConvBwdDefault
,
// ConvolutionBackwardDataSpecialization
_t
ConvBwdDefault
,
// ConvolutionBackwardDataSpecialization
256
,
// BlockSize
256
,
// BlockSize
128
,
// MPerBlock
128
,
// MPerBlock
128
,
// NPerBlock
128
,
// NPerBlock
...
@@ -247,6 +249,6 @@ int main(int argc, char* argv[])
...
@@ -247,6 +249,6 @@ int main(int argc, char* argv[])
in_device_buf
.
FromDevice
(
in_n_c_hi_wi_device_result
.
mData
.
data
());
in_device_buf
.
FromDevice
(
in_n_c_hi_wi_device_result
.
mData
.
data
());
check_err
or
(
in_n_c_hi_wi_
host
_result
,
in_n_c_hi_wi_
device
_result
);
ck
::
utils
::
check_err
(
in_n_c_hi_wi_
device
_result
.
mData
,
in_n_c_hi_wi_
host
_result
.
mData
);
}
}
}
}
example/11_conv2d_bwd_weight/CMakeLists.txt
0 → 100644
View file @
07a673c6
add_example_executable
(
example_conv2d_bwd_weight_xdl conv2d_bwd_weight_xdl.cpp
)
example/11_conv2d_bwd_w
g
t/README.md
→
example/11_conv2d_bwd_w
eigh
t/README.md
View file @
07a673c6
# Instructions for ```
conv2d_wrw
_xdl``` Example
# Instructions for ```
example_conv2d_bwd_weight
_xdl``` Example
## Docker script
## Run ```example_conv2d_bwd_weight_xdl```
```
bash
docker run
\
-it
\
--rm
\
--privileged
\
--group-add
sudo
\
-w
/root/workspace
\
-v
${
PATH_TO_LOCAL_WORKSPACE
}
:/root/workspace
\
rocm/tensorflow:rocm4.3.1-tf2.6-dev
\
/bin/bash
```
## Build ```conv2d_wrw_xdl```
```
bash
mkdir
build
&&
cd
build
```
```
bash
# Need to specify target ID, example below is gfx908
cmake
\
-D
BUILD_DEV
=
OFF
\
-D
CMAKE_BUILD_TYPE
=
Release
\
-D
CMAKE_CXX_FLAGS
=
"-DCK_AMD_GPU_GFX908 --amdgpu-target=gfx908 -O3 "
\
-D
CMAKE_CXX_COMPILER
=
/opt/rocm/bin/hipcc
\
-D
CMAKE_PREFIX_PATH
=
/opt/rocm
\
..
```
```
bash
make
-j
conv2d_wrw_xdl
```
## Run ```conv2d_wrw_xdl```
```
bash
```
bash
#arg1: verification (0=no, 1=yes)
#arg1: verification (0=no, 1=yes)
#arg2: initialization (0=no init, 1=integer value, 2=decimal value)
#arg2: initialization (0=no init, 1=integer value, 2=decimal value)
#arg3: run kernel # of times (>1)
#arg3: run kernel # of times (>1)
#arg4: is show log (0=no, 1=yes)
#arg4: is show log (0=no, 1=yes)
#arg5 to 19: N, K, C, Y, X, Hi, Wi, Sy, Sx, Dy, Dx, LeftPy, LeftPx, RightPy, RightPx, split-k
#arg5 to 19: N, K, C, Y, X, Hi, Wi, Sy, Sx, Dy, Dx, LeftPy, LeftPx, RightPy, RightPx, split-k
./example
/
conv2d_
f
wd_xdl 0 1 5 0 4
./
bin/
example
_
conv2d_
b
wd_
weight_
xdl 0 1 5 0 4
```
```
Result
Result
...
...
example/11_conv2d_bwd_w
g
t/conv2d_bwd_w
g
t_xdl.cpp
→
example/11_conv2d_bwd_w
eigh
t/conv2d_bwd_w
eigh
t_xdl.cpp
View file @
07a673c6
...
@@ -4,6 +4,8 @@
...
@@ -4,6 +4,8 @@
#include <cstdlib>
#include <cstdlib>
#include <stdlib.h>
#include <stdlib.h>
#include <half.hpp>
#include <half.hpp>
#include "check_err.hpp"
#include "config.hpp"
#include "config.hpp"
#include "print.hpp"
#include "print.hpp"
#include "device.hpp"
#include "device.hpp"
...
@@ -32,8 +34,8 @@ using WeiElementOp = ck::tensor_operation::element_wise::PassThrough;
...
@@ -32,8 +34,8 @@ using WeiElementOp = ck::tensor_operation::element_wise::PassThrough;
using
OutElementOp
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
using
OutElementOp
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
// clang-format off
// clang-format off
using
DeviceConv
WrW
Instance
=
ck
::
tensor_operation
::
device
::
using
DeviceConv
BwdWeight
Instance
=
ck
::
tensor_operation
::
device
::
DeviceConv2d
WrW
Xdl_C_Shuffle_Input_N_Hi_Wi_C_Weight_K_Y_X_C_Output_N_Ho_Wo_K
<
DeviceConv2d
BwdWeight
Xdl_C_Shuffle_Input_N_Hi_Wi_C_Weight_K_Y_X_C_Output_N_Ho_Wo_K
<
InDataType
,
// InDataType
InDataType
,
// InDataType
WeiDataType
,
// WeiDataType
WeiDataType
,
// WeiDataType
OutDataType
,
// OutDataType
OutDataType
,
// OutDataType
...
@@ -70,8 +72,8 @@ using DeviceConvWrWInstance = ck::tensor_operation::device::
...
@@ -70,8 +72,8 @@ using DeviceConvWrWInstance = ck::tensor_operation::device::
8
>
;
// CBlockTransferScalarPerVector_NWaveNPerXdl
8
>
;
// CBlockTransferScalarPerVector_NWaveNPerXdl
// clang-format on
// clang-format on
using
ReferenceConv
Wrw
Instance
=
ck
::
tensor_operation
::
host
::
using
ReferenceConv
BwdWeight
Instance
=
ck
::
tensor_operation
::
host
::
ReferenceConv
Wrw
<
InDataType
,
WeiDataType
,
OutDataType
,
InElementOp
,
WeiElementOp
,
OutElementOp
>
;
ReferenceConv
BwdWeight
<
InDataType
,
WeiDataType
,
OutDataType
,
InElementOp
,
WeiElementOp
,
OutElementOp
>
;
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
...
@@ -211,7 +213,7 @@ int main(int argc, char* argv[])
...
@@ -211,7 +213,7 @@ int main(int argc, char* argv[])
wei_device_buf
.
ToDevice
(
wei_k_c_y_x_device_result
.
mData
.
data
());
wei_device_buf
.
ToDevice
(
wei_k_c_y_x_device_result
.
mData
.
data
());
// do GEMM
// do GEMM
auto
conv
=
DeviceConv
WrW
Instance
{};
auto
conv
=
DeviceConv
BwdWeight
Instance
{};
auto
invoker
=
conv
.
MakeInvoker
();
auto
invoker
=
conv
.
MakeInvoker
();
auto
argument
=
conv
.
MakeArgument
(
static_cast
<
InDataType
*>
(
in_device_buf
.
GetDeviceBuffer
()),
auto
argument
=
conv
.
MakeArgument
(
static_cast
<
InDataType
*>
(
in_device_buf
.
GetDeviceBuffer
()),
static_cast
<
WeiDataType
*>
(
wei_device_buf
.
GetDeviceBuffer
()),
static_cast
<
WeiDataType
*>
(
wei_device_buf
.
GetDeviceBuffer
()),
...
@@ -256,7 +258,7 @@ int main(int argc, char* argv[])
...
@@ -256,7 +258,7 @@ int main(int argc, char* argv[])
if
(
do_verification
)
if
(
do_verification
)
{
{
auto
ref_conv
=
ReferenceConv
Wrw
Instance
{};
auto
ref_conv
=
ReferenceConv
BwdWeight
Instance
{};
auto
ref_invoker
=
ref_conv
.
MakeInvoker
();
auto
ref_invoker
=
ref_conv
.
MakeInvoker
();
auto
ref_argument
=
ref_conv
.
MakeArgument
(
in_n_c_hi_wi
,
auto
ref_argument
=
ref_conv
.
MakeArgument
(
in_n_c_hi_wi
,
...
@@ -284,6 +286,6 @@ int main(int argc, char* argv[])
...
@@ -284,6 +286,6 @@ int main(int argc, char* argv[])
LogRangeAsType
<
float
>
(
std
::
cout
<<
"wei_host : "
,
wei_k_c_y_x_host_result
.
mData
,
","
)
LogRangeAsType
<
float
>
(
std
::
cout
<<
"wei_host : "
,
wei_k_c_y_x_host_result
.
mData
,
","
)
<<
std
::
endl
;
<<
std
::
endl
;
}
}
check_err
or
(
wei_k_c_y_x_
host
_result
,
wei_k_c_y_x_
device
_result
);
ck
::
utils
::
check_err
(
wei_k_c_y_x_
device
_result
.
mData
,
wei_k_c_y_x_
host
_result
.
mData
);
}
}
}
}
example/11_conv2d_bwd_wgt/CMakeLists.txt
deleted
100644 → 0
View file @
c0f698d5
add_example_executable
(
example_conv2d_bwd_wgt_xdl conv2d_bwd_wgt_xdl.cpp
)
example/12_reduce/README.md
View file @
07a673c6
# Instructions for ```reduce_blockwise```
Example
# Instructions for ```
example_
reduce_blockwise```
## Docker script
## Run ```example_reduce_blockwise```
```
bash
docker run
\
-it
\
--rm
\
--privileged
\
--group-add
sudo
\
-w
/root/workspace
\
-v
${
PATH_TO_LOCAL_WORKSPACE
}
:/root/workspace
\
rocm/tensorflow:rocm4.3.1-tf2.6-dev
\
/bin/bash
```
## Build ```reduce_blockwise```
```
bash
mkdir
build
&&
cd
build
```
```
bash
# Need to specify target ID, example below is gfx908
cmake
\
-D
BUILD_DEV
=
OFF
\
-D
CMAKE_BUILD_TYPE
=
Release
\
-D
CMAKE_CXX_FLAGS
=
"-DCK_AMD_GPU_GFX908 --amdgpu-target=gfx908 -O3 "
\
-D
CMAKE_CXX_COMPILER
=
/opt/rocm/bin/hipcc
\
-D
CMAKE_PREFIX_PATH
=
/opt/rocm
\
..
```
```
bash
make
-j
reduce_blockwise
```
## Run ```reduce_blockwise```
```
bash
```
bash
# -D <xxx> : input 4-d tensor lengths
# -D <xxx> : input 4-d tensor lengths
# -v <x> : verification (0=no, 1=yes)
# -v <x> : verification (0=no, 1=yes)
#arg1: initialization (0=no init, 1=single integer value, 2=scope integer value, 3=decimal value)
#arg1: initialization (0=no init, 1=single integer value, 2=scope integer value, 3=decimal value)
#arg2: run kernel # of times (>1)
#arg2: run kernel # of times (>1)
./bin/reduce_blockwise
-D
16,64,32,960
-v
1 1 10
./bin/
example_
reduce_blockwise
-D
16,64,32,960
-v
1 1 10
```
```
Result
Result
...
@@ -50,7 +17,7 @@ Start running 3 times...
...
@@ -50,7 +17,7 @@ Start running 3 times...
Perf: 0.23536 ms, 267.32 GB/s, DeviceReduceBlockWise<256,M_C4_S1,K_C64_S1,InSrcVectorDim_0_InSrcVectorSize_1_OutDstVectorSize_1>
Perf: 0.23536 ms, 267.32 GB/s, DeviceReduceBlockWise<256,M_C4_S1,K_C64_S1,InSrcVectorDim_0_InSrcVectorSize_1_OutDstVectorSize_1>
error: 0
error: 0
max_diff: 0, 529, 529
max_diff: 0, 529, 529
root@dc-smc-18:/data/composable_kernel/Build3# bin/reduce_blockwise -D 16,64,32,960 -v 1 1 10
root@dc-smc-18:/data/composable_kernel/Build3# bin/
example_
reduce_blockwise -D 16,64,32,960 -v 1 1 10
launch_and_time_kernel: grid_dim {240, 1, 1}, block_dim {256, 1, 1}
launch_and_time_kernel: grid_dim {240, 1, 1}, block_dim {256, 1, 1}
Warm up
Warm up
Start running 10 times...
Start running 10 times...
...
...
example/12_reduce/reduce_blockwise.cpp
View file @
07a673c6
...
@@ -4,6 +4,8 @@
...
@@ -4,6 +4,8 @@
#include <cstdlib>
#include <cstdlib>
#include <getopt.h>
#include <getopt.h>
#include <half.hpp>
#include <half.hpp>
#include "check_err.hpp"
#include "config.hpp"
#include "config.hpp"
#include "print.hpp"
#include "print.hpp"
#include "device.hpp"
#include "device.hpp"
...
@@ -32,10 +34,10 @@ using HostAccDataType = float;
...
@@ -32,10 +34,10 @@ using HostAccDataType = float;
constexpr
int
Rank
=
4
;
constexpr
int
Rank
=
4
;
constexpr
int
NumReduceDim
=
3
;
constexpr
int
NumReduceDim
=
3
;
constexpr
ReduceTensorOp
_t
ReduceOpId
=
ReduceTensorOp
_t
::
NORM2
;
constexpr
ReduceTensorOp
ReduceOpId
=
ReduceTensorOp
::
NORM2
;
constexpr
NanPropagation
_t
NanOpt
=
NanPropagation
_t
::
PROPAGATE_NAN
;
constexpr
NanPropagation
NanOpt
=
NanPropagation
::
PROPAGATE_NAN
;
constexpr
bool
PropagateNan
=
(
NanOpt
==
NanPropagation
_t
::
NOT_PROPAGATE_NAN
)
?
false
:
true
;
constexpr
bool
PropagateNan
=
(
NanOpt
==
NanPropagation
::
NOT_PROPAGATE_NAN
)
?
false
:
true
;
constexpr
ReduceTensorIndices
_t
IndicesOpt
=
ReduceTensorIndices
_t
::
NO_INDICES
;
constexpr
ReduceTensorIndices
IndicesOpt
=
ReduceTensorIndices
::
NO_INDICES
;
using
ReduceOperation
=
typename
reduce_binary_operator
<
AccDataType
,
ReduceOpId
>::
opType
;
using
ReduceOperation
=
typename
reduce_binary_operator
<
AccDataType
,
ReduceOpId
>::
opType
;
using
InElementwiseOperation
=
using
InElementwiseOperation
=
...
@@ -210,11 +212,11 @@ int main(int argc, char* argv[])
...
@@ -210,11 +212,11 @@ int main(int argc, char* argv[])
return
(
-
1
);
return
(
-
1
);
constexpr
bool
op_support_indices
=
constexpr
bool
op_support_indices
=
(
ReduceOpId
==
ReduceTensorOp
_t
::
MIN
||
ReduceOpId
==
ReduceTensorOp
_t
::
MAX
||
(
ReduceOpId
==
ReduceTensorOp
::
MIN
||
ReduceOpId
==
ReduceTensorOp
::
MAX
||
ReduceOpId
==
ReduceTensorOp
_t
::
AMAX
);
ReduceOpId
==
ReduceTensorOp
::
AMAX
);
constexpr
bool
NeedIndices
=
constexpr
bool
NeedIndices
=
(
op_support_indices
&&
(
IndicesOpt
!=
ReduceTensorIndices
_t
::
NO_INDICES
));
(
op_support_indices
&&
(
IndicesOpt
!=
ReduceTensorIndices
::
NO_INDICES
));
// if input is half type, no reason to use float for indiced reduction operation and must use
// if input is half type, no reason to use float for indiced reduction operation and must use
// float for non-indiced reduction operation for accuracy
// float for non-indiced reduction operation for accuracy
...
@@ -230,7 +232,7 @@ int main(int argc, char* argv[])
...
@@ -230,7 +232,7 @@ int main(int argc, char* argv[])
// indices option can only be used when it is really needed
// indices option can only be used when it is really needed
constexpr
bool
invalid_reduce_3
=
constexpr
bool
invalid_reduce_3
=
(
!
op_support_indices
&&
IndicesOpt
!=
ReduceTensorIndices
_t
::
NO_INDICES
);
(
!
op_support_indices
&&
IndicesOpt
!=
ReduceTensorIndices
::
NO_INDICES
);
constexpr
bool
invalid_reduce
=
(
invalid_reduce_1
||
invalid_reduce_2
||
invalid_reduce_3
);
constexpr
bool
invalid_reduce
=
(
invalid_reduce_1
||
invalid_reduce_2
||
invalid_reduce_3
);
...
@@ -371,12 +373,13 @@ int main(int argc, char* argv[])
...
@@ -371,12 +373,13 @@ int main(int argc, char* argv[])
if
(
args
.
do_verification
)
if
(
args
.
do_verification
)
{
{
out_dev
.
FromDevice
(
out
.
mData
.
data
());
out_dev
.
FromDevice
(
out
.
mData
.
data
());
c
heck_error
(
out_ref
,
out
);
c
k
::
utils
::
check_err
(
out
.
mData
,
out_ref
.
mData
);
if
(
NeedIndices
)
if
(
NeedIndices
)
{
{
out_indices_dev
.
FromDevice
(
out_indices
.
mData
.
data
());
out_indices_dev
.
FromDevice
(
out_indices
.
mData
.
data
());
check_indices
(
out_indices_ref
,
out_indices
);
ck
::
utils
::
check_err
(
out_indices
.
mData
,
out_indices_ref
.
mData
);
;
};
};
};
};
}
}
example/13_pool2d_fwd/README.md
View file @
07a673c6
# Instructions for ```pool2d_fwd``` Example
# Instructions for ```
example_
pool2d_fwd``` Example
## Docker script
## Run ```example_pool2d_fwd```
```
bash
docker run
\
-it
\
--rm
\
--privileged
\
--group-add
sudo
\
-w
/root/workspace
\
-v
${
PATH_TO_LOCAL_WORKSPACE
}
:/root/workspace
\
rocm/tensorflow:rocm4.3.1-tf2.6-dev
\
/bin/bash
```
## Build ```pool2d_fwd```
```
bash
mkdir
build
&&
cd
build
```
```
bash
# Need to specify target ID, example below is gfx908
cmake
\
-D
BUILD_DEV
=
OFF
\
-D
CMAKE_BUILD_TYPE
=
Release
\
-D
CMAKE_CXX_FLAGS
=
"-DCK_AMD_GPU_GFX908 --amdgpu-target=gfx908 -O3 "
\
-D
CMAKE_CXX_COMPILER
=
/opt/rocm/bin/hipcc
\
-D
CMAKE_PREFIX_PATH
=
/opt/rocm
\
..
```
```
bash
make
-j
pool2d_fwd
```
## Run ```pool2d_fwd```
```
bash
```
bash
#arg1: verification (0=no, 1=yes)
#arg1: verification (0=no, 1=yes)
#arg2: initialization (0=no init, 1=single integer value, 2=scope integer value, 3=decimal value)
#arg2: initialization (0=no init, 1=single integer value, 2=scope integer value, 3=decimal value)
#arg3: run kernel # of times (>1)
#arg3: run kernel # of times (>1)
#arg4 to 15: N, C, Y, X, Hi, Wi, Sy, Sx, LeftPy, LeftPx, RightPy, RightPx
#arg4 to 15: N, C, Y, X, Hi, Wi, Sy, Sx, LeftPy, LeftPx, RightPy, RightPx
./example
/
pool2d_fwd 1 1 10
./
bin/
example
_
pool2d_fwd 1 1 10
```
```
Result
Result
...
...
example/13_pool2d_fwd/pool2d_fwd.cpp
View file @
07a673c6
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
#include <initializer_list>
#include <initializer_list>
#include <cstdlib>
#include <cstdlib>
#include <stdlib.h>
#include <stdlib.h>
#include "check_err.hpp"
#include "config.hpp"
#include "config.hpp"
#include "print.hpp"
#include "print.hpp"
#include "device.hpp"
#include "device.hpp"
...
@@ -22,9 +24,9 @@ using InLayout = ck::tensor_layout::convolution::NHWC;
...
@@ -22,9 +24,9 @@ using InLayout = ck::tensor_layout::convolution::NHWC;
using
OutLayout
=
ck
::
tensor_layout
::
convolution
::
NHWC
;
using
OutLayout
=
ck
::
tensor_layout
::
convolution
::
NHWC
;
#if 1
#if 1
static
constexpr
auto
ReduceOpId
=
ck
::
ReduceTensorOp
_t
::
MAX
;
static
constexpr
auto
ReduceOpId
=
ck
::
ReduceTensorOp
::
MAX
;
#else
#else
static
constexpr
auto
ReduceOpId
=
ck
::
ReduceTensorOp
_t
::
AVG
;
static
constexpr
auto
ReduceOpId
=
ck
::
ReduceTensorOp
::
AVG
;
#endif
#endif
static
constexpr
bool
NeedIndices
=
false
;
static
constexpr
bool
NeedIndices
=
false
;
...
@@ -47,7 +49,7 @@ using DevicePoolFwdInstance =
...
@@ -47,7 +49,7 @@ using DevicePoolFwdInstance =
template
<
typename
InDataType
,
template
<
typename
InDataType
,
typename
OutDataType
,
typename
OutDataType
,
typename
AccDataType
,
typename
AccDataType
,
ck
::
ReduceTensorOp
_t
ReduceOpId
,
ck
::
ReduceTensorOp
ReduceOpId
,
bool
PropagateNan
,
bool
PropagateNan
,
bool
NeedIndices
>
bool
NeedIndices
>
static
void
pool_host_verify
(
const
Tensor
<
InDataType
>&
in
,
static
void
pool_host_verify
(
const
Tensor
<
InDataType
>&
in
,
...
@@ -300,13 +302,14 @@ int main(int argc, char* argv[])
...
@@ -300,13 +302,14 @@ int main(int argc, char* argv[])
out_device_buf
.
FromDevice
(
out_n_c_ho_wo_device
.
mData
.
data
());
out_device_buf
.
FromDevice
(
out_n_c_ho_wo_device
.
mData
.
data
());
check_err
or
(
out_n_c_ho_wo_
host
,
out_n_c_ho_wo_
device
);
ck
::
utils
::
check_err
(
out_n_c_ho_wo_
device
.
mData
,
out_n_c_ho_wo_
host
.
mData
);
if
constexpr
(
NeedIndices
)
if
constexpr
(
NeedIndices
)
{
{
out_indices_device_buf
.
FromDevice
(
out_indices_n_c_ho_wo_device
.
mData
.
data
());
out_indices_device_buf
.
FromDevice
(
out_indices_n_c_ho_wo_device
.
mData
.
data
());
// check_indices(out_indices_n_c_ho_wo_host, out_indices_n_c_ho_wo_device);
// ck::utils::check_err(out_indices_n_c_ho_wo_device.mData,
// out_indices_n_c_ho_wo_host.mData);;
};
};
}
}
}
}
example/14_gemm_xdl_requant_relu_requant/gemm_xdl_requant_relu_requant_int8.cpp
View file @
07a673c6
...
@@ -4,6 +4,8 @@
...
@@ -4,6 +4,8 @@
#include <cstdlib>
#include <cstdlib>
#include <stdlib.h>
#include <stdlib.h>
#include <half.hpp>
#include <half.hpp>
#include "check_err.hpp"
#include "config.hpp"
#include "config.hpp"
#include "print.hpp"
#include "print.hpp"
#include "device.hpp"
#include "device.hpp"
...
@@ -225,7 +227,7 @@ int main(int argc, char* argv[])
...
@@ -225,7 +227,7 @@ int main(int argc, char* argv[])
ref_invoker
.
Run
(
ref_argument
);
ref_invoker
.
Run
(
ref_argument
);
check_err
or
(
c_m_n_
host
_result
,
c_m_n_
device
_result
);
ck
::
utils
::
check_err
(
c_m_n_
device
_result
.
mData
,
c_m_n_
host
_result
.
mData
);
}
}
return
0
;
return
0
;
...
...
example/15_grouped_gemm/README.md
View file @
07a673c6
# Instructions for ```grouped_gemm_xdl```
Example
# Instructions for ```
example_
grouped_gemm_xdl```
## Docker script
## Run ```example_grouped_gemm_xdl```
```
bash
docker run
\
-it
\
--rm
\
--privileged
\
--group-add
sudo
\
-w
/root/workspace
\
-v
${
PATH_TO_LOCAL_WORKSPACE
}
:/root/workspace
\
rocm/tensorflow:rocm4.3.1-tf2.6-dev
\
/bin/bash
```
## Build ```grouped_gemm_xdl```
```
bash
mkdir
build
&&
cd
build
```
```
bash
# Need to specify target ID, example below is gfx908
cmake
\
-D
BUILD_DEV
=
OFF
\
-D
CMAKE_BUILD_TYPE
=
Release
\
-D
CMAKE_CXX_FLAGS
=
"-DCK_AMD_GPU_GFX908 --amdgpu-target=gfx908 -O3 "
\
-D
CMAKE_CXX_COMPILER
=
/opt/rocm/bin/hipcc
\
-D
CMAKE_PREFIX_PATH
=
/opt/rocm
\
..
```
```
bash
make
-j
example_grouped_gemm_xdl_fp16
```
## Run ```grouped_gemm_xdl```
```
bash
```
bash
#arg1: verification (0=no, 1=yes)
#arg1: verification (0=no, 1=yes)
#arg2: initialization (0=no init, 1=integer value, 2=decimal value)
#arg2: initialization (0=no init, 1=integer value, 2=decimal value)
...
...
Prev
1
2
3
4
5
6
…
16
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment