mirror of
https://github.com/ROCm/composable_kernel.git
synced 2026-04-20 14:59:17 +00:00
Unified implementation of 1d/2d/3d conv bwd-data. fp32/fp16/bfp16/int8 (#134)
* start convnd bwd data * add 3d laoyout name * add conv1d reference * add con3d reference * finished example client code * conv1d kernel finished * fix input error * add conv3d * add 3d layout in conv_utils.hpp * fix sepecial check * addconvnd lib * add test for bwd data * finished test * add check slice length * convnd bwd data start * profiler can be compiled * fix some bug * set input to zero * modify readme for example * fix test_convnd_bwd_data bug * test_convnd_bwd_data parameter desc * workaround for 1d * workaroud for 2d * change init value * workaround for 3d int8 * fix init value bug * remove workaround * fix acc data type * add int32 * change select function to template * tilda to tilde * remove int32 instance * fix commit for device hpp * fix comments for profiler * using profile imp to test * add pass verification * fix conv2d reference * fix conflict * remove double batched_gemm * fix exampel conv2d data and test convnd * format * change conv2d_bwd_data return value * remove repeat = 1 * remove conv bwd data Co-authored-by: ltqin <letaoqin@amd.com> Co-authored-by: Chao Liu <chao.liu2@amd.com>
This commit is contained in:
8
test/convnd_bwd_data/CMakeLists.txt
Normal file
8
test/convnd_bwd_data/CMakeLists.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
include_directories(BEFORE
|
||||
${PROJECT_SOURCE_DIR}/profiler/include
|
||||
${PROJECT_SOURCE_DIR}/external/include/half
|
||||
)
|
||||
|
||||
add_test_executable(test_convnd_bwd_data convnd_bwd_data.cpp)
|
||||
target_link_libraries(test_convnd_bwd_data PRIVATE host_tensor)
|
||||
target_link_libraries(test_convnd_bwd_data PRIVATE device_convnd_bwd_data_instance)
|
||||
330
test/convnd_bwd_data/convnd_bwd_data.cpp
Normal file
330
test/convnd_bwd_data/convnd_bwd_data.cpp
Normal file
@@ -0,0 +1,330 @@
|
||||
#include <iostream>
|
||||
#include <numeric>
|
||||
#include <initializer_list>
|
||||
#include <cstdlib>
|
||||
#include <stdlib.h>
|
||||
#include <half.hpp>
|
||||
#include <vector>
|
||||
|
||||
#include "profile_convnd_bwd_data_impl.hpp"
|
||||
|
||||
int main()
|
||||
{
|
||||
bool pass = true;
|
||||
// check 1d
|
||||
std::vector<ck::conv_util::ConvParams> params;
|
||||
params.push_back({1, 128, 128, 256, {1}, {14}, {2}, {1}, {0}, {0}});
|
||||
params.push_back({1, 128, 128, 256, {3}, {28}, {1}, {1}, {1}, {1}});
|
||||
params.push_back({1, 128, 128, 256, {1}, {3}, {1}, {1}, {0}, {0}});
|
||||
|
||||
for(auto& param : params)
|
||||
{
|
||||
pass &= ck::profiler::profile_convnd_bwd_data_impl<1,
|
||||
float,
|
||||
float,
|
||||
float,
|
||||
float,
|
||||
ck::tensor_layout::convolution::NWC,
|
||||
ck::tensor_layout::convolution::KXC,
|
||||
ck::tensor_layout::convolution::NWK>(
|
||||
1, // do_verification,
|
||||
1, // init_method,
|
||||
0, // do_log,
|
||||
1, // nrepeat,
|
||||
param.N,
|
||||
param.K,
|
||||
param.C,
|
||||
param.input_spatial_lengths,
|
||||
param.filter_spatial_lengths,
|
||||
param.GetOutputSpatialLengths(),
|
||||
param.conv_filter_strides,
|
||||
param.conv_filter_dilations,
|
||||
param.input_left_pads,
|
||||
param.input_right_pads);
|
||||
|
||||
pass &= ck::profiler::profile_convnd_bwd_data_impl<1,
|
||||
ck::half_t,
|
||||
ck::half_t,
|
||||
ck::half_t,
|
||||
float,
|
||||
ck::tensor_layout::convolution::NWC,
|
||||
ck::tensor_layout::convolution::KXC,
|
||||
ck::tensor_layout::convolution::NWK>(
|
||||
1, // do_verification,
|
||||
1, // init_method,
|
||||
0, // do_log,
|
||||
1, // nrepeat,
|
||||
param.N,
|
||||
param.K,
|
||||
param.C,
|
||||
param.input_spatial_lengths,
|
||||
param.filter_spatial_lengths,
|
||||
param.GetOutputSpatialLengths(),
|
||||
param.conv_filter_strides,
|
||||
param.conv_filter_dilations,
|
||||
param.input_left_pads,
|
||||
param.input_right_pads);
|
||||
|
||||
pass &= ck::profiler::profile_convnd_bwd_data_impl<1,
|
||||
ck::bhalf_t,
|
||||
ck::bhalf_t,
|
||||
ck::bhalf_t,
|
||||
float,
|
||||
ck::tensor_layout::convolution::NWC,
|
||||
ck::tensor_layout::convolution::KXC,
|
||||
ck::tensor_layout::convolution::NWK>(
|
||||
1, // do_verification,
|
||||
1, // init_method,
|
||||
0, // do_log,
|
||||
1, // nrepeat,
|
||||
param.N,
|
||||
param.K,
|
||||
param.C,
|
||||
param.input_spatial_lengths,
|
||||
param.filter_spatial_lengths,
|
||||
param.GetOutputSpatialLengths(),
|
||||
param.conv_filter_strides,
|
||||
param.conv_filter_dilations,
|
||||
param.input_left_pads,
|
||||
param.input_right_pads);
|
||||
|
||||
pass &= ck::profiler::profile_convnd_bwd_data_impl<1,
|
||||
int8_t,
|
||||
int8_t,
|
||||
int8_t,
|
||||
int,
|
||||
ck::tensor_layout::convolution::NWC,
|
||||
ck::tensor_layout::convolution::KXC,
|
||||
ck::tensor_layout::convolution::NWK>(
|
||||
1, // do_verification,
|
||||
1, // init_method,
|
||||
0, // do_log,
|
||||
1, // nrepeat,
|
||||
param.N,
|
||||
param.K,
|
||||
param.C,
|
||||
param.input_spatial_lengths,
|
||||
param.filter_spatial_lengths,
|
||||
param.GetOutputSpatialLengths(),
|
||||
param.conv_filter_strides,
|
||||
param.conv_filter_dilations,
|
||||
param.input_left_pads,
|
||||
param.input_right_pads);
|
||||
}
|
||||
|
||||
// check 2d
|
||||
params.clear();
|
||||
params.push_back({2, 128, 128, 256, {1, 1}, {7, 7}, {2, 2}, {1, 1}, {0, 0}, {0, 0}});
|
||||
params.push_back({2, 128, 128, 256, {3, 3}, {14, 14}, {1, 1}, {1, 1}, {1, 1}, {1, 1}});
|
||||
params.push_back({2, 128, 128, 256, {1, 1}, {3, 3}, {1, 1}, {1, 1}, {0, 0}, {0, 0}});
|
||||
|
||||
for(auto& param : params)
|
||||
{
|
||||
pass &= ck::profiler::profile_convnd_bwd_data_impl<2,
|
||||
float,
|
||||
float,
|
||||
float,
|
||||
float,
|
||||
ck::tensor_layout::convolution::NHWC,
|
||||
ck::tensor_layout::convolution::KYXC,
|
||||
ck::tensor_layout::convolution::NHWK>(
|
||||
1, // do_verification,
|
||||
1, // init_method,
|
||||
0, // do_log,
|
||||
1, // nrepeat,
|
||||
param.N,
|
||||
param.K,
|
||||
param.C,
|
||||
param.input_spatial_lengths,
|
||||
param.filter_spatial_lengths,
|
||||
param.GetOutputSpatialLengths(),
|
||||
param.conv_filter_strides,
|
||||
param.conv_filter_dilations,
|
||||
param.input_left_pads,
|
||||
param.input_right_pads);
|
||||
|
||||
pass &= ck::profiler::profile_convnd_bwd_data_impl<2,
|
||||
ck::half_t,
|
||||
ck::half_t,
|
||||
ck::half_t,
|
||||
float,
|
||||
ck::tensor_layout::convolution::NHWC,
|
||||
ck::tensor_layout::convolution::KYXC,
|
||||
ck::tensor_layout::convolution::NHWK>(
|
||||
1, // do_verification,
|
||||
1, // init_method,
|
||||
0, // do_log,
|
||||
1, // nrepeat,
|
||||
param.N,
|
||||
param.K,
|
||||
param.C,
|
||||
param.input_spatial_lengths,
|
||||
param.filter_spatial_lengths,
|
||||
param.GetOutputSpatialLengths(),
|
||||
param.conv_filter_strides,
|
||||
param.conv_filter_dilations,
|
||||
param.input_left_pads,
|
||||
param.input_right_pads);
|
||||
|
||||
pass &= ck::profiler::profile_convnd_bwd_data_impl<2,
|
||||
ck::bhalf_t,
|
||||
ck::bhalf_t,
|
||||
ck::bhalf_t,
|
||||
float,
|
||||
ck::tensor_layout::convolution::NHWC,
|
||||
ck::tensor_layout::convolution::KYXC,
|
||||
ck::tensor_layout::convolution::NHWK>(
|
||||
1, // do_verification,
|
||||
1, // init_method,
|
||||
0, // do_log,
|
||||
1, // nrepeat,
|
||||
param.N,
|
||||
param.K,
|
||||
param.C,
|
||||
param.input_spatial_lengths,
|
||||
param.filter_spatial_lengths,
|
||||
param.GetOutputSpatialLengths(),
|
||||
param.conv_filter_strides,
|
||||
param.conv_filter_dilations,
|
||||
param.input_left_pads,
|
||||
param.input_right_pads);
|
||||
|
||||
pass &= ck::profiler::profile_convnd_bwd_data_impl<2,
|
||||
int8_t,
|
||||
int8_t,
|
||||
int8_t,
|
||||
int,
|
||||
ck::tensor_layout::convolution::NHWC,
|
||||
ck::tensor_layout::convolution::KYXC,
|
||||
ck::tensor_layout::convolution::NHWK>(
|
||||
1, // do_verification,
|
||||
1, // init_method,
|
||||
0, // do_log,
|
||||
1, // nrepeat,
|
||||
param.N,
|
||||
param.K,
|
||||
param.C,
|
||||
param.input_spatial_lengths,
|
||||
param.filter_spatial_lengths,
|
||||
param.GetOutputSpatialLengths(),
|
||||
param.conv_filter_strides,
|
||||
param.conv_filter_dilations,
|
||||
param.input_left_pads,
|
||||
param.input_right_pads);
|
||||
}
|
||||
|
||||
// check 3d
|
||||
params.clear();
|
||||
params.push_back(
|
||||
{3, 128, 128, 256, {1, 1, 1}, {7, 7, 7}, {2, 2, 2}, {1, 1, 1}, {0, 0, 0}, {0, 0, 0}});
|
||||
params.push_back(
|
||||
{3, 128, 128, 256, {3, 3, 3}, {14, 14, 14}, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}});
|
||||
params.push_back(
|
||||
{3, 128, 128, 256, {1, 1, 1}, {3, 3, 3}, {1, 1, 1}, {1, 1, 1}, {0, 0, 0}, {0, 0, 0}});
|
||||
|
||||
for(auto& param : params)
|
||||
{
|
||||
pass &= ck::profiler::profile_convnd_bwd_data_impl<3,
|
||||
float,
|
||||
float,
|
||||
float,
|
||||
float,
|
||||
ck::tensor_layout::convolution::NDHWC,
|
||||
ck::tensor_layout::convolution::KZYXC,
|
||||
ck::tensor_layout::convolution::NDHWK>(
|
||||
1, // do_verification,
|
||||
1, // init_method,
|
||||
0, // do_log,
|
||||
1, // nrepeat,
|
||||
param.N,
|
||||
param.K,
|
||||
param.C,
|
||||
param.input_spatial_lengths,
|
||||
param.filter_spatial_lengths,
|
||||
param.GetOutputSpatialLengths(),
|
||||
param.conv_filter_strides,
|
||||
param.conv_filter_dilations,
|
||||
param.input_left_pads,
|
||||
param.input_right_pads);
|
||||
|
||||
pass &= ck::profiler::profile_convnd_bwd_data_impl<3,
|
||||
ck::half_t,
|
||||
ck::half_t,
|
||||
ck::half_t,
|
||||
float,
|
||||
ck::tensor_layout::convolution::NDHWC,
|
||||
ck::tensor_layout::convolution::KZYXC,
|
||||
ck::tensor_layout::convolution::NDHWK>(
|
||||
1, // do_verification,
|
||||
1, // init_method,
|
||||
0, // do_log,
|
||||
1, // nrepeat,
|
||||
param.N,
|
||||
param.K,
|
||||
param.C,
|
||||
param.input_spatial_lengths,
|
||||
param.filter_spatial_lengths,
|
||||
param.GetOutputSpatialLengths(),
|
||||
param.conv_filter_strides,
|
||||
param.conv_filter_dilations,
|
||||
param.input_left_pads,
|
||||
param.input_right_pads);
|
||||
|
||||
pass &= ck::profiler::profile_convnd_bwd_data_impl<3,
|
||||
ck::bhalf_t,
|
||||
ck::bhalf_t,
|
||||
ck::bhalf_t,
|
||||
float,
|
||||
ck::tensor_layout::convolution::NDHWC,
|
||||
ck::tensor_layout::convolution::KZYXC,
|
||||
ck::tensor_layout::convolution::NDHWK>(
|
||||
1, // do_verification,
|
||||
1, // init_method,
|
||||
0, // do_log,
|
||||
1, // nrepeat,
|
||||
param.N,
|
||||
param.K,
|
||||
param.C,
|
||||
param.input_spatial_lengths,
|
||||
param.filter_spatial_lengths,
|
||||
param.GetOutputSpatialLengths(),
|
||||
param.conv_filter_strides,
|
||||
param.conv_filter_dilations,
|
||||
param.input_left_pads,
|
||||
param.input_right_pads);
|
||||
|
||||
pass &= ck::profiler::profile_convnd_bwd_data_impl<3,
|
||||
int8_t,
|
||||
int8_t,
|
||||
int8_t,
|
||||
int,
|
||||
ck::tensor_layout::convolution::NDHWC,
|
||||
ck::tensor_layout::convolution::KZYXC,
|
||||
ck::tensor_layout::convolution::NDHWK>(
|
||||
1, // do_verification,
|
||||
1, // init_method,
|
||||
0, // do_log,
|
||||
1, // nrepeat,
|
||||
param.N,
|
||||
param.K,
|
||||
param.C,
|
||||
param.input_spatial_lengths,
|
||||
param.filter_spatial_lengths,
|
||||
param.GetOutputSpatialLengths(),
|
||||
param.conv_filter_strides,
|
||||
param.conv_filter_dilations,
|
||||
param.input_left_pads,
|
||||
param.input_right_pads);
|
||||
}
|
||||
|
||||
if(pass)
|
||||
{
|
||||
std::cout << "test convnd bwd : Pass" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "test convnd bwd: Fail " << std::endl;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user