mirror of
https://github.com/ROCm/composable_kernel.git
synced 2026-05-12 01:10:17 +00:00
Pool3d fwd (#697)
* Expand the base class of pool2d, prepare to share base class with pool3d * Add pool3d device op * Add pool3d f16 example * Refactor the base class. implement generic pooling in the future * clang format * get original index in max pooling * Add outputindex to base class * Fix dimension * Add pooling instance * Use indexType instead * Remove useless header * Extract IndexDataType to template * Extract pooling reference code * clang format * clang format * Fix typo * Add tensor stride * Add missing header * Add index stride and output stride * Refine naming * Add type to base class * Rename file * Use proper size * Fix typo * Refine naming * Modify the argument into vector. * Add max pool profiler * Refine naming * Support f32 pool * Fix typo * Add avg pool2d fwd in profiler * clang format * Rename AccDatatype to ComputeDatatype * Fix init * test pool * Extract variable * Add client example * Check the pooling dim * clang format * Connect argv and arg_parser * Add found check * Remove useless header * Refine naming * Adjust the order of device_pool_fwd
This commit is contained in:
@@ -25,6 +25,8 @@ set(PROFILER_SOURCES
|
||||
profile_reduce.cpp
|
||||
profile_groupnorm.cpp
|
||||
profile_layernorm.cpp
|
||||
profile_avg_pool2d_fwd.cpp
|
||||
profile_max_pool3d_fwd.cpp
|
||||
profile_softmax.cpp
|
||||
profile_batchnorm_fwd.cpp
|
||||
profile_batchnorm_bwd.cpp
|
||||
@@ -74,4 +76,6 @@ target_link_libraries(${PROFILER_EXECUTABLE} PRIVATE device_batchnorm_instance)
|
||||
target_link_libraries(${PROFILER_EXECUTABLE} PRIVATE device_grouped_gemm_fastgelu_instance)
|
||||
target_link_libraries(${PROFILER_EXECUTABLE} PRIVATE device_contraction_bilinear_instance)
|
||||
target_link_libraries(${PROFILER_EXECUTABLE} PRIVATE device_contraction_scale_instance)
|
||||
target_link_libraries(${PROFILER_EXECUTABLE} PRIVATE device_pool_fwd_instance)
|
||||
|
||||
rocm_install(TARGETS ${PROFILER_EXECUTABLE} COMPONENT profiler)
|
||||
|
||||
141
profiler/src/profile_avg_pool2d_fwd.cpp
Normal file
141
profiler/src/profile_avg_pool2d_fwd.cpp
Normal file
@@ -0,0 +1,141 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "profiler/data_type_enum.hpp"
|
||||
#include "profiler/profile_pool2d_fwd_impl.hpp"
|
||||
#include "profiler_operation_registry.hpp"
|
||||
|
||||
using ck::index_t;
|
||||
|
||||
struct avgPoolFwdArgParser
|
||||
{
|
||||
std::unordered_map<std::string, std::vector<int>> long_opts = {
|
||||
{"length", {}}, {"wsize", {}}, {"wstride", {}}, {"pad1", {}}, {"pad2", {}}};
|
||||
|
||||
bool parse_opt(int argc, char* argv[], const std::string& key, int i)
|
||||
{
|
||||
if(std::string("--") + key == argv[i])
|
||||
{
|
||||
int pos = i;
|
||||
while(++i < argc && argv[i][0] != '-') {}
|
||||
int end = i;
|
||||
for(int j = pos + 1; j < end; j++)
|
||||
{
|
||||
long_opts[key].push_back(std::stoi(argv[j]));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void operator()(int argc, char* argv[])
|
||||
{
|
||||
for(auto& kv : long_opts)
|
||||
{
|
||||
for(int i = 1; i < argc; i++)
|
||||
{
|
||||
if(parse_opt(argc, argv, kv.first, i))
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void print_help_avg_pool2d_fwd()
|
||||
{
|
||||
std::cout << "arg1: data type (0: fp16; 1: fp32)\n"
|
||||
<< "arg2: verification (0: no; 1: yes)\n"
|
||||
<< "arg3: initialization (0: no init; 1: integer value; 2: decimal value)\n"
|
||||
<< "arg4: print tensor value (0: no; 1: yes)\n"
|
||||
<< "arg5: time kernel (0=no, 1=yes)\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"
|
||||
<< "--wstride: window stride for HW (e.g, --wstride 2 2) \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"
|
||||
<< "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"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
int profile_avg_pool2d_fwd(int argc, char* argv[])
|
||||
{
|
||||
ck::DataTypeEnum data_type = ck::DataTypeEnum::Half;
|
||||
bool do_verification = true;
|
||||
int init_method = 0;
|
||||
bool do_log = false;
|
||||
bool time_kernel = true;
|
||||
|
||||
std::vector<index_t> in_length = {2, 32, 30, 30};
|
||||
std::vector<index_t> wsize = {2, 2};
|
||||
std::vector<index_t> wstride = {2, 2};
|
||||
std::vector<index_t> pad1 = {1, 1};
|
||||
std::vector<index_t> pad2 = {1, 1};
|
||||
|
||||
if(argc != 2 && argc != 25)
|
||||
{
|
||||
print_help_avg_pool2d_fwd();
|
||||
return 0;
|
||||
}
|
||||
else if(argc == 25)
|
||||
{
|
||||
data_type = static_cast<ck::DataTypeEnum>(std::stoi(argv[2]));
|
||||
do_verification = std::stoi(argv[3]);
|
||||
init_method = std::stoi(argv[4]);
|
||||
do_log = std::stoi(argv[5]);
|
||||
time_kernel = std::stoi(argv[6]);
|
||||
|
||||
// parse the long options
|
||||
avgPoolFwdArgParser arg_parser;
|
||||
arg_parser(argc, argv);
|
||||
in_length = arg_parser.long_opts["length"];
|
||||
wsize = arg_parser.long_opts["wsize"];
|
||||
wstride = arg_parser.long_opts["wstride"];
|
||||
pad1 = arg_parser.long_opts["pad1"];
|
||||
pad2 = arg_parser.long_opts["pad2"];
|
||||
}
|
||||
|
||||
using F16 = ck::half_t;
|
||||
using F32 = float;
|
||||
using I32 = int32_t;
|
||||
constexpr auto ReduceOpId = ck::ReduceTensorOp::AVG;
|
||||
|
||||
if(data_type == ck::DataTypeEnum::Half)
|
||||
{
|
||||
ck::profiler::profile_pool2d_fwd_impl<F16, F16, F32, I32, ReduceOpId, false, false>(
|
||||
do_verification,
|
||||
init_method,
|
||||
do_log,
|
||||
time_kernel,
|
||||
in_length,
|
||||
wsize,
|
||||
wstride,
|
||||
pad1,
|
||||
pad2);
|
||||
}
|
||||
else if(data_type == ck::DataTypeEnum::Float)
|
||||
{
|
||||
ck::profiler::profile_pool2d_fwd_impl<F32, F32, F32, I32, ReduceOpId, false, false>(
|
||||
do_verification,
|
||||
init_method,
|
||||
do_log,
|
||||
time_kernel,
|
||||
in_length,
|
||||
wsize,
|
||||
wstride,
|
||||
pad1,
|
||||
pad2);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error("not implemented yet");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
REGISTER_PROFILER_OPERATION("avg_pool2d_fwd", "avg_pool2d fwd", profile_avg_pool2d_fwd);
|
||||
@@ -64,7 +64,7 @@ int profile_groupnorm(int argc, char* argv[])
|
||||
ck::DataTypeEnum data_type = ck::DataTypeEnum::Half;
|
||||
bool do_verification = false;
|
||||
int init_method = 0;
|
||||
bool do_log = 0;
|
||||
bool do_log = false;
|
||||
bool time_kernel = 1;
|
||||
std::vector<index_t> length = {64, 16, 16, 32, 40};
|
||||
|
||||
|
||||
168
profiler/src/profile_max_pool3d_fwd.cpp
Normal file
168
profiler/src/profile_max_pool3d_fwd.cpp
Normal file
@@ -0,0 +1,168 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "profiler/data_type_enum.hpp"
|
||||
#include "profiler/profile_pool3d_fwd_impl.hpp"
|
||||
#include "profiler_operation_registry.hpp"
|
||||
|
||||
using ck::index_t;
|
||||
|
||||
struct maxPoolFwdArgParser
|
||||
{
|
||||
std::unordered_map<std::string, std::vector<int>> long_opts = {
|
||||
{"length", {}}, {"wsize", {}}, {"wstride", {}}, {"pad1", {}}, {"pad2", {}}};
|
||||
|
||||
bool parse_opt(int argc, char* argv[], const std::string& key, int i)
|
||||
{
|
||||
if(std::string("--") + key == argv[i])
|
||||
{
|
||||
int pos = i;
|
||||
while(++i < argc && argv[i][0] != '-') {}
|
||||
int end = i;
|
||||
for(int j = pos + 1; j < end; j++)
|
||||
{
|
||||
long_opts[key].push_back(std::stoi(argv[j]));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void operator()(int argc, char* argv[])
|
||||
{
|
||||
for(auto& kv : long_opts)
|
||||
{
|
||||
for(int i = 1; i < argc; i++)
|
||||
{
|
||||
if(parse_opt(argc, argv, kv.first, i))
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void print_help_max_pool3d_fwd()
|
||||
{
|
||||
std::cout << "arg1: data type (0: fp16; 1: fp32)\n"
|
||||
<< "arg2: verification (0: no; 1: yes)\n"
|
||||
<< "arg3: initialization (0: no init; 1: integer value; 2: decimal value)\n"
|
||||
<< "arg4: print tensor value (0: no; 1: yes)\n"
|
||||
<< "arg5: time kernel (0=no, 1=yes)\n"
|
||||
<< "arg6: return index (0=no, 1=yes)\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"
|
||||
<< "--wstride: window stride for DHW (e.g, --wstride 2 2 2) \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"
|
||||
<< "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"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
int profile_max_pool3d_fwd(int argc, char* argv[])
|
||||
{
|
||||
ck::DataTypeEnum data_type = ck::DataTypeEnum::Half;
|
||||
bool do_verification = true;
|
||||
int init_method = 0;
|
||||
bool do_log = false;
|
||||
bool time_kernel = true;
|
||||
bool return_index = false;
|
||||
|
||||
std::vector<index_t> in_length = {2, 32, 30, 30, 30};
|
||||
std::vector<index_t> wsize = {2, 2, 2};
|
||||
std::vector<index_t> wstride = {2, 2, 2};
|
||||
std::vector<index_t> pad1 = {1, 1, 1};
|
||||
std::vector<index_t> pad2 = {1, 1, 1};
|
||||
|
||||
if(argc != 2 && argc != 30)
|
||||
{
|
||||
print_help_max_pool3d_fwd();
|
||||
return 0;
|
||||
}
|
||||
else if(argc == 30)
|
||||
{
|
||||
data_type = static_cast<ck::DataTypeEnum>(std::stoi(argv[2]));
|
||||
do_verification = std::stoi(argv[3]);
|
||||
init_method = std::stoi(argv[4]);
|
||||
do_log = std::stoi(argv[5]);
|
||||
time_kernel = std::stoi(argv[6]);
|
||||
return_index = std::stoi(argv[7]);
|
||||
|
||||
// parse the long options
|
||||
maxPoolFwdArgParser arg_parser;
|
||||
arg_parser(argc, argv);
|
||||
in_length = arg_parser.long_opts["length"];
|
||||
wsize = arg_parser.long_opts["wsize"];
|
||||
wstride = arg_parser.long_opts["wstride"];
|
||||
pad1 = arg_parser.long_opts["pad1"];
|
||||
pad2 = arg_parser.long_opts["pad2"];
|
||||
}
|
||||
|
||||
using F16 = ck::half_t;
|
||||
using F32 = float;
|
||||
using I32 = int32_t;
|
||||
constexpr auto ReduceOpId = ck::ReduceTensorOp::MAX;
|
||||
|
||||
if(data_type == ck::DataTypeEnum::Half)
|
||||
{
|
||||
if(return_index)
|
||||
ck::profiler::profile_pool3d_fwd_impl<F16, F16, F16, I32, ReduceOpId, false, true>(
|
||||
do_verification,
|
||||
init_method,
|
||||
do_log,
|
||||
time_kernel,
|
||||
in_length,
|
||||
wsize,
|
||||
wstride,
|
||||
pad1,
|
||||
pad2);
|
||||
else
|
||||
ck::profiler::profile_pool3d_fwd_impl<F16, F16, F16, I32, ReduceOpId, false, false>(
|
||||
do_verification,
|
||||
init_method,
|
||||
do_log,
|
||||
time_kernel,
|
||||
in_length,
|
||||
wsize,
|
||||
wstride,
|
||||
pad1,
|
||||
pad2);
|
||||
}
|
||||
else if(data_type == ck::DataTypeEnum::Float)
|
||||
{
|
||||
if(return_index)
|
||||
ck::profiler::profile_pool3d_fwd_impl<F32, F32, F32, I32, ReduceOpId, false, true>(
|
||||
do_verification,
|
||||
init_method,
|
||||
do_log,
|
||||
time_kernel,
|
||||
in_length,
|
||||
wsize,
|
||||
wstride,
|
||||
pad1,
|
||||
pad2);
|
||||
else
|
||||
ck::profiler::profile_pool3d_fwd_impl<F32, F32, F32, I32, ReduceOpId, false, false>(
|
||||
do_verification,
|
||||
init_method,
|
||||
do_log,
|
||||
time_kernel,
|
||||
in_length,
|
||||
wsize,
|
||||
wstride,
|
||||
pad1,
|
||||
pad2);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error("not implemented yet");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
REGISTER_PROFILER_OPERATION("max_pool3d_fwd", "max_pool3d fwd", profile_max_pool3d_fwd);
|
||||
Reference in New Issue
Block a user