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
92a0945d
Commit
92a0945d
authored
Jul 11, 2022
by
Chao Liu
Browse files
convnd_fwd fp16 example
parent
63914743
Changes
28
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
327 additions
and
822 deletions
+327
-822
README.md
README.md
+2
-1
example/09_convnd_fwd/CMakeLists.txt
example/09_convnd_fwd/CMakeLists.txt
+0
-4
example/09_convnd_fwd/convnd_fwd_xdl_fp16.cpp
example/09_convnd_fwd/convnd_fwd_xdl_fp16.cpp
+95
-200
example/09_convnd_fwd/parse_conv_parameter.hpp
example/09_convnd_fwd/parse_conv_parameter.hpp
+70
-0
example/CMakeLists.txt
example/CMakeLists.txt
+2
-2
include/ck/tensor_operation/gpu/device/device_conv_fwd.hpp
include/ck/tensor_operation/gpu/device/device_conv_fwd.hpp
+28
-4
include/ck/tensor_operation/gpu/device/device_convnd_fwd_nwc_kxc_nwk_xdl.hpp
...peration/gpu/device/device_convnd_fwd_nwc_kxc_nwk_xdl.hpp
+26
-8
include/ck/tensor_operation/gpu/device/device_gemm.hpp
include/ck/tensor_operation/gpu/device/device_gemm.hpp
+0
-19
library/CMakeLists.txt
library/CMakeLists.txt
+0
-1
library/include/ck/library/reference_tensor_operation/cpu/reference_conv_fwd.hpp
...ary/reference_tensor_operation/cpu/reference_conv_fwd.hpp
+5
-2
library/include/ck/library/utility/check_err.hpp
library/include/ck/library/utility/check_err.hpp
+3
-7
library/include/ck/library/utility/conv_common.hpp
library/include/ck/library/utility/conv_common.hpp
+0
-0
library/include/ck/library/utility/conv_util.hpp
library/include/ck/library/utility/conv_util.hpp
+0
-574
library/include/ck/library/utility/convolution_parameter.hpp
library/include/ck/library/utility/convolution_parameter.hpp
+80
-0
library/include/ck/library/utility/device_memory.hpp
library/include/ck/library/utility/device_memory.hpp
+0
-0
library/include/ck/library/utility/host_common_util.hpp
library/include/ck/library/utility/host_common_util.hpp
+0
-0
library/include/ck/library/utility/host_conv.hpp
library/include/ck/library/utility/host_conv.hpp
+0
-0
library/include/ck/library/utility/host_gemm.hpp
library/include/ck/library/utility/host_gemm.hpp
+0
-0
library/include/ck/library/utility/host_reduction.hpp
library/include/ck/library/utility/host_reduction.hpp
+0
-0
library/include/ck/library/utility/host_tensor.hpp
library/include/ck/library/utility/host_tensor.hpp
+16
-0
No files found.
README.md
View file @
92a0945d
...
@@ -10,7 +10,7 @@ rocm/tensorflow:rocm5.1-tf2.6-dev \
...
@@ -10,7 +10,7 @@ rocm/tensorflow:rocm5.1-tf2.6-dev \
/bin/bash
/bin/bash
```
```
# Install
the new
rocm-cmake
version
# Install
newer version of
rocm-cmake
https://github.com/RadeonOpenCompute/rocm-cmake
https://github.com/RadeonOpenCompute/rocm-cmake
## Build
## Build
...
@@ -54,6 +54,7 @@ make install
...
@@ -54,6 +54,7 @@ make install
```
```
## Using CK as pre-built kernel library
## Using CK as pre-built kernel library
Instructions for using CK as a pre-built kernel library are under
```client_example/```
## Caveat
## Caveat
### Kernel Timing and Verification
### Kernel Timing and Verification
...
...
example/09_convnd_fwd/CMakeLists.txt
View file @
92a0945d
...
@@ -3,7 +3,3 @@ add_example_executable(example_convnd_fwd_xdl_int8 convnd_fwd_xdl_int8.cpp)
...
@@ -3,7 +3,3 @@ 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
)
add_example_executable
(
example_convnd_fwd_xdl_fp16 convnd_fwd_xdl_fp16.cpp
)
# FIXME: re-enable this exampe as test when SWDEV-335738 is fixed
# FIXME: re-enable this exampe as test when SWDEV-335738 is fixed
add_example_executable_no_testing
(
example_convnd_fwd_xdl_fp64 convnd_fwd_xdl_fp64.cpp
)
add_example_executable_no_testing
(
example_convnd_fwd_xdl_fp64 convnd_fwd_xdl_fp64.cpp
)
target_link_libraries
(
example_convnd_fwd_xdl_fp64 PRIVATE conv_util
)
target_link_libraries
(
example_convnd_fwd_xdl_fp32 PRIVATE conv_util
)
target_link_libraries
(
example_convnd_fwd_xdl_int8 PRIVATE conv_util
)
target_link_libraries
(
example_convnd_fwd_xdl_fp16 PRIVATE conv_util
)
example/09_convnd_fwd/convnd_fwd_xdl_fp16.cpp
View file @
92a0945d
...
@@ -8,17 +8,17 @@
...
@@ -8,17 +8,17 @@
#include "ck/ck.hpp"
#include "ck/ck.hpp"
#include "ck/tensor_operation/gpu/device/tensor_layout.hpp"
#include "ck/tensor_operation/gpu/device/tensor_layout.hpp"
#include "ck/tensor_operation/gpu/device/device_convnd_fwd_
xdl_nh
wc_k
y
xc_n
h
wk.hpp"
#include "ck/tensor_operation/gpu/device/device_convnd_fwd_
n
wc_kxc_nwk
_xdl
.hpp"
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp"
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/library/utility/conv
_
uti
l
.hpp"
#include "ck/library/utility/conv
ol
uti
on_parameter
.hpp"
#include "ck/library/
host_tensor
/device_memory.hpp"
#include "ck/library/
utility
/device_memory.hpp"
#include "ck/library/
host_tensor
/host_tensor.hpp"
#include "ck/library/
utility
/host_tensor.hpp"
#include "ck/library/
host_tensor
/host_tensor_generator.hpp"
#include "ck/library/
utility
/host_tensor_generator.hpp"
#include "ck/library/reference_tensor_operation/cpu/reference_conv_fwd.hpp"
#include "ck/library/reference_tensor_operation/cpu/reference_conv_fwd.hpp"
namespace
{
#include "parse_conv_parameter.hpp"
using
InDataType
=
ck
::
half_t
;
using
InDataType
=
ck
::
half_t
;
using
WeiDataType
=
ck
::
half_t
;
using
WeiDataType
=
ck
::
half_t
;
...
@@ -39,47 +39,42 @@ using OutElementOp = ck::tensor_operation::element_wise::PassThrough;
...
@@ -39,47 +39,42 @@ using OutElementOp = ck::tensor_operation::element_wise::PassThrough;
static
constexpr
auto
ConvFwdDefault
=
static
constexpr
auto
ConvFwdDefault
=
ck
::
tensor_operation
::
device
::
ConvolutionForwardSpecialization
::
Default
;
ck
::
tensor_operation
::
device
::
ConvolutionForwardSpecialization
::
Default
;
using
DeviceConvFwdBasePtr
=
ck
::
tensor_operation
::
device
::
DeviceConvFwdPtr
<
InElementOp
,
WeiElementOp
,
OutElementOp
>
;
template
<
ck
::
index_t
NumDimSpatial
>
template
<
ck
::
index_t
NumDimSpatial
>
using
DeviceConvNDFwdInstance
=
ck
::
tensor_operation
::
device
::
using
DeviceConvNDFwdInstance
=
ck
::
tensor_operation
::
device
::
DeviceConvNdFwdNwcKxcNwk_Xdl
<
DeviceConvNDFwdXdl_Input_N_Hi_Wi_C_Weight_K_Y_X_C_Output_N_Ho_Wo_K
<
InDataType
,
//
// clang-format off
WeiDataType
,
//
InDataType
,
//
OutDataType
,
//
WeiDataType
,
//
AccDataType
,
//
OutDataType
,
//
InElementOp
,
// Input Elementwise Operation
AccDataType
,
//
WeiElementOp
,
// Weights Elementwise Operation
InElementOp
,
// Input Elementwise Operation
OutElementOp
,
// Output Elementwise Operation
WeiElementOp
,
// Weights Elementwise Operation
ConvFwdDefault
,
// ConvForwardSpecialization
OutElementOp
,
// Output Elementwise Operation
NumDimSpatial
,
// NumDimSpatial
ConvFwdDefault
,
// ConvForwardSpecialization
256
,
// BlockSize
NumDimSpatial
,
// NumDimSpatial
128
,
// MPerBlock
256
,
// BlockSize
256
,
// NPerBlock
128
,
// MPerBlock
4
,
// K0PerBlock
256
,
// NPerBlock
8
,
// K1
4
,
// K0PerBlock
32
,
// MPerXdl
8
,
// K1
32
,
// NPerXdl
32
,
// MPerXdl
2
,
// MXdlPerWave
32
,
// NPerXdl
4
,
// NXdlPerWave
2
,
// MXdlPerWave
S
<
4
,
64
,
1
>
,
// ABlockTransferThreadClusterLengths_K0_M_K1
4
,
// NXdlPerWave
S
<
1
,
0
,
2
>
,
// ABlockTransferThreadClusterArrangeOrder
S
<
4
,
64
,
1
>
,
// ABlockTransferThreadClusterLengths_K0_M_K1
S
<
1
,
0
,
2
>
,
// ABlockTransferSrcAccessOrder
S
<
1
,
0
,
2
>
,
// ABlockTransferThreadClusterArrangeOrder
2
,
// ABlockTransferSrcVectorDim
S
<
1
,
0
,
2
>
,
// ABlockTransferSrcAccessOrder
8
,
// ABlockTransferSrcScalarPerVector
2
,
// ABlockTransferSrcVectorDim
8
,
// ABlockTransferDstScalarPerVector_K1
8
,
// ABlockTransferSrcScalarPerVector
true
,
// ABlockLdsAddExtraM
8
,
// ABlockTransferDstScalarPerVector_K1
S
<
4
,
64
,
1
>
,
// BBlockTransferThreadClusterLengths_K0_N_K1
true
,
// ABlockLdsAddExtraM
S
<
1
,
0
,
2
>
,
// BBlockTransferThreadClusterArrangeOrder
S
<
4
,
64
,
1
>
,
// BBlockTransferThreadClusterLengths_K0_N_K1
S
<
1
,
0
,
2
>
,
// BBlockTransferSrcAccessOrder
S
<
1
,
0
,
2
>
,
// BBlockTransferThreadClusterArrangeOrder
2
,
// BBlockTransferSrcVectorDim
S
<
1
,
0
,
2
>
,
// BBlockTransferSrcAccessOrder
8
,
// BBlockTransferSrcScalarPerVector
2
,
// BBlockTransferSrcVectorDim
8
,
// BBlockTransferDstScalarPerVector_K1
8
,
// BBlockTransferSrcScalarPerVector
true
,
// BBlockLdsAddExtraN
8
,
// BBlockTransferDstScalarPerVector_K1
7
,
// CThreadTransferSrcDstVectorDim
true
,
// BBlockLdsAddExtraN
1
>
;
// CThreadTransferDstScalarPerVector
7
,
// CThreadTransferSrcDstVectorDim
1
>
;
// CThreadTransferDstScalarPerVector
template
<
ck
::
index_t
NumDimSpatial
>
template
<
ck
::
index_t
NumDimSpatial
>
using
ReferenceConvNDFwdInstance
=
ck
::
tensor_operation
::
host
::
ReferenceConvFwd
<
InDataType
,
using
ReferenceConvNDFwdInstance
=
ck
::
tensor_operation
::
host
::
ReferenceConvFwd
<
InDataType
,
...
@@ -90,107 +85,14 @@ using ReferenceConvNDFwdInstance = ck::tensor_operation::host::ReferenceConvFwd<
...
@@ -90,107 +85,14 @@ using ReferenceConvNDFwdInstance = ck::tensor_operation::host::ReferenceConvFwd<
OutElementOp
,
OutElementOp
,
NumDimSpatial
>
;
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: time kernel (0=n0, 1=yes)
\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
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
using
namespace
ck
::
utils
::
conv
;
bool
do_verification
=
true
;
bool
do_verification
=
true
;
int
init_method
=
1
;
int
init_method
=
1
;
bool
time_kernel
=
fals
e
;
bool
time_kernel
=
tru
e
;
int
num_dim_spatial
=
2
;
int
num_dim_spatial
=
2
;
ck
::
utils
::
conv
::
ConvParams
params
;
ck
::
tensor_operation
::
device
::
ConvParams
params
;
if
(
argc
>=
5
)
if
(
argc
>=
5
)
{
{
...
@@ -205,29 +107,25 @@ int main(int argc, char* argv[])
...
@@ -205,29 +107,25 @@ int main(int argc, char* argv[])
params
=
parse_conv_params
(
num_dim_spatial
,
argc
,
argv
);
params
=
parse_conv_params
(
num_dim_spatial
,
argc
,
argv
);
}
}
std
::
vector
<
std
::
size_t
>
input_dims
{
static_cast
<
std
::
size_t
>
(
params
.
N_
),
auto
f_nchw_host_tensor_descriptor
=
static_cast
<
std
::
size_t
>
(
params
.
C_
)};
[](
ck
::
index_t
n
,
ck
::
index_t
c
,
std
::
vector
<
ck
::
index_t
>
spatial_lengths
)
{
input_dims
.
insert
(
std
::
end
(
input_dims
),
std
::
vector
<
std
::
size_t
>
nhwc_lengths
{
static_cast
<
std
::
size_t
>
(
n
),
std
::
begin
(
params
.
input_spatial_lengths_
),
static_cast
<
std
::
size_t
>
(
c
)};
std
::
end
(
params
.
input_spatial_lengths_
));
nhwc_lengths
.
insert
(
nhwc_lengths
.
begin
()
+
1
,
spatial_lengths
.
begin
(),
spatial_lengths
.
end
());
std
::
vector
<
std
::
size_t
>
filter_dims
{
static_cast
<
std
::
size_t
>
(
params
.
K_
),
return
transpose_host_tensor_descriptor_given_new2old
(
static_cast
<
std
::
size_t
>
(
params
.
C_
)};
HostTensorDescriptor
(
nhwc_lengths
),
std
::
vector
<
std
::
size_t
>
({
0
,
3
,
1
,
2
}));
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
<
InDataType
>
input
(
Tensor
<
WeiDataType
>
weights
(
get_filters_host_tensor_descriptor
(
filter_dims
,
num_dim_spatial
));
f_nchw_host_tensor_descriptor
(
params
.
N_
,
params
.
C_
,
params
.
input_spatial_lengths_
));
Tensor
<
OutDataType
>
host_output
(
get_output_host_tensor_descriptor
(
output_dims
,
num_dim_spatial
));
Tensor
<
InDataType
>
weights
(
Tensor
<
OutDataType
>
device_output
(
get_output_host_tensor_descriptor
(
output_dims
,
num_dim_spatial
));
f_nchw_host_tensor_descriptor
(
params
.
K_
,
params
.
C_
,
params
.
filter_spatial_lengths_
));
Tensor
<
InDataType
>
host_output
(
f_nchw_host_tensor_descriptor
(
params
.
N_
,
params
.
K_
,
params
.
GetOutputSpatialLengths
()));
Tensor
<
InDataType
>
device_output
(
f_nchw_host_tensor_descriptor
(
params
.
N_
,
params
.
K_
,
params
.
GetOutputSpatialLengths
()));
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
;
...
@@ -253,49 +151,41 @@ int main(int argc, char* argv[])
...
@@ -253,49 +151,41 @@ 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
=
get_conv_instance
(
num_dim_spatial
);
auto
conv
=
DeviceConvNDFwdInstance
<
2
>
{};
auto
invoker
=
conv
->
MakeInvokerPointer
();
auto
invoker
=
conv
.
MakeInvoker
();
auto
argument
=
auto
argument
=
conv
.
MakeArgument
(
static_cast
<
InDataType
*>
(
in_device_buf
.
GetDeviceBuffer
()),
conv
->
MakeArgumentPointer
(
static_cast
<
InDataType
*>
(
in_device_buf
.
GetDeviceBuffer
()),
static_cast
<
WeiDataType
*>
(
wei_device_buf
.
GetDeviceBuffer
()),
static_cast
<
WeiDataType
*>
(
wei_device_buf
.
GetDeviceBuffer
()),
static_cast
<
OutDataType
*>
(
out_device_buf
.
GetDeviceBuffer
()),
static_cast
<
OutDataType
*>
(
out_device_buf
.
GetDeviceBuffer
()),
params
.
N_
,
params
.
N_
,
params
.
K_
,
params
.
K_
,
params
.
C_
,
params
.
C_
,
params
.
input_spatial_lengths_
,
params
.
input_spatial_lengths_
,
params
.
filter_spatial_lengths_
,
params
.
filter_spatial_lengths_
,
params
.
GetOutputSpatialLengths
(),
output_spatial_lengths
,
params
.
conv_filter_strides_
,
params
.
conv_filter_strides_
,
params
.
conv_filter_dilations_
,
params
.
conv_filter_dilations_
,
params
.
input_left_pads_
,
params
.
input_left_pads_
,
params
.
input_right_pads_
,
params
.
input_right_pads_
,
InElementOp
{},
InElementOp
{},
WeiElementOp
{},
WeiElementOp
{},
OutElementOp
{});
OutElementOp
{});
if
(
!
conv
.
IsSupportedArgument
(
argument
))
if
(
!
conv
->
IsSupportedArgument
(
argument
.
get
()))
{
{
throw
std
::
runtime_error
(
throw
std
::
runtime_error
(
"wrong! device_conv with the specified compilation parameters does "
"wrong! device_conv with the specified compilation parameters does "
"not support this Conv problem"
);
"not support this Conv problem"
);
}
}
float
ave_time
=
invoker
->
Run
(
argument
.
get
()
,
StreamConfig
{
nullptr
,
time_kernel
});
float
ave_time
=
invoker
.
Run
(
argument
,
StreamConfig
{
nullptr
,
time_kernel
});
std
::
size_t
flop
=
get_flops
(
std
::
size_t
flop
=
params
.
GetFlops
();
params
.
N_
,
params
.
C_
,
params
.
K_
,
params
.
filter_spatial_lengths_
,
output_spatial_lengths
);
std
::
size_t
num_btype
=
params
.
GetByte
<
InDataType
,
WeiDataType
,
OutDataType
>
();
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
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
;
std
::
cout
<<
"Perf: "
<<
ave_time
<<
" ms, "
<<
tflops
<<
" TFlops, "
<<
gb_per_sec
<<
" GB/s, "
std
::
cout
<<
"Perf: "
<<
ave_time
<<
" ms, "
<<
tflops
<<
" TFlops, "
<<
gb_per_sec
<<
" GB/s, "
<<
conv
->
GetTypeString
()
<<
std
::
endl
;
<<
conv
.
GetTypeString
()
<<
std
::
endl
;
if
(
do_verification
)
if
(
do_verification
)
{
{
...
@@ -315,22 +205,27 @@ int main(int argc, char* argv[])
...
@@ -315,22 +205,27 @@ 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
());
return
ck
::
utils
::
check_err
(
return
ck
::
utils
::
check_err
(
host_output
.
mData
,
host_output
.
mData
,
device_output
.
mData
,
"Error: incorrect results!"
,
1e-5
f
,
1e-4
f
)
?
0
:
1
;
device_output
.
mData
,
"Error: incorrect results!"
,
1e-5
f
,
1e-4
f
)
?
0
:
1
;
};
};
switch
(
num_dim_spatial
)
switch
(
num_dim_spatial
)
{
{
case
3
:
{
case
1
:
{
auto
ref_conv
=
ReferenceConvNDFwdInstance
<
3
>
();
auto
ref_conv
=
ReferenceConvNDFwdInstance
<
1
>
();
return
verify_f
(
ref_conv
);
return
verify_f
(
ref_conv
);
}
}
case
2
:
{
case
2
:
{
auto
ref_conv
=
ReferenceConvNDFwdInstance
<
2
>
();
auto
ref_conv
=
ReferenceConvNDFwdInstance
<
2
>
();
return
verify_f
(
ref_conv
);
return
verify_f
(
ref_conv
);
}
}
case
1
:
{
case
3
:
{
auto
ref_conv
=
ReferenceConvNDFwdInstance
<
1
>
();
auto
ref_conv
=
ReferenceConvNDFwdInstance
<
3
>
();
return
verify_f
(
ref_conv
);
return
verify_f
(
ref_conv
);
}
}
default:
{
default:
{
...
...
example/09_convnd_fwd/parse_conv_parameter.hpp
0 → 100644
View file @
92a0945d
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include <cstdlib>
#include <iostream>
#include "ck/ck.hpp"
#include "ck/library/utility/convolution_parameter.hpp"
ck
::
tensor_operation
::
device
::
ConvParams
parse_conv_params
(
int
num_dim_spatial
,
int
arg_idx
,
char
*
const
argv
[])
{
ck
::
tensor_operation
::
device
::
ConvParams
params
;
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
;
}
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: time kernel (0=n0, 1=yes)
\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
;
}
example/CMakeLists.txt
View file @
92a0945d
...
@@ -8,7 +8,7 @@ add_custom_target(examples)
...
@@ -8,7 +8,7 @@ add_custom_target(examples)
function
(
add_example_executable EXAMPLE_NAME FILE_NAME
)
function
(
add_example_executable EXAMPLE_NAME FILE_NAME
)
message
(
"adding example
${
EXAMPLE_NAME
}
"
)
message
(
"adding example
${
EXAMPLE_NAME
}
"
)
add_executable
(
${
EXAMPLE_NAME
}
${
FILE_NAME
}
)
add_executable
(
${
EXAMPLE_NAME
}
${
FILE_NAME
}
)
target_link_libraries
(
${
EXAMPLE_NAME
}
PRIVATE
host_tensor
)
target_link_libraries
(
${
EXAMPLE_NAME
}
PRIVATE
utility
)
add_test
(
NAME
${
EXAMPLE_NAME
}
COMMAND $<TARGET_FILE:
${
EXAMPLE_NAME
}
>
${
ARGN
}
)
add_test
(
NAME
${
EXAMPLE_NAME
}
COMMAND $<TARGET_FILE:
${
EXAMPLE_NAME
}
>
${
ARGN
}
)
add_dependencies
(
examples
${
EXAMPLE_NAME
}
)
add_dependencies
(
examples
${
EXAMPLE_NAME
}
)
add_dependencies
(
check
${
EXAMPLE_NAME
}
)
add_dependencies
(
check
${
EXAMPLE_NAME
}
)
...
@@ -17,7 +17,7 @@ endfunction(add_example_executable EXAMPLE_NAME)
...
@@ -17,7 +17,7 @@ endfunction(add_example_executable EXAMPLE_NAME)
function
(
add_example_executable_no_testing EXAMPLE_NAME FILE_NAME
)
function
(
add_example_executable_no_testing EXAMPLE_NAME FILE_NAME
)
message
(
"adding example
${
EXAMPLE_NAME
}
"
)
message
(
"adding example
${
EXAMPLE_NAME
}
"
)
add_executable
(
${
EXAMPLE_NAME
}
${
FILE_NAME
}
)
add_executable
(
${
EXAMPLE_NAME
}
${
FILE_NAME
}
)
target_link_libraries
(
${
EXAMPLE_NAME
}
PRIVATE
host_tensor
)
target_link_libraries
(
${
EXAMPLE_NAME
}
PRIVATE
utility
)
add_dependencies
(
examples
${
EXAMPLE_NAME
}
)
add_dependencies
(
examples
${
EXAMPLE_NAME
}
)
endfunction
(
add_example_executable_no_testing EXAMPLE_NAME
)
endfunction
(
add_example_executable_no_testing EXAMPLE_NAME
)
...
...
include/ck/tensor_operation/gpu/device/device_conv_fwd.hpp
View file @
92a0945d
...
@@ -12,7 +12,14 @@ namespace ck {
...
@@ -12,7 +12,14 @@ namespace ck {
namespace
tensor_operation
{
namespace
tensor_operation
{
namespace
device
{
namespace
device
{
template
<
typename
InElementwiseOperation
,
template
<
ck
::
index_t
NumDimSpatial
,
typename
InLayout
,
typename
WeiLayout
,
typename
OutLayout
,
typename
InDataType
,
typename
WeiDataType
,
typename
OutDataType
,
typename
InElementwiseOperation
,
typename
WeiElementwiseOperation
,
typename
WeiElementwiseOperation
,
typename
OutElementwiseOperation
>
typename
OutElementwiseOperation
>
struct
DeviceConvFwd
:
public
BaseOperator
struct
DeviceConvFwd
:
public
BaseOperator
...
@@ -38,11 +45,28 @@ struct DeviceConvFwd : public BaseOperator
...
@@ -38,11 +45,28 @@ struct DeviceConvFwd : public BaseOperator
virtual
std
::
unique_ptr
<
BaseInvoker
>
MakeInvokerPointer
()
=
0
;
virtual
std
::
unique_ptr
<
BaseInvoker
>
MakeInvokerPointer
()
=
0
;
};
};
template
<
typename
InElementwiseOperation
,
#if 0
template <ck::index_t NumDimSpatial,
typename InLayout,
typename WeiLayout,
typename OutLayout,
typename InDataType,
typename WeiDataType,
typename OutDataType,
typename InElementwiseOperation,
typename WeiElementwiseOperation,
typename WeiElementwiseOperation,
typename OutElementwiseOperation>
typename OutElementwiseOperation>
using
DeviceConvFwdPtr
=
std
::
unique_ptr
<
using DeviceConvFwdPtr = std::unique_ptr<DeviceConvFwd<NumDimSpatial,
DeviceConvFwd
<
InElementwiseOperation
,
WeiElementwiseOperation
,
OutElementwiseOperation
>>
;
InLayout,
WeiLayout,
OutLayout,
InDataType,
WeiDataType,
OutDataType,
InElementwiseOperation,
WeiElementwiseOperation,
OutElementwiseOperation>>;
#endif
}
// namespace device
}
// namespace device
}
// namespace tensor_operation
}
// namespace tensor_operation
...
...
include/ck/tensor_operation/gpu/device/device_convnd_fwd_
xdl_nh
wc_k
y
xc_n
h
wk.hpp
→
include/ck/tensor_operation/gpu/device/device_convnd_fwd_
n
wc_kxc_nwk
_xdl
.hpp
View file @
92a0945d
...
@@ -27,10 +27,10 @@ namespace device {
...
@@ -27,10 +27,10 @@ namespace device {
// @brief Device Convolution operation.
// @brief Device Convolution operation.
//
//
// Supports:
// Supports:
// @li
Inputs
with up to 3 spatial dimentions
// @li
Forward convolution
with up to 3 spatial dimentions
// @li Input tensor in N
H
WC data format
// @li Input tensor in NWC data format
// @li Weight tensor in K
Y
XC data format
// @li Weight tensor in KXC data format
// @li Output tensor in N
H
WK data format
// @li Output tensor in NWK data format
//
//
// 1D:
// 1D:
// out[N, Wo, K] = in[N, Wi, C] * wei[K, X, C]
// out[N, Wo, K] = in[N, Wi, C] * wei[K, X, C]
...
@@ -73,10 +73,28 @@ template <typename InDataType,
...
@@ -73,10 +73,28 @@ template <typename InDataType,
bool
BBlockLdsAddExtraN
,
bool
BBlockLdsAddExtraN
,
ck
::
index_t
CThreadTransferSrcDstVectorDim
,
ck
::
index_t
CThreadTransferSrcDstVectorDim
,
ck
::
index_t
CThreadTransferDstScalarPerVector
>
ck
::
index_t
CThreadTransferDstScalarPerVector
>
struct
DeviceConvNDFwdXdl_Input_N_Hi_Wi_C_Weight_K_Y_X_C_Output_N_Ho_Wo_K
struct
DeviceConvNdFwdNwcKxcNwk_Xdl
:
public
DeviceConvFwd
<
InElementwiseOperation
,
WeiElementwiseOperation
,
OutElementwiseOperation
>
:
public
DeviceConvFwd
<
NumDimSpatial
,
ck
::
tuple_element_t
<
NumDimSpatial
-
1
,
ck
::
Tuple
<
ck
::
tensor_layout
::
convolution
::
NWC
,
ck
::
tensor_layout
::
convolution
::
NHWC
,
ck
::
tensor_layout
::
convolution
::
NDHWC
>>
,
ck
::
tuple_element_t
<
NumDimSpatial
-
1
,
ck
::
Tuple
<
ck
::
tensor_layout
::
convolution
::
KXC
,
ck
::
tensor_layout
::
convolution
::
KYXC
,
ck
::
tensor_layout
::
convolution
::
KZYXC
>>
,
ck
::
tuple_element_t
<
NumDimSpatial
-
1
,
ck
::
Tuple
<
ck
::
tensor_layout
::
convolution
::
NWC
,
ck
::
tensor_layout
::
convolution
::
NHWC
,
ck
::
tensor_layout
::
convolution
::
NDHWC
>>
,
InDataType
,
WeiDataType
,
OutDataType
,
InElementwiseOperation
,
WeiElementwiseOperation
,
OutElementwiseOperation
>
{
{
using
DeviceOp
=
DeviceConvN
D
Fwd
Xdl_Input_N_Hi_Wi_C_Weight_K_Y_X_C_Output_N_Ho_Wo_K
;
using
DeviceOp
=
DeviceConvN
d
Fwd
NwcKxcNwk_Xdl
;
using
ADataType
=
InDataType
;
using
ADataType
=
InDataType
;
using
BDataType
=
WeiDataType
;
using
BDataType
=
WeiDataType
;
...
@@ -1027,7 +1045,7 @@ struct DeviceConvNDFwdXdl_Input_N_Hi_Wi_C_Weight_K_Y_X_C_Output_N_Ho_Wo_K
...
@@ -1027,7 +1045,7 @@ struct DeviceConvNDFwdXdl_Input_N_Hi_Wi_C_Weight_K_Y_X_C_Output_N_Ho_Wo_K
auto
str
=
std
::
stringstream
();
auto
str
=
std
::
stringstream
();
// clang-format off
// clang-format off
str
<<
"DeviceConvN
D
Fwd
Xdl_Input_N_Hi_Wi_C_Weight_K_Y_X_C_Output_N_Ho_Wo_K
"
str
<<
"DeviceConvN
d
Fwd
NwcKxcNwk_Xdl
"
<<
"<"
<<
"<"
<<
BlockSize
<<
", "
<<
BlockSize
<<
", "
<<
MPerBlock
<<
", "
<<
MPerBlock
<<
", "
...
...
include/ck/tensor_operation/gpu/device/device_gemm.hpp
View file @
92a0945d
...
@@ -46,25 +46,6 @@ struct DeviceGemm : public BaseOperator
...
@@ -46,25 +46,6 @@ struct DeviceGemm : public BaseOperator
virtual
std
::
unique_ptr
<
BaseInvoker
>
MakeInvokerPointer
()
=
0
;
virtual
std
::
unique_ptr
<
BaseInvoker
>
MakeInvokerPointer
()
=
0
;
};
};
template
<
typename
ALayout
,
typename
BLayout
,
typename
CLayout
,
typename
ADataType
,
typename
BDataType
,
typename
CDataType
,
typename
AElementwiseOperation
,
typename
BElementwiseOperation
,
typename
CElementwiseOperation
>
using
DeviceGemmPtr
=
std
::
unique_ptr
<
DeviceGemm
<
ALayout
,
BLayout
,
CLayout
,
ADataType
,
BDataType
,
CDataType
,
AElementwiseOperation
,
BElementwiseOperation
,
CElementwiseOperation
>>
;
template
<
typename
AElementwiseOperation
,
template
<
typename
AElementwiseOperation
,
typename
BElementwiseOperation
,
typename
BElementwiseOperation
,
typename
CElementwiseOperation
>
typename
CElementwiseOperation
>
...
...
library/CMakeLists.txt
View file @
92a0945d
add_subdirectory
(
src/tensor_operation_instance/gpu
)
add_subdirectory
(
src/tensor_operation_instance/gpu
)
add_subdirectory
(
src/host_tensor
)
add_subdirectory
(
src/utility
)
add_subdirectory
(
src/utility
)
library/include/ck/library/reference_tensor_operation/cpu/reference_conv_fwd.hpp
View file @
92a0945d
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
#include <sstream>
#include <sstream>
#include "ck/tensor_operation/gpu/device/device_base.hpp"
#include "ck/tensor_operation/gpu/device/device_base.hpp"
#include "ck/library/
host_tensor
/host_tensor.hpp"
#include "ck/library/
utility
/host_tensor.hpp"
namespace
ck
{
namespace
ck
{
namespace
tensor_operation
{
namespace
tensor_operation
{
...
@@ -267,7 +267,10 @@ struct ReferenceConvFwd : public device::BaseOperator
...
@@ -267,7 +267,10 @@ struct ReferenceConvFwd : public device::BaseOperator
return
true
;
return
true
;
}
}
bool
IsSupportedArgument
(
const
device
::
BaseArgument
*
)
override
{
return
true
;
}
bool
IsSupportedArgument
(
const
device
::
BaseArgument
*
)
override
{
return
NumDimSpatial
>=
1
&&
NumDimSpatial
<=
3
;
}
static
auto
MakeArgument
(
const
Tensor
<
InDataType
>&
input
,
static
auto
MakeArgument
(
const
Tensor
<
InDataType
>&
input
,
const
Tensor
<
WeiDataType
>&
weight
,
const
Tensor
<
WeiDataType
>&
weight
,
...
...
library/include/ck/library/utility/check_err.hpp
View file @
92a0945d
...
@@ -13,8 +13,11 @@
...
@@ -13,8 +13,11 @@
#include <type_traits>
#include <type_traits>
#include <vector>
#include <vector>
#include "ck/ck.hpp"
#include "ck/utility/data_type.hpp"
#include "ck/utility/data_type.hpp"
#include "ck/library/utility/io.hpp"
namespace
ck
{
namespace
ck
{
namespace
utils
{
namespace
utils
{
...
@@ -201,10 +204,3 @@ check_err(const std::vector<T>& out,
...
@@ -201,10 +204,3 @@ check_err(const std::vector<T>& out,
}
// namespace utils
}
// namespace utils
}
// namespace ck
}
// namespace ck
template
<
typename
T
>
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
std
::
vector
<
T
>&
v
)
{
std
::
copy
(
std
::
begin
(
v
),
std
::
end
(
v
),
std
::
ostream_iterator
<
T
>
(
os
,
" "
));
return
os
;
}
library/include/ck/library/
host_tensor
/conv_common.hpp
→
library/include/ck/library/
utility
/conv_common.hpp
View file @
92a0945d
File moved
library/include/ck/library/utility/conv_util.hpp
deleted
100644 → 0
View file @
63914743
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#pragma once
#include <cstdlib>
#include <functional>
#include <iterator>
#include <numeric>
#include <sstream>
#include <tuple>
#include <type_traits>
#include <vector>
#include "ck/ck.hpp"
#include "ck/tensor_operation/gpu/device/tensor_layout.hpp"
#include "ck/tensor_operation/gpu/device/device_conv_fwd.hpp"
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/library/utility/fill.hpp"
#include "ck/library/utility/op_instance_engine.hpp"
#include "ck/library/host_tensor/device_memory.hpp"
#include "ck/library/host_tensor/host_tensor.hpp"
#include "ck/library/reference_tensor_operation/cpu/reference_conv_fwd.hpp"
namespace
ck
{
namespace
tensor_operation
{
namespace
device
{
using
DeviceConvFwdNoOpPtr
=
DeviceConvFwdPtr
<
element_wise
::
PassThrough
,
element_wise
::
PassThrough
,
element_wise
::
PassThrough
>
;
namespace
instance
{
void
add_device_conv1d_fwd_xdl_nwc_kxc_nwk_bf16_instances
(
std
::
vector
<
DeviceConvFwdNoOpPtr
>&
);
void
add_device_conv1d_fwd_xdl_nwc_kxc_nwk_f16_instances
(
std
::
vector
<
DeviceConvFwdNoOpPtr
>&
);
void
add_device_conv1d_fwd_xdl_nwc_kxc_nwk_f32_instances
(
std
::
vector
<
DeviceConvFwdNoOpPtr
>&
);
void
add_device_conv1d_fwd_xdl_nwc_kxc_nwk_int8_instances
(
std
::
vector
<
DeviceConvFwdNoOpPtr
>&
);
}
// namespace instance
namespace
instance
{
void
add_device_conv2d_fwd_xdl_nhwc_kyxc_nhwk_bf16_instances
(
std
::
vector
<
DeviceConvFwdNoOpPtr
>&
);
void
add_device_conv2d_fwd_xdl_nhwc_kyxc_nhwk_f16_instances
(
std
::
vector
<
DeviceConvFwdNoOpPtr
>&
);
void
add_device_conv2d_fwd_xdl_c_shuffle_nhwc_kyxc_nhwk_f16_instances
(
std
::
vector
<
DeviceConvFwdNoOpPtr
>&
);
void
add_device_conv2d_fwd_xdl_nhwc_kyxc_nhwk_f32_instances
(
std
::
vector
<
DeviceConvFwdNoOpPtr
>&
);
void
add_device_conv2d_fwd_xdl_nhwc_kyxc_nhwk_int8_instances
(
std
::
vector
<
DeviceConvFwdNoOpPtr
>&
);
}
// namespace instance
namespace
instance
{
void
add_device_conv3d_fwd_xdl_ndhwc_kzyxc_ndhwk_bf16_instances
(
std
::
vector
<
DeviceConvFwdNoOpPtr
>&
);
void
add_device_conv3d_fwd_xdl_ndhwc_kzyxc_ndhwk_f16_instances
(
std
::
vector
<
DeviceConvFwdNoOpPtr
>&
);
void
add_device_conv3d_fwd_xdl_ndhwc_kzyxc_ndhwk_f32_instances
(
std
::
vector
<
DeviceConvFwdNoOpPtr
>&
);
void
add_device_conv3d_fwd_xdl_ndhwc_kzyxc_ndhwk_int8_instances
(
std
::
vector
<
DeviceConvFwdNoOpPtr
>&
);
}
// namespace instance
}
// namespace device
}
// namespace tensor_operation
}
// namespace ck
namespace
ck
{
namespace
utils
{
namespace
conv
{
using
DeviceConvFwdNoOpPtr
=
ck
::
tensor_operation
::
device
::
DeviceConvFwdPtr
<
ck
::
tensor_operation
::
element_wise
::
PassThrough
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
>
;
/**
* @brief Calculate number of FLOPs for Convolution
*
* @param[in] N Batch size.
* @param[in] C Number of input channels.
* @param[in] K Number of output channels.
* @param[in] filter_spatial_lengths Filter spatial dimensions lengths.
* @param[in] output_spatial_lengths Convolution output spatial dimensions
* lengths.
*
* @return The number of flops.
*/
std
::
size_t
get_flops
(
ck
::
index_t
N
,
ck
::
index_t
C
,
ck
::
index_t
K
,
const
std
::
vector
<
ck
::
index_t
>&
filter_spatial_lengths
,
const
std
::
vector
<
ck
::
index_t
>&
output_spatial_lengths
);
/**
* @brief Calculate number of bytes read/write by convolution algorithm.
*
* @param[in] N Batch size.
* @param[in] C Number of input channels.
* @param[in] K Number of output channels.
* @param[in] input_spatial_lengths Input spatial dimensions lengths.
* @param[in] filter_spatial_lengths Filter spatial dimensions lengths.
* @param[in] output_spatial_lengths Output spatial dimensions lengths
*
* @tparam InDataType Input tensor data type.
* @tparam WeiDataType Weights tensor data type.
* @tparam OutDataType Output tensor data type.
*
* @return The number of used bytes.
*/
template
<
typename
InDataType
=
float
,
typename
WeiDataType
=
InDataType
,
typename
OutDataType
=
InDataType
>
std
::
size_t
get_btype
(
ck
::
index_t
N
,
ck
::
index_t
C
,
ck
::
index_t
K
,
const
std
::
vector
<
ck
::
index_t
>&
input_spatial_lengths
,
const
std
::
vector
<
ck
::
index_t
>&
filter_spatial_lengths
,
const
std
::
vector
<
ck
::
index_t
>&
output_spatial_lengths
)
{
// sizeof(InDataType) * (N * C * <input spatial lengths product>) +
// sizeof(WeiDataType) * (K * C * <filter spatial lengths product>) +
// sizeof(OutDataType) * (N * K * <output spatial lengths product>);
return
sizeof
(
InDataType
)
*
(
N
*
C
*
std
::
accumulate
(
std
::
begin
(
input_spatial_lengths
),
std
::
end
(
input_spatial_lengths
),
static_cast
<
std
::
size_t
>
(
1
),
std
::
multiplies
<
std
::
size_t
>
()))
+
sizeof
(
WeiDataType
)
*
(
K
*
C
*
std
::
accumulate
(
std
::
begin
(
filter_spatial_lengths
),
std
::
end
(
filter_spatial_lengths
),
static_cast
<
std
::
size_t
>
(
1
),
std
::
multiplies
<
std
::
size_t
>
()))
+
sizeof
(
OutDataType
)
*
(
N
*
K
*
std
::
accumulate
(
std
::
begin
(
output_spatial_lengths
),
std
::
end
(
output_spatial_lengths
),
static_cast
<
std
::
size_t
>
(
1
),
std
::
multiplies
<
std
::
size_t
>
()));
}
struct
ConvParams
{
ConvParams
();
ConvParams
(
ck
::
index_t
n_dim
,
ck
::
index_t
n_batch
,
ck
::
index_t
n_out_channels
,
ck
::
index_t
n_in_channels
,
const
std
::
vector
<
ck
::
index_t
>&
filters_len
,
const
std
::
vector
<
ck
::
index_t
>&
input_len
,
const
std
::
vector
<
ck
::
index_t
>&
strides
,
const
std
::
vector
<
ck
::
index_t
>&
dilations
,
const
std
::
vector
<
ck
::
index_t
>&
left_pads
,
const
std
::
vector
<
ck
::
index_t
>&
right_pads
);
ck
::
index_t
num_dim_spatial_
;
ck
::
index_t
N_
;
ck
::
index_t
K_
;
ck
::
index_t
C_
;
std
::
vector
<
ck
::
index_t
>
filter_spatial_lengths_
;
std
::
vector
<
ck
::
index_t
>
input_spatial_lengths_
;
std
::
vector
<
ck
::
index_t
>
conv_filter_strides_
;
std
::
vector
<
ck
::
index_t
>
conv_filter_dilations_
;
std
::
vector
<
ck
::
index_t
>
input_left_pads_
;
std
::
vector
<
ck
::
index_t
>
input_right_pads_
;
std
::
vector
<
ck
::
index_t
>
GetOutputSpatialLengths
()
const
;
};
ConvParams
parse_conv_params
(
int
num_dim_spatial
,
int
arg_idx
,
char
*
const
argv
[]);
/**
* @brief Gets the host tensor descriptor.
*
* @param[in] dims The tensor dimensions lengths. Always in NCHW format.
* @param[in] layout The tensor data layout.
*
* @tparam TensorLayout Layout type.
*
* @return The host tensor descriptor object.
*/
template
<
typename
TensorLayout
>
HostTensorDescriptor
get_host_tensor_descriptor
(
const
std
::
vector
<
std
::
size_t
>&
dims
,
const
TensorLayout
&
layout
)
{
std
::
size_t
C
=
dims
[
1
];
// 1D
if
constexpr
(
std
::
is_same
<
TensorLayout
,
ck
::
tensor_layout
::
convolution
::
NCW
>::
value
||
std
::
is_same
<
TensorLayout
,
ck
::
tensor_layout
::
convolution
::
KCX
>::
value
||
std
::
is_same
<
TensorLayout
,
ck
::
tensor_layout
::
convolution
::
NKW
>::
value
)
{
return
HostTensorDescriptor
(
dims
,
std
::
vector
<
std
::
size_t
>
{
C
*
dims
[
2
],
dims
[
2
],
1
});
}
else
if
constexpr
(
std
::
is_same
<
TensorLayout
,
ck
::
tensor_layout
::
convolution
::
NWC
>::
value
||
std
::
is_same
<
TensorLayout
,
ck
::
tensor_layout
::
convolution
::
KXC
>::
value
||
std
::
is_same
<
TensorLayout
,
ck
::
tensor_layout
::
convolution
::
NWK
>::
value
)
{
return
HostTensorDescriptor
(
dims
,
std
::
vector
<
std
::
size_t
>
{
C
*
dims
[
2
],
1
,
C
});
}
// 2D
else
if
constexpr
(
std
::
is_same
<
TensorLayout
,
ck
::
tensor_layout
::
convolution
::
NCHW
>::
value
||
std
::
is_same
<
TensorLayout
,
ck
::
tensor_layout
::
convolution
::
KCYX
>::
value
||
std
::
is_same
<
TensorLayout
,
ck
::
tensor_layout
::
convolution
::
NKHW
>::
value
)
{
return
HostTensorDescriptor
(
dims
,
std
::
vector
<
std
::
size_t
>
{
C
*
dims
[
2
]
*
dims
[
3
],
dims
[
2
]
*
dims
[
3
],
dims
[
3
],
1
});
}
else
if
constexpr
(
std
::
is_same
<
TensorLayout
,
ck
::
tensor_layout
::
convolution
::
NHWC
>::
value
||
std
::
is_same
<
TensorLayout
,
ck
::
tensor_layout
::
convolution
::
KYXC
>::
value
||
std
::
is_same
<
TensorLayout
,
ck
::
tensor_layout
::
convolution
::
NHWK
>::
value
)
{
return
HostTensorDescriptor
(
dims
,
std
::
vector
<
std
::
size_t
>
{
C
*
dims
[
2
]
*
dims
[
3
],
1
,
dims
[
3
]
*
C
,
C
});
}
// 3D
else
if
constexpr
(
std
::
is_same
<
TensorLayout
,
ck
::
tensor_layout
::
convolution
::
NCDHW
>::
value
||
std
::
is_same
<
TensorLayout
,
ck
::
tensor_layout
::
convolution
::
KCZYX
>::
value
||
std
::
is_same
<
TensorLayout
,
ck
::
tensor_layout
::
convolution
::
NKDHW
>::
value
)
{
return
HostTensorDescriptor
(
dims
,
std
::
vector
<
std
::
size_t
>
{
C
*
dims
[
2
]
*
dims
[
3
]
*
dims
[
4
],
dims
[
2
]
*
dims
[
3
]
*
dims
[
4
],
dims
[
3
]
*
dims
[
4
],
dims
[
4
],
1
});
}
else
if
constexpr
(
std
::
is_same
<
TensorLayout
,
ck
::
tensor_layout
::
convolution
::
NDHWC
>::
value
||
std
::
is_same
<
TensorLayout
,
ck
::
tensor_layout
::
convolution
::
KZYXC
>::
value
||
std
::
is_same
<
TensorLayout
,
ck
::
tensor_layout
::
convolution
::
NDHWK
>::
value
)
{
return
HostTensorDescriptor
(
dims
,
std
::
vector
<
std
::
size_t
>
{
C
*
dims
[
2
]
*
dims
[
3
]
*
dims
[
4
],
1
,
C
*
dims
[
3
]
*
dims
[
4
],
C
*
dims
[
4
],
C
});
}
std
::
stringstream
err_msg
;
err_msg
<<
"Unsupported data layout provided: "
<<
layout
<<
"!"
;
throw
std
::
runtime_error
(
err_msg
.
str
());
}
HostTensorDescriptor
get_output_host_tensor_descriptor
(
const
std
::
vector
<
std
::
size_t
>&
dims
,
int
num_dim_spatial
=
2
);
HostTensorDescriptor
get_filters_host_tensor_descriptor
(
const
std
::
vector
<
std
::
size_t
>&
dims
,
int
num_dim_spatial
=
2
);
HostTensorDescriptor
get_input_host_tensor_descriptor
(
const
std
::
vector
<
std
::
size_t
>&
dims
,
int
num_dim_spatial
=
2
);
template
<
ck
::
index_t
NDim
,
typename
InDataType
=
float
,
typename
WeiDataType
=
float
,
typename
OutDataType
=
float
>
void
run_reference_convolution_forward
(
const
ConvParams
&
params
,
const
Tensor
<
InDataType
>&
input
,
const
Tensor
<
WeiDataType
>&
weights
,
Tensor
<
OutDataType
>&
output
)
{
using
PassThrough
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
auto
ref_conv
=
ck
::
tensor_operation
::
host
::
ReferenceConvFwd
<
InDataType
,
WeiDataType
,
OutDataType
,
PassThrough
,
PassThrough
,
PassThrough
,
NDim
>
();
auto
ref_invoker
=
ref_conv
.
MakeInvoker
();
auto
ref_argument
=
ref_conv
.
MakeArgument
(
input
,
weights
,
output
,
params
.
conv_filter_strides_
,
params
.
conv_filter_dilations_
,
params
.
input_left_pads_
,
params
.
input_right_pads_
,
PassThrough
{},
PassThrough
{},
PassThrough
{});
ref_invoker
.
Run
(
ref_argument
);
}
template
<
typename
InDataType
,
typename
WeiDataType
,
typename
OutDataType
>
struct
ConvolutionFwdInstances
;
template
<
>
struct
ConvolutionFwdInstances
<
float
,
float
,
float
>
{
template
<
int
NumDimSpatial
,
typename
std
::
enable_if
<
NumDimSpatial
>
=
1
&&
NumDimSpatial
<=
3
,
bool
>::
type
=
false
>
static
std
::
vector
<
DeviceConvFwdNoOpPtr
>
Get
()
{
std
::
vector
<
DeviceConvFwdNoOpPtr
>
conv_ptrs
;
if
constexpr
(
NumDimSpatial
==
1
)
{
ck
::
tensor_operation
::
device
::
instance
::
add_device_conv1d_fwd_xdl_nwc_kxc_nwk_f32_instances
(
conv_ptrs
);
}
else
if
constexpr
(
NumDimSpatial
==
2
)
{
ck
::
tensor_operation
::
device
::
instance
::
add_device_conv2d_fwd_xdl_nhwc_kyxc_nhwk_f32_instances
(
conv_ptrs
);
}
else
if
constexpr
(
NumDimSpatial
==
3
)
{
ck
::
tensor_operation
::
device
::
instance
::
add_device_conv3d_fwd_xdl_ndhwc_kzyxc_ndhwk_f32_instances
(
conv_ptrs
);
}
return
conv_ptrs
;
}
};
template
<
>
struct
ConvolutionFwdInstances
<
half_t
,
half_t
,
half_t
>
{
template
<
int
NumDimSpatial
,
typename
std
::
enable_if
<
NumDimSpatial
>
=
1
&&
NumDimSpatial
<=
3
,
bool
>::
type
=
false
>
static
std
::
vector
<
DeviceConvFwdNoOpPtr
>
Get
()
{
std
::
vector
<
DeviceConvFwdNoOpPtr
>
conv_ptrs
;
if
constexpr
(
NumDimSpatial
==
1
)
{
ck
::
tensor_operation
::
device
::
instance
::
add_device_conv1d_fwd_xdl_nwc_kxc_nwk_f16_instances
(
conv_ptrs
);
return
conv_ptrs
;
}
else
if
constexpr
(
NumDimSpatial
==
2
)
{
ck
::
tensor_operation
::
device
::
instance
::
add_device_conv2d_fwd_xdl_nhwc_kyxc_nhwk_f16_instances
(
conv_ptrs
);
ck
::
tensor_operation
::
device
::
instance
::
add_device_conv2d_fwd_xdl_c_shuffle_nhwc_kyxc_nhwk_f16_instances
(
conv_ptrs
);
}
else
if
constexpr
(
NumDimSpatial
==
3
)
{
ck
::
tensor_operation
::
device
::
instance
::
add_device_conv3d_fwd_xdl_ndhwc_kzyxc_ndhwk_f16_instances
(
conv_ptrs
);
}
return
conv_ptrs
;
}
};
template
<
>
struct
ConvolutionFwdInstances
<
bhalf_t
,
bhalf_t
,
bhalf_t
>
{
template
<
int
NumDimSpatial
,
typename
std
::
enable_if
<
NumDimSpatial
>
=
1
&&
NumDimSpatial
<=
3
,
bool
>::
type
=
false
>
static
std
::
vector
<
DeviceConvFwdNoOpPtr
>
Get
()
{
std
::
vector
<
DeviceConvFwdNoOpPtr
>
conv_ptrs
;
if
constexpr
(
NumDimSpatial
==
1
)
{
ck
::
tensor_operation
::
device
::
instance
::
add_device_conv1d_fwd_xdl_nwc_kxc_nwk_bf16_instances
(
conv_ptrs
);
}
else
if
constexpr
(
NumDimSpatial
==
2
)
{
ck
::
tensor_operation
::
device
::
instance
::
add_device_conv2d_fwd_xdl_nhwc_kyxc_nhwk_bf16_instances
(
conv_ptrs
);
}
else
if
constexpr
(
NumDimSpatial
==
3
)
{
ck
::
tensor_operation
::
device
::
instance
::
add_device_conv3d_fwd_xdl_ndhwc_kzyxc_ndhwk_bf16_instances
(
conv_ptrs
);
}
return
conv_ptrs
;
}
};
template
<
>
struct
ConvolutionFwdInstances
<
int8_t
,
int8_t
,
int8_t
>
{
template
<
int
NumDimSpatial
,
typename
std
::
enable_if
<
NumDimSpatial
>
=
1
&&
NumDimSpatial
<=
3
,
bool
>::
type
=
false
>
static
std
::
vector
<
DeviceConvFwdNoOpPtr
>
Get
()
{
std
::
vector
<
DeviceConvFwdNoOpPtr
>
conv_ptrs
;
if
constexpr
(
NumDimSpatial
==
1
)
{
ck
::
tensor_operation
::
device
::
instance
::
add_device_conv1d_fwd_xdl_nwc_kxc_nwk_int8_instances
(
conv_ptrs
);
}
else
if
constexpr
(
NumDimSpatial
==
2
)
{
ck
::
tensor_operation
::
device
::
instance
::
add_device_conv2d_fwd_xdl_nhwc_kyxc_nhwk_int8_instances
(
conv_ptrs
);
}
else
if
constexpr
(
NumDimSpatial
==
3
)
{
ck
::
tensor_operation
::
device
::
instance
::
add_device_conv3d_fwd_xdl_ndhwc_kzyxc_ndhwk_int8_instances
(
conv_ptrs
);
}
return
conv_ptrs
;
}
};
template
<
typename
InDataType
,
typename
WeiDataType
,
typename
OutDataType
,
typename
InLayout
=
ck
::
tensor_layout
::
convolution
::
NHWC
,
typename
WeiLayout
=
ck
::
tensor_layout
::
convolution
::
KYXC
,
typename
OutLayout
=
ck
::
tensor_layout
::
convolution
::
NHWK
,
typename
InElementwiseOp
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
,
typename
WeiElementwiseOp
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
,
typename
OutElementwiseOp
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
,
typename
InputInitFun
=
FillUniformDistribution
<
InDataType
>,
typename
WeightsInitFun
=
FillUniformDistribution
<
WeiDataType
>>
class
ConvFwdOpInstance
:
public
ck
::
utils
::
OpInstance
<
OutDataType
,
InDataType
,
WeiDataType
>
{
using
DeviceConvFwdOp
=
tensor_operation
::
device
::
DeviceConvFwd
<
InElementwiseOp
,
WeiElementwiseOp
,
OutElementwiseOp
>
;
using
DeviceMemPtr
=
std
::
unique_ptr
<
DeviceMem
>
;
using
DeviceBuffers
=
std
::
vector
<
DeviceMemPtr
>
;
using
BaseType
=
ck
::
utils
::
OpInstance
<
OutDataType
,
InDataType
,
WeiDataType
>
;
template
<
typename
T
>
using
TensorPtr
=
std
::
unique_ptr
<
Tensor
<
T
>>
;
using
InTensorsTuple
=
std
::
tuple
<
TensorPtr
<
InDataType
>
,
TensorPtr
<
WeiDataType
>>
;
public:
ConvFwdOpInstance
()
=
delete
;
ConvFwdOpInstance
(
const
ConvFwdOpInstance
&
)
=
default
;
ConvFwdOpInstance
&
operator
=
(
const
ConvFwdOpInstance
&
)
=
default
;
ConvFwdOpInstance
(
const
ConvParams
&
params
,
bool
do_init
=
true
,
const
InputInitFun
&
input_init_f
=
InputInitFun
(),
const
WeightsInitFun
&
weights_init_f
=
WeightsInitFun
())
:
BaseType
(),
params_
{
params
},
output_spatial_lengths_
{
params
.
GetOutputSpatialLengths
()},
do_init_
{
do_init
},
input_init_f_
{
input_init_f
},
weights_init_f_
{
weights_init_f
}
{
}
virtual
~
ConvFwdOpInstance
()
override
{};
virtual
InTensorsTuple
GetInputTensors
()
const
override
{
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_
));
auto
input
=
std
::
make_unique
<
Tensor
<
InDataType
>>
(
get_host_tensor_descriptor
(
input_dims
,
InLayout
{}));
auto
weights
=
std
::
make_unique
<
Tensor
<
WeiDataType
>>
(
get_host_tensor_descriptor
(
filter_dims
,
WeiLayout
{}));
if
(
do_init_
)
{
input_init_f_
(
input
->
begin
(),
input
->
end
());
weights_init_f_
(
weights
->
begin
(),
weights
->
end
());
}
return
std
::
make_tuple
(
std
::
move
(
input
),
std
::
move
(
weights
));
}
virtual
TensorPtr
<
OutDataType
>
GetOutputTensor
()
const
override
{
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_
));
auto
output
=
std
::
make_unique
<
Tensor
<
OutDataType
>>
(
get_host_tensor_descriptor
(
output_dims
,
OutLayout
{}));
if
(
do_init_
)
{
std
::
fill
(
output
->
begin
(),
output
->
end
(),
OutDataType
(
0.
f
));
}
return
output
;
}
virtual
std
::
unique_ptr
<
tensor_operation
::
device
::
BaseInvoker
>
MakeInvokerPointer
(
tensor_operation
::
device
::
BaseOperator
*
op_ptr
)
const
override
{
static_assert
(
std
::
is_same_v
<
InElementwiseOp
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
>
);
static_assert
(
std
::
is_same_v
<
OutElementwiseOp
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
>
);
static_assert
(
std
::
is_same_v
<
WeiElementwiseOp
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
>
);
auto
conv_ptr
=
dynamic_cast
<
DeviceConvFwdOp
*>
(
op_ptr
);
if
(
!
conv_ptr
)
{
throw
std
::
runtime_error
(
"[ConvFwdOpInstance]: couldn't cast op_ptr to DeviceConvFwdNoOpPtr type!"
);
}
return
conv_ptr
->
MakeInvokerPointer
();
}
virtual
std
::
unique_ptr
<
tensor_operation
::
device
::
BaseArgument
>
MakeArgumentPointer
(
tensor_operation
::
device
::
BaseOperator
*
op_ptr
,
const
DeviceBuffers
&
in_device_buffers
,
const
DeviceMemPtr
&
out_device_buffer
)
const
override
{
static_assert
(
std
::
is_same_v
<
InElementwiseOp
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
>
);
static_assert
(
std
::
is_same_v
<
OutElementwiseOp
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
>
);
static_assert
(
std
::
is_same_v
<
WeiElementwiseOp
,
ck
::
tensor_operation
::
element_wise
::
PassThrough
>
);
auto
conv_ptr
=
dynamic_cast
<
DeviceConvFwdOp
*>
(
op_ptr
);
if
(
!
conv_ptr
)
{
throw
std
::
runtime_error
(
"[ConvFwdOpInstance]: couldn't cast op_ptr to DeviceConvFwdNoOpPtr type!"
);
}
return
conv_ptr
->
MakeArgumentPointer
(
static_cast
<
InDataType
*>
(
in_device_buffers
[
0
]
->
GetDeviceBuffer
()),
static_cast
<
WeiDataType
*>
(
in_device_buffers
[
1
]
->
GetDeviceBuffer
()),
static_cast
<
OutDataType
*>
(
out_device_buffer
->
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_
,
InElementwiseOp
{},
WeiElementwiseOp
{},
OutElementwiseOp
{});
}
virtual
std
::
size_t
GetFlops
()
const
override
{
return
get_flops
(
params_
.
N_
,
params_
.
C_
,
params_
.
K_
,
params_
.
filter_spatial_lengths_
,
output_spatial_lengths_
);
}
virtual
std
::
size_t
GetBtype
()
const
override
{
return
get_btype
<
InDataType
,
WeiDataType
,
OutDataType
>
(
params_
.
N_
,
params_
.
C_
,
params_
.
K_
,
params_
.
input_spatial_lengths_
,
params_
.
filter_spatial_lengths_
,
output_spatial_lengths_
);
}
private:
const
ConvParams
&
params_
;
const
std
::
vector
<
ck
::
index_t
>
output_spatial_lengths_
;
const
bool
do_init_
;
InputInitFun
input_init_f_
;
WeightsInitFun
weights_init_f_
;
};
}
// namespace conv
}
// namespace utils
}
// namespace ck
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
ck
::
utils
::
conv
::
ConvParams
&
p
);
library/include/ck/library/utility/convolution_parameter.hpp
0 → 100644
View file @
92a0945d
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#pragma once
#include <cstdlib>
#include <numeric>
#include <iterator>
#include <vector>
#include "ck/ck.hpp"
#include "ck/library/utility/io.hpp"
namespace
ck
{
namespace
tensor_operation
{
namespace
device
{
struct
ConvParams
{
ConvParams
();
ConvParams
(
ck
::
index_t
n_dim
,
ck
::
index_t
n_batch
,
ck
::
index_t
n_out_channels
,
ck
::
index_t
n_in_channels
,
const
std
::
vector
<
ck
::
index_t
>&
filters_len
,
const
std
::
vector
<
ck
::
index_t
>&
input_len
,
const
std
::
vector
<
ck
::
index_t
>&
strides
,
const
std
::
vector
<
ck
::
index_t
>&
dilations
,
const
std
::
vector
<
ck
::
index_t
>&
left_pads
,
const
std
::
vector
<
ck
::
index_t
>&
right_pads
);
ck
::
index_t
num_dim_spatial_
;
ck
::
index_t
N_
;
ck
::
index_t
K_
;
ck
::
index_t
C_
;
std
::
vector
<
ck
::
index_t
>
filter_spatial_lengths_
;
std
::
vector
<
ck
::
index_t
>
input_spatial_lengths_
;
std
::
vector
<
ck
::
index_t
>
output_spatial_lengths_
;
std
::
vector
<
ck
::
index_t
>
conv_filter_strides_
;
std
::
vector
<
ck
::
index_t
>
conv_filter_dilations_
;
std
::
vector
<
ck
::
index_t
>
input_left_pads_
;
std
::
vector
<
ck
::
index_t
>
input_right_pads_
;
std
::
vector
<
ck
::
index_t
>
GetOutputSpatialLengths
()
const
;
std
::
size_t
GetFlops
()
const
;
template
<
typename
InDataType
,
typename
WeiDataType
,
typename
OutDataType
>
std
::
size_t
GetByte
()
const
{
// sizeof(InDataType) * (N * C * <input spatial lengths product>) +
// sizeof(WeiDataType) * (K * C * <filter spatial lengths product>) +
// sizeof(OutDataType) * (N * K * <output spatial lengths product>);
return
sizeof
(
InDataType
)
*
(
N_
*
C_
*
std
::
accumulate
(
std
::
begin
(
input_spatial_lengths_
),
std
::
end
(
input_spatial_lengths_
),
static_cast
<
std
::
size_t
>
(
1
),
std
::
multiplies
<
std
::
size_t
>
()))
+
sizeof
(
WeiDataType
)
*
(
K_
*
C_
*
std
::
accumulate
(
std
::
begin
(
filter_spatial_lengths_
),
std
::
end
(
filter_spatial_lengths_
),
static_cast
<
std
::
size_t
>
(
1
),
std
::
multiplies
<
std
::
size_t
>
()))
+
sizeof
(
OutDataType
)
*
(
N_
*
K_
*
std
::
accumulate
(
std
::
begin
(
output_spatial_lengths_
),
std
::
end
(
output_spatial_lengths_
),
static_cast
<
std
::
size_t
>
(
1
),
std
::
multiplies
<
std
::
size_t
>
()));
}
};
}
// namespace device
}
// namespace tensor_operation
}
// namespace ck
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
ck
::
tensor_operation
::
device
::
ConvParams
&
p
);
library/include/ck/library/
host_tensor
/device_memory.hpp
→
library/include/ck/library/
utility
/device_memory.hpp
View file @
92a0945d
File moved
library/include/ck/library/
host_tensor
/host_common_util.hpp
→
library/include/ck/library/
utility
/host_common_util.hpp
View file @
92a0945d
File moved
library/include/ck/library/
host_tensor
/host_conv.hpp
→
library/include/ck/library/
utility
/host_conv.hpp
View file @
92a0945d
File moved
library/include/ck/library/
host_tensor
/host_gemm.hpp
→
library/include/ck/library/
utility
/host_gemm.hpp
View file @
92a0945d
File moved
library/include/ck/library/
host_tensor
/host_reduction.hpp
→
library/include/ck/library/
utility
/host_reduction.hpp
View file @
92a0945d
File moved
library/include/ck/library/
host_tensor
/host_tensor.hpp
→
library/include/ck/library/
utility
/host_tensor.hpp
View file @
92a0945d
...
@@ -122,6 +122,22 @@ struct HostTensorDescriptor
...
@@ -122,6 +122,22 @@ struct HostTensorDescriptor
std
::
vector
<
std
::
size_t
>
mStrides
;
std
::
vector
<
std
::
size_t
>
mStrides
;
};
};
template
<
typename
New2Old
>
HostTensorDescriptor
transpose_host_tensor_descriptor_given_new2old
(
const
HostTensorDescriptor
&
a
,
const
New2Old
&
new2old
)
{
std
::
vector
<
std
::
size_t
>
new_lengths
(
a
.
GetNumOfDimension
());
std
::
vector
<
std
::
size_t
>
new_strides
(
a
.
GetNumOfDimension
());
for
(
std
::
size_t
i
=
0
;
i
<
a
.
GetNumOfDimension
();
i
++
)
{
new_lengths
[
i
]
=
a
.
GetLengths
()[
new2old
[
i
]];
new_strides
[
i
]
=
a
.
GetStrides
()[
new2old
[
i
]];
}
return
HostTensorDescriptor
(
new_lengths
,
new_strides
);
}
struct
joinable_thread
:
std
::
thread
struct
joinable_thread
:
std
::
thread
{
{
template
<
typename
...
Xs
>
template
<
typename
...
Xs
>
...
...
Prev
1
2
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