Commit 6871fe41 authored by rocking's avatar rocking
Browse files

Modify ckProfiler

parent 04800608
...@@ -17,8 +17,9 @@ namespace tensor_operation { ...@@ -17,8 +17,9 @@ namespace tensor_operation {
namespace device { namespace device {
namespace instance { namespace instance {
static constexpr auto InOutRank = 4; // pool2d inherit pool3d
static constexpr auto WindowRank = 2; static constexpr auto InOutRank = 5;
static constexpr auto WindowRank = 3;
static constexpr auto MaxOp = ck::ReduceTensorOp::MAX; static constexpr auto MaxOp = ck::ReduceTensorOp::MAX;
static constexpr auto AvgOp = ck::ReduceTensorOp::AVG; static constexpr auto AvgOp = ck::ReduceTensorOp::AVG;
......
...@@ -31,15 +31,16 @@ bool profile_pool2d_fwd_impl(int do_verification, ...@@ -31,15 +31,16 @@ bool profile_pool2d_fwd_impl(int do_verification,
std::vector<index_t> in_length, // NCHW std::vector<index_t> in_length, // NCHW
std::vector<index_t> window_spatial_lengths, std::vector<index_t> window_spatial_lengths,
std::vector<index_t> window_strides, std::vector<index_t> window_strides,
std::vector<index_t> window_dilations,
std::vector<index_t> input_left_pads, std::vector<index_t> input_left_pads,
std::vector<index_t> input_right_pads) std::vector<index_t> input_right_pads)
{ {
constexpr index_t InOutRank = 4; constexpr index_t InOutRank = 5;
constexpr index_t WindowRank = 2; constexpr index_t WindowRank = 3;
if(in_length.size() != InOutRank || window_spatial_lengths.size() != WindowRank || if(in_length.size() != InOutRank || window_spatial_lengths.size() != WindowRank ||
window_strides.size() != WindowRank || input_left_pads.size() != WindowRank || window_strides.size() != WindowRank || window_dilations.size() != WindowRank ||
input_right_pads.size() != WindowRank) input_left_pads.size() != WindowRank || input_right_pads.size() != WindowRank)
return false; return false;
std::vector<index_t> out_length(InOutRank); std::vector<index_t> out_length(InOutRank);
...@@ -53,11 +54,13 @@ bool profile_pool2d_fwd_impl(int do_verification, ...@@ -53,11 +54,13 @@ bool profile_pool2d_fwd_impl(int do_verification,
// Calculate Ho, Wo // Calculate Ho, Wo
for(int i = 2; i < InOutRank; ++i) for(int i = 2; i < InOutRank; ++i)
{ {
auto pad1 = input_left_pads[i - 2]; auto pad1 = input_left_pads[i - 2];
auto pad2 = input_right_pads[i - 2]; auto pad2 = input_right_pads[i - 2];
auto windows_size = window_spatial_lengths[i - 2]; auto windows_size = window_spatial_lengths[i - 2];
auto windows_stride = window_strides[i - 2]; auto windows_stride = window_strides[i - 2];
out_length[i] = (in_length[i] + pad1 + pad2 - windows_size) / windows_stride + 1; auto windows_dilation = window_dilations[i - 2];
auto eff = (windows_size - 1) * windows_dilation + 1;
out_length[i] = (in_length[i] + pad1 + pad2 - eff) / windows_stride + 1;
} }
int Hi = in_length[2]; int Hi = in_length[2];
...@@ -131,6 +134,7 @@ bool profile_pool2d_fwd_impl(int do_verification, ...@@ -131,6 +134,7 @@ bool profile_pool2d_fwd_impl(int do_verification,
out_indices_n_c_ho_wo_host, out_indices_n_c_ho_wo_host,
window_spatial_lengths, window_spatial_lengths,
window_strides, window_strides,
window_dilations,
input_left_pads, input_left_pads,
input_right_pads); input_right_pads);
auto ref_invoker = ref.MakeInvoker(); auto ref_invoker = ref.MakeInvoker();
...@@ -152,6 +156,7 @@ bool profile_pool2d_fwd_impl(int do_verification, ...@@ -152,6 +156,7 @@ bool profile_pool2d_fwd_impl(int do_verification,
{C * Ho * Wo, 1, Wo * C, C}, {C * Ho * Wo, 1, Wo * C, C},
{C * Ho * Wo, 1, Wo * C, C}, {C * Ho * Wo, 1, Wo * C, C},
window_strides, window_strides,
window_dilations,
input_left_pads, input_left_pads,
input_right_pads, input_right_pads,
{2, 3}); {2, 3});
......
...@@ -31,6 +31,7 @@ bool profile_pool3d_fwd_impl(int do_verification, ...@@ -31,6 +31,7 @@ bool profile_pool3d_fwd_impl(int do_verification,
std::vector<index_t> in_length, // NCDHW std::vector<index_t> in_length, // NCDHW
std::vector<index_t> window_spatial_lengths, std::vector<index_t> window_spatial_lengths,
std::vector<index_t> window_strides, std::vector<index_t> window_strides,
std::vector<index_t> window_dilations,
std::vector<index_t> input_left_pads, std::vector<index_t> input_left_pads,
std::vector<index_t> input_right_pads) std::vector<index_t> input_right_pads)
{ {
...@@ -38,8 +39,8 @@ bool profile_pool3d_fwd_impl(int do_verification, ...@@ -38,8 +39,8 @@ bool profile_pool3d_fwd_impl(int do_verification,
constexpr index_t WindowRank = 3; constexpr index_t WindowRank = 3;
if(in_length.size() != InOutRank || window_spatial_lengths.size() != WindowRank || if(in_length.size() != InOutRank || window_spatial_lengths.size() != WindowRank ||
window_strides.size() != WindowRank || input_left_pads.size() != WindowRank || window_strides.size() != WindowRank || window_dilations.size() != WindowRank ||
input_right_pads.size() != WindowRank) input_left_pads.size() != WindowRank || input_right_pads.size() != WindowRank)
return false; return false;
std::vector<index_t> out_length(InOutRank); std::vector<index_t> out_length(InOutRank);
...@@ -53,11 +54,13 @@ bool profile_pool3d_fwd_impl(int do_verification, ...@@ -53,11 +54,13 @@ bool profile_pool3d_fwd_impl(int do_verification,
// Calculate Do, Ho, Wo // Calculate Do, Ho, Wo
for(int i = 2; i < InOutRank; ++i) for(int i = 2; i < InOutRank; ++i)
{ {
auto pad1 = input_left_pads[i - 2]; auto pad1 = input_left_pads[i - 2];
auto pad2 = input_right_pads[i - 2]; auto pad2 = input_right_pads[i - 2];
auto windows_size = window_spatial_lengths[i - 2]; auto windows_size = window_spatial_lengths[i - 2];
auto windows_stride = window_strides[i - 2]; auto windows_stride = window_strides[i - 2];
out_length[i] = (in_length[i] + pad1 + pad2 - windows_size) / windows_stride + 1; auto windows_dilation = window_dilations[i - 2];
auto eff = (windows_size - 1) * windows_dilation + 1;
out_length[i] = (in_length[i] + pad1 + pad2 - eff) / windows_stride + 1;
} }
int Di = in_length[2]; int Di = in_length[2];
...@@ -136,6 +139,7 @@ bool profile_pool3d_fwd_impl(int do_verification, ...@@ -136,6 +139,7 @@ bool profile_pool3d_fwd_impl(int do_verification,
out_indices_n_c_do_ho_wo_host, out_indices_n_c_do_ho_wo_host,
window_spatial_lengths, window_spatial_lengths,
window_strides, window_strides,
window_dilations,
input_left_pads, input_left_pads,
input_right_pads); input_right_pads);
auto ref_invoker = ref.MakeInvoker(); auto ref_invoker = ref.MakeInvoker();
...@@ -157,6 +161,7 @@ bool profile_pool3d_fwd_impl(int do_verification, ...@@ -157,6 +161,7 @@ bool profile_pool3d_fwd_impl(int do_verification,
{Do * C * Ho * Wo, 1, C * Ho * Wo, Wo * C, C}, {Do * C * Ho * Wo, 1, C * Ho * Wo, Wo * C, C},
{Do * C * Ho * Wo, 1, C * Ho * Wo, Wo * C, C}, {Do * C * Ho * Wo, 1, C * Ho * Wo, Wo * C, C},
window_strides, window_strides,
window_dilations,
input_left_pads, input_left_pads,
input_right_pads, input_right_pads,
{2, 3, 4}); {2, 3, 4});
......
...@@ -13,8 +13,12 @@ using ck::index_t; ...@@ -13,8 +13,12 @@ using ck::index_t;
struct avgPoolFwdArgParser struct avgPoolFwdArgParser
{ {
std::unordered_map<std::string, std::vector<int>> long_opts = { std::unordered_map<std::string, std::vector<int>> long_opts = {{"length", {}},
{"length", {}}, {"wsize", {}}, {"wstride", {}}, {"pad1", {}}, {"pad2", {}}}; {"wsize", {}},
{"wstride", {}},
{"wdilation", {}},
{"pad1", {}},
{"pad2", {}}};
bool parse_opt(int argc, char* argv[], const std::string& key, int i) bool parse_opt(int argc, char* argv[], const std::string& key, int i)
{ {
...@@ -55,10 +59,11 @@ void print_help_avg_pool2d_fwd() ...@@ -55,10 +59,11 @@ void print_help_avg_pool2d_fwd()
<< "--length: input tensor length for NDHW(e.g, --length 2 32 30 30) \n" << "--length: input tensor length for NDHW(e.g, --length 2 32 30 30) \n"
<< "--wsize: window size for YX (e.g, --wsize 2 2) \n" << "--wsize: window size for YX (e.g, --wsize 2 2) \n"
<< "--wstride: window stride for HW (e.g, --wstride 2 2) \n" << "--wstride: window stride for HW (e.g, --wstride 2 2) \n"
<< "--wdilation: window dilation for DHW (e.g, --wdilation 1 1) \n"
<< "--pad1: left side of padding in HW (e.g, --pad1 1 1) \n" << "--pad1: left side of padding in HW (e.g, --pad1 1 1) \n"
<< "--pad2: right side of padding in HW (e.g, --pad2 1 1) \n" << "--pad2: right side of padding in HW (e.g, --pad2 1 1) \n"
<< "eg: ckProfiler avg_pool2d_fwd 0 1 2 0 1 0 --length 2 32 30 30 --wsize 2 2 " << "eg: ckProfiler avg_pool2d_fwd 0 1 2 0 1 0 --length 2 32 30 30 --wsize 2 2 "
"--wstride 2 2 --pad1 1 1 --pad2 1 1" "--wstride 2 2 --wdilation 1 1 --pad1 1 1 --pad2 1 1"
<< std::endl; << std::endl;
} }
...@@ -73,15 +78,16 @@ int profile_avg_pool2d_fwd(int argc, char* argv[]) ...@@ -73,15 +78,16 @@ int profile_avg_pool2d_fwd(int argc, char* argv[])
std::vector<index_t> in_length = {2, 32, 30, 30}; std::vector<index_t> in_length = {2, 32, 30, 30};
std::vector<index_t> wsize = {2, 2}; std::vector<index_t> wsize = {2, 2};
std::vector<index_t> wstride = {2, 2}; std::vector<index_t> wstride = {2, 2};
std::vector<index_t> wdilation = {1, 1};
std::vector<index_t> pad1 = {1, 1}; std::vector<index_t> pad1 = {1, 1};
std::vector<index_t> pad2 = {1, 1}; std::vector<index_t> pad2 = {1, 1};
if(argc != 2 && argc != 25) if(argc != 2 && argc != 26)
{ {
print_help_avg_pool2d_fwd(); print_help_avg_pool2d_fwd();
return 0; return 0;
} }
else if(argc == 25) else if(argc == 26)
{ {
data_type = static_cast<ck::DataTypeEnum>(std::stoi(argv[2])); data_type = static_cast<ck::DataTypeEnum>(std::stoi(argv[2]));
do_verification = std::stoi(argv[3]); do_verification = std::stoi(argv[3]);
...@@ -95,6 +101,7 @@ int profile_avg_pool2d_fwd(int argc, char* argv[]) ...@@ -95,6 +101,7 @@ int profile_avg_pool2d_fwd(int argc, char* argv[])
in_length = arg_parser.long_opts["length"]; in_length = arg_parser.long_opts["length"];
wsize = arg_parser.long_opts["wsize"]; wsize = arg_parser.long_opts["wsize"];
wstride = arg_parser.long_opts["wstride"]; wstride = arg_parser.long_opts["wstride"];
wdilation = arg_parser.long_opts["wdilation"];
pad1 = arg_parser.long_opts["pad1"]; pad1 = arg_parser.long_opts["pad1"];
pad2 = arg_parser.long_opts["pad2"]; pad2 = arg_parser.long_opts["pad2"];
} }
...@@ -114,6 +121,7 @@ int profile_avg_pool2d_fwd(int argc, char* argv[]) ...@@ -114,6 +121,7 @@ int profile_avg_pool2d_fwd(int argc, char* argv[])
in_length, in_length,
wsize, wsize,
wstride, wstride,
wdilation,
pad1, pad1,
pad2); pad2);
} }
...@@ -127,6 +135,7 @@ int profile_avg_pool2d_fwd(int argc, char* argv[]) ...@@ -127,6 +135,7 @@ int profile_avg_pool2d_fwd(int argc, char* argv[])
in_length, in_length,
wsize, wsize,
wstride, wstride,
wdilation,
pad1, pad1,
pad2); pad2);
} }
......
...@@ -13,8 +13,12 @@ using ck::index_t; ...@@ -13,8 +13,12 @@ using ck::index_t;
struct maxPoolFwdArgParser struct maxPoolFwdArgParser
{ {
std::unordered_map<std::string, std::vector<int>> long_opts = { std::unordered_map<std::string, std::vector<int>> long_opts = {{"length", {}},
{"length", {}}, {"wsize", {}}, {"wstride", {}}, {"pad1", {}}, {"pad2", {}}}; {"wsize", {}},
{"wstride", {}},
{"wdilation", {}},
{"pad1", {}},
{"pad2", {}}};
bool parse_opt(int argc, char* argv[], const std::string& key, int i) bool parse_opt(int argc, char* argv[], const std::string& key, int i)
{ {
...@@ -56,10 +60,11 @@ void print_help_max_pool3d_fwd() ...@@ -56,10 +60,11 @@ void print_help_max_pool3d_fwd()
<< "--length: input tensor length for NCDHW(e.g, --length 2 32 30 30 30) \n" << "--length: input tensor length for NCDHW(e.g, --length 2 32 30 30 30) \n"
<< "--wsize: window size for ZYX (e.g, --wsize 2 2 2) \n" << "--wsize: window size for ZYX (e.g, --wsize 2 2 2) \n"
<< "--wstride: window stride for DHW (e.g, --wstride 2 2 2) \n" << "--wstride: window stride for DHW (e.g, --wstride 2 2 2) \n"
<< "--wdilation: window dilation for DHW (e.g, --wdilation 1 1 1) \n"
<< "--pad1: left side of padding in DHW (e.g, --pad1 1 1 1) \n" << "--pad1: left side of padding in DHW (e.g, --pad1 1 1 1) \n"
<< "--pad2: right side of padding in DHW (e.g, --pad2 1 1 1) \n" << "--pad2: right side of padding in DHW (e.g, --pad2 1 1 1) \n"
<< "eg: ckProfiler max_pool3d_fwd 0 1 2 0 1 0 --length 2 32 30 30 30 --wsize 2 2 2 " << "eg: ckProfiler max_pool3d_fwd 0 1 2 0 1 0 --length 2 32 30 30 30 --wsize 2 2 2 "
"--wstride 2 2 2 --pad1 1 1 1 --pad2 1 1 1" "--wstride 2 2 2 --wdilation 1 1 1 --pad1 1 1 1 --pad2 1 1 1"
<< std::endl; << std::endl;
} }
...@@ -75,15 +80,16 @@ int profile_max_pool3d_fwd(int argc, char* argv[]) ...@@ -75,15 +80,16 @@ int profile_max_pool3d_fwd(int argc, char* argv[])
std::vector<index_t> in_length = {2, 32, 30, 30, 30}; std::vector<index_t> in_length = {2, 32, 30, 30, 30};
std::vector<index_t> wsize = {2, 2, 2}; std::vector<index_t> wsize = {2, 2, 2};
std::vector<index_t> wstride = {2, 2, 2}; std::vector<index_t> wstride = {2, 2, 2};
std::vector<index_t> wdilation = {1, 1, 1};
std::vector<index_t> pad1 = {1, 1, 1}; std::vector<index_t> pad1 = {1, 1, 1};
std::vector<index_t> pad2 = {1, 1, 1}; std::vector<index_t> pad2 = {1, 1, 1};
if(argc != 2 && argc != 30) if(argc != 2 && argc != 31)
{ {
print_help_max_pool3d_fwd(); print_help_max_pool3d_fwd();
return 0; return 0;
} }
else if(argc == 30) else if(argc == 31)
{ {
data_type = static_cast<ck::DataTypeEnum>(std::stoi(argv[2])); data_type = static_cast<ck::DataTypeEnum>(std::stoi(argv[2]));
do_verification = std::stoi(argv[3]); do_verification = std::stoi(argv[3]);
...@@ -98,6 +104,7 @@ int profile_max_pool3d_fwd(int argc, char* argv[]) ...@@ -98,6 +104,7 @@ int profile_max_pool3d_fwd(int argc, char* argv[])
in_length = arg_parser.long_opts["length"]; in_length = arg_parser.long_opts["length"];
wsize = arg_parser.long_opts["wsize"]; wsize = arg_parser.long_opts["wsize"];
wstride = arg_parser.long_opts["wstride"]; wstride = arg_parser.long_opts["wstride"];
wdilation = arg_parser.long_opts["wdilation"];
pad1 = arg_parser.long_opts["pad1"]; pad1 = arg_parser.long_opts["pad1"];
pad2 = arg_parser.long_opts["pad2"]; pad2 = arg_parser.long_opts["pad2"];
} }
...@@ -118,6 +125,7 @@ int profile_max_pool3d_fwd(int argc, char* argv[]) ...@@ -118,6 +125,7 @@ int profile_max_pool3d_fwd(int argc, char* argv[])
in_length, in_length,
wsize, wsize,
wstride, wstride,
wdilation,
pad1, pad1,
pad2); pad2);
else else
...@@ -129,6 +137,7 @@ int profile_max_pool3d_fwd(int argc, char* argv[]) ...@@ -129,6 +137,7 @@ int profile_max_pool3d_fwd(int argc, char* argv[])
in_length, in_length,
wsize, wsize,
wstride, wstride,
wdilation,
pad1, pad1,
pad2); pad2);
} }
...@@ -143,6 +152,7 @@ int profile_max_pool3d_fwd(int argc, char* argv[]) ...@@ -143,6 +152,7 @@ int profile_max_pool3d_fwd(int argc, char* argv[])
in_length, in_length,
wsize, wsize,
wstride, wstride,
wdilation,
pad1, pad1,
pad2); pad2);
else else
...@@ -154,6 +164,7 @@ int profile_max_pool3d_fwd(int argc, char* argv[]) ...@@ -154,6 +164,7 @@ int profile_max_pool3d_fwd(int argc, char* argv[])
in_length, in_length,
wsize, wsize,
wstride, wstride,
wdilation,
pad1, pad1,
pad2); pad2);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment