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
0be1cf14
Commit
0be1cf14
authored
Jul 17, 2022
by
Chao Liu
Browse files
update conv bwd weight
parent
b054669b
Changes
30
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
1520 additions
and
1637 deletions
+1520
-1637
example/09_convnd_fwd/convnd_fwd_common.hpp
example/09_convnd_fwd/convnd_fwd_common.hpp
+67
-56
example/09_convnd_fwd/convnd_fwd_xdl_bf16.cpp
example/09_convnd_fwd/convnd_fwd_xdl_bf16.cpp
+54
-44
example/09_convnd_fwd/convnd_fwd_xdl_fp16.cpp
example/09_convnd_fwd/convnd_fwd_xdl_fp16.cpp
+30
-25
example/09_convnd_fwd/convnd_fwd_xdl_fp32.cpp
example/09_convnd_fwd/convnd_fwd_xdl_fp32.cpp
+54
-44
example/09_convnd_fwd/convnd_fwd_xdl_fp64.cpp
example/09_convnd_fwd/convnd_fwd_xdl_fp64.cpp
+54
-44
example/09_convnd_fwd/convnd_fwd_xdl_int8.cpp
example/09_convnd_fwd/convnd_fwd_xdl_int8.cpp
+35
-41
example/10_conv2d_bwd_data/CMakeLists.txt
example/10_conv2d_bwd_data/CMakeLists.txt
+1
-1
example/10_conv2d_bwd_data/conv2d_bwd_data_xdl.cpp
example/10_conv2d_bwd_data/conv2d_bwd_data_xdl.cpp
+150
-108
example/11_conv2d_bwd_weight/CMakeLists.txt
example/11_conv2d_bwd_weight/CMakeLists.txt
+1
-1
example/11_conv2d_bwd_weight/conv2d_bwd_weight_xdl.cpp
example/11_conv2d_bwd_weight/conv2d_bwd_weight_xdl.cpp
+159
-149
example/17_convnd_bwd_data_xdl/CMakeLists.txt
example/17_convnd_bwd_data_xdl/CMakeLists.txt
+1
-1
example/17_convnd_bwd_data_xdl/convnd_bwd_data_common.hpp
example/17_convnd_bwd_data_xdl/convnd_bwd_data_common.hpp
+230
-0
example/17_convnd_bwd_data_xdl/convnd_bwd_data_xdl.cpp
example/17_convnd_bwd_data_xdl/convnd_bwd_data_xdl.cpp
+104
-304
example/20_convnd_bwd_weight_xdl/CMakeLists.txt
example/20_convnd_bwd_weight_xdl/CMakeLists.txt
+5
-4
example/20_convnd_bwd_weight_xdl/convnd_bwd_weight_common.hpp
...ple/20_convnd_bwd_weight_xdl/convnd_bwd_weight_common.hpp
+235
-0
example/20_convnd_bwd_weight_xdl/convnd_bwd_weight_xdl.cpp
example/20_convnd_bwd_weight_xdl/convnd_bwd_weight_xdl.cpp
+0
-385
example/20_convnd_bwd_weight_xdl/convnd_bwd_weight_xdl_bf16.cpp
...e/20_convnd_bwd_weight_xdl/convnd_bwd_weight_xdl_bf16.cpp
+164
-0
example/20_convnd_bwd_weight_xdl/convnd_bwd_weight_xdl_bf16_splitk.cpp
...nvnd_bwd_weight_xdl/convnd_bwd_weight_xdl_bf16_splitk.cpp
+0
-427
example/20_convnd_bwd_weight_xdl/convnd_bwd_weight_xdl_fp16.cpp
...e/20_convnd_bwd_weight_xdl/convnd_bwd_weight_xdl_fp16.cpp
+163
-0
include/ck/tensor_operation/gpu/device/convolution_backward_data_specialization.hpp
...n/gpu/device/convolution_backward_data_specialization.hpp
+13
-3
No files found.
example/09_convnd_fwd/convnd_fwd_common.hpp
View file @
0be1cf14
...
@@ -8,7 +8,6 @@
...
@@ -8,7 +8,6 @@
#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_nwc_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"
...
@@ -18,7 +17,24 @@
...
@@ -18,7 +17,24 @@
#include "ck/library/utility/convolution_parameter.hpp"
#include "ck/library/utility/convolution_parameter.hpp"
#include "ck/library/reference_tensor_operation/cpu/reference_conv_fwd.hpp"
#include "ck/library/reference_tensor_operation/cpu/reference_conv_fwd.hpp"
void
print_helper_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=no, 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
"
<<
" <in_n_hi_wi_c 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
::
tensor_operation
::
device
::
ConvParams
ck
::
tensor_operation
::
device
::
ConvParams
parse_conv_params
(
int
num_dim_spatial
,
int
arg_idx
,
char
*
const
argv
[])
parse_conv_params
(
int
num_dim_spatial
,
int
arg_idx
,
char
*
const
argv
[])
{
{
const
ck
::
index_t
N
=
std
::
stoi
(
argv
[
arg_idx
++
]);
const
ck
::
index_t
N
=
std
::
stoi
(
argv
[
arg_idx
++
]);
...
@@ -74,23 +90,6 @@ parse_conv_params(int num_dim_spatial, int arg_idx, char* const argv[])
...
@@ -74,23 +90,6 @@ parse_conv_params(int num_dim_spatial, int arg_idx, char* const argv[])
input_right_pads
};
input_right_pads
};
}
}
void
print_helper_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=no, 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
;
}
template
<
ck
::
index_t
NDimSpatial
,
template
<
ck
::
index_t
NDimSpatial
,
typename
InDataType
,
typename
InDataType
,
typename
WeiDataType
,
typename
WeiDataType
,
...
@@ -99,12 +98,14 @@ template <ck::index_t NDimSpatial,
...
@@ -99,12 +98,14 @@ template <ck::index_t NDimSpatial,
typename
InElementOp
,
typename
InElementOp
,
typename
WeiElementOp
,
typename
WeiElementOp
,
typename
OutElementOp
,
typename
OutElementOp
,
typename
DeviceConvNDFwdInstance
,
typename
DeviceConvNDFwdInstance
>
typename
ReferenceConvNDFwdInstance
>
int
run_conv_fwd_nhwc
(
bool
do_verification
,
int
run_conv_fwd_nhwc
(
const
ck
::
tensor_operation
::
device
::
ConvParams
&
params
,
bool
do_verification
,
int
init_method
,
int
init_method
,
bool
time_kernel
)
bool
time_kernel
,
const
ck
::
tensor_operation
::
device
::
ConvParams
&
params
,
const
InElementOp
&
in_element_op
,
const
WeiElementOp
&
wei_element_op
,
const
OutElementOp
&
out_element_op
)
{
{
auto
f_nhwc_host_tensor_descriptor
=
auto
f_nhwc_host_tensor_descriptor
=
[](
ck
::
index_t
n
,
ck
::
index_t
c
,
std
::
vector
<
ck
::
index_t
>
spatial_lengths
)
{
[](
ck
::
index_t
n
,
ck
::
index_t
c
,
std
::
vector
<
ck
::
index_t
>
spatial_lengths
)
{
...
@@ -116,37 +117,37 @@ int run_conv_fwd_nhwc(const ck::tensor_operation::device::ConvParams& params,
...
@@ -116,37 +117,37 @@ int run_conv_fwd_nhwc(const ck::tensor_operation::device::ConvParams& params,
return
HostTensorDescriptor
(
nhwc_lengths
);
return
HostTensorDescriptor
(
nhwc_lengths
);
};
};
Tensor
<
InDataType
>
in
put
(
Tensor
<
InDataType
>
in
_n_hi_wi_c
(
f_nhwc_host_tensor_descriptor
(
params
.
N_
,
params
.
C_
,
params
.
input_spatial_lengths_
));
f_nhwc_host_tensor_descriptor
(
params
.
N_
,
params
.
C_
,
params
.
input_spatial_lengths_
));
Tensor
<
WeiDataType
>
wei
ght
(
Tensor
<
WeiDataType
>
wei
_k_y_x_c
(
f_nhwc_host_tensor_descriptor
(
params
.
K_
,
params
.
C_
,
params
.
filter_spatial_lengths_
));
f_nhwc_host_tensor_descriptor
(
params
.
K_
,
params
.
C_
,
params
.
filter_spatial_lengths_
));
Tensor
<
OutDataType
>
host_outpu
t
(
Tensor
<
OutDataType
>
out_n_ho_wo_k_hos
t
(
f_nhwc_host_tensor_descriptor
(
params
.
N_
,
params
.
K_
,
params
.
GetOutputSpatialLengths
()));
f_nhwc_host_tensor_descriptor
(
params
.
N_
,
params
.
K_
,
params
.
GetOutputSpatialLengths
()));
Tensor
<
OutDataType
>
device_output
(
Tensor
<
OutDataType
>
out_n_ho_wo_k_device
(
f_nhwc_host_tensor_descriptor
(
params
.
N_
,
params
.
K_
,
params
.
GetOutputSpatialLengths
()));
f_nhwc_host_tensor_descriptor
(
params
.
N_
,
params
.
K_
,
params
.
GetOutputSpatialLengths
()));
std
::
cout
<<
"in
put: "
<<
input
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"in
_n_hi_wi_c: "
<<
in_n_hi_wi_c
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"wei
ght
: "
<<
wei
ght
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"wei
_k_y_x_c
: "
<<
wei
_k_y_x_c
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"output: "
<<
host_outpu
t
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"output: "
<<
out_n_ho_wo_k_hos
t
.
mDesc
<<
std
::
endl
;
switch
(
init_method
)
switch
(
init_method
)
{
{
case
0
:
break
;
case
0
:
break
;
case
1
:
case
1
:
in
put
.
GenerateTensorValue
(
GeneratorTensor_2
<
InDataType
>
{
-
5
,
5
});
in
_n_hi_wi_c
.
GenerateTensorValue
(
GeneratorTensor_2
<
InDataType
>
{
-
5
,
5
});
wei
ght
.
GenerateTensorValue
(
GeneratorTensor_2
<
WeiDataType
>
{
-
5
,
5
});
wei
_k_y_x_c
.
GenerateTensorValue
(
GeneratorTensor_2
<
WeiDataType
>
{
-
5
,
5
});
break
;
break
;
default:
default:
in
put
.
GenerateTensorValue
(
GeneratorTensor_3
<
InDataType
>
{
0.0
,
1.0
});
in
_n_hi_wi_c
.
GenerateTensorValue
(
GeneratorTensor_3
<
InDataType
>
{
0.0
,
1.0
});
wei
ght
.
GenerateTensorValue
(
GeneratorTensor_3
<
WeiDataType
>
{
-
0.5
,
0.5
});
wei
_k_y_x_c
.
GenerateTensorValue
(
GeneratorTensor_3
<
WeiDataType
>
{
-
0.5
,
0.5
});
}
}
DeviceMem
in_device_buf
(
sizeof
(
InDataType
)
*
in
put
.
mDesc
.
GetElementSpace
());
DeviceMem
in_device_buf
(
sizeof
(
InDataType
)
*
in
_n_hi_wi_c
.
mDesc
.
GetElementSpace
());
DeviceMem
wei_device_buf
(
sizeof
(
WeiDataType
)
*
wei
ght
.
mDesc
.
GetElementSpace
());
DeviceMem
wei_device_buf
(
sizeof
(
WeiDataType
)
*
wei
_k_y_x_c
.
mDesc
.
GetElementSpace
());
DeviceMem
out_device_buf
(
sizeof
(
OutDataType
)
*
device_output
.
mDesc
.
GetElementSpace
());
DeviceMem
out_device_buf
(
sizeof
(
OutDataType
)
*
out_n_ho_wo_k_device
.
mDesc
.
GetElementSpace
());
in_device_buf
.
ToDevice
(
in
put
.
mData
.
data
());
in_device_buf
.
ToDevice
(
in
_n_hi_wi_c
.
mData
.
data
());
wei_device_buf
.
ToDevice
(
wei
ght
.
mData
.
data
());
wei_device_buf
.
ToDevice
(
wei
_k_y_x_c
.
mData
.
data
());
// do GEMM
// do GEMM
auto
conv
=
DeviceConvNDFwdInstance
{};
auto
conv
=
DeviceConvNDFwdInstance
{};
...
@@ -164,9 +165,9 @@ int run_conv_fwd_nhwc(const ck::tensor_operation::device::ConvParams& params,
...
@@ -164,9 +165,9 @@ int run_conv_fwd_nhwc(const ck::tensor_operation::device::ConvParams& params,
params
.
conv_filter_dilations_
,
params
.
conv_filter_dilations_
,
params
.
input_left_pads_
,
params
.
input_left_pads_
,
params
.
input_right_pads_
,
params
.
input_right_pads_
,
InE
lement
Op
{}
,
in_e
lement
_op
,
W
ei
E
lement
Op
{}
,
w
ei
_e
lement
_op
,
O
ut
E
lement
Op
{}
);
o
ut
_e
lement
_op
);
if
(
!
conv
.
IsSupportedArgument
(
argument
))
if
(
!
conv
.
IsSupportedArgument
(
argument
))
{
{
...
@@ -175,38 +176,48 @@ int run_conv_fwd_nhwc(const ck::tensor_operation::device::ConvParams& params,
...
@@ -175,38 +176,48 @@ int run_conv_fwd_nhwc(const ck::tensor_operation::device::ConvParams& params,
"not support this Conv problem"
);
"not support this Conv problem"
);
}
}
float
av
e
_time
=
invoker
.
Run
(
argument
,
StreamConfig
{
nullptr
,
time_kernel
});
float
av
g
_time
=
invoker
.
Run
(
argument
,
StreamConfig
{
nullptr
,
time_kernel
});
std
::
size_t
flop
=
params
.
GetFlops
();
std
::
size_t
flop
=
params
.
GetFlops
();
std
::
size_t
num_btype
=
params
.
GetByte
<
InDataType
,
WeiDataType
,
OutDataType
>
();
std
::
size_t
num_btype
=
params
.
GetByte
<
InDataType
,
WeiDataType
,
OutDataType
>
();
float
tflops
=
static_cast
<
float
>
(
flop
)
/
1.E9
/
av
e
_time
;
float
tflops
=
static_cast
<
float
>
(
flop
)
/
1.E9
/
av
g
_time
;
float
gb_per_sec
=
num_btype
/
1.E6
/
av
e
_time
;
float
gb_per_sec
=
num_btype
/
1.E6
/
av
g
_time
;
std
::
cout
<<
"Perf: "
<<
av
e
_time
<<
" ms, "
<<
tflops
<<
" TFlops, "
<<
gb_per_sec
<<
" GB/s, "
std
::
cout
<<
"Perf: "
<<
av
g
_time
<<
" ms, "
<<
tflops
<<
" TFlops, "
<<
gb_per_sec
<<
" GB/s, "
<<
conv
.
GetTypeString
()
<<
std
::
endl
;
<<
conv
.
GetTypeString
()
<<
std
::
endl
;
if
(
do_verification
)
if
(
do_verification
)
{
{
auto
ref_conv
=
ReferenceConvNDFwdInstance
();
auto
ref_conv
=
ck
::
tensor_operation
::
host
::
ReferenceConvFwd
<
NDimSpatial
,
ck
::
tensor_layout
::
convolution
::
NHWC
,
ck
::
tensor_layout
::
convolution
::
KYXC
,
ck
::
tensor_layout
::
convolution
::
NHWK
,
InDataType
,
WeiDataType
,
OutDataType
,
InElementOp
,
WeiElementOp
,
OutElementOp
>
();
auto
ref_invoker
=
ref_conv
.
MakeInvoker
();
auto
ref_invoker
=
ref_conv
.
MakeInvoker
();
auto
ref_argument
=
ref_conv
.
MakeArgument
(
in
put
,
auto
ref_argument
=
ref_conv
.
MakeArgument
(
in
_n_hi_wi_c
,
wei
ght
,
wei
_k_y_x_c
,
host_outpu
t
,
out_n_ho_wo_k_hos
t
,
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_
,
InE
lement
Op
{}
,
in_e
lement
_op
,
W
ei
E
lement
Op
{}
,
w
ei
_e
lement
_op
,
O
ut
E
lement
Op
{}
);
o
ut
_e
lement
_op
);
ref_invoker
.
Run
(
ref_argument
);
ref_invoker
.
Run
(
ref_argument
);
out_device_buf
.
FromDevice
(
device_output
.
mData
.
data
());
out_device_buf
.
FromDevice
(
out_n_ho_wo_k_device
.
mData
.
data
());
return
ck
::
utils
::
check_err
(
host_outpu
t
.
mData
,
return
ck
::
utils
::
check_err
(
out_n_ho_wo_k_hos
t
.
mData
,
device_output
.
mData
,
out_n_ho_wo_k_device
.
mData
,
"Error: incorrect results!"
,
"Error: incorrect results!"
,
1e-5
f
,
1e-5
f
,
1e-4
f
)
1e-4
f
)
...
...
example/09_convnd_fwd/convnd_fwd_xdl_bf16.cpp
View file @
0be1cf14
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
#include "convnd_fwd_common.hpp"
#include "convnd_fwd_common.hpp"
#include "ck/tensor_operation/gpu/device/device_convnd_fwd_nwc_kxc_nwk_xdl.hpp"
using
InDataType
=
ck
::
bhalf_t
;
using
InDataType
=
ck
::
bhalf_t
;
using
WeiDataType
=
ck
::
bhalf_t
;
using
WeiDataType
=
ck
::
bhalf_t
;
using
OutDataType
=
ck
::
bhalf_t
;
using
OutDataType
=
ck
::
bhalf_t
;
...
@@ -55,15 +57,6 @@ using DeviceConvNDFwdInstance = ck::tensor_operation::device::DeviceConvNdFwdNwc
...
@@ -55,15 +57,6 @@ using DeviceConvNDFwdInstance = ck::tensor_operation::device::DeviceConvNdFwdNwc
7
,
// CThreadTransferSrcDstVectorDim
7
,
// CThreadTransferSrcDstVectorDim
1
>
;
// CThreadTransferDstScalarPerVector
1
>
;
// CThreadTransferDstScalarPerVector
template
<
ck
::
index_t
NumDimSpatial
>
using
ReferenceConvNDFwdInstance
=
ck
::
tensor_operation
::
host
::
ReferenceConvFwd
<
InDataType
,
WeiDataType
,
OutDataType
,
InElementOp
,
WeiElementOp
,
OutElementOp
,
NumDimSpatial
>
;
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
print_helper_msg
();
print_helper_msg
();
...
@@ -73,7 +66,8 @@ int main(int argc, char* argv[])
...
@@ -73,7 +66,8 @@ int main(int argc, char* argv[])
bool
time_kernel
=
false
;
bool
time_kernel
=
false
;
int
num_dim_spatial
=
2
;
int
num_dim_spatial
=
2
;
ck
::
tensor_operation
::
device
::
ConvParams
params
;
ck
::
tensor_operation
::
device
::
ConvParams
params
{
2
,
128
,
256
,
192
,
{
3
,
3
},
{
71
,
71
},
{
2
,
2
},
{
1
,
1
},
{
1
,
1
},
{
1
,
1
}};
if
(
argc
==
1
)
if
(
argc
==
1
)
{
{
...
@@ -92,50 +86,66 @@ int main(int argc, char* argv[])
...
@@ -92,50 +86,66 @@ int main(int argc, char* argv[])
time_kernel
=
std
::
stoi
(
argv
[
3
]);
time_kernel
=
std
::
stoi
(
argv
[
3
]);
num_dim_spatial
=
std
::
stoi
(
argv
[
4
]);
num_dim_spatial
=
std
::
stoi
(
argv
[
4
]);
params
=
parse_conv_params
(
num_dim_spatial
,
argc
,
argv
);
params
=
parse_conv_params
(
num_dim_spatial
,
5
,
argv
);
}
}
const
auto
in_element_op
=
InElementOp
{};
const
auto
wei_element_op
=
WeiElementOp
{};
const
auto
out_element_op
=
OutElementOp
{};
if
(
num_dim_spatial
==
1
)
if
(
num_dim_spatial
==
1
)
{
{
return
run_conv_fwd
<
1
,
return
run_conv_fwd_nhwc
<
1
,
InDataType
,
InDataType
,
WeiDataType
,
WeiDataType
,
OutDataType
,
OutDataType
,
AccDataType
,
AccDataType
,
InElementOp
,
InElementOp
,
WeiElementOp
,
WeiElementOp
,
OutElementOp
,
OutElementOp
,
DeviceConvNDFwdInstance
<
1
>
,
DeviceConvNDFwdInstance
<
1
>>
(
do_verification
,
ReferenceConvNDFwdInstance
<
1
>>
(
init_method
,
params
,
do_verification
,
init_method
,
time_kernel
);
time_kernel
,
params
,
in_element_op
,
wei_element_op
,
out_element_op
);
}
}
else
if
(
num_dim_spatial
==
2
)
else
if
(
num_dim_spatial
==
2
)
{
{
return
run_conv_fwd
<
2
,
return
run_conv_fwd_nhwc
<
2
,
InDataType
,
InDataType
,
WeiDataType
,
WeiDataType
,
OutDataType
,
OutDataType
,
AccDataType
,
AccDataType
,
InElementOp
,
InElementOp
,
WeiElementOp
,
WeiElementOp
,
OutElementOp
,
OutElementOp
,
DeviceConvNDFwdInstance
<
2
>
,
DeviceConvNDFwdInstance
<
2
>>
(
do_verification
,
ReferenceConvNDFwdInstance
<
2
>>
(
init_method
,
params
,
do_verification
,
init_method
,
time_kernel
);
time_kernel
,
params
,
in_element_op
,
wei_element_op
,
out_element_op
);
}
}
else
if
(
num_dim_spatial
==
3
)
else
if
(
num_dim_spatial
==
3
)
{
{
return
run_conv_fwd
<
3
,
return
run_conv_fwd_nhwc
<
3
,
InDataType
,
InDataType
,
WeiDataType
,
WeiDataType
,
OutDataType
,
OutDataType
,
AccDataType
,
AccDataType
,
InElementOp
,
InElementOp
,
WeiElementOp
,
WeiElementOp
,
OutElementOp
,
OutElementOp
,
DeviceConvNDFwdInstance
<
3
>
,
DeviceConvNDFwdInstance
<
3
>>
(
do_verification
,
ReferenceConvNDFwdInstance
<
3
>>
(
init_method
,
params
,
do_verification
,
init_method
,
time_kernel
);
time_kernel
,
params
,
in_element_op
,
wei_element_op
,
out_element_op
);
}
}
return
0
;
return
0
;
...
...
example/09_convnd_fwd/convnd_fwd_xdl_fp16.cpp
View file @
0be1cf14
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
#include "convnd_fwd_common.hpp"
#include "convnd_fwd_common.hpp"
#include "ck/tensor_operation/gpu/device/device_convnd_fwd_nwc_kxc_nwk_xdl.hpp"
using
InDataType
=
ck
::
half_t
;
using
InDataType
=
ck
::
half_t
;
using
WeiDataType
=
ck
::
half_t
;
using
WeiDataType
=
ck
::
half_t
;
using
OutDataType
=
ck
::
half_t
;
using
OutDataType
=
ck
::
half_t
;
...
@@ -18,15 +20,15 @@ using OutElementOp = ck::tensor_operation::element_wise::PassThrough;
...
@@ -18,15 +20,15 @@ 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
;
template
<
ck
::
index_t
N
um
DimSpatial
>
template
<
ck
::
index_t
NDimSpatial
>
using
DeviceConvNDFwdInstance
=
ck
::
tensor_operation
::
device
::
DeviceConvNdFwdNwcKxcNwk_Xdl
<
using
DeviceConvNDFwdInstance
=
ck
::
tensor_operation
::
device
::
DeviceConvNdFwdNwcKxcNwk_Xdl
<
N
um
DimSpatial
,
//
NumDimSpatial
NDimSpatial
,
//
InDataType
,
//
InDataType
,
//
WeiDataType
,
//
WeiDataType
,
//
OutDataType
,
//
OutDataType
,
//
AccDataType
,
//
AccDataType
,
//
InElementOp
,
// Input Elementwise Operation
InElementOp
,
// Input Elementwise Operation
WeiElementOp
,
// Weights Elementwise Operation
=
WeiElementOp
,
// Weights Elementwise Operation
OutElementOp
,
// Output Elementwise Operation
OutElementOp
,
// Output Elementwise Operation
ConvFwdDefault
,
// ConvForwardSpecialization
ConvFwdDefault
,
// ConvForwardSpecialization
256
,
// BlockSize
256
,
// BlockSize
...
@@ -55,19 +57,6 @@ using DeviceConvNDFwdInstance = ck::tensor_operation::device::DeviceConvNdFwdNwc
...
@@ -55,19 +57,6 @@ using DeviceConvNDFwdInstance = ck::tensor_operation::device::DeviceConvNdFwdNwc
7
,
// CThreadTransferSrcDstVectorDim
7
,
// CThreadTransferSrcDstVectorDim
1
>
;
// CThreadTransferDstScalarPerVector
1
>
;
// CThreadTransferDstScalarPerVector
template
<
ck
::
index_t
NumDimSpatial
>
using
ReferenceConvNDFwdInstance
=
ck
::
tensor_operation
::
host
::
ReferenceConvFwd
<
NumDimSpatial
,
ck
::
tensor_layout
::
convolution
::
NHWC
,
ck
::
tensor_layout
::
convolution
::
KYXC
,
ck
::
tensor_layout
::
convolution
::
NHWK
,
InDataType
,
WeiDataType
,
OutDataType
,
InElementOp
,
WeiElementOp
,
OutElementOp
>
;
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
print_helper_msg
();
print_helper_msg
();
...
@@ -100,6 +89,10 @@ int main(int argc, char* argv[])
...
@@ -100,6 +89,10 @@ int main(int argc, char* argv[])
params
=
parse_conv_params
(
num_dim_spatial
,
5
,
argv
);
params
=
parse_conv_params
(
num_dim_spatial
,
5
,
argv
);
}
}
const
auto
in_element_op
=
InElementOp
{};
const
auto
wei_element_op
=
WeiElementOp
{};
const
auto
out_element_op
=
OutElementOp
{};
if
(
num_dim_spatial
==
1
)
if
(
num_dim_spatial
==
1
)
{
{
return
run_conv_fwd_nhwc
<
1
,
return
run_conv_fwd_nhwc
<
1
,
...
@@ -110,9 +103,13 @@ int main(int argc, char* argv[])
...
@@ -110,9 +103,13 @@ int main(int argc, char* argv[])
InElementOp
,
InElementOp
,
WeiElementOp
,
WeiElementOp
,
OutElementOp
,
OutElementOp
,
DeviceConvNDFwdInstance
<
1
>
,
DeviceConvNDFwdInstance
<
1
>>
(
do_verification
,
ReferenceConvNDFwdInstance
<
1
>>
(
init_method
,
params
,
do_verification
,
init_method
,
time_kernel
);
time_kernel
,
params
,
in_element_op
,
wei_element_op
,
out_element_op
);
}
}
else
if
(
num_dim_spatial
==
2
)
else
if
(
num_dim_spatial
==
2
)
{
{
...
@@ -124,9 +121,13 @@ int main(int argc, char* argv[])
...
@@ -124,9 +121,13 @@ int main(int argc, char* argv[])
InElementOp
,
InElementOp
,
WeiElementOp
,
WeiElementOp
,
OutElementOp
,
OutElementOp
,
DeviceConvNDFwdInstance
<
2
>
,
DeviceConvNDFwdInstance
<
2
>>
(
do_verification
,
ReferenceConvNDFwdInstance
<
2
>>
(
init_method
,
params
,
do_verification
,
init_method
,
time_kernel
);
time_kernel
,
params
,
in_element_op
,
wei_element_op
,
out_element_op
);
}
}
else
if
(
num_dim_spatial
==
3
)
else
if
(
num_dim_spatial
==
3
)
{
{
...
@@ -138,9 +139,13 @@ int main(int argc, char* argv[])
...
@@ -138,9 +139,13 @@ int main(int argc, char* argv[])
InElementOp
,
InElementOp
,
WeiElementOp
,
WeiElementOp
,
OutElementOp
,
OutElementOp
,
DeviceConvNDFwdInstance
<
3
>
,
DeviceConvNDFwdInstance
<
3
>>
(
do_verification
,
ReferenceConvNDFwdInstance
<
3
>>
(
init_method
,
params
,
do_verification
,
init_method
,
time_kernel
);
time_kernel
,
params
,
in_element_op
,
wei_element_op
,
out_element_op
);
}
}
return
0
;
return
0
;
...
...
example/09_convnd_fwd/convnd_fwd_xdl_fp32.cpp
View file @
0be1cf14
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
#include "convnd_fwd_common.hpp"
#include "convnd_fwd_common.hpp"
#include "ck/tensor_operation/gpu/device/device_convnd_fwd_nwc_kxc_nwk_xdl.hpp"
using
InDataType
=
float
;
using
InDataType
=
float
;
using
WeiDataType
=
float
;
using
WeiDataType
=
float
;
using
OutDataType
=
float
;
using
OutDataType
=
float
;
...
@@ -55,15 +57,6 @@ using DeviceConvNDFwdInstance = ck::tensor_operation::device::DeviceConvNdFwdNwc
...
@@ -55,15 +57,6 @@ using DeviceConvNDFwdInstance = ck::tensor_operation::device::DeviceConvNdFwdNwc
7
,
// CThreadTransferSrcDstVectorDim
7
,
// CThreadTransferSrcDstVectorDim
1
>
;
// CThreadTransferDstScalarPerVector
1
>
;
// CThreadTransferDstScalarPerVector
template
<
ck
::
index_t
NumDimSpatial
>
using
ReferenceConvNDFwdInstance
=
ck
::
tensor_operation
::
host
::
ReferenceConvFwd
<
InDataType
,
WeiDataType
,
OutDataType
,
InElementOp
,
WeiElementOp
,
OutElementOp
,
NumDimSpatial
>
;
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
print_helper_msg
();
print_helper_msg
();
...
@@ -73,7 +66,8 @@ int main(int argc, char* argv[])
...
@@ -73,7 +66,8 @@ int main(int argc, char* argv[])
bool
time_kernel
=
false
;
bool
time_kernel
=
false
;
int
num_dim_spatial
=
2
;
int
num_dim_spatial
=
2
;
ck
::
tensor_operation
::
device
::
ConvParams
params
;
ck
::
tensor_operation
::
device
::
ConvParams
params
{
2
,
128
,
256
,
192
,
{
3
,
3
},
{
71
,
71
},
{
2
,
2
},
{
1
,
1
},
{
1
,
1
},
{
1
,
1
}};
if
(
argc
==
1
)
if
(
argc
==
1
)
{
{
...
@@ -92,50 +86,66 @@ int main(int argc, char* argv[])
...
@@ -92,50 +86,66 @@ int main(int argc, char* argv[])
time_kernel
=
std
::
stoi
(
argv
[
3
]);
time_kernel
=
std
::
stoi
(
argv
[
3
]);
num_dim_spatial
=
std
::
stoi
(
argv
[
4
]);
num_dim_spatial
=
std
::
stoi
(
argv
[
4
]);
params
=
parse_conv_params
(
num_dim_spatial
,
argc
,
argv
);
params
=
parse_conv_params
(
num_dim_spatial
,
5
,
argv
);
}
}
const
auto
in_element_op
=
InElementOp
{};
const
auto
wei_element_op
=
WeiElementOp
{};
const
auto
out_element_op
=
OutElementOp
{};
if
(
num_dim_spatial
==
1
)
if
(
num_dim_spatial
==
1
)
{
{
return
run_conv_fwd
<
1
,
return
run_conv_fwd_nhwc
<
1
,
InDataType
,
InDataType
,
WeiDataType
,
WeiDataType
,
OutDataType
,
OutDataType
,
AccDataType
,
AccDataType
,
InElementOp
,
InElementOp
,
WeiElementOp
,
WeiElementOp
,
OutElementOp
,
OutElementOp
,
DeviceConvNDFwdInstance
<
1
>
,
DeviceConvNDFwdInstance
<
1
>>
(
do_verification
,
ReferenceConvNDFwdInstance
<
1
>>
(
init_method
,
params
,
do_verification
,
init_method
,
time_kernel
);
time_kernel
,
params
,
in_element_op
,
wei_element_op
,
out_element_op
);
}
}
else
if
(
num_dim_spatial
==
2
)
else
if
(
num_dim_spatial
==
2
)
{
{
return
run_conv_fwd
<
2
,
return
run_conv_fwd_nhwc
<
2
,
InDataType
,
InDataType
,
WeiDataType
,
WeiDataType
,
OutDataType
,
OutDataType
,
AccDataType
,
AccDataType
,
InElementOp
,
InElementOp
,
WeiElementOp
,
WeiElementOp
,
OutElementOp
,
OutElementOp
,
DeviceConvNDFwdInstance
<
2
>
,
DeviceConvNDFwdInstance
<
2
>>
(
do_verification
,
ReferenceConvNDFwdInstance
<
2
>>
(
init_method
,
params
,
do_verification
,
init_method
,
time_kernel
);
time_kernel
,
params
,
in_element_op
,
wei_element_op
,
out_element_op
);
}
}
else
if
(
num_dim_spatial
==
3
)
else
if
(
num_dim_spatial
==
3
)
{
{
return
run_conv_fwd
<
3
,
return
run_conv_fwd_nhwc
<
3
,
InDataType
,
InDataType
,
WeiDataType
,
WeiDataType
,
OutDataType
,
OutDataType
,
AccDataType
,
AccDataType
,
InElementOp
,
InElementOp
,
WeiElementOp
,
WeiElementOp
,
OutElementOp
,
OutElementOp
,
DeviceConvNDFwdInstance
<
3
>
,
DeviceConvNDFwdInstance
<
3
>>
(
do_verification
,
ReferenceConvNDFwdInstance
<
3
>>
(
init_method
,
params
,
do_verification
,
init_method
,
time_kernel
);
time_kernel
,
params
,
in_element_op
,
wei_element_op
,
out_element_op
);
}
}
return
0
;
return
0
;
...
...
example/09_convnd_fwd/convnd_fwd_xdl_fp64.cpp
View file @
0be1cf14
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
#include "convnd_fwd_common.hpp"
#include "convnd_fwd_common.hpp"
#include "ck/tensor_operation/gpu/device/device_convnd_fwd_nwc_kxc_nwk_xdl.hpp"
using
InDataType
=
double
;
using
InDataType
=
double
;
using
WeiDataType
=
double
;
using
WeiDataType
=
double
;
using
OutDataType
=
double
;
using
OutDataType
=
double
;
...
@@ -55,15 +57,6 @@ using DeviceConvNDFwdInstance = ck::tensor_operation::device::DeviceConvNdFwdNwc
...
@@ -55,15 +57,6 @@ using DeviceConvNDFwdInstance = ck::tensor_operation::device::DeviceConvNdFwdNwc
7
,
// CThreadTransferSrcDstVectorDim
7
,
// CThreadTransferSrcDstVectorDim
1
>
;
// CThreadTransferDstScalarPerVector
1
>
;
// CThreadTransferDstScalarPerVector
template
<
ck
::
index_t
NumDimSpatial
>
using
ReferenceConvNDFwdInstance
=
ck
::
tensor_operation
::
host
::
ReferenceConvFwd
<
InDataType
,
WeiDataType
,
OutDataType
,
InElementOp
,
WeiElementOp
,
OutElementOp
,
NumDimSpatial
>
;
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
print_helper_msg
();
print_helper_msg
();
...
@@ -73,7 +66,8 @@ int main(int argc, char* argv[])
...
@@ -73,7 +66,8 @@ int main(int argc, char* argv[])
bool
time_kernel
=
false
;
bool
time_kernel
=
false
;
int
num_dim_spatial
=
2
;
int
num_dim_spatial
=
2
;
ck
::
tensor_operation
::
device
::
ConvParams
params
;
ck
::
tensor_operation
::
device
::
ConvParams
params
{
2
,
128
,
256
,
192
,
{
3
,
3
},
{
71
,
71
},
{
2
,
2
},
{
1
,
1
},
{
1
,
1
},
{
1
,
1
}};
if
(
argc
==
1
)
if
(
argc
==
1
)
{
{
...
@@ -92,50 +86,66 @@ int main(int argc, char* argv[])
...
@@ -92,50 +86,66 @@ int main(int argc, char* argv[])
time_kernel
=
std
::
stoi
(
argv
[
3
]);
time_kernel
=
std
::
stoi
(
argv
[
3
]);
num_dim_spatial
=
std
::
stoi
(
argv
[
4
]);
num_dim_spatial
=
std
::
stoi
(
argv
[
4
]);
params
=
parse_conv_params
(
num_dim_spatial
,
argc
,
argv
);
params
=
parse_conv_params
(
num_dim_spatial
,
5
,
argv
);
}
}
const
auto
in_element_op
=
InElementOp
{};
const
auto
wei_element_op
=
WeiElementOp
{};
const
auto
out_element_op
=
OutElementOp
{};
if
(
num_dim_spatial
==
1
)
if
(
num_dim_spatial
==
1
)
{
{
return
run_conv_fwd
<
1
,
return
run_conv_fwd_nhwc
<
1
,
InDataType
,
InDataType
,
WeiDataType
,
WeiDataType
,
OutDataType
,
OutDataType
,
AccDataType
,
AccDataType
,
InElementOp
,
InElementOp
,
WeiElementOp
,
WeiElementOp
,
OutElementOp
,
OutElementOp
,
DeviceConvNDFwdInstance
<
1
>
,
DeviceConvNDFwdInstance
<
1
>>
(
do_verification
,
ReferenceConvNDFwdInstance
<
1
>>
(
init_method
,
params
,
do_verification
,
init_method
,
time_kernel
);
time_kernel
,
params
,
in_element_op
,
wei_element_op
,
out_element_op
);
}
}
else
if
(
num_dim_spatial
==
2
)
else
if
(
num_dim_spatial
==
2
)
{
{
return
run_conv_fwd
<
2
,
return
run_conv_fwd_nhwc
<
2
,
InDataType
,
InDataType
,
WeiDataType
,
WeiDataType
,
OutDataType
,
OutDataType
,
AccDataType
,
AccDataType
,
InElementOp
,
InElementOp
,
WeiElementOp
,
WeiElementOp
,
OutElementOp
,
OutElementOp
,
DeviceConvNDFwdInstance
<
2
>
,
DeviceConvNDFwdInstance
<
2
>>
(
do_verification
,
ReferenceConvNDFwdInstance
<
2
>>
(
init_method
,
params
,
do_verification
,
init_method
,
time_kernel
);
time_kernel
,
params
,
in_element_op
,
wei_element_op
,
out_element_op
);
}
}
else
if
(
num_dim_spatial
==
3
)
else
if
(
num_dim_spatial
==
3
)
{
{
return
run_conv_fwd
<
3
,
return
run_conv_fwd_nhwc
<
3
,
InDataType
,
InDataType
,
WeiDataType
,
WeiDataType
,
OutDataType
,
OutDataType
,
AccDataType
,
AccDataType
,
InElementOp
,
InElementOp
,
WeiElementOp
,
WeiElementOp
,
OutElementOp
,
OutElementOp
,
DeviceConvNDFwdInstance
<
3
>
,
DeviceConvNDFwdInstance
<
3
>>
(
do_verification
,
ReferenceConvNDFwdInstance
<
3
>>
(
init_method
,
params
,
do_verification
,
init_method
,
time_kernel
);
time_kernel
,
params
,
in_element_op
,
wei_element_op
,
out_element_op
);
}
}
return
0
;
return
0
;
...
...
example/09_convnd_fwd/convnd_fwd_xdl_int8.cpp
View file @
0be1cf14
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
#include "convnd_fwd_common.hpp"
#include "convnd_fwd_common.hpp"
#include "ck/tensor_operation/gpu/device/device_convnd_fwd_nwc_kxc_nwk_xdl.hpp"
using
InDataType
=
int8_t
;
using
InDataType
=
int8_t
;
using
WeiDataType
=
int8_t
;
using
WeiDataType
=
int8_t
;
using
OutDataType
=
int8_t
;
using
OutDataType
=
int8_t
;
...
@@ -55,15 +57,6 @@ using DeviceConvNDFwdInstance = ck::tensor_operation::device::DeviceConvNdFwdNwc
...
@@ -55,15 +57,6 @@ using DeviceConvNDFwdInstance = ck::tensor_operation::device::DeviceConvNdFwdNwc
7
,
// CThreadTransferSrcDstVectorDim
7
,
// CThreadTransferSrcDstVectorDim
1
>
;
// CThreadTransferDstScalarPerVector
1
>
;
// CThreadTransferDstScalarPerVector
template
<
ck
::
index_t
NumDimSpatial
>
using
ReferenceConvNDFwdInstance
=
ck
::
tensor_operation
::
host
::
ReferenceConvFwd
<
InDataType
,
WeiDataType
,
OutDataType
,
InElementOp
,
WeiElementOp
,
OutElementOp
,
NumDimSpatial
>
;
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
print_helper_msg
();
print_helper_msg
();
...
@@ -73,7 +66,8 @@ int main(int argc, char* argv[])
...
@@ -73,7 +66,8 @@ int main(int argc, char* argv[])
bool
time_kernel
=
false
;
bool
time_kernel
=
false
;
int
num_dim_spatial
=
2
;
int
num_dim_spatial
=
2
;
ck
::
tensor_operation
::
device
::
ConvParams
params
;
ck
::
tensor_operation
::
device
::
ConvParams
params
{
2
,
128
,
256
,
192
,
{
3
,
3
},
{
71
,
71
},
{
2
,
2
},
{
1
,
1
},
{
1
,
1
},
{
1
,
1
}};
if
(
argc
==
1
)
if
(
argc
==
1
)
{
{
...
@@ -92,49 +86,49 @@ int main(int argc, char* argv[])
...
@@ -92,49 +86,49 @@ int main(int argc, char* argv[])
time_kernel
=
std
::
stoi
(
argv
[
3
]);
time_kernel
=
std
::
stoi
(
argv
[
3
]);
num_dim_spatial
=
std
::
stoi
(
argv
[
4
]);
num_dim_spatial
=
std
::
stoi
(
argv
[
4
]);
params
=
parse_conv_params
(
num_dim_spatial
,
argc
,
argv
);
params
=
parse_conv_params
(
num_dim_spatial
,
5
,
argv
);
}
}
if
(
num_dim_spatial
==
1
)
if
(
num_dim_spatial
==
1
)
{
{
return
run_conv_fwd
<
1
,
return
run_conv_fwd
_nhwc
<
1
,
InDataType
,
InDataType
,
WeiDataType
,
WeiDataType
,
OutDataType
,
OutDataType
,
AccDataType
,
AccDataType
,
InElementOp
,
InElementOp
,
WeiElementOp
,
WeiElementOp
,
OutElementOp
,
OutElementOp
,
DeviceConvNDFwdInstance
<
1
>
,
DeviceConvNDFwdInstance
<
1
>
,
ReferenceConvNDFwdInstance
<
1
>>
(
ReferenceConvNDFwdInstance
<
1
>>
(
params
,
do_verification
,
init_method
,
time_kernel
);
params
,
do_verification
,
init_method
,
time_kernel
);
}
}
else
if
(
num_dim_spatial
==
2
)
else
if
(
num_dim_spatial
==
2
)
{
{
return
run_conv_fwd
<
2
,
return
run_conv_fwd
_nhwc
<
2
,
InDataType
,
InDataType
,
WeiDataType
,
WeiDataType
,
OutDataType
,
OutDataType
,
AccDataType
,
AccDataType
,
InElementOp
,
InElementOp
,
WeiElementOp
,
WeiElementOp
,
OutElementOp
,
OutElementOp
,
DeviceConvNDFwdInstance
<
2
>
,
DeviceConvNDFwdInstance
<
2
>
,
ReferenceConvNDFwdInstance
<
2
>>
(
ReferenceConvNDFwdInstance
<
2
>>
(
params
,
do_verification
,
init_method
,
time_kernel
);
params
,
do_verification
,
init_method
,
time_kernel
);
}
}
else
if
(
num_dim_spatial
==
3
)
else
if
(
num_dim_spatial
==
3
)
{
{
return
run_conv_fwd
<
3
,
return
run_conv_fwd
_nhwc
<
3
,
InDataType
,
InDataType
,
WeiDataType
,
WeiDataType
,
OutDataType
,
OutDataType
,
AccDataType
,
AccDataType
,
InElementOp
,
InElementOp
,
WeiElementOp
,
WeiElementOp
,
OutElementOp
,
OutElementOp
,
DeviceConvNDFwdInstance
<
3
>
,
DeviceConvNDFwdInstance
<
3
>
,
ReferenceConvNDFwdInstance
<
3
>>
(
ReferenceConvNDFwdInstance
<
3
>>
(
params
,
do_verification
,
init_method
,
time_kernel
);
params
,
do_verification
,
init_method
,
time_kernel
);
}
}
...
...
example/10_conv2d_bwd_data/CMakeLists.txt
View file @
0be1cf14
add_example_executable
(
example_conv2d_bwd_data_xdl conv2d_bwd_data_xdl.cpp
)
add_example_executable
(
example_conv2d_bwd_data_xdl conv2d_bwd_data_xdl.cpp
)
target_link_libraries
(
example_conv2d_bwd_data_xdl PRIVATE
conv_
util
)
target_link_libraries
(
example_conv2d_bwd_data_xdl PRIVATE util
ity
)
example/10_conv2d_bwd_data/conv2d_bwd_data_xdl.cpp
View file @
0be1cf14
...
@@ -29,6 +29,7 @@ using S = ck::Sequence<Is...>;
...
@@ -29,6 +29,7 @@ using S = ck::Sequence<Is...>;
using
InElementOp
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
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
::
Default
;
ck
::
tensor_operation
::
device
::
ConvolutionBackwardDataSpecialization
::
Default
;
...
@@ -68,125 +69,168 @@ using DeviceConvBwdDataInstance = ck::tensor_operation::device::
...
@@ -68,125 +69,168 @@ using DeviceConvBwdDataInstance = ck::tensor_operation::device::
7
,
7
,
1
>
;
// GemmCThreadTransferDstScalarPerVector
1
>
;
// GemmCThreadTransferDstScalarPerVector
using
ReferenceConvBwdInstance
=
ck
::
tensor_operation
::
host
::
ReferenceConvBwdData
<
InDataType
,
using
ReferenceConvBwdInstance
=
WeiDataType
,
ck
::
tensor_operation
::
host
::
ReferenceConvBwdData
<
2
,
OutDataType
,
ck
::
tensor_layout
::
convolution
::
NHWC
,
AccDataType
,
ck
::
tensor_layout
::
convolution
::
KYXC
,
InElementOp
,
ck
::
tensor_layout
::
convolution
::
NHWK
,
WeiElementOp
,
InDataType
,
OutElementOp
>
;
WeiDataType
,
OutDataType
,
InElementOp
,
WeiElementOp
,
OutElementOp
>
;
ck
::
tensor_operation
::
device
::
ConvParams
parse_conv_params
(
int
num_dim_spatial
,
int
arg_idx
,
char
*
const
argv
[])
{
const
ck
::
index_t
N
=
std
::
stoi
(
argv
[
arg_idx
++
]);
const
ck
::
index_t
K
=
std
::
stoi
(
argv
[
arg_idx
++
]);
const
ck
::
index_t
C
=
std
::
stoi
(
argv
[
arg_idx
++
]);
std
::
vector
<
ck
::
index_t
>
filter_spatial_lengths
(
num_dim_spatial
);
std
::
vector
<
ck
::
index_t
>
input_spatial_lengths
(
num_dim_spatial
);
std
::
vector
<
ck
::
index_t
>
conv_filter_strides
(
num_dim_spatial
);
std
::
vector
<
ck
::
index_t
>
conv_filter_dilations
(
num_dim_spatial
);
std
::
vector
<
ck
::
index_t
>
input_left_pads
(
num_dim_spatial
);
std
::
vector
<
ck
::
index_t
>
input_right_pads
(
num_dim_spatial
);
for
(
int
i
=
0
;
i
<
num_dim_spatial
;
++
i
)
{
filter_spatial_lengths
[
i
]
=
std
::
stoi
(
argv
[
arg_idx
++
]);
}
for
(
int
i
=
0
;
i
<
num_dim_spatial
;
++
i
)
{
input_spatial_lengths
[
i
]
=
std
::
stoi
(
argv
[
arg_idx
++
]);
}
for
(
int
i
=
0
;
i
<
num_dim_spatial
;
++
i
)
{
conv_filter_strides
[
i
]
=
std
::
stoi
(
argv
[
arg_idx
++
]);
}
for
(
int
i
=
0
;
i
<
num_dim_spatial
;
++
i
)
{
conv_filter_dilations
[
i
]
=
std
::
stoi
(
argv
[
arg_idx
++
]);
}
for
(
int
i
=
0
;
i
<
num_dim_spatial
;
++
i
)
{
input_left_pads
[
i
]
=
std
::
stoi
(
argv
[
arg_idx
++
]);
}
for
(
int
i
=
0
;
i
<
num_dim_spatial
;
++
i
)
{
input_right_pads
[
i
]
=
std
::
stoi
(
argv
[
arg_idx
++
]);
}
return
ck
::
tensor_operation
::
device
::
ConvParams
{
num_dim_spatial
,
N
,
K
,
C
,
filter_spatial_lengths
,
input_spatial_lengths
,
conv_filter_strides
,
conv_filter_dilations
,
input_left_pads
,
input_right_pads
};
}
void
print_helper_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=no, 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
;
}
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
print_helper_msg
();
bool
do_verification
=
true
;
bool
do_verification
=
true
;
int
init_method
=
1
;
int
init_method
=
1
;
bool
time_kernel
=
false
;
bool
time_kernel
=
false
;
int
num_dim_spatial
=
2
;
// Conv shape
ck
::
tensor_operation
::
device
::
ConvParams
params
{
ck
::
index_t
N
=
128
;
2
,
128
,
256
,
256
,
{
3
,
3
},
{
71
,
71
},
{
2
,
2
},
{
1
,
1
},
{
1
,
1
},
{
1
,
1
}};
ck
::
index_t
K
=
256
;
ck
::
index_t
C
=
256
;
if
(
argc
==
1
)
ck
::
index_t
Y
=
3
;
{
ck
::
index_t
X
=
3
;
// use default
ck
::
index_t
Hi
=
71
;
}
ck
::
index_t
Wi
=
71
;
else
if
(
argc
==
4
)
ck
::
index_t
conv_stride_h
=
2
;
ck
::
index_t
conv_stride_w
=
2
;
ck
::
index_t
conv_dilation_h
=
1
;
ck
::
index_t
conv_dilation_w
=
1
;
ck
::
index_t
in_left_pad_h
=
1
;
ck
::
index_t
in_left_pad_w
=
1
;
ck
::
index_t
in_right_pad_h
=
1
;
ck
::
index_t
in_right_pad_w
=
1
;
if
(
argc
==
4
)
{
{
do_verification
=
std
::
stoi
(
argv
[
1
]);
do_verification
=
std
::
stoi
(
argv
[
1
]);
init_method
=
std
::
stoi
(
argv
[
2
]);
init_method
=
std
::
stoi
(
argv
[
2
]);
time_kernel
=
std
::
stoi
(
argv
[
3
]);
time_kernel
=
std
::
stoi
(
argv
[
3
]);
}
}
else
if
(
argc
==
19
)
else
{
{
do_verification
=
std
::
stoi
(
argv
[
1
]);
do_verification
=
std
::
stoi
(
argv
[
1
]);
init_method
=
std
::
stoi
(
argv
[
2
]);
init_method
=
std
::
stoi
(
argv
[
2
]);
time_kernel
=
std
::
stoi
(
argv
[
3
]);
time_kernel
=
std
::
stoi
(
argv
[
3
]);
num_dim_spatial
=
std
::
stoi
(
argv
[
4
]);
N
=
std
::
stoi
(
argv
[
4
]);
params
=
parse_conv_params
(
num_dim_spatial
,
5
,
argv
);
K
=
std
::
stoi
(
argv
[
5
]);
C
=
std
::
stoi
(
argv
[
6
]);
Y
=
std
::
stoi
(
argv
[
7
]);
X
=
std
::
stoi
(
argv
[
8
]);
Hi
=
std
::
stoi
(
argv
[
9
]);
Wi
=
std
::
stoi
(
argv
[
10
]);
conv_stride_h
=
std
::
stoi
(
argv
[
11
]);
conv_stride_w
=
std
::
stoi
(
argv
[
12
]);
conv_dilation_h
=
std
::
stoi
(
argv
[
13
]);
conv_dilation_w
=
std
::
stoi
(
argv
[
14
]);
in_left_pad_h
=
std
::
stoi
(
argv
[
15
]);
in_left_pad_w
=
std
::
stoi
(
argv
[
16
]);
in_right_pad_h
=
std
::
stoi
(
argv
[
17
]);
in_right_pad_w
=
std
::
stoi
(
argv
[
18
]);
}
else
{
printf
(
"arg1: verification (0=no, 1=yes)
\n
"
);
printf
(
"arg2: initialization (0=no init, 1=integer value, 2=decimal value)
\n
"
);
printf
(
"arg3: time kernel (0=n0, 1=yes)
\n
"
);
printf
(
"arg4 to 18: N, K, C, Y, X, Hi, Wi, Sy, Sx, Dy, Dx, LeftPy, LeftPx, RightPy, "
"RightPx
\n
"
);
exit
(
0
);
}
}
const
ck
::
index_t
YEff
=
(
Y
-
1
)
*
conv_dilation_h
+
1
;
auto
f_nhwc_host_tensor_descriptor
=
const
ck
::
index_t
XEff
=
(
X
-
1
)
*
conv_dilation_w
+
1
;
[](
ck
::
index_t
n
,
ck
::
index_t
c
,
std
::
vector
<
ck
::
index_t
>
spatial_lengths
)
{
std
::
vector
<
std
::
size_t
>
nhwc_lengths
{
static_cast
<
std
::
size_t
>
(
n
),
static_cast
<
std
::
size_t
>
(
c
)};
nhwc_lengths
.
insert
(
nhwc_lengths
.
begin
()
+
1
,
spatial_lengths
.
begin
(),
spatial_lengths
.
end
());
const
ck
::
index_t
Ho
=
(
Hi
+
in_left_pad_h
+
in_right_pad_h
-
YEff
)
/
conv_stride_h
+
1
;
return
HostTensorDescriptor
(
nhwc_lengths
);
const
ck
::
index_t
Wo
=
(
Wi
+
in_left_pad_w
+
in_right_pad_w
-
XEff
)
/
conv_stride_w
+
1
;
const
std
::
vector
<
ck
::
index_t
>
conv_filter_strides
{{
conv_stride_h
,
conv_stride_w
}};
const
std
::
vector
<
ck
::
index_t
>
conv_filter_dilations
{{
conv_dilation_h
,
conv_dilation_w
}};
const
std
::
vector
<
ck
::
index_t
>
input_left_pads
{{
in_left_pad_h
,
in_left_pad_w
}};
const
std
::
vector
<
ck
::
index_t
>
input_right_pads
{{
in_right_pad_h
,
in_right_pad_w
}};
// tensor layout
auto
f_host_tensor_descriptor
=
[](
std
::
size_t
N_
,
std
::
size_t
C_
,
std
::
size_t
H
,
std
::
size_t
W
)
{
return
HostTensorDescriptor
(
std
::
vector
<
std
::
size_t
>
({
N_
,
C_
,
H
,
W
}),
std
::
vector
<
std
::
size_t
>
({
C_
*
H
*
W
,
1
,
W
*
C_
,
C_
}));
};
};
Tensor
<
OutDataType
>
out_n_k_ho_wo
(
f_host_tensor_descriptor
(
N
,
K
,
Ho
,
Wo
));
Tensor
<
InDataType
>
in_n_hi_wi_c_host_result
(
Tensor
<
WeiDataType
>
wei_k_c_y_x
(
f_host_tensor_descriptor
(
K
,
C
,
Y
,
X
));
f_nhwc_host_tensor_descriptor
(
params
.
N_
,
params
.
C_
,
params
.
input_spatial_lengths_
));
Tensor
<
InDataType
>
in_n_c_hi_wi_host_result
(
f_host_tensor_descriptor
(
N
,
C
,
Hi
,
Wi
));
Tensor
<
InDataType
>
in_n_hi_wi_c_device_result
(
Tensor
<
InDataType
>
in_n_c_hi_wi_device_result
(
f_host_tensor_descriptor
(
N
,
C
,
Hi
,
Wi
));
f_nhwc_host_tensor_descriptor
(
params
.
N_
,
params
.
C_
,
params
.
input_spatial_lengths_
));
Tensor
<
WeiDataType
>
wei_k_y_x_c
(
f_nhwc_host_tensor_descriptor
(
params
.
K_
,
params
.
C_
,
params
.
filter_spatial_lengths_
));
Tensor
<
OutDataType
>
out_n_ho_wo_k
(
f_nhwc_host_tensor_descriptor
(
params
.
N_
,
params
.
K_
,
params
.
GetOutputSpatialLengths
()));
std
::
cout
<<
"in_n_
c_
hi_wi: "
<<
in_n_
c_
hi_wi_host_result
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"in_n_hi_wi
_c
: "
<<
in_n_hi_wi_
c_
host_result
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"wei_k_
c_
y_x: "
<<
wei_k_
c_
y_x
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"wei_k_y_x
_c
: "
<<
wei_k_y_x
_c
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"out_n_
k_
ho_wo: "
<<
out_n_
k_
ho_wo
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"out_n_ho_wo
_k
: "
<<
out_n_ho_wo
_k
.
mDesc
<<
std
::
endl
;
switch
(
init_method
)
switch
(
init_method
)
{
{
case
0
:
break
;
case
0
:
break
;
case
1
:
case
1
:
out_n_
k_
ho_wo
.
GenerateTensorValue
(
GeneratorTensor_2
<
OutDataType
>
{
-
5
,
5
});
out_n_ho_wo
_k
.
GenerateTensorValue
(
GeneratorTensor_2
<
OutDataType
>
{
-
5
,
5
});
wei_k_
c_
y_x
.
GenerateTensorValue
(
GeneratorTensor_2
<
WeiDataType
>
{
-
5
,
5
});
wei_k_y_x
_c
.
GenerateTensorValue
(
GeneratorTensor_2
<
WeiDataType
>
{
-
5
,
5
});
break
;
break
;
default:
default:
out_n_
k_
ho_wo
.
GenerateTensorValue
(
GeneratorTensor_1
<
OutDataType
>
{
1
});
out_n_ho_wo
_k
.
GenerateTensorValue
(
GeneratorTensor_1
<
OutDataType
>
{
1
});
wei_k_
c_
y_x
.
GenerateTensorValue
(
GeneratorTensor_1
<
WeiDataType
>
{
1
});
wei_k_y_x
_c
.
GenerateTensorValue
(
GeneratorTensor_1
<
WeiDataType
>
{
1
});
}
}
DeviceMem
in_device_buf
(
sizeof
(
InDataType
)
*
DeviceMem
in_device_buf
(
sizeof
(
InDataType
)
*
in_n_
c_
hi_wi_device_result
.
mDesc
.
GetElementSpace
());
in_n_hi_wi_
c_
device_result
.
mDesc
.
GetElementSpace
());
DeviceMem
wei_device_buf
(
sizeof
(
WeiDataType
)
*
wei_k_
c_
y_x
.
mDesc
.
GetElementSpace
());
DeviceMem
wei_device_buf
(
sizeof
(
WeiDataType
)
*
wei_k_y_x
_c
.
mDesc
.
GetElementSpace
());
DeviceMem
out_device_buf
(
sizeof
(
OutDataType
)
*
out_n_
k_
ho_wo
.
mDesc
.
GetElementSpace
());
DeviceMem
out_device_buf
(
sizeof
(
OutDataType
)
*
out_n_ho_wo
_k
.
mDesc
.
GetElementSpace
());
out_device_buf
.
ToDevice
(
out_n_
k_
ho_wo
.
mData
.
data
());
out_device_buf
.
ToDevice
(
out_n_ho_wo
_k
.
mData
.
data
());
wei_device_buf
.
ToDevice
(
wei_k_
c_
y_x
.
mData
.
data
());
wei_device_buf
.
ToDevice
(
wei_k_y_x
_c
.
mData
.
data
());
// reset input to zero
// reset input to zero
in_n_c_hi_wi_device_result
.
GenerateTensorValue
(
GeneratorTensor_1
<
InDataType
>
{
0
});
in_device_buf
.
SetZero
();
in_device_buf
.
ToDevice
(
in_n_c_hi_wi_device_result
.
mData
.
data
());
// do GEMM
// do GEMM
auto
conv
=
DeviceConvBwdDataInstance
{};
auto
conv
=
DeviceConvBwdDataInstance
{};
...
@@ -194,16 +238,16 @@ int main(int argc, char* argv[])
...
@@ -194,16 +238,16 @@ int main(int argc, char* argv[])
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
()),
static_cast
<
OutDataType
*>
(
out_device_buf
.
GetDeviceBuffer
()),
static_cast
<
OutDataType
*>
(
out_device_buf
.
GetDeviceBuffer
()),
N
,
params
.
N_
,
K
,
params
.
K_
,
C
,
params
.
C_
,
std
::
vector
<
ck
::
index_t
>
{{
Hi
,
Wi
}}
,
params
.
input_spatial_lengths_
,
std
::
vector
<
ck
::
index_t
>
{{
Y
,
X
}}
,
params
.
filter_spatial_lengths_
,
std
::
vector
<
ck
::
index_t
>
{{
Ho
,
Wo
}}
,
params
.
GetOutputSpatialLengths
()
,
conv_filter_strides
,
params
.
conv_filter_strides
_
,
conv_filter_dilations
,
params
.
conv_filter_dilations
_
,
input_left_pads
,
params
.
input_left_pads
_
,
input_right_pads
,
params
.
input_right_pads
_
,
InElementOp
{},
InElementOp
{},
WeiElementOp
{},
WeiElementOp
{},
OutElementOp
{});
OutElementOp
{});
...
@@ -217,11 +261,8 @@ int main(int argc, char* argv[])
...
@@ -217,11 +261,8 @@ int main(int argc, char* argv[])
float
ave_time
=
invoker
.
Run
(
argument
,
StreamConfig
{
nullptr
,
time_kernel
});
float
ave_time
=
invoker
.
Run
(
argument
,
StreamConfig
{
nullptr
,
time_kernel
});
std
::
size_t
flop
=
std
::
size_t
(
2
)
*
N
*
K
*
Ho
*
Wo
*
C
*
Y
*
X
;
std
::
size_t
flop
=
params
.
GetFlops
();
std
::
size_t
num_btype
=
params
.
GetByte
<
InDataType
,
WeiDataType
,
OutDataType
>
();
std
::
size_t
num_btype
=
sizeof
(
InDataType
)
*
(
N
*
C
*
Hi
*
Wi
)
+
sizeof
(
WeiDataType
)
*
(
K
*
C
*
Y
*
X
)
+
sizeof
(
OutDataType
)
*
(
N
*
K
*
Ho
*
Wo
);
float
tflops
=
static_cast
<
float
>
(
flop
)
/
1.E9
/
ave_time
;
float
tflops
=
static_cast
<
float
>
(
flop
)
/
1.E9
/
ave_time
;
...
@@ -235,25 +276,26 @@ int main(int argc, char* argv[])
...
@@ -235,25 +276,26 @@ int main(int argc, char* argv[])
auto
ref_conv
=
ReferenceConvBwdInstance
{};
auto
ref_conv
=
ReferenceConvBwdInstance
{};
auto
ref_invoker
=
ref_conv
.
MakeInvoker
();
auto
ref_invoker
=
ref_conv
.
MakeInvoker
();
auto
ref_argument
=
ref_conv
.
MakeArgument
(
in_n_
c_
hi_wi_host_result
,
auto
ref_argument
=
ref_conv
.
MakeArgument
(
in_n_hi_wi_
c_
host_result
,
wei_k_
c_
y_x
,
wei_k_y_x
_c
,
out_n_
k_
ho_wo
,
out_n_ho_wo
_k
,
conv_filter_strides
,
params
.
conv_filter_strides
_
,
conv_filter_dilations
,
params
.
conv_filter_dilations
_
,
input_left_pads
,
params
.
input_left_pads
_
,
input_right_pads
,
params
.
input_right_pads
_
,
InElementOp
{},
InElementOp
{},
WeiElementOp
{},
WeiElementOp
{},
OutElementOp
{});
OutElementOp
{});
ref_invoker
.
Run
(
ref_argument
);
ref_invoker
.
Run
(
ref_argument
);
in_device_buf
.
FromDevice
(
in_n_
c_
hi_wi_device_result
.
mData
.
data
());
in_device_buf
.
FromDevice
(
in_n_hi_wi_
c_
device_result
.
mData
.
data
());
return
ck
::
utils
::
check_err
(
in_n_
c_
hi_wi_device_result
.
mData
,
return
ck
::
utils
::
check_err
(
in_n_hi_wi_
c_
device_result
.
mData
,
in_n_
c_
hi_wi_host_result
.
mData
)
in_n_hi_wi_
c_
host_result
.
mData
)
?
0
?
0
:
1
;
:
1
;
}
}
return
0
;
return
0
;
}
}
example/11_conv2d_bwd_weight/CMakeLists.txt
View file @
0be1cf14
add_example_executable
(
example_conv2d_bwd_weight_xdl conv2d_bwd_weight_xdl.cpp
)
add_example_executable
(
example_conv2d_bwd_weight_xdl conv2d_bwd_weight_xdl.cpp
)
target_link_libraries
(
example_conv2d_bwd_weight_xdl PRIVATE
conv_
util
)
target_link_libraries
(
example_conv2d_bwd_weight_xdl PRIVATE util
ity
)
example/11_conv2d_bwd_weight/conv2d_bwd_weight_xdl.cpp
View file @
0be1cf14
...
@@ -74,149 +74,171 @@ using DeviceConvBwdWeightInstance = ck::tensor_operation::device::
...
@@ -74,149 +74,171 @@ using DeviceConvBwdWeightInstance = ck::tensor_operation::device::
// clang-format on
// clang-format on
using
ReferenceConvBwdWeightInstance
=
using
ReferenceConvBwdWeightInstance
=
ck
::
tensor_operation
::
host
::
ReferenceConvBwdWeight
<
InDataType
,
ck
::
tensor_operation
::
host
::
ReferenceConvBwdWeight
<
2
,
InLayout
,
WeiLayout
,
OutLayout
,
InDataType
,
WeiDataType
,
WeiDataType
,
OutDataType
,
OutDataType
,
InElementOp
,
InElementOp
,
WeiElementOp
,
WeiElementOp
,
OutElementOp
>
;
OutElementOp
>
;
void
print_helper_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=no, 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
"
<<
"split_k"
<<
std
::
endl
;
}
ck
::
tensor_operation
::
device
::
ConvParams
parse_conv_params
(
int
num_dim_spatial
,
int
arg_idx
,
char
*
const
argv
[])
{
const
ck
::
index_t
N
=
std
::
stoi
(
argv
[
arg_idx
++
]);
const
ck
::
index_t
K
=
std
::
stoi
(
argv
[
arg_idx
++
]);
const
ck
::
index_t
C
=
std
::
stoi
(
argv
[
arg_idx
++
]);
std
::
vector
<
ck
::
index_t
>
filter_spatial_lengths
(
num_dim_spatial
);
std
::
vector
<
ck
::
index_t
>
input_spatial_lengths
(
num_dim_spatial
);
std
::
vector
<
ck
::
index_t
>
conv_filter_strides
(
num_dim_spatial
);
std
::
vector
<
ck
::
index_t
>
conv_filter_dilations
(
num_dim_spatial
);
std
::
vector
<
ck
::
index_t
>
input_left_pads
(
num_dim_spatial
);
std
::
vector
<
ck
::
index_t
>
input_right_pads
(
num_dim_spatial
);
for
(
int
i
=
0
;
i
<
num_dim_spatial
;
++
i
)
{
filter_spatial_lengths
[
i
]
=
std
::
stoi
(
argv
[
arg_idx
++
]);
}
for
(
int
i
=
0
;
i
<
num_dim_spatial
;
++
i
)
{
input_spatial_lengths
[
i
]
=
std
::
stoi
(
argv
[
arg_idx
++
]);
}
for
(
int
i
=
0
;
i
<
num_dim_spatial
;
++
i
)
{
conv_filter_strides
[
i
]
=
std
::
stoi
(
argv
[
arg_idx
++
]);
}
for
(
int
i
=
0
;
i
<
num_dim_spatial
;
++
i
)
{
conv_filter_dilations
[
i
]
=
std
::
stoi
(
argv
[
arg_idx
++
]);
}
for
(
int
i
=
0
;
i
<
num_dim_spatial
;
++
i
)
{
input_left_pads
[
i
]
=
std
::
stoi
(
argv
[
arg_idx
++
]);
}
for
(
int
i
=
0
;
i
<
num_dim_spatial
;
++
i
)
{
input_right_pads
[
i
]
=
std
::
stoi
(
argv
[
arg_idx
++
]);
}
return
ck
::
tensor_operation
::
device
::
ConvParams
{
num_dim_spatial
,
N
,
K
,
C
,
filter_spatial_lengths
,
input_spatial_lengths
,
conv_filter_strides
,
conv_filter_dilations
,
input_left_pads
,
input_right_pads
};
}
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
print_helper_msg
();
bool
do_verification
=
true
;
bool
do_verification
=
true
;
int
init_method
=
1
;
int
init_method
=
1
;
bool
time_kernel
=
false
;
bool
time_kernel
=
false
;
int
do_log
=
0
;
int
num_dim_spatial
=
2
;
int
split_k
=
4
;
ck
::
tensor_operation
::
device
::
ConvParams
params
{
// Conv shape
2
,
32
,
256
,
1024
,
{
3
,
3
},
{
14
,
14
},
{
2
,
2
},
{
1
,
1
},
{
1
,
1
},
{
1
,
1
}};
ck
::
index_t
N
=
128
;
ck
::
index_t
K
=
256
;
ck
::
index_t
split_k
=
4
;
ck
::
index_t
C
=
1024
;
ck
::
index_t
Y
=
3
;
if
(
argc
==
1
)
ck
::
index_t
X
=
3
;
ck
::
index_t
Hi
=
14
;
ck
::
index_t
Wi
=
14
;
ck
::
index_t
conv_stride_h
=
2
;
ck
::
index_t
conv_stride_w
=
2
;
ck
::
index_t
conv_dilation_h
=
1
;
ck
::
index_t
conv_dilation_w
=
1
;
ck
::
index_t
in_left_pad_h
=
0
;
ck
::
index_t
in_left_pad_w
=
0
;
ck
::
index_t
in_right_pad_h
=
0
;
ck
::
index_t
in_right_pad_w
=
0
;
if
(
argc
==
6
)
{
{
do_verification
=
std
::
stoi
(
argv
[
1
]);
// use default
init_method
=
std
::
stoi
(
argv
[
2
]);
time_kernel
=
std
::
stoi
(
argv
[
3
]);
do_log
=
std
::
stoi
(
argv
[
4
]);
split_k
=
std
::
stoi
(
argv
[
5
]);
}
}
else
if
(
argc
==
21
)
else
if
(
argc
==
4
)
{
{
do_verification
=
std
::
stoi
(
argv
[
1
]);
do_verification
=
std
::
stoi
(
argv
[
1
]);
init_method
=
std
::
stoi
(
argv
[
2
]);
init_method
=
std
::
stoi
(
argv
[
2
]);
time_kernel
=
std
::
stoi
(
argv
[
3
]);
time_kernel
=
std
::
stoi
(
argv
[
3
]);
do_log
=
std
::
stoi
(
argv
[
4
]);
split_k
=
std
::
stoi
(
argv
[
5
]);
N
=
std
::
stoi
(
argv
[
6
]);
K
=
std
::
stoi
(
argv
[
7
]);
C
=
std
::
stoi
(
argv
[
8
]);
Y
=
std
::
stoi
(
argv
[
9
]);
X
=
std
::
stoi
(
argv
[
10
]);
Hi
=
std
::
stoi
(
argv
[
11
]);
Wi
=
std
::
stoi
(
argv
[
12
]);
conv_stride_h
=
std
::
stoi
(
argv
[
13
]);
conv_stride_w
=
std
::
stoi
(
argv
[
14
]);
conv_dilation_h
=
std
::
stoi
(
argv
[
15
]);
conv_dilation_w
=
std
::
stoi
(
argv
[
16
]);
in_left_pad_h
=
std
::
stoi
(
argv
[
17
]);
in_left_pad_w
=
std
::
stoi
(
argv
[
18
]);
in_right_pad_h
=
std
::
stoi
(
argv
[
19
]);
in_right_pad_w
=
std
::
stoi
(
argv
[
20
]);
}
}
else
else
{
{
printf
(
"arg1: verification (0=no, 1=yes)
\n
"
);
do_verification
=
std
::
stoi
(
argv
[
1
]);
printf
(
"arg2: initialization (0=no init, 1=integer value, 2=decimal value)
\n
"
);
init_method
=
std
::
stoi
(
argv
[
2
]);
printf
(
"arg3: time kernel (0=n0, 1=yes)
\n
"
);
time_kernel
=
std
::
stoi
(
argv
[
3
]);
printf
(
"arg4: is show log (0=no, 1=yes)
\n
"
);
num_dim_spatial
=
std
::
stoi
(
argv
[
4
]);
printf
(
"arg5: split-k
\n
"
);
printf
(
"arg6 to 19: N, K, C, Y, X, Hi, Wi, Sy, Sx, Dy, Dx, LeftPy, LeftPx, RightPy, "
params
=
parse_conv_params
(
num_dim_spatial
,
5
,
argv
);
"RightPx
\n
"
);
exit
(
0
);
split_k
=
std
::
stoi
(
argv
[
5
+
3
+
6
*
num_dim_spatial
-
1
]);
split_k
=
std
::
max
(
1
,
split_k
);
}
}
const
ck
::
index_t
YEff
=
(
Y
-
1
)
*
conv_dilation_h
+
1
;
auto
f_nhwc_host_tensor_descriptor
=
const
ck
::
index_t
XEff
=
(
X
-
1
)
*
conv_dilation_w
+
1
;
[](
ck
::
index_t
n
,
ck
::
index_t
c
,
std
::
vector
<
ck
::
index_t
>
spatial_lengths
)
{
std
::
vector
<
std
::
size_t
>
nhwc_lengths
{
static_cast
<
std
::
size_t
>
(
n
),
const
ck
::
index_t
Ho
=
(
Hi
+
in_left_pad_h
+
in_right_pad_h
-
YEff
)
/
conv_stride_h
+
1
;
static_cast
<
std
::
size_t
>
(
c
)};
const
ck
::
index_t
Wo
=
(
Wi
+
in_left_pad_w
+
in_right_pad_w
-
XEff
)
/
conv_stride_w
+
1
;
nhwc_lengths
.
insert
(
nhwc_lengths
.
begin
()
+
1
,
spatial_lengths
.
begin
(),
spatial_lengths
.
end
());
const
std
::
vector
<
ck
::
index_t
>
conv_filter_strides
{{
conv_stride_h
,
conv_stride_w
}};
const
std
::
vector
<
ck
::
index_t
>
conv_filter_dilations
{{
conv_dilation_h
,
conv_dilation_w
}};
return
HostTensorDescriptor
(
nhwc_lengths
);
const
std
::
vector
<
ck
::
index_t
>
input_left_pads
{{
in_left_pad_h
,
in_left_pad_w
}};
};
const
std
::
vector
<
ck
::
index_t
>
input_right_pads
{{
in_right_pad_h
,
in_right_pad_w
}};
Tensor
<
InDataType
>
in_n_hi_wi_c
(
// tensor layout
f_nhwc_host_tensor_descriptor
(
params
.
N_
,
params
.
C_
,
params
.
input_spatial_lengths_
));
auto
f_host_tensor_descriptor
=
[](
std
::
size_t
N_
,
Tensor
<
WeiDataType
>
wei_k_y_x_c_host_result
(
std
::
size_t
C_
,
f_nhwc_host_tensor_descriptor
(
params
.
K_
,
params
.
C_
,
params
.
filter_spatial_lengths_
));
std
::
size_t
H
,
Tensor
<
WeiDataType
>
wei_k_y_x_c_device_result
(
std
::
size_t
W
,
f_nhwc_host_tensor_descriptor
(
params
.
K_
,
params
.
C_
,
params
.
filter_spatial_lengths_
));
auto
layout
)
{
Tensor
<
OutDataType
>
out_n_ho_wo_k
(
if
constexpr
(
ck
::
is_same
<
decltype
(
layout
),
ck
::
tensor_layout
::
convolution
::
NCHW
>::
value
||
f_nhwc_host_tensor_descriptor
(
params
.
N_
,
params
.
K_
,
params
.
GetOutputSpatialLengths
()));
ck
::
is_same
<
decltype
(
layout
),
ck
::
tensor_layout
::
convolution
::
KCYX
>::
value
||
ck
::
is_same
<
decltype
(
layout
),
ck
::
tensor_layout
::
convolution
::
NKHW
>::
value
)
std
::
cout
<<
"input: "
<<
in_n_hi_wi_c
.
mDesc
<<
std
::
endl
;
{
std
::
cout
<<
"weight: "
<<
wei_k_y_x_c_host_result
.
mDesc
<<
std
::
endl
;
return
HostTensorDescriptor
(
std
::
vector
<
std
::
size_t
>
({
N_
,
C_
,
H
,
W
}),
std
::
cout
<<
"output: "
<<
out_n_ho_wo_k
.
mDesc
<<
std
::
endl
;
std
::
vector
<
std
::
size_t
>
({
C_
*
H
*
W
,
H
*
W
,
W
,
1
}));
}
else
if
constexpr
(
ck
::
is_same
<
decltype
(
layout
),
ck
::
tensor_layout
::
convolution
::
NHWC
>::
value
||
ck
::
is_same
<
decltype
(
layout
),
ck
::
tensor_layout
::
convolution
::
KYXC
>::
value
||
ck
::
is_same
<
decltype
(
layout
),
ck
::
tensor_layout
::
convolution
::
NHWK
>::
value
)
{
return
HostTensorDescriptor
(
std
::
vector
<
std
::
size_t
>
({
N_
,
C_
,
H
,
W
}),
std
::
vector
<
std
::
size_t
>
({
C_
*
H
*
W
,
1
,
W
*
C_
,
C_
}));
}
};
Tensor
<
InDataType
>
in_n_c_hi_wi
(
f_host_tensor_descriptor
(
N
,
C
,
Hi
,
Wi
,
InLayout
{}));
Tensor
<
WeiDataType
>
wei_k_c_y_x_host_result
(
f_host_tensor_descriptor
(
K
,
C
,
Y
,
X
,
WeiLayout
{}));
Tensor
<
WeiDataType
>
wei_k_c_y_x_device_result
(
f_host_tensor_descriptor
(
K
,
C
,
Y
,
X
,
WeiLayout
{}));
Tensor
<
OutDataType
>
out_n_k_ho_wo
(
f_host_tensor_descriptor
(
N
,
K
,
Ho
,
Wo
,
OutLayout
{}));
std
::
cout
<<
"in_n_c_hi_wi: "
<<
in_n_c_hi_wi
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"wei_k_c_y_x: "
<<
wei_k_c_y_x_host_result
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"out_n_k_ho_wo: "
<<
out_n_k_ho_wo
.
mDesc
<<
std
::
endl
;
switch
(
init_method
)
switch
(
init_method
)
{
{
case
0
:
break
;
case
0
:
break
;
case
1
:
case
1
:
in_n_
c_
hi_wi
.
GenerateTensorValue
(
GeneratorTensor_2
<
InDataType
>
{
-
5
,
5
});
in_n_hi_wi
_c
.
GenerateTensorValue
(
GeneratorTensor_2
<
InDataType
>
{
-
5
,
5
});
out_n_
k_
ho_wo
.
GenerateTensorValue
(
GeneratorTensor_2
<
OutDataType
>
{
-
5
,
5
});
out_n_ho_wo
_k
.
GenerateTensorValue
(
GeneratorTensor_2
<
OutDataType
>
{
-
5
,
5
});
break
;
break
;
default:
default:
in_n_
c_
hi_wi
.
GenerateTensorValue
(
GeneratorTensor_
1
<
InDataType
>
{
1
});
in_n_hi_wi
_c
.
GenerateTensorValue
(
GeneratorTensor_
3
<
InDataType
>
{
0.0
,
1.0
});
out_n_
k_
ho_wo
.
GenerateTensorValue
(
GeneratorTensor_
1
<
OutDataType
>
{
1
});
out_n_ho_wo
_k
.
GenerateTensorValue
(
GeneratorTensor_
3
<
OutDataType
>
{
-
0.5
,
0.5
});
}
}
wei_k_c_y_x_device_result
.
GenerateTensorValue
(
GeneratorTensor_1
<
WeiDataType
>
{
0
});
DeviceMem
in_device_buf
(
sizeof
(
InDataType
)
*
in_n_
c_
hi_wi
.
mDesc
.
GetElementSpace
());
DeviceMem
in_device_buf
(
sizeof
(
InDataType
)
*
in_n_hi_wi
_c
.
mDesc
.
GetElementSpace
());
DeviceMem
wei_device_buf
(
sizeof
(
WeiDataType
)
*
DeviceMem
wei_device_buf
(
sizeof
(
WeiDataType
)
*
wei_k_c_y_x_device_result
.
mDesc
.
GetElementSpace
());
wei_k_y_x_c_device_result
.
mDesc
.
GetElementSpace
());
DeviceMem
out_device_buf
(
sizeof
(
OutDataType
)
*
out_n_k_ho_wo
.
mDesc
.
GetElementSpace
());
DeviceMem
out_device_buf
(
sizeof
(
OutDataType
)
*
out_n_ho_wo_k
.
mDesc
.
GetElementSpace
());
in_device_buf
.
ToDevice
(
in_n_hi_wi_c
.
mData
.
data
());
out_device_buf
.
ToDevice
(
out_n_ho_wo_k
.
mData
.
data
());
in_device_buf
.
ToDevice
(
in_n_c_hi_wi
.
mData
.
data
());
// wei_device_buf.SetZero();
out_device_buf
.
ToDevice
(
out_n_k_ho_wo
.
mData
.
data
());
wei_device_buf
.
ToDevice
(
wei_k_c_y_x_device_result
.
mData
.
data
());
// do GEMM
// do GEMM
auto
conv
=
DeviceConvBwdWeightInstance
{};
auto
conv
=
DeviceConvBwdWeightInstance
{};
...
@@ -224,16 +246,16 @@ int main(int argc, char* argv[])
...
@@ -224,16 +246,16 @@ int main(int argc, char* argv[])
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
()),
static_cast
<
OutDataType
*>
(
out_device_buf
.
GetDeviceBuffer
()),
static_cast
<
OutDataType
*>
(
out_device_buf
.
GetDeviceBuffer
()),
N
,
params
.
N_
,
K
,
params
.
K_
,
C
,
params
.
C_
,
std
::
vector
<
ck
::
index_t
>
{{
Hi
,
Wi
}}
,
params
.
input_spatial_lengths_
,
std
::
vector
<
ck
::
index_t
>
{{
Y
,
X
}}
,
params
.
filter_spatial_lengths_
,
std
::
vector
<
ck
::
index_t
>
{{
Ho
,
Wo
}}
,
params
.
output_spatial_lengths_
,
conv_filter_strides
,
params
.
conv_filter_strides
_
,
conv_filter_dilations
,
params
.
conv_filter_dilations
_
,
input_left_pads
,
params
.
input_left_pads
_
,
input_right_pads
,
params
.
input_right_pads
_
,
InElementOp
{},
InElementOp
{},
WeiElementOp
{},
WeiElementOp
{},
OutElementOp
{},
OutElementOp
{},
...
@@ -247,19 +269,16 @@ int main(int argc, char* argv[])
...
@@ -247,19 +269,16 @@ int main(int argc, char* argv[])
return
1
;
return
1
;
}
}
float
ave_time
=
invoker
.
Run
(
argument
,
StreamConfig
{
nullptr
,
time_kernel
});
float
avg_time
=
invoker
.
Run
(
argument
,
StreamConfig
{
nullptr
,
time_kernel
});
std
::
size_t
flop
=
std
::
size_t
(
2
)
*
N
*
K
*
Ho
*
Wo
*
C
*
Y
*
X
;
std
::
size_t
num_btype
=
sizeof
(
InDataType
)
*
(
N
*
C
*
Hi
*
Wi
)
+
std
::
size_t
flop
=
params
.
GetFlops
();
sizeof
(
WeiDataType
)
*
(
K
*
C
*
Y
*
X
)
+
std
::
size_t
num_btype
=
params
.
GetByte
<
InDataType
,
WeiDataType
,
OutDataType
>
();
sizeof
(
OutDataType
)
*
(
N
*
K
*
Ho
*
Wo
);
float
tflops
=
static_cast
<
float
>
(
flop
)
/
1.E9
/
av
e
_time
;
float
tflops
=
static_cast
<
float
>
(
flop
)
/
1.E9
/
av
g
_time
;
float
gb_per_sec
=
num_btype
/
1.E6
/
av
e
_time
;
float
gb_per_sec
=
num_btype
/
1.E6
/
av
g
_time
;
std
::
cout
<<
"Perf: "
<<
av
e
_time
<<
" ms, "
<<
tflops
<<
" TFlops, "
<<
gb_per_sec
<<
" GB/s"
std
::
cout
<<
"Perf: "
<<
av
g
_time
<<
" ms, "
<<
tflops
<<
" TFlops, "
<<
gb_per_sec
<<
" GB/s"
<<
std
::
endl
;
<<
std
::
endl
;
if
(
do_verification
)
if
(
do_verification
)
...
@@ -267,34 +286,25 @@ int main(int argc, char* argv[])
...
@@ -267,34 +286,25 @@ int main(int argc, char* argv[])
auto
ref_conv
=
ReferenceConvBwdWeightInstance
{};
auto
ref_conv
=
ReferenceConvBwdWeightInstance
{};
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_hi_wi
_c
,
wei_k_
c_
y_x_host_result
,
wei_k_y_x_
c_
host_result
,
out_n_
k_
ho_wo
,
out_n_ho_wo
_k
,
conv_filter_strides
,
params
.
conv_filter_strides
_
,
conv_filter_dilations
,
params
.
conv_filter_dilations
_
,
input_left_pads
,
params
.
input_left_pads
_
,
input_right_pads
,
params
.
input_right_pads
_
,
InElementOp
{},
InElementOp
{},
WeiElementOp
{},
WeiElementOp
{},
OutElementOp
{});
OutElementOp
{});
ref_invoker
.
Run
(
ref_argument
);
ref_invoker
.
Run
(
ref_argument
);
wei_device_buf
.
FromDevice
(
wei_k_c_y_x_device_result
.
mData
.
data
());
wei_device_buf
.
FromDevice
(
wei_k_y_x_c_device_result
.
mData
.
data
());
if
(
do_log
)
return
ck
::
utils
::
check_err
(
wei_k_y_x_c_device_result
.
mData
,
wei_k_y_x_c_host_result
.
mData
)
{
LogRangeAsType
<
float
>
(
std
::
cout
<<
"out: "
,
out_n_k_ho_wo
.
mData
,
","
)
<<
std
::
endl
;
LogRangeAsType
<
float
>
(
std
::
cout
<<
"in : "
,
in_n_c_hi_wi
.
mData
,
","
)
<<
std
::
endl
;
LogRangeAsType
<
float
>
(
std
::
cout
<<
"wei_device(after): "
,
wei_k_c_y_x_device_result
.
mData
,
","
)
<<
std
::
endl
;
LogRangeAsType
<
float
>
(
std
::
cout
<<
"wei_host : "
,
wei_k_c_y_x_host_result
.
mData
,
","
)
<<
std
::
endl
;
}
return
ck
::
utils
::
check_err
(
wei_k_c_y_x_device_result
.
mData
,
wei_k_c_y_x_host_result
.
mData
)
?
0
?
0
:
1
;
:
1
;
}
}
return
0
;
return
0
;
}
}
example/17_convnd_bwd_data_xdl/CMakeLists.txt
View file @
0be1cf14
add_example_executable
(
example_convnd_bwd_data_xdl convnd_bwd_data_xdl.cpp
)
add_example_executable
(
example_convnd_bwd_data_xdl convnd_bwd_data_xdl.cpp
)
target_link_libraries
(
example_convnd_bwd_data_xdl PRIVATE
conv_
util
)
target_link_libraries
(
example_convnd_bwd_data_xdl PRIVATE util
ity
)
example/17_convnd_bwd_data_xdl/convnd_bwd_data_common.hpp
0 → 100644
View file @
0be1cf14
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include <iostream>
#include <numeric>
#include <initializer_list>
#include <cstdlib>
#include "ck/ck.hpp"
#include "ck/tensor_operation/gpu/device/tensor_layout.hpp"
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/library/utility/convolution_parameter.hpp"
#include "ck/library/utility/device_memory.hpp"
#include "ck/library/utility/host_tensor.hpp"
#include "ck/library/utility/host_tensor_generator.hpp"
#include "ck/library/reference_tensor_operation/cpu/reference_conv_bwd_data.hpp"
ck
::
tensor_operation
::
device
::
ConvParams
parse_conv_params
(
int
num_dim_spatial
,
int
arg_idx
,
char
*
const
argv
[])
{
const
ck
::
index_t
N
=
std
::
stoi
(
argv
[
arg_idx
++
]);
const
ck
::
index_t
K
=
std
::
stoi
(
argv
[
arg_idx
++
]);
const
ck
::
index_t
C
=
std
::
stoi
(
argv
[
arg_idx
++
]);
std
::
vector
<
ck
::
index_t
>
filter_spatial_lengths
(
num_dim_spatial
);
std
::
vector
<
ck
::
index_t
>
input_spatial_lengths
(
num_dim_spatial
);
std
::
vector
<
ck
::
index_t
>
conv_filter_strides
(
num_dim_spatial
);
std
::
vector
<
ck
::
index_t
>
conv_filter_dilations
(
num_dim_spatial
);
std
::
vector
<
ck
::
index_t
>
input_left_pads
(
num_dim_spatial
);
std
::
vector
<
ck
::
index_t
>
input_right_pads
(
num_dim_spatial
);
for
(
int
i
=
0
;
i
<
num_dim_spatial
;
++
i
)
{
filter_spatial_lengths
[
i
]
=
std
::
stoi
(
argv
[
arg_idx
++
]);
}
for
(
int
i
=
0
;
i
<
num_dim_spatial
;
++
i
)
{
input_spatial_lengths
[
i
]
=
std
::
stoi
(
argv
[
arg_idx
++
]);
}
for
(
int
i
=
0
;
i
<
num_dim_spatial
;
++
i
)
{
conv_filter_strides
[
i
]
=
std
::
stoi
(
argv
[
arg_idx
++
]);
}
for
(
int
i
=
0
;
i
<
num_dim_spatial
;
++
i
)
{
conv_filter_dilations
[
i
]
=
std
::
stoi
(
argv
[
arg_idx
++
]);
}
for
(
int
i
=
0
;
i
<
num_dim_spatial
;
++
i
)
{
input_left_pads
[
i
]
=
std
::
stoi
(
argv
[
arg_idx
++
]);
}
for
(
int
i
=
0
;
i
<
num_dim_spatial
;
++
i
)
{
input_right_pads
[
i
]
=
std
::
stoi
(
argv
[
arg_idx
++
]);
}
return
ck
::
tensor_operation
::
device
::
ConvParams
{
num_dim_spatial
,
N
,
K
,
C
,
filter_spatial_lengths
,
input_spatial_lengths
,
conv_filter_strides
,
conv_filter_dilations
,
input_left_pads
,
input_right_pads
};
}
void
print_helper_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=no, 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
;
}
template
<
ck
::
index_t
NDimSpatial
,
typename
InDataType
,
typename
WeiDataType
,
typename
OutDataType
,
typename
AccDataType
,
typename
InElementOp
,
typename
WeiElementOp
,
typename
OutElementOp
,
typename
DeviceConvNdBwdDataInstance
>
int
run_conv_bwd_data_nhwc
(
bool
do_verification
,
int
init_method
,
bool
time_kernel
,
const
ck
::
tensor_operation
::
device
::
ConvParams
&
params
,
const
InElementOp
&
in_element_op
,
const
WeiElementOp
&
wei_element_op
,
const
OutElementOp
&
out_element_op
)
{
auto
f_nhwc_host_tensor_descriptor
=
[](
ck
::
index_t
n
,
ck
::
index_t
c
,
std
::
vector
<
ck
::
index_t
>
spatial_lengths
)
{
std
::
vector
<
std
::
size_t
>
nhwc_lengths
{
static_cast
<
std
::
size_t
>
(
n
),
static_cast
<
std
::
size_t
>
(
c
)};
nhwc_lengths
.
insert
(
nhwc_lengths
.
begin
()
+
1
,
spatial_lengths
.
begin
(),
spatial_lengths
.
end
());
return
HostTensorDescriptor
(
nhwc_lengths
);
};
Tensor
<
InDataType
>
in_n_hi_wi_c_host
(
f_nhwc_host_tensor_descriptor
(
params
.
N_
,
params
.
C_
,
params
.
input_spatial_lengths_
));
Tensor
<
InDataType
>
in_n_hi_wi_c_device
(
f_nhwc_host_tensor_descriptor
(
params
.
N_
,
params
.
C_
,
params
.
input_spatial_lengths_
));
Tensor
<
WeiDataType
>
wei_k_y_x_c
(
f_nhwc_host_tensor_descriptor
(
params
.
K_
,
params
.
C_
,
params
.
filter_spatial_lengths_
));
Tensor
<
OutDataType
>
out_n_ho_wo_k
(
f_nhwc_host_tensor_descriptor
(
params
.
N_
,
params
.
K_
,
params
.
GetOutputSpatialLengths
()));
std
::
cout
<<
"in_n_hi_wi_c: "
<<
in_n_hi_wi_c_host
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"wei_k_y_x_c: "
<<
wei_k_y_x_c
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"out_n_ho_wo_k: "
<<
out_n_ho_wo_k
.
mDesc
<<
std
::
endl
;
switch
(
init_method
)
{
case
0
:
break
;
case
1
:
out_n_ho_wo_k
.
GenerateTensorValue
(
GeneratorTensor_2
<
OutDataType
>
{
-
5
,
5
});
wei_k_y_x_c
.
GenerateTensorValue
(
GeneratorTensor_2
<
WeiDataType
>
{
-
5
,
5
});
break
;
default:
out_n_ho_wo_k
.
GenerateTensorValue
(
GeneratorTensor_1
<
OutDataType
>
{
1
});
wei_k_y_x_c
.
GenerateTensorValue
(
GeneratorTensor_1
<
WeiDataType
>
{
1
});
}
DeviceMem
in_device_buf
(
sizeof
(
InDataType
)
*
in_n_hi_wi_c_device
.
mDesc
.
GetElementSpace
());
DeviceMem
wei_device_buf
(
sizeof
(
WeiDataType
)
*
wei_k_y_x_c
.
mDesc
.
GetElementSpace
());
DeviceMem
out_device_buf
(
sizeof
(
OutDataType
)
*
out_n_ho_wo_k
.
mDesc
.
GetElementSpace
());
out_device_buf
.
ToDevice
(
out_n_ho_wo_k
.
mData
.
data
());
wei_device_buf
.
ToDevice
(
wei_k_y_x_c
.
mData
.
data
());
// reset input to zero
in_device_buf
.
SetZero
();
// do GEMM
auto
conv
=
DeviceConvNdBwdDataInstance
{};
auto
invoker
=
conv
.
MakeInvoker
();
auto
argument
=
conv
.
MakeArgument
(
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_
,
params
.
GetOutputSpatialLengths
(),
params
.
conv_filter_strides_
,
params
.
conv_filter_dilations_
,
params
.
input_left_pads_
,
params
.
input_right_pads_
,
in_element_op
,
wei_element_op
,
out_element_op
);
if
(
!
conv
.
IsSupportedArgument
(
argument
))
{
throw
std
::
runtime_error
(
"wrong! device_conv with the specified compilation parameters does "
"not support this Conv problem"
);
}
float
ave_time
=
invoker
.
Run
(
argument
,
StreamConfig
{
nullptr
,
time_kernel
});
std
::
size_t
flop
=
params
.
GetFlops
();
std
::
size_t
num_btype
=
params
.
GetByte
<
InDataType
,
WeiDataType
,
OutDataType
>
();
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
ref_conv
=
ck
::
tensor_operation
::
host
::
ReferenceConvBwdData
<
NDimSpatial
,
ck
::
tensor_layout
::
convolution
::
NHWC
,
ck
::
tensor_layout
::
convolution
::
KYXC
,
ck
::
tensor_layout
::
convolution
::
NHWK
,
InDataType
,
WeiDataType
,
OutDataType
,
InElementOp
,
WeiElementOp
,
OutElementOp
>
();
auto
ref_invoker
=
ref_conv
.
MakeInvoker
();
auto
ref_argument
=
ref_conv
.
MakeArgument
(
in_n_hi_wi_c_host
,
wei_k_y_x_c
,
out_n_ho_wo_k
,
params
.
conv_filter_strides_
,
params
.
conv_filter_dilations_
,
params
.
input_left_pads_
,
params
.
input_right_pads_
,
in_element_op
,
wei_element_op
,
out_element_op
);
ref_invoker
.
Run
(
ref_argument
);
in_device_buf
.
FromDevice
(
in_n_hi_wi_c_device
.
mData
.
data
());
return
ck
::
utils
::
check_err
(
in_n_hi_wi_c_device
.
mData
,
in_n_hi_wi_c_host
.
mData
)
?
0
:
1
;
}
return
0
;
}
example/17_convnd_bwd_data_xdl/convnd_bwd_data_xdl.cpp
View file @
0be1cf14
// SPDX-License-Identifier: MIT
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include <iostream>
#include "convnd_bwd_data_common.hpp"
#include <numeric>
#include <initializer_list>
#include <cstdlib>
#include "ck/ck.hpp"
#include "ck/tensor_operation/gpu/device/device_convnd_bwd_data_nwc_kxc_nwk_xdl.hpp"
#include "ck/tensor_operation/gpu/device/tensor_layout.hpp"
#include "ck/tensor_operation/gpu/device/device_convnd_bwd_data_xdl_ndhwc_kzyxc_ndhwk.hpp"
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/library/utility/convolution_parameter.hpp"
#include "ck/library/utility/device_memory.hpp"
#include "ck/library/utility/host_tensor.hpp"
#include "ck/library/utility/host_tensor_generator.hpp"
#include "ck/library/reference_tensor_operation/cpu/reference_conv_bwd_data.hpp"
using
InDataType
=
ck
::
half_t
;
using
InDataType
=
ck
::
half_t
;
using
WeiDataType
=
ck
::
half_t
;
using
WeiDataType
=
ck
::
half_t
;
...
@@ -29,324 +16,137 @@ using S = ck::Sequence<Is...>;
...
@@ -29,324 +16,137 @@ using S = ck::Sequence<Is...>;
using
InElementOp
=
ck
::
tensor_operation
::
element_wise
::
PassThrough
;
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
::
Default
;
ck
::
tensor_operation
::
device
::
ConvolutionBackwardDataSpecialization
::
Default
;
using
DeviceConvBwdDataBasePtr
=
template
<
ck
::
index_t
NDimSpatial
>
ck
::
tensor_operation
::
device
::
DeviceConvBwdDataPtr
<
InElementOp
,
WeiElementOp
,
OutElementOp
>
;
using
DeviceConvNdBwdDataInstance
=
ck
::
tensor_operation
::
device
::
DeviceConvNdBwdDataNwcKxcNwk_Xdl
<
NDimSpatial
,
// NDimSpatial
template
<
ck
::
index_t
NumDimSpatial
>
InDataType
,
// InDataType
using
DeviceConvNDBwdDataInstance
=
ck
::
tensor_operation
::
device
::
WeiDataType
,
// WeiDataType
DeviceConvndBwdDataXdl_Input_N_Di_Hi_Wi_C_Weight_K_Z_Y_X_C_Output_N_Do_Ho_Wo_K
<
OutDataType
,
// OutDataType
InDataType
,
// InDataType
AccDataType
,
// AccDataType
WeiDataType
,
// WeiDataType
InElementOp
,
// InElementwiseOperation
OutDataType
,
// OutDataType
WeiElementOp
,
// WeiElementwiseOperation
AccDataType
,
// AccDataType
OutElementOp
,
// OutElementwiseOperation
InElementOp
,
// InElementwiseOperation
ConvBwdDefault
,
// ConvolutionBackwardDataSpecialization
WeiElementOp
,
// WeiElementwiseOperation
256
,
// BlockSize
OutElementOp
,
// OutElementwiseOperation
128
,
// MPerBlock
ConvBwdDefault
,
// ConvolutionBackwardDataSpecialization
128
,
// NPerBlock
NumDimSpatial
,
// NumDimSpatial
4
,
// K0PerBlock
256
,
// BlockSize
8
,
// K1
128
,
// MPerBlock
32
,
// MPerXdl
128
,
// NPerBlock
32
,
// NPerXdl
4
,
// K0PerBlock
2
,
// MXdlPerWave
8
,
// K1
2
,
// NXdlPerWave
32
,
// MPerXdl
S
<
4
,
64
,
1
>
,
// ABlockTransferThreadClusterLengths_K0_M_K1
32
,
// NPerXdl
S
<
1
,
0
,
2
>
,
// ABlockTransferThreadClusterArrangeOrder
2
,
// MXdlPerWave
S
<
1
,
0
,
2
>
,
// ABlockTransferSrcAccessOrder
2
,
// NXdlPerWave
2
,
// ABlockTransferSrcVectorDim
S
<
4
,
64
,
1
>
,
// ABlockTransferThreadClusterLengths_K0_M_K1
8
,
// ABlockTransferSrcScalarPerVector
S
<
1
,
0
,
2
>
,
// ABlockTransferThreadClusterArrangeOrder
8
,
// ABlockTransferDstScalarPerVector_K1
S
<
1
,
0
,
2
>
,
// ABlockTransferSrcAccessOrder
true
,
// ABlockLdsAddExtraM
2
,
// ABlockTransferSrcVectorDim
S
<
4
,
64
,
1
>
,
// BBlockTransferThreadClusterLengths_K0_N_K1
8
,
// ABlockTransferSrcScalarPerVector
S
<
2
,
0
,
1
>
,
// BBlockTransferThreadClusterArrangeOrder
8
,
// ABlockTransferDstScalarPerVector_K1
S
<
0
,
2
,
1
>
,
// BBlockTransferSrcAccessOrder
true
,
// ABlockLdsAddExtraM
1
,
// BBlockTransferSrcVectorDim
S
<
4
,
64
,
1
>
,
// BBlockTransferThreadClusterLengths_K0_N_K1
2
,
// BBlockTransferSrcScalarPerVector
S
<
2
,
0
,
1
>
,
// BBlockTransferThreadClusterArrangeOrder
8
,
// BBlockTransferDstScalarPerVector_K1
S
<
0
,
2
,
1
>
,
// BBlockTransferSrcAccessOrder
true
,
// BBlockLdsAddExtraN
1
,
// BBlockTransferSrcVectorDim
7
,
2
,
// BBlockTransferSrcScalarPerVector
1
>
;
// GemmCThreadTransferDstScalarPerVector
8
,
// BBlockTransferDstScalarPerVector_K1
true
,
// BBlockLdsAddExtraN
7
,
1
>
;
// GemmCThreadTransferDstScalarPerVector
template
<
ck
::
index_t
NumDimSpatial
>
using
ReferenceConvBwdDataInstance
=
ck
::
tensor_operation
::
host
::
ReferenceConvBwdData
<
InDataType
,
WeiDataType
,
OutDataType
,
AccDataType
,
InElementOp
,
WeiElementOp
,
OutElementOp
,
NumDimSpatial
>
;
void
print_use_msg
()
{
std
::
cout
<<
"arg1: verification (0=no, 1=yes)
\n
"
<<
"arg2: initialization (0=no init, 1=random value, 2= init to 1 )
\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
::
tensor_operation
::
device
::
ConvParams
parse_conv_params
(
int
num_dim_spatial
,
char
*
argv
[])
{
// (N, K, C) + num_dim_spatial * 6 (filter, input, strides, dilations, pad left, pad right)
ck
::
tensor_operation
::
device
::
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
;
}
DeviceConvBwdDataBasePtr
get_conv_instance
(
int
num_dim_spatial
)
{
switch
(
num_dim_spatial
)
{
case
3
:
{
return
std
::
make_unique
<
DeviceConvNDBwdDataInstance
<
3
>>
();
}
case
2
:
{
return
std
::
make_unique
<
DeviceConvNDBwdDataInstance
<
2
>>
();
}
case
1
:
{
return
std
::
make_unique
<
DeviceConvNDBwdDataInstance
<
1
>>
();
}
default:
{
throw
std
::
runtime_error
(
"Unsupported number of spatial dimensions provided!"
);
}
}
}
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
print_helper_msg
();
bool
do_verification
=
true
;
bool
do_verification
=
true
;
int
init_method
=
1
;
int
init_method
=
1
;
bool
time_kernel
=
false
;
bool
time_kernel
=
false
;
int
num_dim_spatial
=
2
;
int
num_dim_spatial
=
2
;
ck
::
tensor_operation
::
device
::
ConvParams
params
;
ck
::
tensor_operation
::
device
::
ConvParams
params
{
params
.
C_
=
128
;
2
,
128
,
256
,
256
,
{
3
,
3
},
{
71
,
71
},
{
2
,
2
},
{
1
,
1
},
{
1
,
1
},
{
1
,
1
}}
;
if
(
argc
==
4
)
if
(
argc
==
1
)
{
// use default
}
else
if
(
argc
==
4
)
{
{
do_verification
=
std
::
stoi
(
argv
[
1
]);
do_verification
=
std
::
stoi
(
argv
[
1
]);
init_method
=
std
::
stoi
(
argv
[
2
]);
init_method
=
std
::
stoi
(
argv
[
2
]);
time_kernel
=
std
::
stoi
(
argv
[
3
]);
time_kernel
=
std
::
stoi
(
argv
[
3
]);
}
}
else
if
(
argc
>
4
)
else
{
{
do_verification
=
std
::
stoi
(
argv
[
1
]);
do_verification
=
std
::
stoi
(
argv
[
1
]);
init_method
=
std
::
stoi
(
argv
[
2
]);
init_method
=
std
::
stoi
(
argv
[
2
]);
time_kernel
=
std
::
stoi
(
argv
[
3
]);
time_kernel
=
std
::
stoi
(
argv
[
3
]);
num_dim_spatial
=
std
::
stoi
(
argv
[
4
]);
num_dim_spatial
=
std
::
stoi
(
argv
[
4
]);
// check args number
int
conv_args
=
3
+
num_dim_spatial
*
6
;
int
cmdline_nargs
=
conv_args
+
5
;
if
(
cmdline_nargs
!=
argc
)
{
print_use_msg
();
exit
(
1
);
}
params
=
parse_conv_params
(
num_dim_spatial
,
argv
);
params
=
parse_conv_params
(
num_dim_spatial
,
5
,
argv
);
}
else
if
(
argc
!=
1
)
{
print_use_msg
();
exit
(
1
);
}
}
std
::
vector
<
std
::
size_t
>
input_dims
{
static_cast
<
std
::
size_t
>
(
params
.
N_
),
const
auto
in_element_op
=
InElementOp
{};
static_cast
<
std
::
size_t
>
(
params
.
C_
)};
const
auto
wei_element_op
=
WeiElementOp
{};
input_dims
.
insert
(
std
::
end
(
input_dims
),
const
auto
out_element_op
=
OutElementOp
{};
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_
),
if
(
num_dim_spatial
==
1
)
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
>
in_n_c_hi_wi_host_result
(
ck
::
utils
::
conv
::
get_input_host_tensor_descriptor
(
input_dims
,
num_dim_spatial
));
Tensor
<
InDataType
>
in_n_c_hi_wi_device_result
(
ck
::
utils
::
conv
::
get_input_host_tensor_descriptor
(
input_dims
,
num_dim_spatial
));
Tensor
<
WeiDataType
>
wei_k_c_y_x
(
ck
::
utils
::
conv
::
get_filters_host_tensor_descriptor
(
filter_dims
,
num_dim_spatial
));
Tensor
<
OutDataType
>
out_n_k_ho_wo
(
ck
::
utils
::
conv
::
get_output_host_tensor_descriptor
(
output_dims
,
num_dim_spatial
));
std
::
cout
<<
"in_n_c_hi_wi: "
<<
in_n_c_hi_wi_host_result
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"wei_k_c_y_x: "
<<
wei_k_c_y_x
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"out_n_k_ho_wo: "
<<
out_n_k_ho_wo
.
mDesc
<<
std
::
endl
;
switch
(
init_method
)
{
{
case
0
:
break
;
return
run_conv_bwd_data_nhwc
<
1
,
case
1
:
InDataType
,
out_n_k_ho_wo
.
GenerateTensorValue
(
GeneratorTensor_3
<
OutDataType
>
{
-
0.2
,
0.2
});
WeiDataType
,
wei_k_c_y_x
.
GenerateTensorValue
(
GeneratorTensor_3
<
WeiDataType
>
{
-
0.2
,
0.2
});
OutDataType
,
break
;
AccDataType
,
default:
InElementOp
,
out_n_k_ho_wo
.
GenerateTensorValue
(
GeneratorTensor_1
<
OutDataType
>
{
1
});
WeiElementOp
,
wei_k_c_y_x
.
GenerateTensorValue
(
GeneratorTensor_1
<
WeiDataType
>
{
1
});
OutElementOp
,
}
DeviceConvNdBwdDataInstance
<
1
>>
(
do_verification
,
init_method
,
DeviceMem
in_device_buf
(
sizeof
(
InDataType
)
*
time_kernel
,
in_n_c_hi_wi_device_result
.
mDesc
.
GetElementSpace
());
params
,
DeviceMem
wei_device_buf
(
sizeof
(
WeiDataType
)
*
wei_k_c_y_x
.
mDesc
.
GetElementSpace
());
in_element_op
,
DeviceMem
out_device_buf
(
sizeof
(
OutDataType
)
*
out_n_k_ho_wo
.
mDesc
.
GetElementSpace
());
wei_element_op
,
out_element_op
);
out_device_buf
.
ToDevice
(
out_n_k_ho_wo
.
mData
.
data
());
}
wei_device_buf
.
ToDevice
(
wei_k_c_y_x
.
mData
.
data
());
else
if
(
num_dim_spatial
==
2
)
// reset input to zero
in_device_buf
.
SetZero
();
// 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
(
return
run_conv_bwd_data_nhwc
<
2
,
"wrong! device_conv with the specified compilation parameters does "
InDataType
,
"not support this Conv problem"
);
WeiDataType
,
}
OutDataType
,
AccDataType
,
float
ave_time
=
invoker
->
Run
(
argument
.
get
(),
StreamConfig
{
nullptr
,
time_kernel
});
InElementOp
,
WeiElementOp
,
std
::
size_t
flop
=
ck
::
utils
::
conv
::
get_flops
(
OutElementOp
,
params
.
N_
,
params
.
C_
,
params
.
K_
,
params
.
filter_spatial_lengths_
,
output_spatial_lengths
);
DeviceConvNdBwdDataInstance
<
2
>>
(
do_verification
,
std
::
size_t
num_btype
=
ck
::
utils
::
conv
::
get_btype
<
InDataType
,
WeiDataType
,
OutDataType
>
(
init_method
,
params
.
N_
,
time_kernel
,
params
.
C_
,
params
,
params
.
K_
,
in_element_op
,
params
.
input_spatial_lengths_
,
wei_element_op
,
params
.
filter_spatial_lengths_
,
out_element_op
);
output_spatial_lengths
);
}
else
if
(
num_dim_spatial
==
3
)
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
=
[
&
](
const
auto
&
ref_conv
)
{
return
run_conv_bwd_data_nhwc
<
3
,
auto
ref_invoker
=
ref_conv
.
MakeInvoker
();
InDataType
,
WeiDataType
,
auto
ref_argument
=
ref_conv
.
MakeArgument
(
in_n_c_hi_wi_host_result
,
OutDataType
,
wei_k_c_y_x
,
AccDataType
,
out_n_k_ho_wo
,
InElementOp
,
params
.
conv_filter_strides_
,
WeiElementOp
,
params
.
conv_filter_dilations_
,
OutElementOp
,
params
.
input_left_pads_
,
DeviceConvNdBwdDataInstance
<
3
>>
(
do_verification
,
params
.
input_right_pads_
,
init_method
,
InElementOp
{},
time_kernel
,
WeiElementOp
{},
params
,
OutElementOp
{});
in_element_op
,
wei_element_op
,
ref_invoker
.
Run
(
ref_argument
);
out_element_op
);
in_device_buf
.
FromDevice
(
in_n_c_hi_wi_device_result
.
mData
.
data
());
return
ck
::
utils
::
check_err
(
in_n_c_hi_wi_device_result
.
mData
,
in_n_c_hi_wi_host_result
.
mData
)
?
0
:
1
;
};
switch
(
num_dim_spatial
)
{
case
3
:
{
auto
ref_conv
=
ReferenceConvBwdDataInstance
<
3
>
();
return
verify_f
(
ref_conv
);
}
case
2
:
{
auto
ref_conv
=
ReferenceConvBwdDataInstance
<
2
>
();
return
verify_f
(
ref_conv
);
}
case
1
:
{
auto
ref_conv
=
ReferenceConvBwdDataInstance
<
1
>
();
return
verify_f
(
ref_conv
);
}
default:
{
throw
std
::
runtime_error
(
"Unsupported number of spatial dimensions provided!"
);
}
}
}
}
return
0
;
return
0
;
}
}
example/20_convnd_bwd_weight_xdl/CMakeLists.txt
View file @
0be1cf14
add_example_executable
(
example_convnd_bwd_weight_xdl convnd_bwd_weight_xdl.cpp
)
add_example_executable
(
example_convnd_bwd_weight_xdl_fp16 convnd_bwd_weight_xdl_fp16.cpp
)
add_example_executable
(
example_convnd_bwd_weight_xdl_bf16_splitk convnd_bwd_weight_xdl_bf16_splitk.cpp
)
add_example_executable
(
example_convnd_bwd_weight_xdl_bf16 convnd_bwd_weight_xdl_bf16.cpp
)
target_link_libraries
(
example_convnd_bwd_weight_xdl PRIVATE conv_util
)
target_link_libraries
(
example_convnd_bwd_weight_xdl_bf16_splitk PRIVATE conv_util
)
target_link_libraries
(
example_convnd_bwd_weight_xdl_fp16 PRIVATE utility
)
\ No newline at end of file
target_link_libraries
(
example_convnd_bwd_weight_xdl_bf16 PRIVATE utility
)
example/20_convnd_bwd_weight_xdl/convnd_bwd_weight_common.hpp
0 → 100644
View file @
0be1cf14
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include <iostream>
#include <numeric>
#include <initializer_list>
#include <cstdlib>
#include "ck/ck.hpp"
#include "ck/tensor_operation/gpu/device/tensor_layout.hpp"
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/library/utility/convolution_parameter.hpp"
#include "ck/library/utility/device_memory.hpp"
#include "ck/library/utility/host_tensor.hpp"
#include "ck/library/utility/host_tensor_generator.hpp"
#include "ck/library/reference_tensor_operation/cpu/reference_conv_backward_weight.hpp"
void
print_helper_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=no, 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
"
<<
"split_k"
<<
std
::
endl
;
}
ck
::
tensor_operation
::
device
::
ConvParams
parse_conv_params
(
int
num_dim_spatial
,
int
arg_idx
,
char
*
const
argv
[])
{
const
ck
::
index_t
N
=
std
::
stoi
(
argv
[
arg_idx
++
]);
const
ck
::
index_t
K
=
std
::
stoi
(
argv
[
arg_idx
++
]);
const
ck
::
index_t
C
=
std
::
stoi
(
argv
[
arg_idx
++
]);
std
::
vector
<
ck
::
index_t
>
filter_spatial_lengths
(
num_dim_spatial
);
std
::
vector
<
ck
::
index_t
>
input_spatial_lengths
(
num_dim_spatial
);
std
::
vector
<
ck
::
index_t
>
conv_filter_strides
(
num_dim_spatial
);
std
::
vector
<
ck
::
index_t
>
conv_filter_dilations
(
num_dim_spatial
);
std
::
vector
<
ck
::
index_t
>
input_left_pads
(
num_dim_spatial
);
std
::
vector
<
ck
::
index_t
>
input_right_pads
(
num_dim_spatial
);
for
(
int
i
=
0
;
i
<
num_dim_spatial
;
++
i
)
{
filter_spatial_lengths
[
i
]
=
std
::
stoi
(
argv
[
arg_idx
++
]);
}
for
(
int
i
=
0
;
i
<
num_dim_spatial
;
++
i
)
{
input_spatial_lengths
[
i
]
=
std
::
stoi
(
argv
[
arg_idx
++
]);
}
for
(
int
i
=
0
;
i
<
num_dim_spatial
;
++
i
)
{
conv_filter_strides
[
i
]
=
std
::
stoi
(
argv
[
arg_idx
++
]);
}
for
(
int
i
=
0
;
i
<
num_dim_spatial
;
++
i
)
{
conv_filter_dilations
[
i
]
=
std
::
stoi
(
argv
[
arg_idx
++
]);
}
for
(
int
i
=
0
;
i
<
num_dim_spatial
;
++
i
)
{
input_left_pads
[
i
]
=
std
::
stoi
(
argv
[
arg_idx
++
]);
}
for
(
int
i
=
0
;
i
<
num_dim_spatial
;
++
i
)
{
input_right_pads
[
i
]
=
std
::
stoi
(
argv
[
arg_idx
++
]);
}
return
ck
::
tensor_operation
::
device
::
ConvParams
{
num_dim_spatial
,
N
,
K
,
C
,
filter_spatial_lengths
,
input_spatial_lengths
,
conv_filter_strides
,
conv_filter_dilations
,
input_left_pads
,
input_right_pads
};
}
template
<
ck
::
index_t
NDimSpatial
,
typename
InDataType
,
typename
WeiDataType
,
typename
OutDataType
,
typename
AccDataType
,
typename
InElementOp
,
typename
WeiElementOp
,
typename
OutElementOp
,
typename
DeviceConvBwdWeightInstance
>
int
run_conv_bwd_weight_nhwc
(
bool
do_verification
,
int
init_method
,
bool
time_kernel
,
const
ck
::
tensor_operation
::
device
::
ConvParams
&
params
,
const
InElementOp
&
in_element_op
,
const
WeiElementOp
&
wei_element_op
,
const
OutElementOp
&
out_element_op
,
ck
::
index_t
split_k
)
{
auto
f_nhwc_host_tensor_descriptor
=
[](
ck
::
index_t
n
,
ck
::
index_t
c
,
std
::
vector
<
ck
::
index_t
>
spatial_lengths
)
{
std
::
vector
<
std
::
size_t
>
nhwc_lengths
{
static_cast
<
std
::
size_t
>
(
n
),
static_cast
<
std
::
size_t
>
(
c
)};
nhwc_lengths
.
insert
(
nhwc_lengths
.
begin
()
+
1
,
spatial_lengths
.
begin
(),
spatial_lengths
.
end
());
return
HostTensorDescriptor
(
nhwc_lengths
);
};
Tensor
<
InDataType
>
in_n_hi_wi_c
(
f_nhwc_host_tensor_descriptor
(
params
.
N_
,
params
.
C_
,
params
.
input_spatial_lengths_
));
Tensor
<
WeiDataType
>
wei_k_y_x_c_host_result
(
f_nhwc_host_tensor_descriptor
(
params
.
K_
,
params
.
C_
,
params
.
filter_spatial_lengths_
));
Tensor
<
WeiDataType
>
wei_k_y_x_c_device_result
(
f_nhwc_host_tensor_descriptor
(
params
.
K_
,
params
.
C_
,
params
.
filter_spatial_lengths_
));
Tensor
<
OutDataType
>
out_n_ho_wo_k
(
f_nhwc_host_tensor_descriptor
(
params
.
N_
,
params
.
K_
,
params
.
GetOutputSpatialLengths
()));
std
::
cout
<<
"input: "
<<
in_n_hi_wi_c
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"weight: "
<<
wei_k_y_x_c_host_result
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"output: "
<<
out_n_ho_wo_k
.
mDesc
<<
std
::
endl
;
switch
(
init_method
)
{
case
0
:
break
;
case
1
:
in_n_hi_wi_c
.
GenerateTensorValue
(
GeneratorTensor_2
<
InDataType
>
{
-
5
,
5
});
out_n_ho_wo_k
.
GenerateTensorValue
(
GeneratorTensor_2
<
OutDataType
>
{
-
5
,
5
});
break
;
default:
in_n_hi_wi_c
.
GenerateTensorValue
(
GeneratorTensor_3
<
InDataType
>
{
0.0
,
1.0
});
out_n_ho_wo_k
.
GenerateTensorValue
(
GeneratorTensor_3
<
OutDataType
>
{
-
0.5
,
0.5
});
}
DeviceMem
in_device_buf
(
sizeof
(
InDataType
)
*
in_n_hi_wi_c
.
mDesc
.
GetElementSpace
());
DeviceMem
wei_device_buf
(
sizeof
(
WeiDataType
)
*
wei_k_y_x_c_device_result
.
mDesc
.
GetElementSpace
());
DeviceMem
out_device_buf
(
sizeof
(
OutDataType
)
*
out_n_ho_wo_k
.
mDesc
.
GetElementSpace
());
in_device_buf
.
ToDevice
(
in_n_hi_wi_c
.
mData
.
data
());
out_device_buf
.
ToDevice
(
out_n_ho_wo_k
.
mData
.
data
());
// init to 0
wei_device_buf
.
SetZero
();
// do GEMM
auto
conv
=
DeviceConvBwdWeightInstance
{};
auto
invoker
=
conv
.
MakeInvoker
();
auto
argument
=
conv
.
MakeArgument
(
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_
,
params
.
output_spatial_lengths_
,
params
.
conv_filter_strides_
,
params
.
conv_filter_dilations_
,
params
.
input_left_pads_
,
params
.
input_right_pads_
,
in_element_op
,
wei_element_op
,
out_element_op
,
split_k
);
if
(
!
conv
.
IsSupportedArgument
(
argument
))
{
std
::
cout
<<
"wrong! device_conv with the specified compilation parameters does "
"not support this Conv problem"
<<
std
::
endl
;
return
1
;
}
float
avg_time
=
invoker
.
Run
(
argument
,
StreamConfig
{
nullptr
,
time_kernel
});
std
::
size_t
flop
=
params
.
GetFlops
();
std
::
size_t
num_btype
=
params
.
GetByte
<
InDataType
,
WeiDataType
,
OutDataType
>
();
float
tflops
=
static_cast
<
float
>
(
flop
)
/
1.E9
/
avg_time
;
float
gb_per_sec
=
num_btype
/
1.E6
/
avg_time
;
std
::
cout
<<
"Perf: "
<<
avg_time
<<
" ms, "
<<
tflops
<<
" TFlops, "
<<
gb_per_sec
<<
" GB/s"
<<
conv
.
GetTypeString
()
<<
std
::
endl
;
if
(
do_verification
)
{
auto
ref_conv
=
ck
::
tensor_operation
::
host
::
ReferenceConvBwdWeight
<
2
,
ck
::
tensor_layout
::
convolution
::
NHWC
,
ck
::
tensor_layout
::
convolution
::
KYXC
,
ck
::
tensor_layout
::
convolution
::
NHWK
,
InDataType
,
WeiDataType
,
OutDataType
,
InElementOp
,
WeiElementOp
,
OutElementOp
>
{};
auto
ref_invoker
=
ref_conv
.
MakeInvoker
();
auto
ref_argument
=
ref_conv
.
MakeArgument
(
in_n_hi_wi_c
,
wei_k_y_x_c_host_result
,
out_n_ho_wo_k
,
params
.
conv_filter_strides_
,
params
.
conv_filter_dilations_
,
params
.
input_left_pads_
,
params
.
input_right_pads_
,
InElementOp
{},
WeiElementOp
{},
OutElementOp
{});
ref_invoker
.
Run
(
ref_argument
);
wei_device_buf
.
FromDevice
(
wei_k_y_x_c_device_result
.
mData
.
data
());
return
ck
::
utils
::
check_err
(
wei_k_y_x_c_device_result
.
mData
,
wei_k_y_x_c_host_result
.
mData
)
?
0
:
1
;
}
return
0
;
}
example/20_convnd_bwd_weight_xdl/convnd_bwd_weight_xdl.cpp
deleted
100644 → 0
View file @
b054669b
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include <iostream>
#include <numeric>
#include <initializer_list>
#include <cstdlib>
#include "ck/ck.hpp"
#include "ck/tensor_operation/gpu/device/tensor_layout.hpp"
#include "ck/tensor_operation/gpu/device/device_convnd_backward_weight_xdl_c_shuffle_nhwc_kyxc_nhwk.hpp"
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/library/utility/convolution_parameter.hpp"
#include "ck/library/utility/device_memory.hpp"
#include "ck/library/utility/host_tensor.hpp"
#include "ck/library/utility/host_tensor_generator.hpp"
#include "ck/library/reference_tensor_operation/cpu/reference_conv_backward_weight.hpp"
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
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
ConvBwdWeightDefault
=
ck
::
tensor_operation
::
device
::
ConvolutionBackwardWeightSpecialization
::
Default
;
using
DeviceConvBwdWeightBasePtr
=
ck
::
tensor_operation
::
device
::
DeviceConvBwdWeightPtr
<
InElementOp
,
WeiElementOp
,
OutElementOp
>
;
// clang-format off
template
<
ck
::
index_t
NumDimSpatial
>
using
DeviceConvndBwdWeightInstance
=
ck
::
tensor_operation
::
device
::
DeviceConvndBwdWeightXdl_C_Shuffle_Input_N_Hi_Wi_C_Weight_K_Y_X_C_Output_N_Ho_Wo_K
<
InDataType
,
// InDataType
WeiDataType
,
// WeiDataType
OutDataType
,
// OutDataType
AccDataType
,
// AccDataType
InElementOp
,
// InElementwiseOperation
WeiElementOp
,
// WeiElementwiseOperation
OutElementOp
,
// OutElementwiseOperation
ConvBwdWeightDefault
,
// ConvolutionBackwardWeightSpecialization
NumDimSpatial
,
// NumDimSpatial
256
,
// BlockSize
128
,
// MPerBlock
128
,
// NPerBlock
4
,
// K0PerBlock
8
,
// K1
32
,
// MPerXdl
32
,
// NPerXdl
2
,
// MXdlPerWave
2
,
// NXdlPerWave
S
<
1
,
4
,
16
,
4
>
,
// ABlockTransferThreadClusterLengths_K0_M_K1
S
<
0
,
3
,
1
,
2
>
,
// ABlockTransferThreadClusterArrangeOrder
S
<
0
,
2
,
1
,
3
>
,
// ABlockTransferSrcAccessOrder
2
,
// ABlockTransferSrcVectorDim
8
,
// ABlockTransferSrcScalarPerVector
2
,
// ABlockTransferDstScalarPerVector_K1
true
,
// ABlockLdsAddExtraM
S
<
1
,
4
,
16
,
4
>
,
// BBlockTransferThreadClusterLengths_K0_N_K1
S
<
0
,
3
,
1
,
2
>
,
// BBlockTransferThreadClusterArrangeOrder
S
<
0
,
2
,
1
,
3
>
,
// BBlockTransferSrcAccessOrder
2
,
// BBlockTransferSrcVectorDim
8
,
// BBlockTransferSrcScalarPerVector
2
,
// BBlockTransferDstScalarPerVector_K1
true
,
// BBlockLdsAddExtraN
1
,
// CShuffleMXdlPerWavePerShuffle
1
,
// CShuffleNXdlPerWavePerShuffle
S
<
1
,
32
,
1
,
4
>
,
// CBlockTransferClusterLengths_MBlock_MPerBlock_NBlock_NPerBlock
8
>
;
// CBlockTransferScalarPerVector_NWaveNPerXdl
// clang-format on
template
<
ck
::
index_t
NumDimSpatial
>
using
ReferenceConvBwdWeightInstance
=
ck
::
tensor_operation
::
host
::
ReferenceConvBwdWeight
<
InDataType
,
WeiDataType
,
OutDataType
,
InElementOp
,
WeiElementOp
,
OutElementOp
,
NumDimSpatial
>
;
void
print_use_msg
()
{
std
::
cout
<<
"arg1: verification (0=no, 1=yes)
\n
"
<<
"arg2: initialization (0=no init, 1=random value, 2= init to 1 )
\n
"
<<
"arg3: time kernel (0=n0, 1=yes)
\n
"
<<
"arg4: is show log (0=no, 1=yes)
\n
"
<<
"arg5: split-k
\n
"
<<
"arg6: 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
::
tensor_operation
::
device
::
ConvParams
parse_conv_params
(
int
num_dim_spatial
,
char
*
argv
[])
{
// (N, K, C) + num_dim_spatial * 6 (filter, input, strides, dilations, pad left, pad right)
ck
::
tensor_operation
::
device
::
ConvParams
params
;
int
arg_idx
=
7
;
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
;
}
DeviceConvBwdWeightBasePtr
get_conv_instance
(
int
num_dim_spatial
)
{
switch
(
num_dim_spatial
)
{
case
3
:
{
return
std
::
make_unique
<
DeviceConvndBwdWeightInstance
<
3
>>
();
}
case
2
:
{
return
std
::
make_unique
<
DeviceConvndBwdWeightInstance
<
2
>>
();
}
case
1
:
{
return
std
::
make_unique
<
DeviceConvndBwdWeightInstance
<
1
>>
();
}
default:
{
throw
std
::
runtime_error
(
"Unsupported number of spatial dimensions provided!"
);
}
}
}
int
main
(
int
argc
,
char
*
argv
[])
{
bool
do_verification
=
true
;
int
init_method
=
1
;
bool
time_kernel
=
false
;
int
num_dim_spatial
=
2
;
int
do_log
=
0
;
int
split_k
=
1
;
ck
::
tensor_operation
::
device
::
ConvParams
params
;
params
.
C_
=
128
;
if
(
argc
==
6
)
{
do_verification
=
std
::
stoi
(
argv
[
1
]);
init_method
=
std
::
stoi
(
argv
[
2
]);
time_kernel
=
std
::
stoi
(
argv
[
3
]);
do_log
=
std
::
stoi
(
argv
[
4
]);
split_k
=
std
::
stoi
(
argv
[
5
]);
}
else
if
(
argc
>
6
)
{
do_verification
=
std
::
stoi
(
argv
[
1
]);
init_method
=
std
::
stoi
(
argv
[
2
]);
time_kernel
=
std
::
stoi
(
argv
[
3
]);
do_log
=
std
::
stoi
(
argv
[
4
]);
split_k
=
std
::
stoi
(
argv
[
5
]);
num_dim_spatial
=
std
::
stoi
(
argv
[
6
]);
// check args number
int
conv_args
=
3
+
num_dim_spatial
*
6
;
int
cmdline_nargs
=
conv_args
+
7
;
if
(
cmdline_nargs
!=
argc
)
{
print_use_msg
();
exit
(
1
);
}
params
=
parse_conv_params
(
num_dim_spatial
,
argv
);
}
else
if
(
argc
!=
1
)
{
print_use_msg
();
exit
(
1
);
}
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
>
in_n_c_hi_wi
(
ck
::
utils
::
conv
::
get_input_host_tensor_descriptor
(
input_dims
,
num_dim_spatial
));
Tensor
<
WeiDataType
>
wei_k_c_y_x_host_result
(
ck
::
utils
::
conv
::
get_filters_host_tensor_descriptor
(
filter_dims
,
num_dim_spatial
));
Tensor
<
WeiDataType
>
wei_k_c_y_x_device_result
(
ck
::
utils
::
conv
::
get_filters_host_tensor_descriptor
(
filter_dims
,
num_dim_spatial
));
Tensor
<
OutDataType
>
out_n_k_ho_wo
(
ck
::
utils
::
conv
::
get_output_host_tensor_descriptor
(
output_dims
,
num_dim_spatial
));
std
::
cout
<<
"in_n_c_hi_wi: "
<<
in_n_c_hi_wi
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"wei_k_c_y_x: "
<<
wei_k_c_y_x_device_result
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"out_n_k_ho_wo: "
<<
out_n_k_ho_wo
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"in_n_c_hi_wi: "
<<
in_n_c_hi_wi
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"wei_k_c_y_x: "
<<
wei_k_c_y_x_host_result
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"out_n_k_ho_wo: "
<<
out_n_k_ho_wo
.
mDesc
<<
std
::
endl
;
switch
(
init_method
)
{
case
0
:
break
;
case
1
:
out_n_k_ho_wo
.
GenerateTensorValue
(
GeneratorTensor_2
<
OutDataType
>
{
-
2
,
2
});
in_n_c_hi_wi
.
GenerateTensorValue
(
GeneratorTensor_2
<
InDataType
>
{
-
2
,
2
});
break
;
default:
out_n_k_ho_wo
.
GenerateTensorValue
(
GeneratorTensor_1
<
OutDataType
>
{
1
});
in_n_c_hi_wi
.
GenerateTensorValue
(
GeneratorTensor_1
<
InDataType
>
{
1
});
}
DeviceMem
in_device_buf
(
sizeof
(
InDataType
)
*
in_n_c_hi_wi
.
mDesc
.
GetElementSpace
());
DeviceMem
wei_device_buf
(
sizeof
(
WeiDataType
)
*
wei_k_c_y_x_device_result
.
mDesc
.
GetElementSpace
());
DeviceMem
out_device_buf
(
sizeof
(
OutDataType
)
*
out_n_k_ho_wo
.
mDesc
.
GetElementSpace
());
in_device_buf
.
ToDevice
(
in_n_c_hi_wi
.
mData
.
data
());
out_device_buf
.
ToDevice
(
out_n_k_ho_wo
.
mData
.
data
());
// reset input to zero
wei_device_buf
.
SetZero
();
// 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
{},
split_k
);
// alloc work space
float
ave_time
=
0.
f
;
if
(
!
conv
->
IsSupportedArgument
(
argument
.
get
()))
{
std
::
cout
<<
"wrong! device_conv with the specified compilation parameters does "
"not support this Conv problem"
<<
std
::
endl
;
return
1
;
}
ave_time
=
invoker
->
Run
(
argument
.
get
(),
StreamConfig
{
nullptr
,
time_kernel
});
std
::
size_t
flop
=
ck
::
utils
::
conv
::
get_flops
(
params
.
N_
,
params
.
C_
,
params
.
K_
,
params
.
filter_spatial_lengths_
,
output_spatial_lengths
);
std
::
size_t
num_btype
=
ck
::
utils
::
conv
::
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
=
[
&
](
const
auto
&
ref_conv
)
{
auto
ref_invoker
=
ref_conv
.
MakeInvoker
();
auto
ref_argument
=
ref_conv
.
MakeArgument
(
in_n_c_hi_wi
,
wei_k_c_y_x_host_result
,
out_n_k_ho_wo
,
params
.
conv_filter_strides_
,
params
.
conv_filter_dilations_
,
params
.
input_left_pads_
,
params
.
input_right_pads_
,
InElementOp
{},
WeiElementOp
{},
OutElementOp
{});
ref_invoker
.
Run
(
ref_argument
);
wei_device_buf
.
FromDevice
(
wei_k_c_y_x_device_result
.
mData
.
data
());
if
(
do_log
)
{
LogRangeAsType
<
float
>
(
std
::
cout
<<
"out: "
,
out_n_k_ho_wo
.
mData
,
","
)
<<
std
::
endl
;
LogRangeAsType
<
float
>
(
std
::
cout
<<
"in : "
,
in_n_c_hi_wi
.
mData
,
","
)
<<
std
::
endl
;
LogRangeAsType
<
float
>
(
std
::
cout
<<
"wei_device(after): "
,
wei_k_c_y_x_device_result
.
mData
,
","
)
<<
std
::
endl
;
LogRangeAsType
<
float
>
(
std
::
cout
<<
"wei_host : "
,
wei_k_c_y_x_host_result
.
mData
,
","
)
<<
std
::
endl
;
}
return
ck
::
utils
::
check_err
(
wei_k_c_y_x_device_result
.
mData
,
wei_k_c_y_x_host_result
.
mData
)
?
0
:
1
;
};
switch
(
num_dim_spatial
)
{
case
3
:
{
auto
ref_conv
=
ReferenceConvBwdWeightInstance
<
3
>
();
return
verify_f
(
ref_conv
);
}
case
2
:
{
auto
ref_conv
=
ReferenceConvBwdWeightInstance
<
2
>
();
return
verify_f
(
ref_conv
);
}
case
1
:
{
auto
ref_conv
=
ReferenceConvBwdWeightInstance
<
1
>
();
return
verify_f
(
ref_conv
);
}
default:
{
throw
std
::
runtime_error
(
"Unsupported number of spatial dimensions provided!"
);
}
}
}
return
0
;
}
example/20_convnd_bwd_weight_xdl/convnd_bwd_weight_xdl_bf16.cpp
0 → 100644
View file @
0be1cf14
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include "convnd_bwd_weight_common.hpp"
#include "ck/tensor_operation/gpu/device/device_convnd_bwd_weight_nwc_kxc_nwk_xdl_cshuffle.hpp"
using
InDataType
=
ck
::
bhalf_t
;
using
WeiDataType
=
float
;
// bf16 kernel use fp32 atomic add to accumulate Weight tensor into global memory
using
OutDataType
=
ck
::
bhalf_t
;
using
AccDataType
=
float
;
template
<
ck
::
index_t
...
Is
>
using
S
=
ck
::
Sequence
<
Is
...
>
;
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
ConvBwdWeightDefault
=
ck
::
tensor_operation
::
device
::
ConvolutionBackwardWeightSpecialization
::
Default
;
template
<
ck
::
index_t
NDimSpatial
>
using
DeviceConvndBwdWeightInstance
=
ck
::
tensor_operation
::
device
::
DeviceConvNdBwdWeightNwcKxcNwk_Xdl_CShuffle
<
NDimSpatial
,
// NDimSpatial
InDataType
,
// InDataType
WeiDataType
,
// WeiDataType
OutDataType
,
// OutDataType
AccDataType
,
// AccDataType
InElementOp
,
// InElementwiseOperation
WeiElementOp
,
// WeiElementwiseOperation
OutElementOp
,
// OutElementwiseOperation
ConvBwdWeightDefault
,
// ConvolutionBackwardWeightSpecialization
256
,
// BlockSize
128
,
// MPerBlock
128
,
// NPerBlock
4
,
// K0PerBlock
8
,
// K1
32
,
// MPerXdl
32
,
// NPerXdl
2
,
// MXdlPerWave
2
,
// NXdlPerWave
S
<
1
,
4
,
16
,
4
>
,
// ABlockTransferThreadClusterLengths_K0_M_K1
S
<
0
,
3
,
1
,
2
>
,
// ABlockTransferThreadClusterArrangeOrder
S
<
0
,
2
,
1
,
3
>
,
// ABlockTransferSrcAccessOrder
2
,
// ABlockTransferSrcVectorDim
8
,
// ABlockTransferSrcScalarPerVector
2
,
// ABlockTransferDstScalarPerVector_K1
true
,
// ABlockLdsAddExtraM
S
<
1
,
4
,
16
,
4
>
,
// BBlockTransferThreadClusterLengths_K0_N_K1
S
<
0
,
3
,
1
,
2
>
,
// BBlockTransferThreadClusterArrangeOrder
S
<
0
,
2
,
1
,
3
>
,
// BBlockTransferSrcAccessOrder
2
,
// BBlockTransferSrcVectorDim
8
,
// BBlockTransferSrcScalarPerVector
2
,
// BBlockTransferDstScalarPerVector_K1
true
,
// BBlockLdsAddExtraN
1
,
// CShuffleMXdlPerWavePerShuffle
1
,
// CShuffleNXdlPerWavePerShuffle
S
<
1
,
32
,
1
,
4
>
,
// CBlockTransferClusterLengths_MBlock_MPerBlock_NBlock_NPerBlock
4
>
;
// CBlockTransferScalarPerVector_NWaveNPerXdl
int
main
(
int
argc
,
char
*
argv
[])
{
print_helper_msg
();
bool
do_verification
=
true
;
int
init_method
=
1
;
bool
time_kernel
=
false
;
int
num_dim_spatial
=
2
;
ck
::
tensor_operation
::
device
::
ConvParams
params
{
2
,
32
,
256
,
1024
,
{
3
,
3
},
{
14
,
14
},
{
2
,
2
},
{
1
,
1
},
{
1
,
1
},
{
1
,
1
}};
ck
::
index_t
split_k
=
4
;
if
(
argc
==
1
)
{
// use default
}
else
if
(
argc
==
4
)
{
do_verification
=
std
::
stoi
(
argv
[
1
]);
init_method
=
std
::
stoi
(
argv
[
2
]);
time_kernel
=
std
::
stoi
(
argv
[
3
]);
}
else
{
do_verification
=
std
::
stoi
(
argv
[
1
]);
init_method
=
std
::
stoi
(
argv
[
2
]);
time_kernel
=
std
::
stoi
(
argv
[
3
]);
num_dim_spatial
=
std
::
stoi
(
argv
[
4
]);
params
=
parse_conv_params
(
num_dim_spatial
,
5
,
argv
);
split_k
=
std
::
stoi
(
argv
[
5
+
3
+
6
*
num_dim_spatial
-
1
]);
split_k
=
std
::
max
(
1
,
split_k
);
}
const
auto
in_element_op
=
InElementOp
{};
const
auto
wei_element_op
=
WeiElementOp
{};
const
auto
out_element_op
=
OutElementOp
{};
if
(
num_dim_spatial
==
1
)
{
return
run_conv_bwd_weight_nhwc
<
1
,
InDataType
,
WeiDataType
,
OutDataType
,
AccDataType
,
InElementOp
,
WeiElementOp
,
OutElementOp
,
DeviceConvndBwdWeightInstance
<
1
>>
(
do_verification
,
init_method
,
time_kernel
,
params
,
in_element_op
,
wei_element_op
,
out_element_op
,
split_k
);
}
else
if
(
num_dim_spatial
==
2
)
{
return
run_conv_bwd_weight_nhwc
<
2
,
InDataType
,
WeiDataType
,
OutDataType
,
AccDataType
,
InElementOp
,
WeiElementOp
,
OutElementOp
,
DeviceConvndBwdWeightInstance
<
2
>>
(
do_verification
,
init_method
,
time_kernel
,
params
,
in_element_op
,
wei_element_op
,
out_element_op
,
split_k
);
}
else
if
(
num_dim_spatial
==
3
)
{
return
run_conv_bwd_weight_nhwc
<
3
,
InDataType
,
WeiDataType
,
OutDataType
,
AccDataType
,
InElementOp
,
WeiElementOp
,
OutElementOp
,
DeviceConvndBwdWeightInstance
<
3
>>
(
do_verification
,
init_method
,
time_kernel
,
params
,
in_element_op
,
wei_element_op
,
out_element_op
,
split_k
);
}
return
0
;
}
example/20_convnd_bwd_weight_xdl/convnd_bwd_weight_xdl_bf16_splitk.cpp
deleted
100644 → 0
View file @
b054669b
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include <iostream>
#include <numeric>
#include <initializer_list>
#include <cstdlib>
#include "ck/ck.hpp"
#include "ck/tensor_operation/gpu/device/tensor_layout.hpp"
#include "ck/tensor_operation/gpu/device/device_convnd_backward_weight_xdl_c_shuffle_nhwc_kyxc_nhwk.hpp"
#include "ck/tensor_operation/gpu/device/device_unary_elementwise.hpp"
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp"
#include "ck/library/utility/check_err.hpp"
#include "ck/library/utility/convolution_parameter.hpp"
#include "ck/library/utility/device_memory.hpp"
#include "ck/library/utility/host_tensor.hpp"
#include "ck/library/utility/host_tensor_generator.hpp"
#include "ck/library/reference_tensor_operation/cpu/reference_conv_backward_weight.hpp"
using
InDataType
=
ck
::
bhalf_t
;
using
WeiDataType
=
ck
::
bhalf_t
;
using
OutDataType
=
ck
::
bhalf_t
;
using
AccDataType
=
float
;
template
<
ck
::
index_t
...
Is
>
using
S
=
ck
::
Sequence
<
Is
...
>
;
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
UnaryTypeConvert
=
ck
::
tensor_operation
::
element_wise
::
UnaryTypeConvert
<
ck
::
bhalf_t
,
float
>
;
using
DeviceUnaryElementwiseTypeConvertInstance
=
ck
::
tensor_operation
::
device
::
DeviceUnaryElementwise
<
AccDataType
,
WeiDataType
,
UnaryTypeConvert
,
1
,
4
>
;
static
constexpr
auto
ConvBwdWeightDefault
=
ck
::
tensor_operation
::
device
::
ConvolutionBackwardWeightSpecialization
::
Default
;
using
DeviceConvBwdWeightBasePtr
=
ck
::
tensor_operation
::
device
::
DeviceConvBwdWeightPtr
<
InElementOp
,
WeiElementOp
,
OutElementOp
>
;
// clang-format off
template
<
ck
::
index_t
NumDimSpatial
>
using
DeviceConvndBwdWeightInstance_bf16_splitk
=
ck
::
tensor_operation
::
device
::
DeviceConvndBwdWeightXdl_C_Shuffle_Input_N_Hi_Wi_C_Weight_K_Y_X_C_Output_N_Ho_Wo_K
<
InDataType
,
// InDataType
AccDataType
,
// WeiDataType
OutDataType
,
// OutDataType
AccDataType
,
// AccDataType
InElementOp
,
// InElementwiseOperation
WeiElementOp
,
// WeiElementwiseOperation
OutElementOp
,
// OutElementwiseOperation
ConvBwdWeightDefault
,
// ConvolutionBackwardWeightSpecialization
NumDimSpatial
,
// NumDimSpatial
256
,
// BlockSize
128
,
// MPerBlock
128
,
// NPerBlock
4
,
// K0PerBlock
8
,
// K1
32
,
// MPerXdl
32
,
// NPerXdl
2
,
// MXdlPerWave
2
,
// NXdlPerWave
S
<
1
,
4
,
16
,
4
>
,
// ABlockTransferThreadClusterLengths_K0_M_K1
S
<
0
,
3
,
1
,
2
>
,
// ABlockTransferThreadClusterArrangeOrder
S
<
0
,
2
,
1
,
3
>
,
// ABlockTransferSrcAccessOrder
2
,
// ABlockTransferSrcVectorDim
8
,
// ABlockTransferSrcScalarPerVector
2
,
// ABlockTransferDstScalarPerVector_K1
true
,
// ABlockLdsAddExtraM
S
<
1
,
4
,
16
,
4
>
,
// BBlockTransferThreadClusterLengths_K0_N_K1
S
<
0
,
3
,
1
,
2
>
,
// BBlockTransferThreadClusterArrangeOrder
S
<
0
,
2
,
1
,
3
>
,
// BBlockTransferSrcAccessOrder
2
,
// BBlockTransferSrcVectorDim
8
,
// BBlockTransferSrcScalarPerVector
2
,
// BBlockTransferDstScalarPerVector_K1
true
,
// BBlockLdsAddExtraN
1
,
// CShuffleMXdlPerWavePerShuffle
1
,
// CShuffleNXdlPerWavePerShuffle
S
<
1
,
32
,
1
,
4
>
,
// CBlockTransferClusterLengths_MBlock_MPerBlock_NBlock_NPerBlock
4
>
;
// CBlockTransferScalarPerVector_NWaveNPerXdl
// clang-format on
template
<
ck
::
index_t
NumDimSpatial
>
using
ReferenceConvBwdWeightInstance
=
ck
::
tensor_operation
::
host
::
ReferenceConvBwdWeight
<
InDataType
,
WeiDataType
,
OutDataType
,
InElementOp
,
WeiElementOp
,
OutElementOp
,
NumDimSpatial
>
;
template
<
typename
HostTensorB
,
typename
HostTensorA
,
typename
Functor
>
void
host_elementwise
(
HostTensorB
&
B
,
const
HostTensorA
&
A
,
const
std
::
vector
<
std
::
size_t
>&
shape
,
Functor
functor
)
{
size_t
tensor_size
=
std
::
accumulate
(
shape
.
begin
(),
shape
.
end
(),
1
,
std
::
multiplies
<
int
>
{});
std
::
cout
<<
__LINE__
<<
":"
<<
tensor_size
<<
", "
<<
A
.
mData
[
0
]
<<
std
::
endl
;
for
(
std
::
size_t
n
=
0
;
n
<
tensor_size
;
++
n
)
{
B
.
mData
[
n
]
=
functor
(
A
.
mData
[
n
]);
}
}
void
print_use_msg
()
{
std
::
cout
<<
"arg1: verification (0=no, 1=yes)
\n
"
<<
"arg2: initialization (0=no init, 1=random value, 2= init to 1 )
\n
"
<<
"arg3: time kernel (0=n0, 1=yes)
\n
"
<<
"arg4: is show log (0=no, 1=yes)
\n
"
<<
"arg5: split-k : in this example split-k must be larger than 1
\n
"
<<
"arg6: 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
::
tensor_operation
::
device
::
ConvParams
parse_conv_params
(
int
num_dim_spatial
,
char
*
argv
[])
{
// (N, K, C) + num_dim_spatial * 6 (filter, input, strides, dilations, pad left, pad right)
ck
::
tensor_operation
::
device
::
ConvParams
params
;
int
arg_idx
=
7
;
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
;
}
DeviceConvBwdWeightBasePtr
get_conv_instance
(
int
num_dim_spatial
)
{
switch
(
num_dim_spatial
)
{
case
3
:
{
return
std
::
make_unique
<
DeviceConvndBwdWeightInstance_bf16_splitk
<
3
>>
();
}
case
2
:
{
return
std
::
make_unique
<
DeviceConvndBwdWeightInstance_bf16_splitk
<
2
>>
();
}
case
1
:
{
return
std
::
make_unique
<
DeviceConvndBwdWeightInstance_bf16_splitk
<
1
>>
();
}
default:
{
throw
std
::
runtime_error
(
"Unsupported number of spatial dimensions provided!"
);
}
}
}
int
main
(
int
argc
,
char
*
argv
[])
{
bool
do_verification
=
true
;
int
init_method
=
1
;
bool
time_kernel
=
false
;
int
num_dim_spatial
=
2
;
int
do_log
=
0
;
int
split_k
=
2
;
ck
::
tensor_operation
::
device
::
ConvParams
params
;
params
.
C_
=
128
;
if
(
argc
==
6
)
{
do_verification
=
std
::
stoi
(
argv
[
1
]);
init_method
=
std
::
stoi
(
argv
[
2
]);
time_kernel
=
std
::
stoi
(
argv
[
3
]);
do_log
=
std
::
stoi
(
argv
[
4
]);
split_k
=
std
::
stoi
(
argv
[
5
]);
}
else
if
(
argc
>
6
)
{
do_verification
=
std
::
stoi
(
argv
[
1
]);
init_method
=
std
::
stoi
(
argv
[
2
]);
time_kernel
=
std
::
stoi
(
argv
[
3
]);
do_log
=
std
::
stoi
(
argv
[
4
]);
split_k
=
std
::
stoi
(
argv
[
5
]);
num_dim_spatial
=
std
::
stoi
(
argv
[
6
]);
// check args number
int
conv_args
=
3
+
num_dim_spatial
*
6
;
int
cmdline_nargs
=
conv_args
+
7
;
if
(
cmdline_nargs
!=
argc
)
{
print_use_msg
();
exit
(
1
);
}
params
=
parse_conv_params
(
num_dim_spatial
,
argv
);
}
else
if
(
argc
!=
1
)
{
print_use_msg
();
exit
(
1
);
}
if
(
split_k
<=
1
)
{
print_use_msg
();
exit
(
1
);
}
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
>
in_n_c_hi_wi
(
ck
::
utils
::
conv
::
get_input_host_tensor_descriptor
(
input_dims
,
num_dim_spatial
));
Tensor
<
WeiDataType
>
wei_k_c_y_x_host_result
(
ck
::
utils
::
conv
::
get_filters_host_tensor_descriptor
(
filter_dims
,
num_dim_spatial
));
Tensor
<
WeiDataType
>
wei_k_c_y_x_device_result
(
ck
::
utils
::
conv
::
get_filters_host_tensor_descriptor
(
filter_dims
,
num_dim_spatial
));
Tensor
<
OutDataType
>
out_n_k_ho_wo
(
ck
::
utils
::
conv
::
get_output_host_tensor_descriptor
(
output_dims
,
num_dim_spatial
));
std
::
cout
<<
"in_n_c_hi_wi: "
<<
in_n_c_hi_wi
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"wei_k_c_y_x: "
<<
wei_k_c_y_x_device_result
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"out_n_k_ho_wo: "
<<
out_n_k_ho_wo
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"in_n_c_hi_wi: "
<<
in_n_c_hi_wi
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"wei_k_c_y_x: "
<<
wei_k_c_y_x_host_result
.
mDesc
<<
std
::
endl
;
std
::
cout
<<
"out_n_k_ho_wo: "
<<
out_n_k_ho_wo
.
mDesc
<<
std
::
endl
;
switch
(
init_method
)
{
case
0
:
break
;
case
1
:
out_n_k_ho_wo
.
GenerateTensorValue
(
GeneratorTensor_2
<
OutDataType
>
{
-
2
,
2
});
in_n_c_hi_wi
.
GenerateTensorValue
(
GeneratorTensor_2
<
InDataType
>
{
-
2
,
2
});
break
;
default:
out_n_k_ho_wo
.
GenerateTensorValue
(
GeneratorTensor_1
<
OutDataType
>
{
1
});
in_n_c_hi_wi
.
GenerateTensorValue
(
GeneratorTensor_1
<
InDataType
>
{
1
});
}
DeviceMem
in_device_buf
(
sizeof
(
InDataType
)
*
in_n_c_hi_wi
.
mDesc
.
GetElementSpace
());
DeviceMem
wei_device_buf
(
sizeof
(
WeiDataType
)
*
wei_k_c_y_x_device_result
.
mDesc
.
GetElementSpace
());
DeviceMem
out_device_buf
(
sizeof
(
OutDataType
)
*
out_n_k_ho_wo
.
mDesc
.
GetElementSpace
());
in_device_buf
.
ToDevice
(
in_n_c_hi_wi
.
mData
.
data
());
out_device_buf
.
ToDevice
(
out_n_k_ho_wo
.
mData
.
data
());
// reset input to zero
wei_device_buf
.
SetZero
();
// 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
{},
split_k
);
// alloc work space
size_t
bwd_weight_workspace_size
=
conv
->
GetWorkSpaceSize
(
argument
.
get
());
if
(
bwd_weight_workspace_size
<=
0
)
{
print_use_msg
();
exit
(
1
);
}
float
conv_ave_time
=
0.
f
;
DeviceMem
wei_work_space_device_buf
(
bwd_weight_workspace_size
);
wei_work_space_device_buf
.
SetZero
();
conv
->
SetWorkSpacePointer
(
argument
.
get
(),
wei_work_space_device_buf
.
GetDeviceBuffer
());
if
(
!
conv
->
IsSupportedArgument
(
argument
.
get
()))
{
std
::
cout
<<
"wrong! device_conv with the specified compilation parameters does "
"not support this Conv problem"
<<
std
::
endl
;
return
1
;
}
conv_ave_time
=
invoker
->
Run
(
argument
.
get
(),
StreamConfig
{
nullptr
,
time_kernel
});
std
::
size_t
flop
=
ck
::
utils
::
conv
::
get_flops
(
params
.
N_
,
params
.
C_
,
params
.
K_
,
params
.
filter_spatial_lengths_
,
output_spatial_lengths
);
std
::
size_t
num_btype
=
ck
::
utils
::
conv
::
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
/
conv_ave_time
;
float
gb_per_sec
=
num_btype
/
1.E6
/
conv_ave_time
;
std
::
cout
<<
"Perf: conv: "
<<
conv_ave_time
<<
" ms, "
<<
tflops
<<
" TFlops, "
<<
gb_per_sec
<<
" GB/s"
<<
std
::
endl
;
if
(
do_verification
)
{
auto
verify_f
=
[
&
](
const
auto
&
ref_conv
)
{
auto
ref_invoker
=
ref_conv
.
MakeInvoker
();
auto
ref_argument
=
ref_conv
.
MakeArgument
(
in_n_c_hi_wi
,
wei_k_c_y_x_host_result
,
out_n_k_ho_wo
,
params
.
conv_filter_strides_
,
params
.
conv_filter_dilations_
,
params
.
input_left_pads_
,
params
.
input_right_pads_
,
InElementOp
{},
WeiElementOp
{},
OutElementOp
{});
ref_invoker
.
Run
(
ref_argument
);
wei_device_buf
.
FromDevice
(
wei_k_c_y_x_device_result
.
mData
.
data
());
if
(
do_log
)
{
LogRangeAsType
<
float
>
(
std
::
cout
<<
"out: "
,
out_n_k_ho_wo
.
mData
,
","
)
<<
std
::
endl
;
LogRangeAsType
<
float
>
(
std
::
cout
<<
"in : "
,
in_n_c_hi_wi
.
mData
,
","
)
<<
std
::
endl
;
LogRangeAsType
<
float
>
(
std
::
cout
<<
"wei_device(after): "
,
wei_k_c_y_x_device_result
.
mData
,
","
)
<<
std
::
endl
;
LogRangeAsType
<
float
>
(
std
::
cout
<<
"wei_host : "
,
wei_k_c_y_x_host_result
.
mData
,
","
)
<<
std
::
endl
;
}
return
ck
::
utils
::
check_err
(
wei_k_c_y_x_device_result
.
mData
,
wei_k_c_y_x_host_result
.
mData
)
?
0
:
1
;
};
switch
(
num_dim_spatial
)
{
case
3
:
{
auto
ref_conv
=
ReferenceConvBwdWeightInstance
<
3
>
();
verify_f
(
ref_conv
);
break
;
}
case
2
:
{
auto
ref_conv
=
ReferenceConvBwdWeightInstance
<
2
>
();
verify_f
(
ref_conv
);
break
;
}
case
1
:
{
auto
ref_conv
=
ReferenceConvBwdWeightInstance
<
1
>
();
verify_f
(
ref_conv
);
break
;
}
default:
{
throw
std
::
runtime_error
(
"Unsupported number of spatial dimensions provided!"
);
}
}
}
return
0
;
}
example/20_convnd_bwd_weight_xdl/convnd_bwd_weight_xdl_fp16.cpp
0 → 100644
View file @
0be1cf14
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#include "convnd_bwd_weight_common.hpp"
#include "ck/tensor_operation/gpu/device/device_convnd_bwd_weight_nwc_kxc_nwk_xdl_cshuffle.hpp"
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
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
ConvBwdWeightDefault
=
ck
::
tensor_operation
::
device
::
ConvolutionBackwardWeightSpecialization
::
Default
;
template
<
ck
::
index_t
NDimSpatial
>
using
DeviceConvndBwdWeightInstance
=
ck
::
tensor_operation
::
device
::
DeviceConvNdBwdWeightNwcKxcNwk_Xdl_CShuffle
<
NDimSpatial
,
// NDimSpatial
InDataType
,
// InDataType
WeiDataType
,
// WeiDataType
OutDataType
,
// OutDataType
AccDataType
,
// AccDataType
InElementOp
,
// InElementwiseOperation
WeiElementOp
,
// WeiElementwiseOperation
OutElementOp
,
// OutElementwiseOperation
ConvBwdWeightDefault
,
// ConvolutionBackwardWeightSpecialization
256
,
// BlockSize
128
,
// MPerBlock
128
,
// NPerBlock
4
,
// K0PerBlock
8
,
// K1
32
,
// MPerXdl
32
,
// NPerXdl
2
,
// MXdlPerWave
2
,
// NXdlPerWave
S
<
1
,
4
,
16
,
4
>
,
// ABlockTransferThreadClusterLengths_K0_M_K1
S
<
0
,
3
,
1
,
2
>
,
// ABlockTransferThreadClusterArrangeOrder
S
<
0
,
2
,
1
,
3
>
,
// ABlockTransferSrcAccessOrder
2
,
// ABlockTransferSrcVectorDim
8
,
// ABlockTransferSrcScalarPerVector
2
,
// ABlockTransferDstScalarPerVector_K1
true
,
// ABlockLdsAddExtraM
S
<
1
,
4
,
16
,
4
>
,
// BBlockTransferThreadClusterLengths_K0_N_K1
S
<
0
,
3
,
1
,
2
>
,
// BBlockTransferThreadClusterArrangeOrder
S
<
0
,
2
,
1
,
3
>
,
// BBlockTransferSrcAccessOrder
2
,
// BBlockTransferSrcVectorDim
8
,
// BBlockTransferSrcScalarPerVector
2
,
// BBlockTransferDstScalarPerVector_K1
true
,
// BBlockLdsAddExtraN
1
,
// CShuffleMXdlPerWavePerShuffle
1
,
// CShuffleNXdlPerWavePerShuffle
S
<
1
,
32
,
1
,
4
>
,
// CBlockTransferClusterLengths_MBlock_MPerBlock_NBlock_NPerBlock
8
>
;
// CBlockTransferScalarPerVector_NWaveNPerXdl
int
main
(
int
argc
,
char
*
argv
[])
{
print_helper_msg
();
bool
do_verification
=
true
;
int
init_method
=
1
;
bool
time_kernel
=
false
;
int
num_dim_spatial
=
2
;
ck
::
tensor_operation
::
device
::
ConvParams
params
{
2
,
32
,
256
,
1024
,
{
3
,
3
},
{
14
,
14
},
{
2
,
2
},
{
1
,
1
},
{
1
,
1
},
{
1
,
1
}};
ck
::
index_t
split_k
=
4
;
if
(
argc
==
1
)
{
// use default
}
else
if
(
argc
==
4
)
{
do_verification
=
std
::
stoi
(
argv
[
1
]);
init_method
=
std
::
stoi
(
argv
[
2
]);
time_kernel
=
std
::
stoi
(
argv
[
3
]);
}
else
{
do_verification
=
std
::
stoi
(
argv
[
1
]);
init_method
=
std
::
stoi
(
argv
[
2
]);
time_kernel
=
std
::
stoi
(
argv
[
3
]);
num_dim_spatial
=
std
::
stoi
(
argv
[
4
]);
params
=
parse_conv_params
(
num_dim_spatial
,
5
,
argv
);
split_k
=
std
::
stoi
(
argv
[
5
+
3
+
6
*
num_dim_spatial
-
1
]);
split_k
=
std
::
max
(
1
,
split_k
);
}
const
auto
in_element_op
=
InElementOp
{};
const
auto
wei_element_op
=
WeiElementOp
{};
const
auto
out_element_op
=
OutElementOp
{};
if
(
num_dim_spatial
==
1
)
{
return
run_conv_bwd_weight_nhwc
<
1
,
InDataType
,
WeiDataType
,
OutDataType
,
AccDataType
,
InElementOp
,
WeiElementOp
,
OutElementOp
,
DeviceConvndBwdWeightInstance
<
1
>>
(
do_verification
,
init_method
,
time_kernel
,
params
,
in_element_op
,
wei_element_op
,
out_element_op
,
split_k
);
}
else
if
(
num_dim_spatial
==
2
)
{
return
run_conv_bwd_weight_nhwc
<
2
,
InDataType
,
WeiDataType
,
OutDataType
,
AccDataType
,
InElementOp
,
WeiElementOp
,
OutElementOp
,
DeviceConvndBwdWeightInstance
<
2
>>
(
do_verification
,
init_method
,
time_kernel
,
params
,
in_element_op
,
wei_element_op
,
out_element_op
,
split_k
);
}
else
if
(
num_dim_spatial
==
3
)
{
return
run_conv_bwd_weight_nhwc
<
3
,
InDataType
,
WeiDataType
,
OutDataType
,
AccDataType
,
InElementOp
,
WeiElementOp
,
OutElementOp
,
DeviceConvndBwdWeightInstance
<
3
>>
(
do_verification
,
init_method
,
time_kernel
,
params
,
in_element_op
,
wei_element_op
,
out_element_op
,
split_k
);
}
return
0
;
}
include/ck/tensor_operation/gpu/device/convolution_backward_data_specialization.hpp
View file @
0be1cf14
// SPDX-License-Identifier: MIT
// SPDX-License-Identifier: MIT
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
#ifndef CONVOLUTION_BACKWARD_DATA_SPECIALIZATION
#pragma once
#define CONVOLUTION_BACKWARD_DATA_SPECIALIZATION
namespace
ck
{
namespace
ck
{
namespace
tensor_operation
{
namespace
tensor_operation
{
...
@@ -14,7 +13,18 @@ enum struct ConvolutionBackwardDataSpecialization
...
@@ -14,7 +13,18 @@ enum struct ConvolutionBackwardDataSpecialization
Filter1x1Stride1Pad0
,
Filter1x1Stride1Pad0
,
};
};
inline
std
::
string
getConvBackwardDataSpecializationString
(
const
ConvolutionBackwardDataSpecialization
&
s
)
{
switch
(
s
)
{
case
ConvolutionBackwardDataSpecialization
::
Default
:
return
"Default"
;
case
ConvolutionBackwardDataSpecialization
::
FFilter1x1Stride1Pad0
:
return
"FFilter1x1Stride1Pad0"
;
default:
return
"Unrecognized specialization!"
;
}
}
}
// namespace device
}
// namespace device
}
// namespace tensor_operation
}
// namespace tensor_operation
}
// namespace ck
}
// namespace ck
#endif
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