mirror of
https://github.com/ROCm/composable_kernel.git
synced 2026-05-11 08:50: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:
@@ -131,11 +131,12 @@ int main(int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "Best Perf: " << best_ave_time << " ms, " << best_gb_per_sec << " GB/s, "
|
|
||||||
<< best_op_name << std::endl;
|
|
||||||
|
|
||||||
// run the best intance
|
// run the best intance
|
||||||
|
if(found)
|
||||||
{
|
{
|
||||||
|
std::cout << "Best Perf: " << best_ave_time << " ms, " << best_gb_per_sec << " GB/s, "
|
||||||
|
<< best_op_name << std::endl;
|
||||||
|
|
||||||
auto& op_ptr = op_ptrs[best_op_id];
|
auto& op_ptr = op_ptrs[best_op_id];
|
||||||
std::cout << "Run the best instance without timing: " << op_ptr->GetTypeString()
|
std::cout << "Run the best instance without timing: " << op_ptr->GetTypeString()
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
|||||||
5
client_example/19_pool_fwd/CMakeLists.txt
Normal file
5
client_example/19_pool_fwd/CMakeLists.txt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
add_executable(client_max_pool2d_fwd max_pool2d_fwd.cpp)
|
||||||
|
target_link_libraries(client_max_pool2d_fwd PRIVATE composable_kernel::device_operations)
|
||||||
|
|
||||||
|
add_executable(client_avg_pool3d_fwd avg_pool3d_fwd.cpp)
|
||||||
|
target_link_libraries(client_avg_pool3d_fwd PRIVATE composable_kernel::device_operations)
|
||||||
199
client_example/19_pool_fwd/avg_pool3d_fwd.cpp
Normal file
199
client_example/19_pool_fwd/avg_pool3d_fwd.cpp
Normal file
@@ -0,0 +1,199 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
|
||||||
|
|
||||||
|
#include <iomanip>
|
||||||
|
#include <vector>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "ck/ck.hpp"
|
||||||
|
#include "ck/tensor_operation/gpu/device/tensor_layout.hpp"
|
||||||
|
#include "ck/tensor_operation/gpu/device/device_pool_fwd.hpp"
|
||||||
|
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp"
|
||||||
|
|
||||||
|
#include "ck/library/tensor_operation_instance/gpu/pool3d_fwd.hpp"
|
||||||
|
|
||||||
|
using InDataType = ck::half_t;
|
||||||
|
using OutDataType = ck::half_t;
|
||||||
|
using IndexDataType = int32_t;
|
||||||
|
|
||||||
|
constexpr ck::index_t InOutRank = 5;
|
||||||
|
constexpr ck::index_t WindowRank = 3;
|
||||||
|
#if 0
|
||||||
|
constexpr auto ReduceOpId = ck::ReduceTensorOp::MAX;
|
||||||
|
constexpr bool OutputIndex = false;
|
||||||
|
#else
|
||||||
|
constexpr auto ReduceOpId = ck::ReduceTensorOp::AVG;
|
||||||
|
constexpr bool OutputIndex = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct SimpleDeviceMem
|
||||||
|
{
|
||||||
|
SimpleDeviceMem() = delete;
|
||||||
|
|
||||||
|
SimpleDeviceMem(std::size_t mem_size) : p_mem_{}
|
||||||
|
{
|
||||||
|
(void)hipMalloc(static_cast<void**>(&p_mem_), mem_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void* GetDeviceBuffer() { return p_mem_; }
|
||||||
|
|
||||||
|
~SimpleDeviceMem() { (void)hipFree(p_mem_); }
|
||||||
|
|
||||||
|
void* p_mem_;
|
||||||
|
};
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
ck::index_t N = 2;
|
||||||
|
ck::index_t C = 32;
|
||||||
|
ck::index_t Z = 2;
|
||||||
|
ck::index_t Y = 2;
|
||||||
|
ck::index_t X = 2;
|
||||||
|
ck::index_t Di = 30;
|
||||||
|
ck::index_t Hi = 30;
|
||||||
|
ck::index_t Wi = 30;
|
||||||
|
ck::index_t window_stride_d = 2;
|
||||||
|
ck::index_t window_stride_h = 2;
|
||||||
|
ck::index_t window_stride_w = 2;
|
||||||
|
ck::index_t in_left_pad_d = 1;
|
||||||
|
ck::index_t in_left_pad_h = 1;
|
||||||
|
ck::index_t in_left_pad_w = 1;
|
||||||
|
ck::index_t in_right_pad_d = 1;
|
||||||
|
ck::index_t in_right_pad_h = 1;
|
||||||
|
ck::index_t in_right_pad_w = 1;
|
||||||
|
|
||||||
|
ck::index_t Do = (Di + in_left_pad_d + in_right_pad_d - Z) / window_stride_d + 1;
|
||||||
|
ck::index_t Ho = (Hi + in_left_pad_h + in_right_pad_h - Y) / window_stride_h + 1;
|
||||||
|
ck::index_t Wo = (Wi + in_left_pad_w + in_right_pad_w - X) / window_stride_w + 1;
|
||||||
|
|
||||||
|
// Pool API only support the order of NCDHW
|
||||||
|
std::vector<ck::index_t> in_length = {N, C, Di, Hi, Wi};
|
||||||
|
std::vector<ck::index_t> out_length = {N, C, Do, Ho, Wo};
|
||||||
|
std::vector<ck::index_t> window_spatial_lengths = {Z, Y, X};
|
||||||
|
std::vector<ck::index_t> window_strides = {window_stride_d, window_stride_h, window_stride_w};
|
||||||
|
std::vector<ck::index_t> input_left_pads = {in_left_pad_d, in_left_pad_h, in_left_pad_w};
|
||||||
|
std::vector<ck::index_t> input_right_pads = {in_right_pad_d, in_right_pad_h, in_right_pad_w};
|
||||||
|
|
||||||
|
std::size_t in_tensor_size = N * C * Di * Hi * Wi;
|
||||||
|
std::size_t out_tensor_size = N * C * Do * Ho * Wo;
|
||||||
|
|
||||||
|
// tensor layout = NDHWC
|
||||||
|
std::vector<ck::index_t> in_tensor_stride = {Di * C * Hi * Wi, 1, C * Hi * Wi, Wi * C, C};
|
||||||
|
std::vector<ck::index_t> out_tensor_stride = {Do * C * Ho * Wo, 1, C * Ho * Wo, Wo * C, C};
|
||||||
|
|
||||||
|
SimpleDeviceMem in_device_buf(sizeof(InDataType) * in_tensor_size);
|
||||||
|
SimpleDeviceMem out_device_buf(sizeof(OutDataType) * out_tensor_size);
|
||||||
|
SimpleDeviceMem out_indices_device_buf(sizeof(IndexDataType) * out_tensor_size);
|
||||||
|
|
||||||
|
using DeviceOp = ck::tensor_operation::device::DevicePoolFwd<InOutRank,
|
||||||
|
WindowRank,
|
||||||
|
InDataType,
|
||||||
|
OutDataType,
|
||||||
|
IndexDataType,
|
||||||
|
ReduceOpId,
|
||||||
|
OutputIndex>;
|
||||||
|
|
||||||
|
// get device op instances
|
||||||
|
const auto op_ptrs = ck::tensor_operation::device::instance::DeviceOperationInstanceFactory<
|
||||||
|
DeviceOp>::GetInstances();
|
||||||
|
|
||||||
|
std::cout << "found " << op_ptrs.size() << " instances" << std::endl;
|
||||||
|
|
||||||
|
std::string best_op_name;
|
||||||
|
bool found = false;
|
||||||
|
int best_op_id = -1;
|
||||||
|
float best_ave_time = std::numeric_limits<float>::max();
|
||||||
|
float best_gb_per_sec = 0;
|
||||||
|
|
||||||
|
// profile device operation instances
|
||||||
|
std::cout << "Run all instances and do timing" << std::endl;
|
||||||
|
|
||||||
|
for(int i = 0; i < op_ptrs.size(); ++i)
|
||||||
|
{
|
||||||
|
auto& op_ptr = op_ptrs[i];
|
||||||
|
auto argument_ptr = op_ptr->MakeArgumentPointer(
|
||||||
|
static_cast<InDataType*>(in_device_buf.GetDeviceBuffer()),
|
||||||
|
static_cast<OutDataType*>(out_device_buf.GetDeviceBuffer()),
|
||||||
|
static_cast<IndexDataType*>(out_indices_device_buf.GetDeviceBuffer()),
|
||||||
|
in_length,
|
||||||
|
window_spatial_lengths,
|
||||||
|
out_length,
|
||||||
|
in_tensor_stride,
|
||||||
|
out_tensor_stride,
|
||||||
|
out_tensor_stride,
|
||||||
|
window_strides,
|
||||||
|
input_left_pads,
|
||||||
|
input_right_pads,
|
||||||
|
{2, 3, 4});
|
||||||
|
|
||||||
|
auto invoker_ptr = op_ptr->MakeInvokerPointer();
|
||||||
|
|
||||||
|
std::string op_name = op_ptr->GetTypeString();
|
||||||
|
|
||||||
|
if(op_ptr->IsSupportedArgument(argument_ptr.get()))
|
||||||
|
{
|
||||||
|
float ave_time = invoker_ptr->Run(argument_ptr.get(), StreamConfig{nullptr, true});
|
||||||
|
|
||||||
|
std::size_t num_bytes =
|
||||||
|
in_tensor_size * sizeof(InDataType) + out_tensor_size * sizeof(OutDataType);
|
||||||
|
|
||||||
|
if constexpr(OutputIndex)
|
||||||
|
num_bytes += out_tensor_size * sizeof(IndexDataType);
|
||||||
|
|
||||||
|
float gb_per_sec = num_bytes / 1.E6 / ave_time;
|
||||||
|
|
||||||
|
std::cout << "Perf: " << std::setw(10) << ave_time << " ms, " << gb_per_sec << " GB/s, "
|
||||||
|
<< op_name << std::endl;
|
||||||
|
|
||||||
|
if(ave_time < best_ave_time)
|
||||||
|
{
|
||||||
|
found = true;
|
||||||
|
best_op_id = i;
|
||||||
|
best_op_name = op_name;
|
||||||
|
best_ave_time = ave_time;
|
||||||
|
best_gb_per_sec = gb_per_sec;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << op_name << " does not support this problem" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// run the best intance
|
||||||
|
if(found)
|
||||||
|
{
|
||||||
|
std::cout << "Best Perf: " << best_ave_time << " ms, " << best_gb_per_sec << " GB/s, "
|
||||||
|
<< best_op_name << std::endl;
|
||||||
|
|
||||||
|
auto& op_ptr = op_ptrs[best_op_id];
|
||||||
|
std::cout << "Run the best instance without timing: " << op_ptr->GetTypeString()
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
|
auto argument_ptr = op_ptr->MakeArgumentPointer(
|
||||||
|
static_cast<InDataType*>(in_device_buf.GetDeviceBuffer()),
|
||||||
|
static_cast<OutDataType*>(out_device_buf.GetDeviceBuffer()),
|
||||||
|
static_cast<IndexDataType*>(out_indices_device_buf.GetDeviceBuffer()),
|
||||||
|
in_length,
|
||||||
|
window_spatial_lengths,
|
||||||
|
out_length,
|
||||||
|
in_tensor_stride,
|
||||||
|
out_tensor_stride,
|
||||||
|
out_tensor_stride,
|
||||||
|
window_strides,
|
||||||
|
input_left_pads,
|
||||||
|
input_right_pads,
|
||||||
|
{2, 3, 4});
|
||||||
|
|
||||||
|
auto invoker_ptr = op_ptr->MakeInvokerPointer();
|
||||||
|
|
||||||
|
if(op_ptr->IsSupportedArgument(argument_ptr.get()))
|
||||||
|
{
|
||||||
|
invoker_ptr->Run(argument_ptr.get(), StreamConfig{nullptr, false});
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "Done" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
193
client_example/19_pool_fwd/max_pool2d_fwd.cpp
Normal file
193
client_example/19_pool_fwd/max_pool2d_fwd.cpp
Normal file
@@ -0,0 +1,193 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
|
||||||
|
|
||||||
|
#include <iomanip>
|
||||||
|
#include <vector>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "ck/ck.hpp"
|
||||||
|
#include "ck/tensor_operation/gpu/device/tensor_layout.hpp"
|
||||||
|
#include "ck/tensor_operation/gpu/device/device_pool_fwd.hpp"
|
||||||
|
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp"
|
||||||
|
|
||||||
|
#include "ck/library/tensor_operation_instance/gpu/pool2d_fwd.hpp"
|
||||||
|
|
||||||
|
using InDataType = ck::half_t;
|
||||||
|
using OutDataType = ck::half_t;
|
||||||
|
using IndexDataType = int32_t;
|
||||||
|
|
||||||
|
constexpr ck::index_t InOutRank = 4;
|
||||||
|
constexpr ck::index_t WindowRank = 2;
|
||||||
|
#if 1
|
||||||
|
constexpr auto ReduceOpId = ck::ReduceTensorOp::MAX;
|
||||||
|
constexpr bool OutputIndex = true;
|
||||||
|
#else
|
||||||
|
constexpr auto ReduceOpId = ck::ReduceTensorOp::AVG;
|
||||||
|
constexpr bool OutputIndex = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct SimpleDeviceMem
|
||||||
|
{
|
||||||
|
SimpleDeviceMem() = delete;
|
||||||
|
|
||||||
|
SimpleDeviceMem(std::size_t mem_size) : p_mem_{}
|
||||||
|
{
|
||||||
|
(void)hipMalloc(static_cast<void**>(&p_mem_), mem_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void* GetDeviceBuffer() { return p_mem_; }
|
||||||
|
|
||||||
|
~SimpleDeviceMem() { (void)hipFree(p_mem_); }
|
||||||
|
|
||||||
|
void* p_mem_;
|
||||||
|
};
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
ck::index_t N = 2;
|
||||||
|
ck::index_t C = 32;
|
||||||
|
ck::index_t Y = 2;
|
||||||
|
ck::index_t X = 2;
|
||||||
|
ck::index_t Hi = 30;
|
||||||
|
ck::index_t Wi = 30;
|
||||||
|
ck::index_t window_stride_h = 2;
|
||||||
|
ck::index_t window_stride_w = 2;
|
||||||
|
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;
|
||||||
|
|
||||||
|
ck::index_t Ho = (Hi + in_left_pad_h + in_right_pad_h - Y) / window_stride_h + 1;
|
||||||
|
ck::index_t Wo = (Wi + in_left_pad_w + in_right_pad_w - X) / window_stride_w + 1;
|
||||||
|
|
||||||
|
// Pool API only support the order of NCHW
|
||||||
|
std::vector<ck::index_t> in_length = {N, C, Hi, Wi};
|
||||||
|
std::vector<ck::index_t> out_length = {N, C, Ho, Wo};
|
||||||
|
std::vector<ck::index_t> window_spatial_lengths = {Y, X};
|
||||||
|
std::vector<ck::index_t> window_strides = {window_stride_h, window_stride_w};
|
||||||
|
std::vector<ck::index_t> input_left_pads = {in_left_pad_h, in_left_pad_w};
|
||||||
|
std::vector<ck::index_t> input_right_pads = {in_right_pad_h, in_right_pad_w};
|
||||||
|
|
||||||
|
std::size_t in_tensor_size = N * C * Hi * Wi;
|
||||||
|
std::size_t out_tensor_size = N * C * Ho * Wo;
|
||||||
|
|
||||||
|
// tensor layout = NHWC
|
||||||
|
std::vector<ck::index_t> in_tensor_stride = {C * Hi * Wi, 1, Wi * C, C};
|
||||||
|
std::vector<ck::index_t> out_tensor_stride = {C * Ho * Wo, 1, Wo * C, C};
|
||||||
|
|
||||||
|
SimpleDeviceMem in_device_buf(sizeof(InDataType) * in_tensor_size);
|
||||||
|
SimpleDeviceMem out_device_buf(sizeof(OutDataType) * out_tensor_size);
|
||||||
|
SimpleDeviceMem out_indices_device_buf(sizeof(IndexDataType) * out_tensor_size);
|
||||||
|
|
||||||
|
using DeviceOp = ck::tensor_operation::device::DevicePoolFwd<InOutRank,
|
||||||
|
WindowRank,
|
||||||
|
InDataType,
|
||||||
|
OutDataType,
|
||||||
|
IndexDataType,
|
||||||
|
ReduceOpId,
|
||||||
|
OutputIndex>;
|
||||||
|
|
||||||
|
// get device op instances
|
||||||
|
const auto op_ptrs = ck::tensor_operation::device::instance::DeviceOperationInstanceFactory<
|
||||||
|
DeviceOp>::GetInstances();
|
||||||
|
|
||||||
|
std::cout << "found " << op_ptrs.size() << " instances" << std::endl;
|
||||||
|
|
||||||
|
std::string best_op_name;
|
||||||
|
bool found = false;
|
||||||
|
int best_op_id = -1;
|
||||||
|
float best_ave_time = std::numeric_limits<float>::max();
|
||||||
|
float best_gb_per_sec = 0;
|
||||||
|
|
||||||
|
// profile device operation instances
|
||||||
|
std::cout << "Run all instances and do timing" << std::endl;
|
||||||
|
|
||||||
|
for(int i = 0; i < op_ptrs.size(); ++i)
|
||||||
|
{
|
||||||
|
auto& op_ptr = op_ptrs[i];
|
||||||
|
auto argument_ptr = op_ptr->MakeArgumentPointer(
|
||||||
|
static_cast<InDataType*>(in_device_buf.GetDeviceBuffer()),
|
||||||
|
static_cast<OutDataType*>(out_device_buf.GetDeviceBuffer()),
|
||||||
|
static_cast<IndexDataType*>(out_indices_device_buf.GetDeviceBuffer()),
|
||||||
|
in_length,
|
||||||
|
window_spatial_lengths,
|
||||||
|
out_length,
|
||||||
|
in_tensor_stride,
|
||||||
|
out_tensor_stride,
|
||||||
|
out_tensor_stride,
|
||||||
|
window_strides,
|
||||||
|
input_left_pads,
|
||||||
|
input_right_pads,
|
||||||
|
{2, 3});
|
||||||
|
|
||||||
|
auto invoker_ptr = op_ptr->MakeInvokerPointer();
|
||||||
|
|
||||||
|
std::string op_name = op_ptr->GetTypeString();
|
||||||
|
|
||||||
|
if(op_ptr->IsSupportedArgument(argument_ptr.get()))
|
||||||
|
{
|
||||||
|
float ave_time = invoker_ptr->Run(argument_ptr.get(), StreamConfig{nullptr, true});
|
||||||
|
|
||||||
|
std::size_t num_bytes =
|
||||||
|
in_tensor_size * sizeof(InDataType) + out_tensor_size * sizeof(OutDataType);
|
||||||
|
|
||||||
|
if constexpr(OutputIndex)
|
||||||
|
num_bytes += out_tensor_size * sizeof(IndexDataType);
|
||||||
|
|
||||||
|
float gb_per_sec = num_bytes / 1.E6 / ave_time;
|
||||||
|
|
||||||
|
std::cout << "Perf: " << std::setw(10) << ave_time << " ms, " << gb_per_sec << " GB/s, "
|
||||||
|
<< op_name << std::endl;
|
||||||
|
|
||||||
|
if(ave_time < best_ave_time)
|
||||||
|
{
|
||||||
|
found = true;
|
||||||
|
best_op_id = i;
|
||||||
|
best_op_name = op_name;
|
||||||
|
best_ave_time = ave_time;
|
||||||
|
best_gb_per_sec = gb_per_sec;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << op_name << " does not support this problem" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// run the best intance
|
||||||
|
if(found)
|
||||||
|
{
|
||||||
|
std::cout << "Best Perf: " << best_ave_time << " ms, " << best_gb_per_sec << " GB/s, "
|
||||||
|
<< best_op_name << std::endl;
|
||||||
|
|
||||||
|
auto& op_ptr = op_ptrs[best_op_id];
|
||||||
|
std::cout << "Run the best instance without timing: " << op_ptr->GetTypeString()
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
|
auto argument_ptr = op_ptr->MakeArgumentPointer(
|
||||||
|
static_cast<InDataType*>(in_device_buf.GetDeviceBuffer()),
|
||||||
|
static_cast<OutDataType*>(out_device_buf.GetDeviceBuffer()),
|
||||||
|
static_cast<IndexDataType*>(out_indices_device_buf.GetDeviceBuffer()),
|
||||||
|
in_length,
|
||||||
|
window_spatial_lengths,
|
||||||
|
out_length,
|
||||||
|
in_tensor_stride,
|
||||||
|
out_tensor_stride,
|
||||||
|
out_tensor_stride,
|
||||||
|
window_strides,
|
||||||
|
input_left_pads,
|
||||||
|
input_right_pads,
|
||||||
|
{2, 3});
|
||||||
|
|
||||||
|
auto invoker_ptr = op_ptr->MakeInvokerPointer();
|
||||||
|
|
||||||
|
if(op_ptr->IsSupportedArgument(argument_ptr.get()))
|
||||||
|
{
|
||||||
|
invoker_ptr->Run(argument_ptr.get(), StreamConfig{nullptr, false});
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "Done" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -17,115 +17,11 @@
|
|||||||
#include "ck/library/utility/host_tensor.hpp"
|
#include "ck/library/utility/host_tensor.hpp"
|
||||||
#include "ck/library/utility/host_tensor_generator.hpp"
|
#include "ck/library/utility/host_tensor_generator.hpp"
|
||||||
#include "ck/library/utility/literals.hpp"
|
#include "ck/library/utility/literals.hpp"
|
||||||
|
#include "ck/library/reference_tensor_operation/cpu/reference_pool_fwd.hpp"
|
||||||
|
|
||||||
template <typename InDataType,
|
template <typename InDataType,
|
||||||
typename OutDataType,
|
typename OutDataType,
|
||||||
typename AccDataType,
|
typename ComputeDataType,
|
||||||
typename IndexDataType,
|
|
||||||
ck::ReduceTensorOp ReduceOpId,
|
|
||||||
bool PropagateNan,
|
|
||||||
bool OutputIndex>
|
|
||||||
static void pool_host_verify(const Tensor<InDataType>& in,
|
|
||||||
Tensor<OutDataType>& out,
|
|
||||||
Tensor<IndexDataType>& out_indices,
|
|
||||||
const std::array<ck::index_t, 2>& window_spatial_lengths,
|
|
||||||
const std::array<ck::index_t, 2>& window_strides,
|
|
||||||
const std::array<ck::index_t, 2>& in_left_pads,
|
|
||||||
const std::array<ck::index_t, 2>& /*in_right_pads*/)
|
|
||||||
{
|
|
||||||
const int32_t reduceLength = window_spatial_lengths[0] * window_spatial_lengths[1];
|
|
||||||
|
|
||||||
using ReduceOperation = typename ck::reduce_binary_operator<ReduceOpId>::opType;
|
|
||||||
|
|
||||||
auto elementwise_ops =
|
|
||||||
ck::reduce_unary_operator<ReduceOpId, true, true>::GetElementwiseOperator(reduceLength);
|
|
||||||
|
|
||||||
auto in_elementwise_op = std::get<0>(elementwise_ops);
|
|
||||||
auto acc_elementwise_op = std::get<1>(elementwise_ops);
|
|
||||||
|
|
||||||
if constexpr(!OutputIndex)
|
|
||||||
{
|
|
||||||
using Accumulation =
|
|
||||||
ck::detail::AccumulateWithNanCheck<PropagateNan, ReduceOperation, AccDataType>;
|
|
||||||
|
|
||||||
auto f_nchw = [&](auto n, auto c, auto ho, auto wo) {
|
|
||||||
auto accuVal = ReduceOperation::template GetIdentityValue<AccDataType>();
|
|
||||||
|
|
||||||
for(ck::index_t y = 0; y < window_spatial_lengths[0]; ++y)
|
|
||||||
{
|
|
||||||
ck::index_t hi = ho * window_strides[0] + y - in_left_pads[0];
|
|
||||||
for(ck::index_t x = 0; x < window_spatial_lengths[1]; ++x)
|
|
||||||
{
|
|
||||||
ck::index_t wi = wo * window_strides[1] + x - in_left_pads[1];
|
|
||||||
if(hi >= 0 && hi < static_cast<ck::index_t>(in.mDesc.GetLengths()[2]) &&
|
|
||||||
wi >= 0 && wi < static_cast<ck::index_t>(in.mDesc.GetLengths()[3]))
|
|
||||||
{
|
|
||||||
AccDataType currVal = static_cast<AccDataType>(in(n, c, hi, wi));
|
|
||||||
|
|
||||||
in_elementwise_op(currVal, currVal);
|
|
||||||
|
|
||||||
Accumulation::Calculate(accuVal, currVal);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
acc_elementwise_op(accuVal, accuVal);
|
|
||||||
|
|
||||||
out(n, c, ho, wo) = accuVal;
|
|
||||||
};
|
|
||||||
|
|
||||||
make_ParallelTensorFunctor(f_nchw,
|
|
||||||
out.mDesc.GetLengths()[0],
|
|
||||||
out.mDesc.GetLengths()[1],
|
|
||||||
out.mDesc.GetLengths()[2],
|
|
||||||
out.mDesc.GetLengths()[3])(std::thread::hardware_concurrency());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
using Accumulation = ck::detail::AccumulateWithIndexAndNanCheck<PropagateNan,
|
|
||||||
ReduceOperation,
|
|
||||||
AccDataType,
|
|
||||||
IndexDataType>;
|
|
||||||
auto f_nchw = [&](auto n, auto c, auto ho, auto wo) {
|
|
||||||
auto accuVal = ReduceOperation::template GetIdentityValue<AccDataType>();
|
|
||||||
IndexDataType accuIndex = 0;
|
|
||||||
|
|
||||||
for(ck::index_t y = 0; y < window_spatial_lengths[0]; ++y)
|
|
||||||
{
|
|
||||||
ck::index_t hi = ho * window_strides[0] + y - in_left_pads[0];
|
|
||||||
for(ck::index_t x = 0; x < window_spatial_lengths[1]; ++x)
|
|
||||||
{
|
|
||||||
ck::index_t wi = wo * window_strides[1] + x - in_left_pads[1];
|
|
||||||
if(hi >= 0 && hi < in.mDesc.GetLengths()[2] && wi >= 0 &&
|
|
||||||
wi < in.mDesc.GetLengths()[3])
|
|
||||||
{
|
|
||||||
AccDataType currVal = static_cast<AccDataType>(in(n, c, hi, wi));
|
|
||||||
IndexDataType currIndex = y * window_spatial_lengths[1] + x;
|
|
||||||
|
|
||||||
in_elementwise_op(currVal, currVal);
|
|
||||||
|
|
||||||
Accumulation::Calculate(accuVal, currVal, accuIndex, currIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
acc_elementwise_op(accuVal, accuVal);
|
|
||||||
|
|
||||||
out(n, c, ho, wo) = accuVal;
|
|
||||||
out_indices(n, c, ho, wo) = accuIndex;
|
|
||||||
};
|
|
||||||
|
|
||||||
make_ParallelTensorFunctor(f_nchw,
|
|
||||||
out.mDesc.GetLengths()[0],
|
|
||||||
out.mDesc.GetLengths()[1],
|
|
||||||
out.mDesc.GetLengths()[2],
|
|
||||||
out.mDesc.GetLengths()[3])(std::thread::hardware_concurrency());
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename InDataType,
|
|
||||||
typename OutDataType,
|
|
||||||
typename AccDataType,
|
|
||||||
typename IndexDataType,
|
typename IndexDataType,
|
||||||
typename InLayout,
|
typename InLayout,
|
||||||
typename OutLayout,
|
typename OutLayout,
|
||||||
@@ -150,9 +46,10 @@ bool pool_test(bool do_verification,
|
|||||||
{
|
{
|
||||||
using DevicePoolFwdInstance =
|
using DevicePoolFwdInstance =
|
||||||
ck::tensor_operation::device::DevicePool2dFwd_Input_N_Hi_Wi_C_Output_N_Ho_Wo_C<
|
ck::tensor_operation::device::DevicePool2dFwd_Input_N_Hi_Wi_C_Output_N_Ho_Wo_C<
|
||||||
InDataType, // InDataType
|
InDataType, // InDataType
|
||||||
OutDataType, // OutDataType
|
OutDataType, // OutDataType
|
||||||
AccDataType, // AccDataType
|
IndexDataType, // IndexDataType
|
||||||
|
ComputeDataType, // ComputeDataType
|
||||||
ReduceOpId,
|
ReduceOpId,
|
||||||
OutputIndex,
|
OutputIndex,
|
||||||
64, // BlockSize
|
64, // BlockSize
|
||||||
@@ -165,10 +62,10 @@ bool pool_test(bool do_verification,
|
|||||||
const ck::index_t Ho = (Hi + in_left_pad_h + in_right_pad_h - Y) / window_stride_h + 1;
|
const ck::index_t Ho = (Hi + in_left_pad_h + in_right_pad_h - Y) / window_stride_h + 1;
|
||||||
const ck::index_t Wo = (Wi + in_left_pad_w + in_right_pad_w - X) / window_stride_w + 1;
|
const ck::index_t Wo = (Wi + in_left_pad_w + in_right_pad_w - X) / window_stride_w + 1;
|
||||||
|
|
||||||
const std::array<ck::index_t, 2> window_spatial_lengths{{Y, X}};
|
const std::vector<ck::index_t> window_spatial_lengths{Y, X};
|
||||||
const std::array<ck::index_t, 2> window_strides{{window_stride_h, window_stride_w}};
|
const std::vector<ck::index_t> window_strides{window_stride_h, window_stride_w};
|
||||||
const std::array<ck::index_t, 2> input_left_pads{{in_left_pad_h, in_left_pad_w}};
|
const std::vector<ck::index_t> input_left_pads{in_left_pad_h, in_left_pad_w};
|
||||||
const std::array<ck::index_t, 2> input_right_pads{{in_right_pad_h, in_right_pad_w}};
|
const std::vector<ck::index_t> input_right_pads{in_right_pad_h, in_right_pad_w};
|
||||||
|
|
||||||
// tensor layout
|
// tensor layout
|
||||||
auto f_host_tensor_descriptor =
|
auto f_host_tensor_descriptor =
|
||||||
@@ -219,14 +116,16 @@ bool pool_test(bool do_verification,
|
|||||||
static_cast<InDataType*>(in_device_buf.GetDeviceBuffer()),
|
static_cast<InDataType*>(in_device_buf.GetDeviceBuffer()),
|
||||||
static_cast<OutDataType*>(out_device_buf.GetDeviceBuffer()),
|
static_cast<OutDataType*>(out_device_buf.GetDeviceBuffer()),
|
||||||
static_cast<IndexDataType*>(out_indices_device_buf.GetDeviceBuffer()),
|
static_cast<IndexDataType*>(out_indices_device_buf.GetDeviceBuffer()),
|
||||||
N,
|
{N, C, Hi, Wi},
|
||||||
C,
|
{Y, X},
|
||||||
std::array<ck::index_t, 2>{{Hi, Wi}},
|
{N, C, Ho, Wo},
|
||||||
std::array<ck::index_t, 2>{{Y, X}},
|
{C * Hi * Wi, 1, Wi * C, C},
|
||||||
std::array<ck::index_t, 2>{{Ho, Wo}},
|
{C * Ho * Wo, 1, Wo * C, C},
|
||||||
|
{C * Ho * Wo, 1, Wo * C, C},
|
||||||
window_strides,
|
window_strides,
|
||||||
input_left_pads,
|
input_left_pads,
|
||||||
input_right_pads);
|
input_right_pads,
|
||||||
|
{2, 3});
|
||||||
|
|
||||||
if(!pool.IsSupportedArgument(argument_ptr.get()))
|
if(!pool.IsSupportedArgument(argument_ptr.get()))
|
||||||
{
|
{
|
||||||
@@ -252,19 +151,28 @@ bool pool_test(bool do_verification,
|
|||||||
|
|
||||||
if(do_verification)
|
if(do_verification)
|
||||||
{
|
{
|
||||||
pool_host_verify<InDataType,
|
using ReferencePoolingFwdInstance =
|
||||||
OutDataType,
|
ck::tensor_operation::host::ReferencePoolingFwd<4,
|
||||||
AccDataType,
|
2,
|
||||||
IndexDataType,
|
InDataType,
|
||||||
ReduceOpId,
|
OutDataType,
|
||||||
PropagateNan,
|
ComputeDataType,
|
||||||
OutputIndex>(in_n_c_hi_wi,
|
IndexDataType,
|
||||||
out_n_c_ho_wo_host,
|
ReduceOpId,
|
||||||
out_indices_n_c_ho_wo_host,
|
PropagateNan,
|
||||||
window_spatial_lengths,
|
OutputIndex>;
|
||||||
window_strides,
|
|
||||||
input_left_pads,
|
auto ref_pooling = ReferencePoolingFwdInstance{};
|
||||||
input_right_pads);
|
auto ref_pooling_invoker = ref_pooling.MakeInvoker();
|
||||||
|
auto ref_pooling_argument = ref_pooling.MakeArgument(in_n_c_hi_wi,
|
||||||
|
out_n_c_ho_wo_host,
|
||||||
|
out_indices_n_c_ho_wo_host,
|
||||||
|
window_spatial_lengths,
|
||||||
|
window_strides,
|
||||||
|
input_left_pads,
|
||||||
|
input_right_pads);
|
||||||
|
|
||||||
|
ref_pooling_invoker.Run(ref_pooling_argument);
|
||||||
|
|
||||||
out_device_buf.FromDevice(out_n_c_ho_wo_device.mData.data());
|
out_device_buf.FromDevice(out_n_c_ho_wo_device.mData.data());
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
// 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 <iostream>
|
||||||
#include <cstdlib>
|
|
||||||
|
|
||||||
#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"
|
||||||
@@ -10,9 +9,9 @@
|
|||||||
|
|
||||||
#include "pool2d_fwd_common.hpp"
|
#include "pool2d_fwd_common.hpp"
|
||||||
|
|
||||||
using InDataType = ck::half_t;
|
using InDataType = ck::half_t;
|
||||||
using OutDataType = ck::half_t;
|
using OutDataType = ck::half_t;
|
||||||
using AccDataType = float;
|
using ComputeDataType = float;
|
||||||
|
|
||||||
using IndexDataType = int32_t;
|
using IndexDataType = int32_t;
|
||||||
|
|
||||||
@@ -91,7 +90,7 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
bool pass = pool_test<InDataType,
|
bool pass = pool_test<InDataType,
|
||||||
OutDataType,
|
OutDataType,
|
||||||
AccDataType,
|
ComputeDataType,
|
||||||
IndexDataType,
|
IndexDataType,
|
||||||
InLayout,
|
InLayout,
|
||||||
OutLayout,
|
OutLayout,
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
// 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 <iostream>
|
||||||
#include <cstdlib>
|
|
||||||
|
|
||||||
#include "ck/ck.hpp"
|
#include "ck/ck.hpp"
|
||||||
#include "ck/utility/reduction_enums.hpp"
|
#include "ck/utility/reduction_enums.hpp"
|
||||||
@@ -10,9 +9,9 @@
|
|||||||
|
|
||||||
#include "pool2d_fwd_common.hpp"
|
#include "pool2d_fwd_common.hpp"
|
||||||
|
|
||||||
using InDataType = float;
|
using InDataType = float;
|
||||||
using OutDataType = float;
|
using OutDataType = float;
|
||||||
using AccDataType = float;
|
using ComputeDataType = float;
|
||||||
|
|
||||||
using IndexDataType = int32_t;
|
using IndexDataType = int32_t;
|
||||||
|
|
||||||
@@ -91,7 +90,7 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
bool pass = pool_test<InDataType,
|
bool pass = pool_test<InDataType,
|
||||||
OutDataType,
|
OutDataType,
|
||||||
AccDataType,
|
ComputeDataType,
|
||||||
IndexDataType,
|
IndexDataType,
|
||||||
InLayout,
|
InLayout,
|
||||||
OutLayout,
|
OutLayout,
|
||||||
|
|||||||
2
example/48_pool3d_fwd/CMakeLists.txt
Normal file
2
example/48_pool3d_fwd/CMakeLists.txt
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
add_example_executable(example_pool3d_fwd_fp16 pool3d_fwd_fp16.cpp)
|
||||||
|
|
||||||
187
example/48_pool3d_fwd/pool3d_fwd_common.hpp
Normal file
187
example/48_pool3d_fwd/pool3d_fwd_common.hpp
Normal file
@@ -0,0 +1,187 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "ck/ck.hpp"
|
||||||
|
#include "ck/utility/reduction_enums.hpp"
|
||||||
|
#include "ck/utility/reduction_functions_accumulate.hpp"
|
||||||
|
#include "ck/tensor_operation/gpu/device/reduction_operator_mapping.hpp"
|
||||||
|
#include "ck/tensor_operation/gpu/device/impl/device_pool3d_fwd_ndhwc_ndhwc.hpp"
|
||||||
|
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp"
|
||||||
|
|
||||||
|
#include "ck/library/utility/check_err.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/utility/literals.hpp"
|
||||||
|
#include "ck/library/reference_tensor_operation/cpu/reference_pool_fwd.hpp"
|
||||||
|
|
||||||
|
template <typename InDataType,
|
||||||
|
typename OutDataType,
|
||||||
|
typename ComputeDataType,
|
||||||
|
typename IndexDataType,
|
||||||
|
typename InLayout,
|
||||||
|
typename OutLayout,
|
||||||
|
ck::ReduceTensorOp ReduceOpId,
|
||||||
|
bool PropagateNan,
|
||||||
|
bool OutputIndex>
|
||||||
|
bool pool3d_test(bool do_verification,
|
||||||
|
bool time_kernel,
|
||||||
|
ck::index_t N,
|
||||||
|
ck::index_t C,
|
||||||
|
ck::index_t Z,
|
||||||
|
ck::index_t Y,
|
||||||
|
ck::index_t X,
|
||||||
|
ck::index_t Di,
|
||||||
|
ck::index_t Hi,
|
||||||
|
ck::index_t Wi,
|
||||||
|
ck::index_t window_stride_d,
|
||||||
|
ck::index_t window_stride_h,
|
||||||
|
ck::index_t window_stride_w,
|
||||||
|
ck::index_t in_left_pad_d,
|
||||||
|
ck::index_t in_left_pad_h,
|
||||||
|
ck::index_t in_left_pad_w,
|
||||||
|
ck::index_t in_right_pad_d,
|
||||||
|
ck::index_t in_right_pad_h,
|
||||||
|
ck::index_t in_right_pad_w)
|
||||||
|
{
|
||||||
|
using DevicePoolFwdInstance =
|
||||||
|
ck::tensor_operation::device::DevicePool3dFwd_Input_N_Di_Hi_Wi_C_Output_N_Do_Ho_Wo_C<
|
||||||
|
InDataType, // InDataType
|
||||||
|
OutDataType, // OutDataType
|
||||||
|
IndexDataType, // IndexDataType
|
||||||
|
ComputeDataType, // ComputeDataType
|
||||||
|
ReduceOpId,
|
||||||
|
OutputIndex,
|
||||||
|
64, // BlockSize
|
||||||
|
64, // ReduceMThreadClusterSize
|
||||||
|
1, // ReduceKThreadClusterSize
|
||||||
|
4, // ReduceMThreadSliceSize
|
||||||
|
1, // ReduceKThreadSliceSize
|
||||||
|
4>; // InSrcOutDstVectorSize
|
||||||
|
|
||||||
|
const ck::index_t Do = (Di + in_left_pad_d + in_right_pad_d - Z) / window_stride_d + 1;
|
||||||
|
const ck::index_t Ho = (Hi + in_left_pad_h + in_right_pad_h - Y) / window_stride_h + 1;
|
||||||
|
const ck::index_t Wo = (Wi + in_left_pad_w + in_right_pad_w - X) / window_stride_w + 1;
|
||||||
|
|
||||||
|
const std::vector<ck::index_t> window_spatial_lengths{Z, Y, X};
|
||||||
|
const std::vector<ck::index_t> window_strides{
|
||||||
|
window_stride_d, window_stride_h, window_stride_w};
|
||||||
|
const std::vector<ck::index_t> input_left_pads{in_left_pad_d, in_left_pad_h, in_left_pad_w};
|
||||||
|
const std::vector<ck::index_t> input_right_pads{in_right_pad_d, 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 D,
|
||||||
|
std::size_t H,
|
||||||
|
std::size_t W,
|
||||||
|
auto layout) {
|
||||||
|
using namespace ck::literals;
|
||||||
|
|
||||||
|
if constexpr(ck::is_same<decltype(layout), ck::tensor_layout::convolution::NCDHW>::value)
|
||||||
|
{
|
||||||
|
return HostTensorDescriptor({N_, C_, D, H, W},
|
||||||
|
{C_ * D * H * W, D * H * W, H * W, W, 1_uz});
|
||||||
|
}
|
||||||
|
else if constexpr(ck::is_same<decltype(layout),
|
||||||
|
ck::tensor_layout::convolution::NDHWC>::value)
|
||||||
|
{
|
||||||
|
return HostTensorDescriptor({N_, C_, D, H, W},
|
||||||
|
{D * C_ * H * W, 1_uz, C_ * H * W, W * C_, C_});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Tensor<InDataType> in_n_c_di_hi_wi(f_host_tensor_descriptor(N, C, Di, Hi, Wi, InLayout{}));
|
||||||
|
Tensor<OutDataType> out_n_c_do_ho_wo_host(
|
||||||
|
f_host_tensor_descriptor(N, C, Do, Ho, Wo, OutLayout{}));
|
||||||
|
Tensor<IndexDataType> out_indices_n_c_do_ho_wo_host(
|
||||||
|
f_host_tensor_descriptor(N, C, Do, Ho, Wo, OutLayout{}));
|
||||||
|
Tensor<OutDataType> out_n_c_do_ho_wo_device(
|
||||||
|
f_host_tensor_descriptor(N, C, Do, Ho, Wo, OutLayout{}));
|
||||||
|
Tensor<IndexDataType> out_indices_n_c_do_ho_wo_device(
|
||||||
|
f_host_tensor_descriptor(N, C, Do, Ho, Wo, OutLayout{}));
|
||||||
|
|
||||||
|
std::cout << "in_n_c_di_hi_wi: " << in_n_c_di_hi_wi.mDesc << std::endl;
|
||||||
|
std::cout << "out_n_c_do_ho_wo: " << out_n_c_do_ho_wo_host.mDesc << std::endl;
|
||||||
|
|
||||||
|
in_n_c_di_hi_wi.GenerateTensorValue(GeneratorTensor_3<InDataType>{-1.0, 1.0});
|
||||||
|
|
||||||
|
DeviceMem in_device_buf(sizeof(InDataType) * in_n_c_di_hi_wi.mDesc.GetElementSpaceSize());
|
||||||
|
DeviceMem out_device_buf(sizeof(OutDataType) *
|
||||||
|
out_n_c_do_ho_wo_device.mDesc.GetElementSpaceSize());
|
||||||
|
DeviceMem out_indices_device_buf(sizeof(IndexDataType) *
|
||||||
|
out_indices_n_c_do_ho_wo_device.mDesc.GetElementSpaceSize());
|
||||||
|
|
||||||
|
in_device_buf.ToDevice(in_n_c_di_hi_wi.mData.data());
|
||||||
|
|
||||||
|
auto pool = DevicePoolFwdInstance{};
|
||||||
|
auto invoker_ptr = pool.MakeInvokerPointer();
|
||||||
|
auto argument_ptr = pool.MakeArgumentPointer(
|
||||||
|
static_cast<InDataType*>(in_device_buf.GetDeviceBuffer()),
|
||||||
|
static_cast<OutDataType*>(out_device_buf.GetDeviceBuffer()),
|
||||||
|
static_cast<IndexDataType*>(out_indices_device_buf.GetDeviceBuffer()),
|
||||||
|
{N, C, Di, Hi, Wi},
|
||||||
|
{Z, Y, X},
|
||||||
|
{N, C, Do, Ho, Wo},
|
||||||
|
{Di * C * Hi * Wi, 1, C * Hi * Wi, Wi * 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,
|
||||||
|
input_left_pads,
|
||||||
|
input_right_pads,
|
||||||
|
{2, 3, 4});
|
||||||
|
|
||||||
|
if(!pool.IsSupportedArgument(argument_ptr.get()))
|
||||||
|
{
|
||||||
|
throw std::runtime_error("wrong! device_op with the specified compilation parameters does "
|
||||||
|
"not support this problem");
|
||||||
|
}
|
||||||
|
|
||||||
|
float ave_time = invoker_ptr->Run(argument_ptr.get(), StreamConfig{nullptr, time_kernel});
|
||||||
|
std::cout << "Perf: " << ave_time << std::endl;
|
||||||
|
|
||||||
|
bool pass = true;
|
||||||
|
|
||||||
|
if(do_verification)
|
||||||
|
{
|
||||||
|
using ReferencePoolingFwdInstance =
|
||||||
|
ck::tensor_operation::host::ReferencePoolingFwd<5,
|
||||||
|
3,
|
||||||
|
InDataType,
|
||||||
|
OutDataType,
|
||||||
|
ComputeDataType,
|
||||||
|
IndexDataType,
|
||||||
|
ReduceOpId,
|
||||||
|
PropagateNan,
|
||||||
|
OutputIndex>;
|
||||||
|
|
||||||
|
auto ref_pooling = ReferencePoolingFwdInstance{};
|
||||||
|
auto ref_pooling_invoker = ref_pooling.MakeInvoker();
|
||||||
|
auto ref_pooling_argument = ref_pooling.MakeArgument(in_n_c_di_hi_wi,
|
||||||
|
out_n_c_do_ho_wo_host,
|
||||||
|
out_indices_n_c_do_ho_wo_host,
|
||||||
|
window_spatial_lengths,
|
||||||
|
window_strides,
|
||||||
|
input_left_pads,
|
||||||
|
input_right_pads);
|
||||||
|
|
||||||
|
ref_pooling_invoker.Run(ref_pooling_argument);
|
||||||
|
|
||||||
|
out_device_buf.FromDevice(out_n_c_do_ho_wo_device.mData.data());
|
||||||
|
|
||||||
|
pass = pass && ck::utils::check_err(out_n_c_do_ho_wo_device, out_n_c_do_ho_wo_host);
|
||||||
|
|
||||||
|
if constexpr(OutputIndex)
|
||||||
|
{
|
||||||
|
out_indices_device_buf.FromDevice(out_indices_n_c_do_ho_wo_device.mData.data());
|
||||||
|
|
||||||
|
pass = pass && ck::utils::check_err(out_indices_n_c_do_ho_wo_device,
|
||||||
|
out_indices_n_c_do_ho_wo_host);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return (pass);
|
||||||
|
};
|
||||||
83
example/48_pool3d_fwd/pool3d_fwd_fp16.cpp
Normal file
83
example/48_pool3d_fwd/pool3d_fwd_fp16.cpp
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "ck/ck.hpp"
|
||||||
|
#include "ck/tensor_operation/gpu/device/tensor_layout.hpp"
|
||||||
|
#include "ck/utility/reduction_enums.hpp"
|
||||||
|
|
||||||
|
#include "pool3d_fwd_common.hpp"
|
||||||
|
|
||||||
|
using InDataType = ck::half_t;
|
||||||
|
using OutDataType = ck::half_t;
|
||||||
|
using ComputeDataType = float;
|
||||||
|
|
||||||
|
using IndexDataType = int32_t;
|
||||||
|
|
||||||
|
using InLayout = ck::tensor_layout::convolution::NDHWC;
|
||||||
|
using OutLayout = ck::tensor_layout::convolution::NDHWC;
|
||||||
|
|
||||||
|
#if 1
|
||||||
|
static constexpr auto ReduceOpId = ck::ReduceTensorOp::MAX;
|
||||||
|
#else
|
||||||
|
static constexpr auto ReduceOpId = ck::ReduceTensorOp::AVG;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static constexpr bool OutputIndex = false;
|
||||||
|
static constexpr bool PropagateNan = false;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
bool do_verification = true;
|
||||||
|
bool time_kernel = false;
|
||||||
|
|
||||||
|
// Pool shape
|
||||||
|
ck::index_t N = 2;
|
||||||
|
ck::index_t C = 32;
|
||||||
|
ck::index_t Z = 2;
|
||||||
|
ck::index_t Y = 2;
|
||||||
|
ck::index_t X = 2;
|
||||||
|
ck::index_t Di = 30;
|
||||||
|
ck::index_t Hi = 30;
|
||||||
|
ck::index_t Wi = 30;
|
||||||
|
ck::index_t window_stride_d = 2;
|
||||||
|
ck::index_t window_stride_h = 2;
|
||||||
|
ck::index_t window_stride_w = 2;
|
||||||
|
ck::index_t in_left_pad_d = 1;
|
||||||
|
ck::index_t in_left_pad_h = 1;
|
||||||
|
ck::index_t in_left_pad_w = 1;
|
||||||
|
ck::index_t in_right_pad_d = 1;
|
||||||
|
ck::index_t in_right_pad_h = 1;
|
||||||
|
ck::index_t in_right_pad_w = 1;
|
||||||
|
|
||||||
|
bool pass = pool3d_test<InDataType,
|
||||||
|
OutDataType,
|
||||||
|
ComputeDataType,
|
||||||
|
IndexDataType,
|
||||||
|
InLayout,
|
||||||
|
OutLayout,
|
||||||
|
ReduceOpId,
|
||||||
|
PropagateNan,
|
||||||
|
OutputIndex>(do_verification,
|
||||||
|
time_kernel,
|
||||||
|
N,
|
||||||
|
C,
|
||||||
|
Z,
|
||||||
|
Y,
|
||||||
|
X,
|
||||||
|
Di,
|
||||||
|
Hi,
|
||||||
|
Wi,
|
||||||
|
window_stride_d,
|
||||||
|
window_stride_h,
|
||||||
|
window_stride_w,
|
||||||
|
in_left_pad_d,
|
||||||
|
in_left_pad_h,
|
||||||
|
in_left_pad_w,
|
||||||
|
in_right_pad_d,
|
||||||
|
in_right_pad_h,
|
||||||
|
in_right_pad_w);
|
||||||
|
|
||||||
|
return (pass ? 0 : 1);
|
||||||
|
}
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
|
||||||
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <array>
|
|
||||||
|
|
||||||
#include "ck/tensor_operation/gpu/device/device_base.hpp"
|
|
||||||
#include "ck/utility/reduction_enums.hpp"
|
|
||||||
|
|
||||||
namespace ck {
|
|
||||||
namespace tensor_operation {
|
|
||||||
namespace device {
|
|
||||||
|
|
||||||
template <ck::ReduceTensorOp ReduceOpId>
|
|
||||||
struct DevicePool2dFwd : public BaseOperator
|
|
||||||
{
|
|
||||||
virtual std::unique_ptr<BaseArgument>
|
|
||||||
MakeArgumentPointer(const void* in_dev,
|
|
||||||
void* out_dev,
|
|
||||||
void* out_indices_dev,
|
|
||||||
ck::index_t N,
|
|
||||||
ck::index_t C,
|
|
||||||
std::array<ck::index_t, 2> input_spatial_lengths,
|
|
||||||
std::array<ck::index_t, 2> window_spatial_lengths,
|
|
||||||
std::array<ck::index_t, 2> output_spatial_lengths,
|
|
||||||
std::array<ck::index_t, 2> window_strides,
|
|
||||||
std::array<ck::index_t, 2> input_left_pads,
|
|
||||||
std::array<ck::index_t, 2> input_right_pads) = 0;
|
|
||||||
|
|
||||||
virtual std::unique_ptr<BaseInvoker> MakeInvokerPointer() = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <ck::ReduceTensorOp ReduceOpId>
|
|
||||||
using DevicePool2dFwdPtr = std::unique_ptr<DevicePool2dFwd<ReduceOpId>>;
|
|
||||||
|
|
||||||
} // namespace device
|
|
||||||
} // namespace tensor_operation
|
|
||||||
} // namespace ck
|
|
||||||
44
include/ck/tensor_operation/gpu/device/device_pool_fwd.hpp
Normal file
44
include/ck/tensor_operation/gpu/device/device_pool_fwd.hpp
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "ck/tensor_operation/gpu/device/device_base.hpp"
|
||||||
|
#include "ck/utility/reduction_enums.hpp"
|
||||||
|
|
||||||
|
namespace ck {
|
||||||
|
namespace tensor_operation {
|
||||||
|
namespace device {
|
||||||
|
|
||||||
|
template <index_t InOutRank,
|
||||||
|
index_t WindowRank,
|
||||||
|
typename InDataType,
|
||||||
|
typename OutDataType,
|
||||||
|
typename IndexDataType,
|
||||||
|
ReduceTensorOp ReduceOpId,
|
||||||
|
bool OutputIndex>
|
||||||
|
struct DevicePoolFwd : public BaseOperator
|
||||||
|
{
|
||||||
|
virtual std::unique_ptr<BaseArgument>
|
||||||
|
MakeArgumentPointer(const void* p_in_dev,
|
||||||
|
void* p_out_dev,
|
||||||
|
void* p_out_indices_dev,
|
||||||
|
std::vector<ck::index_t> input_lengths,
|
||||||
|
std::vector<ck::index_t> window_lengths,
|
||||||
|
std::vector<ck::index_t> output_lengths,
|
||||||
|
std::vector<ck::index_t> input_stride,
|
||||||
|
std::vector<ck::index_t> output_stride,
|
||||||
|
std::vector<ck::index_t> indices_stride,
|
||||||
|
std::vector<ck::index_t> window_strides,
|
||||||
|
std::vector<ck::index_t> input_left_pads,
|
||||||
|
std::vector<ck::index_t> input_right_pads,
|
||||||
|
std::vector<ck::index_t> pooling_dims) = 0;
|
||||||
|
|
||||||
|
virtual std::unique_ptr<BaseInvoker> MakeInvokerPointer() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace device
|
||||||
|
} // namespace tensor_operation
|
||||||
|
} // namespace ck
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
#include "ck/tensor_description/tensor_descriptor.hpp"
|
#include "ck/tensor_description/tensor_descriptor.hpp"
|
||||||
#include "ck/tensor_description/tensor_descriptor_helper.hpp"
|
#include "ck/tensor_description/tensor_descriptor_helper.hpp"
|
||||||
#include "ck/tensor_operation/gpu/device/reduction_operator_mapping.hpp"
|
#include "ck/tensor_operation/gpu/device/reduction_operator_mapping.hpp"
|
||||||
#include "ck/tensor_operation/gpu/device/device_pool2d_fwd.hpp"
|
#include "ck/tensor_operation/gpu/device/device_pool_fwd.hpp"
|
||||||
#include "ck/tensor_operation/gpu/grid/gridwise_2d_reduction_threadwise.hpp"
|
#include "ck/tensor_operation/gpu/grid/gridwise_2d_reduction_threadwise.hpp"
|
||||||
#include "ck/host_utility/device_prop.hpp"
|
#include "ck/host_utility/device_prop.hpp"
|
||||||
#include "ck/host_utility/kernel_launch.hpp"
|
#include "ck/host_utility/kernel_launch.hpp"
|
||||||
@@ -20,16 +20,18 @@ namespace device {
|
|||||||
|
|
||||||
template <typename InDataType,
|
template <typename InDataType,
|
||||||
typename OutDataType,
|
typename OutDataType,
|
||||||
typename AccDataType,
|
typename IndexDataType, // enable if OutputIndex == true
|
||||||
|
typename ComputeDataType,
|
||||||
ck::ReduceTensorOp ReduceOpId,
|
ck::ReduceTensorOp ReduceOpId,
|
||||||
bool OuputIndex,
|
bool OutputIndex,
|
||||||
ck::index_t BlockSize,
|
ck::index_t BlockSize,
|
||||||
ck::index_t ReduceMThreadClusterSize,
|
ck::index_t ReduceMThreadClusterSize,
|
||||||
ck::index_t ReduceKThreadClusterSize,
|
ck::index_t ReduceKThreadClusterSize,
|
||||||
ck::index_t ReduceMThreadSliceSize,
|
ck::index_t ReduceMThreadSliceSize,
|
||||||
ck::index_t ReduceKThreadSliceSize,
|
ck::index_t ReduceKThreadSliceSize,
|
||||||
ck::index_t InSrcOutDstVectorSize>
|
ck::index_t InSrcOutDstVectorSize>
|
||||||
struct DevicePool2dFwd_Input_N_Hi_Wi_C_Output_N_Ho_Wo_C : public DevicePool2dFwd<ReduceOpId>
|
struct DevicePool2dFwd_Input_N_Hi_Wi_C_Output_N_Ho_Wo_C
|
||||||
|
: public DevicePoolFwd<4, 2, InDataType, OutDataType, IndexDataType, ReduceOpId, OutputIndex>
|
||||||
{
|
{
|
||||||
static constexpr auto I0 = Number<0>{};
|
static constexpr auto I0 = Number<0>{};
|
||||||
static constexpr auto I1 = Number<1>{};
|
static constexpr auto I1 = Number<1>{};
|
||||||
@@ -38,7 +40,8 @@ struct DevicePool2dFwd_Input_N_Hi_Wi_C_Output_N_Ho_Wo_C : public DevicePool2dFwd
|
|||||||
static constexpr auto I4 = Number<4>{};
|
static constexpr auto I4 = Number<4>{};
|
||||||
static constexpr auto I5 = Number<5>{};
|
static constexpr auto I5 = Number<5>{};
|
||||||
|
|
||||||
using IndexDataType = int32_t;
|
static constexpr index_t InOutRank = 4;
|
||||||
|
static constexpr index_t WindowRank = 2;
|
||||||
|
|
||||||
using ReduceOperation = typename reduce_binary_operator<ReduceOpId>::opType;
|
using ReduceOperation = typename reduce_binary_operator<ReduceOpId>::opType;
|
||||||
|
|
||||||
@@ -59,12 +62,12 @@ struct DevicePool2dFwd_Input_N_Hi_Wi_C_Output_N_Ho_Wo_C : public DevicePool2dFwd
|
|||||||
|
|
||||||
static auto MakeABGridDescriptor_A_M_K_B_M(ck::index_t N,
|
static auto MakeABGridDescriptor_A_M_K_B_M(ck::index_t N,
|
||||||
ck::index_t C,
|
ck::index_t C,
|
||||||
std::array<ck::index_t, 2> input_spatial_lengths,
|
std::vector<ck::index_t> input_spatial_lengths,
|
||||||
std::array<ck::index_t, 2> window_spatial_lengths,
|
std::vector<ck::index_t> window_spatial_lengths,
|
||||||
std::array<ck::index_t, 2> output_spatial_lengths,
|
std::vector<ck::index_t> output_spatial_lengths,
|
||||||
std::array<ck::index_t, 2> window_strides,
|
std::vector<ck::index_t> window_strides,
|
||||||
std::array<ck::index_t, 2> input_left_pads,
|
std::vector<ck::index_t> input_left_pads,
|
||||||
std::array<ck::index_t, 2> input_right_pads)
|
std::vector<ck::index_t> input_right_pads)
|
||||||
{
|
{
|
||||||
const index_t Hi = input_spatial_lengths[0];
|
const index_t Hi = input_spatial_lengths[0];
|
||||||
const index_t Wi = input_spatial_lengths[1];
|
const index_t Wi = input_spatial_lengths[1];
|
||||||
@@ -141,9 +144,7 @@ struct DevicePool2dFwd_Input_N_Hi_Wi_C_Output_N_Ho_Wo_C : public DevicePool2dFwd
|
|||||||
return make_tuple(in_grid_desc_reducem_reducek, out_grid_desc_reducem);
|
return make_tuple(in_grid_desc_reducem_reducek, out_grid_desc_reducem);
|
||||||
}
|
}
|
||||||
|
|
||||||
using ABGridDescs = decltype(
|
using ABGridDescs = decltype(MakeABGridDescriptor_A_M_K_B_M(1, 1, {}, {}, {}, {}, {}, {}));
|
||||||
MakeABGridDescriptor_A_M_K_B_M(1, 1, {1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}, {1, 1}));
|
|
||||||
|
|
||||||
using AGridDesc_M_K = remove_cvref_t<decltype(ABGridDescs{}[I0])>;
|
using AGridDesc_M_K = remove_cvref_t<decltype(ABGridDescs{}[I0])>;
|
||||||
using BGridDesc_M = remove_cvref_t<decltype(ABGridDescs{}[I1])>;
|
using BGridDesc_M = remove_cvref_t<decltype(ABGridDescs{}[I1])>;
|
||||||
|
|
||||||
@@ -152,15 +153,15 @@ struct DevicePool2dFwd_Input_N_Hi_Wi_C_Output_N_Ho_Wo_C : public DevicePool2dFwd
|
|||||||
{
|
{
|
||||||
Argument(const InDataType* p_in_dev,
|
Argument(const InDataType* p_in_dev,
|
||||||
OutDataType* p_out_dev,
|
OutDataType* p_out_dev,
|
||||||
int* p_out_indices_dev,
|
IndexDataType* p_out_indices_dev,
|
||||||
ck::index_t N,
|
ck::index_t N,
|
||||||
ck::index_t C,
|
ck::index_t C,
|
||||||
std::array<ck::index_t, 2>& input_spatial_lengths,
|
std::vector<ck::index_t>& input_spatial_lengths,
|
||||||
std::array<ck::index_t, 2>& window_spatial_lengths,
|
std::vector<ck::index_t>& window_spatial_lengths,
|
||||||
std::array<ck::index_t, 2>& output_spatial_lengths,
|
std::vector<ck::index_t>& output_spatial_lengths,
|
||||||
std::array<ck::index_t, 2>& window_strides,
|
std::vector<ck::index_t>& window_strides,
|
||||||
std::array<ck::index_t, 2>& input_left_pads,
|
std::vector<ck::index_t>& input_left_pads,
|
||||||
std::array<ck::index_t, 2>& input_right_pads)
|
std::vector<ck::index_t>& input_right_pads)
|
||||||
: p_in_dev_{p_in_dev},
|
: p_in_dev_{p_in_dev},
|
||||||
p_out_dev_{p_out_dev},
|
p_out_dev_{p_out_dev},
|
||||||
p_out_indices_dev_{p_out_indices_dev},
|
p_out_indices_dev_{p_out_indices_dev},
|
||||||
@@ -190,7 +191,7 @@ struct DevicePool2dFwd_Input_N_Hi_Wi_C_Output_N_Ho_Wo_C : public DevicePool2dFwd
|
|||||||
|
|
||||||
const InDataType* p_in_dev_;
|
const InDataType* p_in_dev_;
|
||||||
OutDataType* p_out_dev_;
|
OutDataType* p_out_dev_;
|
||||||
int* p_out_indices_dev_;
|
IndexDataType* p_out_indices_dev_;
|
||||||
AGridDesc_M_K a_grid_desc_m_k_;
|
AGridDesc_M_K a_grid_desc_m_k_;
|
||||||
BGridDesc_M b_grid_desc_m_;
|
BGridDesc_M b_grid_desc_m_;
|
||||||
InElementwiseOperation in_element_op_;
|
InElementwiseOperation in_element_op_;
|
||||||
@@ -208,7 +209,7 @@ struct DevicePool2dFwd_Input_N_Hi_Wi_C_Output_N_Ho_Wo_C : public DevicePool2dFwd
|
|||||||
using gridwise_reduce =
|
using gridwise_reduce =
|
||||||
GridwiseReduction_mk_to_m_threadwise<InDataType,
|
GridwiseReduction_mk_to_m_threadwise<InDataType,
|
||||||
OutDataType,
|
OutDataType,
|
||||||
AccDataType,
|
ComputeDataType,
|
||||||
IndexDataType,
|
IndexDataType,
|
||||||
AGridDesc_M_K,
|
AGridDesc_M_K,
|
||||||
BGridDesc_M,
|
BGridDesc_M,
|
||||||
@@ -224,17 +225,19 @@ struct DevicePool2dFwd_Input_N_Hi_Wi_C_Output_N_Ho_Wo_C : public DevicePool2dFwd
|
|||||||
InSrcOutDstVectorSize,
|
InSrcOutDstVectorSize,
|
||||||
InSrcOutDstVectorSize>;
|
InSrcOutDstVectorSize>;
|
||||||
|
|
||||||
const auto kernel = kernel_reduce_threadwise<gridwise_reduce,
|
const auto kernel =
|
||||||
OuputIndex,
|
kernel_reduce_threadwise<gridwise_reduce,
|
||||||
false, // don't have index input
|
OutputIndex,
|
||||||
InDataType,
|
true, // pooling need to return global index
|
||||||
OutDataType,
|
false, // don't have index input
|
||||||
AccDataType,
|
InDataType,
|
||||||
IndexDataType,
|
OutDataType,
|
||||||
AGridDesc_M_K,
|
ComputeDataType,
|
||||||
BGridDesc_M,
|
IndexDataType,
|
||||||
InElementwiseOperation,
|
AGridDesc_M_K,
|
||||||
AccElementwiseOperation>;
|
BGridDesc_M,
|
||||||
|
InElementwiseOperation,
|
||||||
|
AccElementwiseOperation>;
|
||||||
|
|
||||||
ck::index_t ReduceM = arg.a_grid_desc_m_k_.GetLength(I0);
|
ck::index_t ReduceM = arg.a_grid_desc_m_k_.GetLength(I0);
|
||||||
|
|
||||||
@@ -280,22 +283,42 @@ struct DevicePool2dFwd_Input_N_Hi_Wi_C_Output_N_Ho_Wo_C : public DevicePool2dFwd
|
|||||||
MakeArgumentPointer(const void* p_in_dev,
|
MakeArgumentPointer(const void* p_in_dev,
|
||||||
void* p_out_dev,
|
void* p_out_dev,
|
||||||
void* p_out_indices_dev,
|
void* p_out_indices_dev,
|
||||||
ck::index_t N,
|
std::vector<ck::index_t> input_lengths,
|
||||||
ck::index_t C,
|
std::vector<ck::index_t> window_lengths,
|
||||||
std::array<ck::index_t, 2> input_spatial_lengths,
|
std::vector<ck::index_t> output_lengths,
|
||||||
std::array<ck::index_t, 2> window_spatial_lengths,
|
std::vector<ck::index_t>, // Suppose tensor layout = NHWC
|
||||||
std::array<ck::index_t, 2> output_spatial_lengths,
|
std::vector<ck::index_t>, // Suppose tensor layout = NHWC
|
||||||
std::array<ck::index_t, 2> window_strides,
|
std::vector<ck::index_t>, // Suppose tensor layout = NHWC
|
||||||
std::array<ck::index_t, 2> input_left_pads,
|
std::vector<ck::index_t> window_strides,
|
||||||
std::array<ck::index_t, 2> input_right_pads) override
|
std::vector<ck::index_t> input_left_pads,
|
||||||
|
std::vector<ck::index_t> input_right_pads,
|
||||||
|
std::vector<ck::index_t> pooling_dims) override
|
||||||
{
|
{
|
||||||
|
if(input_lengths.size() != InOutRank || window_lengths.size() != WindowRank ||
|
||||||
|
input_lengths.size() != InOutRank || window_strides.size() != WindowRank ||
|
||||||
|
input_left_pads.size() != WindowRank || input_right_pads.size() != WindowRank)
|
||||||
|
throw std::runtime_error("dimension is incorrect");
|
||||||
|
|
||||||
|
if(pooling_dims != std::vector<ck::index_t>{2, 3})
|
||||||
|
throw std::runtime_error("pooling_dims only support {2, 3} in pool2d so far");
|
||||||
|
|
||||||
|
index_t N = input_lengths[0];
|
||||||
|
index_t C = input_lengths[1];
|
||||||
|
index_t Hi = input_lengths[2];
|
||||||
|
index_t Wi = input_lengths[3];
|
||||||
|
index_t Ho = output_lengths[2];
|
||||||
|
index_t Wo = output_lengths[3];
|
||||||
|
|
||||||
|
std::vector<ck::index_t> input_spatial_lengths = {Hi, Wi};
|
||||||
|
std::vector<ck::index_t> output_spatial_lengths = {Ho, Wo};
|
||||||
|
|
||||||
return std::make_unique<Argument>(static_cast<const InDataType*>(p_in_dev),
|
return std::make_unique<Argument>(static_cast<const InDataType*>(p_in_dev),
|
||||||
static_cast<OutDataType*>(p_out_dev),
|
static_cast<OutDataType*>(p_out_dev),
|
||||||
static_cast<int*>(p_out_indices_dev),
|
static_cast<IndexDataType*>(p_out_indices_dev),
|
||||||
N,
|
N,
|
||||||
C,
|
C,
|
||||||
input_spatial_lengths,
|
input_spatial_lengths,
|
||||||
window_spatial_lengths,
|
window_lengths,
|
||||||
output_spatial_lengths,
|
output_spatial_lengths,
|
||||||
window_strides,
|
window_strides,
|
||||||
input_left_pads,
|
input_left_pads,
|
||||||
|
|||||||
@@ -0,0 +1,357 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
#include "ck/tensor_description/tensor_descriptor.hpp"
|
||||||
|
#include "ck/tensor_description/tensor_descriptor_helper.hpp"
|
||||||
|
#include "ck/tensor_operation/gpu/device/reduction_operator_mapping.hpp"
|
||||||
|
#include "ck/tensor_operation/gpu/device/device_pool_fwd.hpp"
|
||||||
|
#include "ck/tensor_operation/gpu/grid/gridwise_2d_reduction_threadwise.hpp"
|
||||||
|
#include "ck/host_utility/device_prop.hpp"
|
||||||
|
#include "ck/host_utility/kernel_launch.hpp"
|
||||||
|
|
||||||
|
namespace ck {
|
||||||
|
namespace tensor_operation {
|
||||||
|
namespace device {
|
||||||
|
|
||||||
|
template <typename InDataType,
|
||||||
|
typename OutDataType,
|
||||||
|
typename IndexDataType, // enable if OutputIndex == true
|
||||||
|
typename ComputeDataType,
|
||||||
|
ck::ReduceTensorOp ReduceOpId,
|
||||||
|
bool OutputIndex,
|
||||||
|
ck::index_t BlockSize,
|
||||||
|
ck::index_t MThreadClusterSize,
|
||||||
|
ck::index_t KThreadClusterSize,
|
||||||
|
ck::index_t MThreadSliceSize,
|
||||||
|
ck::index_t KThreadSliceSize,
|
||||||
|
ck::index_t InSrcOutDstVectorSize>
|
||||||
|
struct DevicePool3dFwd_Input_N_Di_Hi_Wi_C_Output_N_Do_Ho_Wo_C
|
||||||
|
: public DevicePoolFwd<5, 3, InDataType, OutDataType, IndexDataType, ReduceOpId, OutputIndex>
|
||||||
|
{
|
||||||
|
static constexpr auto I0 = Number<0>{};
|
||||||
|
static constexpr auto I1 = Number<1>{};
|
||||||
|
static constexpr auto I2 = Number<2>{};
|
||||||
|
static constexpr auto I3 = Number<3>{};
|
||||||
|
static constexpr auto I4 = Number<4>{};
|
||||||
|
static constexpr auto I5 = Number<5>{};
|
||||||
|
|
||||||
|
static constexpr index_t InOutRank = 5;
|
||||||
|
static constexpr index_t WindowRank = 3;
|
||||||
|
|
||||||
|
using ReduceOperation = typename reduce_binary_operator<ReduceOpId>::opType;
|
||||||
|
|
||||||
|
using InElementwiseOperation =
|
||||||
|
typename reduce_unary_operator<ReduceOpId, true, true>::InElementwiseOperation;
|
||||||
|
|
||||||
|
using AccElementwiseOperation =
|
||||||
|
typename reduce_unary_operator<ReduceOpId, true, true>::AccElementwiseOperation;
|
||||||
|
|
||||||
|
// for NDHWC, the dim C is the vector Dim for both input and output in memory, which is not
|
||||||
|
// reduced.
|
||||||
|
static constexpr index_t InSrcOutDstVectorDim = 0;
|
||||||
|
|
||||||
|
static constexpr ck::index_t M_BlockTileSize = MThreadClusterSize * MThreadSliceSize;
|
||||||
|
static constexpr ck::index_t K_BlockTileSize = KThreadClusterSize * KThreadSliceSize;
|
||||||
|
|
||||||
|
static auto MakeABGridDescriptor_A_M_K_B_M(ck::index_t N,
|
||||||
|
ck::index_t C,
|
||||||
|
std::vector<ck::index_t> input_spatial_lengths,
|
||||||
|
std::vector<ck::index_t> window_spatial_lengths,
|
||||||
|
std::vector<ck::index_t> output_spatial_lengths,
|
||||||
|
std::vector<ck::index_t> window_strides,
|
||||||
|
std::vector<ck::index_t> input_left_pads,
|
||||||
|
std::vector<ck::index_t> input_right_pads)
|
||||||
|
{
|
||||||
|
const index_t Di = input_spatial_lengths[0];
|
||||||
|
const index_t Hi = input_spatial_lengths[1];
|
||||||
|
const index_t Wi = input_spatial_lengths[2];
|
||||||
|
|
||||||
|
const index_t Do = output_spatial_lengths[0];
|
||||||
|
const index_t Ho = output_spatial_lengths[1];
|
||||||
|
const index_t Wo = output_spatial_lengths[2];
|
||||||
|
|
||||||
|
const index_t Z = window_spatial_lengths[0];
|
||||||
|
const index_t Y = window_spatial_lengths[1];
|
||||||
|
const index_t X = window_spatial_lengths[2];
|
||||||
|
|
||||||
|
const index_t ConvStrideD = window_strides[0];
|
||||||
|
const index_t ConvStrideH = window_strides[1];
|
||||||
|
const index_t ConvStrideW = window_strides[2];
|
||||||
|
|
||||||
|
const index_t InLeftPadD = input_left_pads[0];
|
||||||
|
const index_t InLeftPadH = input_left_pads[1];
|
||||||
|
const index_t InLeftPadW = input_left_pads[2];
|
||||||
|
|
||||||
|
const index_t InRightPadD = input_right_pads[0];
|
||||||
|
const index_t InRightPadH = input_right_pads[1];
|
||||||
|
const index_t InRightPadW = input_right_pads[2];
|
||||||
|
|
||||||
|
const index_t MRaw = N * Do * Ho * Wo * C;
|
||||||
|
const index_t MPad = math::integer_least_multiple(MRaw, M_BlockTileSize) - MRaw;
|
||||||
|
|
||||||
|
const index_t KRaw = Z * Y * X;
|
||||||
|
const index_t KPad = math::integer_least_multiple(KRaw, K_BlockTileSize) - KRaw;
|
||||||
|
|
||||||
|
// A[ReduceM, ReduceK]
|
||||||
|
const auto in_grid_desc_n_di_hi_wi_c =
|
||||||
|
make_naive_tensor_descriptor_packed(make_tuple(N, Di, Hi, Wi, C));
|
||||||
|
|
||||||
|
const auto in_grid_desc_n_dip_hip_wip_c = transform_tensor_descriptor(
|
||||||
|
in_grid_desc_n_di_hi_wi_c,
|
||||||
|
make_tuple(make_pass_through_transform(N),
|
||||||
|
make_pad_transform(Di, InLeftPadD, InRightPadD),
|
||||||
|
make_pad_transform(Hi, InLeftPadH, InRightPadH),
|
||||||
|
make_pad_transform(Wi, InLeftPadW, InRightPadW),
|
||||||
|
make_pass_through_transform(C)),
|
||||||
|
make_tuple(Sequence<0>{}, Sequence<1>{}, Sequence<2>{}, Sequence<3>{}, Sequence<4>{}),
|
||||||
|
make_tuple(Sequence<0>{}, Sequence<1>{}, Sequence<2>{}, Sequence<3>{}, Sequence<4>{}));
|
||||||
|
|
||||||
|
const auto in_grid_desc_n_z_do_y_ho_x_wo_c = transform_tensor_descriptor(
|
||||||
|
in_grid_desc_n_dip_hip_wip_c,
|
||||||
|
make_tuple(make_pass_through_transform(N),
|
||||||
|
make_embed_transform(make_tuple(Z, Do), make_tuple(I1, ConvStrideD)),
|
||||||
|
make_embed_transform(make_tuple(Y, Ho), make_tuple(I1, ConvStrideH)),
|
||||||
|
make_embed_transform(make_tuple(X, Wo), make_tuple(I1, ConvStrideW)),
|
||||||
|
make_pass_through_transform(C)),
|
||||||
|
make_tuple(Sequence<0>{}, Sequence<1>{}, Sequence<2>{}, Sequence<3>{}, Sequence<4>{}),
|
||||||
|
make_tuple(Sequence<0>{},
|
||||||
|
Sequence<1, 2>{},
|
||||||
|
Sequence<3, 4>{},
|
||||||
|
Sequence<5, 6>{},
|
||||||
|
Sequence<7>{}));
|
||||||
|
|
||||||
|
const auto in_grid_desc_reducemraw_reducekraw = transform_tensor_descriptor(
|
||||||
|
in_grid_desc_n_z_do_y_ho_x_wo_c,
|
||||||
|
make_tuple(make_merge_transform(make_tuple(N, Do, Ho, Wo, C)),
|
||||||
|
make_merge_transform(make_tuple(Z, Y, X))),
|
||||||
|
make_tuple(Sequence<0, 2, 4, 6, 7>{}, Sequence<1, 3, 5>{}),
|
||||||
|
make_tuple(Sequence<0>{}, Sequence<1>{}));
|
||||||
|
|
||||||
|
const auto in_grid_desc_reducem_reducek = transform_tensor_descriptor(
|
||||||
|
in_grid_desc_reducemraw_reducekraw,
|
||||||
|
make_tuple(make_right_pad_transform(MRaw, MPad), make_right_pad_transform(KRaw, KPad)),
|
||||||
|
make_tuple(Sequence<0>{}, Sequence<1>{}),
|
||||||
|
make_tuple(Sequence<0>{}, Sequence<1>{}));
|
||||||
|
|
||||||
|
// B[ReduceM]
|
||||||
|
const auto out_grid_desc_reducemraw =
|
||||||
|
make_naive_tensor_descriptor_packed(make_tuple(N * Do * Ho * Wo * C));
|
||||||
|
|
||||||
|
const auto out_grid_desc_reducem =
|
||||||
|
transform_tensor_descriptor(out_grid_desc_reducemraw,
|
||||||
|
make_tuple(make_right_pad_transform(MRaw, MPad)),
|
||||||
|
make_tuple(Sequence<0>{}),
|
||||||
|
make_tuple(Sequence<0>{}));
|
||||||
|
|
||||||
|
return make_tuple(in_grid_desc_reducem_reducek, out_grid_desc_reducem);
|
||||||
|
}
|
||||||
|
|
||||||
|
using ABGridDescs = decltype(MakeABGridDescriptor_A_M_K_B_M(1, 1, {}, {}, {}, {}, {}, {}));
|
||||||
|
using AGridDesc_M_K = remove_cvref_t<decltype(ABGridDescs{}[I0])>;
|
||||||
|
using BGridDesc_M = remove_cvref_t<decltype(ABGridDescs{}[I1])>;
|
||||||
|
|
||||||
|
struct Argument : public BaseArgument
|
||||||
|
{
|
||||||
|
Argument(const InDataType* p_in_dev,
|
||||||
|
OutDataType* p_out_dev,
|
||||||
|
IndexDataType* p_out_indices_dev,
|
||||||
|
ck::index_t N,
|
||||||
|
ck::index_t C,
|
||||||
|
std::vector<ck::index_t>& input_spatial_lengths,
|
||||||
|
std::vector<ck::index_t>& window_spatial_lengths,
|
||||||
|
std::vector<ck::index_t>& output_spatial_lengths,
|
||||||
|
std::vector<ck::index_t>& window_strides,
|
||||||
|
std::vector<ck::index_t>& input_left_pads,
|
||||||
|
std::vector<ck::index_t>& input_right_pads)
|
||||||
|
: p_in_dev_{p_in_dev},
|
||||||
|
p_out_dev_{p_out_dev},
|
||||||
|
p_out_indices_dev_{p_out_indices_dev},
|
||||||
|
a_grid_desc_m_k_{},
|
||||||
|
b_grid_desc_m_{}
|
||||||
|
{
|
||||||
|
const auto descs = MakeABGridDescriptor_A_M_K_B_M(N,
|
||||||
|
C,
|
||||||
|
input_spatial_lengths,
|
||||||
|
window_spatial_lengths,
|
||||||
|
output_spatial_lengths,
|
||||||
|
window_strides,
|
||||||
|
input_left_pads,
|
||||||
|
input_right_pads);
|
||||||
|
|
||||||
|
a_grid_desc_m_k_ = descs[I0];
|
||||||
|
b_grid_desc_m_ = descs[I1];
|
||||||
|
|
||||||
|
invariant_lowest_length_ = C;
|
||||||
|
|
||||||
|
int32_t reduceLength =
|
||||||
|
window_spatial_lengths[0] * window_spatial_lengths[1] * window_spatial_lengths[2];
|
||||||
|
|
||||||
|
std::tie(in_element_op_, acc_element_op_) =
|
||||||
|
reduce_unary_operator<ReduceOpId, true, true>::GetElementwiseOperator(reduceLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
const InDataType* p_in_dev_;
|
||||||
|
OutDataType* p_out_dev_;
|
||||||
|
IndexDataType* p_out_indices_dev_;
|
||||||
|
AGridDesc_M_K a_grid_desc_m_k_;
|
||||||
|
BGridDesc_M b_grid_desc_m_;
|
||||||
|
InElementwiseOperation in_element_op_;
|
||||||
|
AccElementwiseOperation acc_element_op_;
|
||||||
|
|
||||||
|
// for checking vector load/store
|
||||||
|
ck::index_t invariant_lowest_length_;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Invoker : public BaseInvoker
|
||||||
|
{
|
||||||
|
float Run(const Argument& arg, const StreamConfig& stream_config = StreamConfig{})
|
||||||
|
{
|
||||||
|
using gridwise_reduce =
|
||||||
|
GridwiseReduction_mk_to_m_threadwise<InDataType,
|
||||||
|
OutDataType,
|
||||||
|
ComputeDataType,
|
||||||
|
IndexDataType,
|
||||||
|
AGridDesc_M_K,
|
||||||
|
BGridDesc_M,
|
||||||
|
ReduceOperation,
|
||||||
|
InElementwiseOperation,
|
||||||
|
AccElementwiseOperation,
|
||||||
|
InMemoryDataOperationEnum::Set,
|
||||||
|
false, // propagate_nan
|
||||||
|
BlockSize,
|
||||||
|
MThreadSliceSize,
|
||||||
|
KThreadSliceSize,
|
||||||
|
InSrcOutDstVectorDim,
|
||||||
|
InSrcOutDstVectorSize,
|
||||||
|
InSrcOutDstVectorSize>;
|
||||||
|
|
||||||
|
const auto kernel =
|
||||||
|
kernel_reduce_threadwise<gridwise_reduce,
|
||||||
|
OutputIndex,
|
||||||
|
true, // pooling need to return global index
|
||||||
|
false, // don't have index input
|
||||||
|
InDataType,
|
||||||
|
OutDataType,
|
||||||
|
ComputeDataType,
|
||||||
|
IndexDataType,
|
||||||
|
AGridDesc_M_K,
|
||||||
|
BGridDesc_M,
|
||||||
|
InElementwiseOperation,
|
||||||
|
AccElementwiseOperation>;
|
||||||
|
|
||||||
|
ck::index_t M = arg.a_grid_desc_m_k_.GetLength(I0);
|
||||||
|
|
||||||
|
const index_t grid_size = (M / M_BlockTileSize);
|
||||||
|
|
||||||
|
return launch_and_time_kernel(stream_config,
|
||||||
|
kernel,
|
||||||
|
dim3(grid_size),
|
||||||
|
dim3(BlockSize),
|
||||||
|
0,
|
||||||
|
arg.a_grid_desc_m_k_,
|
||||||
|
arg.b_grid_desc_m_,
|
||||||
|
arg.in_element_op_,
|
||||||
|
arg.acc_element_op_,
|
||||||
|
float(1),
|
||||||
|
arg.p_in_dev_,
|
||||||
|
nullptr,
|
||||||
|
float(0),
|
||||||
|
arg.p_out_dev_,
|
||||||
|
arg.p_out_indices_dev_);
|
||||||
|
}
|
||||||
|
|
||||||
|
float Run(const BaseArgument* p_arg,
|
||||||
|
const StreamConfig& stream_config = StreamConfig{}) override
|
||||||
|
{
|
||||||
|
return Run(*dynamic_cast<const Argument*>(p_arg), stream_config);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
bool IsSupportedArgument(const BaseArgument* p_arg) override
|
||||||
|
{
|
||||||
|
const Argument* pArg = dynamic_cast<const Argument*>(p_arg);
|
||||||
|
|
||||||
|
if(pArg->invariant_lowest_length_ % InSrcOutDstVectorSize != 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<BaseArgument>
|
||||||
|
MakeArgumentPointer(const void* p_in_dev,
|
||||||
|
void* p_out_dev,
|
||||||
|
void* p_out_indices_dev,
|
||||||
|
std::vector<ck::index_t> input_lengths,
|
||||||
|
std::vector<ck::index_t> window_lengths,
|
||||||
|
std::vector<ck::index_t> output_lengths,
|
||||||
|
std::vector<ck::index_t>, // Suppose tensor layout = NDHWC
|
||||||
|
std::vector<ck::index_t>, // Suppose tensor layout = NDHWC
|
||||||
|
std::vector<ck::index_t>, // Suppose tensor layout = NDHWC
|
||||||
|
std::vector<ck::index_t> window_strides,
|
||||||
|
std::vector<ck::index_t> input_left_pads,
|
||||||
|
std::vector<ck::index_t> input_right_pads,
|
||||||
|
std::vector<ck::index_t> pooling_dims) override
|
||||||
|
{
|
||||||
|
if(input_lengths.size() != InOutRank || window_lengths.size() != WindowRank ||
|
||||||
|
input_lengths.size() != InOutRank || window_strides.size() != WindowRank ||
|
||||||
|
input_left_pads.size() != WindowRank || input_right_pads.size() != WindowRank)
|
||||||
|
throw std::runtime_error("dimension is incorrect");
|
||||||
|
|
||||||
|
if(pooling_dims != std::vector<ck::index_t>{2, 3, 4})
|
||||||
|
throw std::runtime_error("pooling_dims only support {2, 3, 4} in pool3d so far");
|
||||||
|
|
||||||
|
index_t N = input_lengths[0];
|
||||||
|
index_t C = input_lengths[1];
|
||||||
|
index_t Di = input_lengths[2];
|
||||||
|
index_t Hi = input_lengths[3];
|
||||||
|
index_t Wi = input_lengths[4];
|
||||||
|
index_t Do = output_lengths[2];
|
||||||
|
index_t Ho = output_lengths[3];
|
||||||
|
index_t Wo = output_lengths[4];
|
||||||
|
|
||||||
|
std::vector<ck::index_t> input_spatial_lengths = {Di, Hi, Wi};
|
||||||
|
std::vector<ck::index_t> output_spatial_lengths = {Do, Ho, Wo};
|
||||||
|
|
||||||
|
return std::make_unique<Argument>(static_cast<const InDataType*>(p_in_dev),
|
||||||
|
static_cast<OutDataType*>(p_out_dev),
|
||||||
|
static_cast<IndexDataType*>(p_out_indices_dev),
|
||||||
|
N,
|
||||||
|
C,
|
||||||
|
input_spatial_lengths,
|
||||||
|
window_lengths,
|
||||||
|
output_spatial_lengths,
|
||||||
|
window_strides,
|
||||||
|
input_left_pads,
|
||||||
|
input_right_pads);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<BaseInvoker> MakeInvokerPointer() override
|
||||||
|
{
|
||||||
|
return std::make_unique<Invoker>(Invoker{});
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GetTypeString() const override
|
||||||
|
{
|
||||||
|
auto str = std::stringstream();
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
|
str << "DevicePool3dFwd_Input_N_Di_Hi_Wi_C_Output_N_Do_Ho_Wo_C<" << BlockSize << ",";
|
||||||
|
str << "M_C" << MThreadClusterSize << "_S" << MThreadSliceSize << ",";
|
||||||
|
str << "K_C" << KThreadClusterSize << "_S" << KThreadSliceSize << ",";
|
||||||
|
str <<"InSrcOutDstVectorSize_" << InSrcOutDstVectorSize << ">";
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
|
return str.str();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace device
|
||||||
|
} // namespace tensor_operation
|
||||||
|
} // namespace ck
|
||||||
@@ -28,6 +28,7 @@ template <typename InDataType,
|
|||||||
typename AccElementwiseOperation,
|
typename AccElementwiseOperation,
|
||||||
bool PropagateNan,
|
bool PropagateNan,
|
||||||
bool OutputIndex,
|
bool OutputIndex,
|
||||||
|
bool TransformIndexKtoGlobal,
|
||||||
bool HaveIndexInputIfOutputIndex,
|
bool HaveIndexInputIfOutputIndex,
|
||||||
index_t BlockSize,
|
index_t BlockSize,
|
||||||
index_t MThreadSliceSize,
|
index_t MThreadSliceSize,
|
||||||
@@ -260,6 +261,7 @@ struct DeviceReduceThreadWise : public DeviceReduce<InDataType,
|
|||||||
|
|
||||||
const auto kernel = kernel_reduce_threadwise<GridwiseReduce,
|
const auto kernel = kernel_reduce_threadwise<GridwiseReduce,
|
||||||
OutputIndex,
|
OutputIndex,
|
||||||
|
TransformIndexKtoGlobal,
|
||||||
HaveIndexInput,
|
HaveIndexInput,
|
||||||
InDataType,
|
InDataType,
|
||||||
OutDataType,
|
OutDataType,
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ namespace ck {
|
|||||||
|
|
||||||
template <typename GridwiseReduction,
|
template <typename GridwiseReduction,
|
||||||
bool OutputIndex,
|
bool OutputIndex,
|
||||||
|
bool TransformIndexKtoGlobal,
|
||||||
bool HaveIndexInput,
|
bool HaveIndexInput,
|
||||||
typename InDataType,
|
typename InDataType,
|
||||||
typename OutDataType,
|
typename OutDataType,
|
||||||
@@ -48,16 +49,17 @@ __global__ void kernel_reduce_threadwise(const InGridDesc_M_K in_grid_desc_m_k,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GridwiseReduction::template RunWithIndex<HaveIndexInput>(in_grid_desc_m_k,
|
GridwiseReduction::template RunWithIndex<TransformIndexKtoGlobal, HaveIndexInput>(
|
||||||
out_grid_desc_m,
|
in_grid_desc_m_k,
|
||||||
in_elementwise_op,
|
out_grid_desc_m,
|
||||||
acc_elementwise_op,
|
in_elementwise_op,
|
||||||
alpha,
|
acc_elementwise_op,
|
||||||
p_in_value_global,
|
alpha,
|
||||||
p_in_index_global,
|
p_in_value_global,
|
||||||
beta,
|
p_in_index_global,
|
||||||
p_out_value_global,
|
beta,
|
||||||
p_out_index_global);
|
p_out_value_global,
|
||||||
|
p_out_index_global);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -232,7 +234,7 @@ struct GridwiseReduction_mk_to_m_threadwise
|
|||||||
reduced_data_desc, make_tuple(I0), accu_value_buf, out_grid_desc_m, dst_global_buf);
|
reduced_data_desc, make_tuple(I0), accu_value_buf, out_grid_desc_m, dst_global_buf);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <bool HaveIndexInput>
|
template <bool TransformIndexKtoGlobal, bool HaveIndexInput>
|
||||||
__device__ static void RunWithIndex(const InGridDesc_M_K& in_grid_desc_m_k,
|
__device__ static void RunWithIndex(const InGridDesc_M_K& in_grid_desc_m_k,
|
||||||
const OutGridDesc_M& out_grid_desc_m,
|
const OutGridDesc_M& out_grid_desc_m,
|
||||||
const InElementwiseOperation& in_elementwise_op,
|
const InElementwiseOperation& in_elementwise_op,
|
||||||
@@ -390,6 +392,18 @@ struct GridwiseReduction_mk_to_m_threadwise
|
|||||||
indexStart += KThreadSliceSize;
|
indexStart += KThreadSliceSize;
|
||||||
reducedLength += KThreadSliceSize;
|
reducedLength += KThreadSliceSize;
|
||||||
} while(reducedLength < toReduceLength);
|
} while(reducedLength < toReduceLength);
|
||||||
|
|
||||||
|
if constexpr(TransformIndexKtoGlobal)
|
||||||
|
{
|
||||||
|
static_for<0, MThreadSliceSize, 1>{}([&](auto I) {
|
||||||
|
const auto coord = make_tensor_coordinate(
|
||||||
|
in_grid_desc_m_k,
|
||||||
|
make_multi_index(thread_global_1d_id * MThreadSliceSize + I,
|
||||||
|
accu_index_buf(I)));
|
||||||
|
|
||||||
|
accu_index_buf(I) = coord.GetOffset();
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// for indiced operation, acc_elementwise_op shoud do nothing
|
// for indiced operation, acc_elementwise_op shoud do nothing
|
||||||
|
|||||||
@@ -0,0 +1,345 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <vector>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include "ck/tensor_operation/gpu/device/device_base.hpp"
|
||||||
|
#include "ck/tensor_operation/gpu/device/reduction_operator_mapping.hpp"
|
||||||
|
#include "ck/utility/reduction_functions_accumulate.hpp"
|
||||||
|
#include "ck/library/utility/host_tensor.hpp"
|
||||||
|
#include "ck/library/utility/host_tensor_generator.hpp"
|
||||||
|
|
||||||
|
namespace ck {
|
||||||
|
namespace tensor_operation {
|
||||||
|
namespace host {
|
||||||
|
|
||||||
|
template <index_t InOutRank,
|
||||||
|
index_t WindowRank,
|
||||||
|
typename InDataType,
|
||||||
|
typename OutDataType,
|
||||||
|
typename ComputeDataType,
|
||||||
|
typename IndexDataType,
|
||||||
|
ck::ReduceTensorOp ReduceOpId,
|
||||||
|
bool PropagateNan,
|
||||||
|
bool OutputIndex>
|
||||||
|
struct ReferencePoolingFwd : public device::BaseOperator
|
||||||
|
{
|
||||||
|
using ReduceOperation = typename ck::reduce_binary_operator<ReduceOpId>::opType;
|
||||||
|
|
||||||
|
// Argument
|
||||||
|
struct Argument : public device::BaseArgument
|
||||||
|
{
|
||||||
|
Argument(const Tensor<InDataType>& in,
|
||||||
|
Tensor<OutDataType>& out,
|
||||||
|
Tensor<IndexDataType>& out_indices,
|
||||||
|
const std::vector<ck::index_t>& window_spatial_lengths,
|
||||||
|
const std::vector<ck::index_t>& window_strides,
|
||||||
|
const std::vector<ck::index_t>& in_left_pads,
|
||||||
|
const std::vector<ck::index_t>& /*in_right_pads*/)
|
||||||
|
: in_(in),
|
||||||
|
out_(out),
|
||||||
|
out_indices_(out_indices),
|
||||||
|
window_spatial_lengths_(window_spatial_lengths),
|
||||||
|
window_strides_(window_strides),
|
||||||
|
in_left_pads_(in_left_pads),
|
||||||
|
reduceLength_(1)
|
||||||
|
{
|
||||||
|
static_for<0, WindowRank, 1>{}(
|
||||||
|
[&](auto I) { reduceLength_ *= window_spatial_lengths[I]; });
|
||||||
|
}
|
||||||
|
|
||||||
|
const Tensor<InDataType>& in_;
|
||||||
|
Tensor<OutDataType>& out_;
|
||||||
|
Tensor<IndexDataType>& out_indices_;
|
||||||
|
const std::vector<ck::index_t>& window_spatial_lengths_;
|
||||||
|
const std::vector<ck::index_t>& window_strides_;
|
||||||
|
const std::vector<ck::index_t>& in_left_pads_;
|
||||||
|
int reduceLength_;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Invoker
|
||||||
|
struct Invoker : public device::BaseInvoker
|
||||||
|
{
|
||||||
|
float RunPooling3dFwd(const Argument& arg)
|
||||||
|
{
|
||||||
|
|
||||||
|
auto elementwise_ops =
|
||||||
|
ck::reduce_unary_operator<ReduceOpId, true, true>::GetElementwiseOperator(
|
||||||
|
arg.reduceLength_);
|
||||||
|
|
||||||
|
auto in_elementwise_op = std::get<0>(elementwise_ops);
|
||||||
|
auto acc_elementwise_op = std::get<1>(elementwise_ops);
|
||||||
|
|
||||||
|
if constexpr(!OutputIndex)
|
||||||
|
{
|
||||||
|
using Accumulation = ck::detail::
|
||||||
|
AccumulateWithNanCheck<PropagateNan, ReduceOperation, ComputeDataType>;
|
||||||
|
|
||||||
|
auto f_ncdhw = [&](auto n, auto c, auto do_, auto ho, auto wo) {
|
||||||
|
auto accuVal = ReduceOperation::template GetIdentityValue<ComputeDataType>();
|
||||||
|
|
||||||
|
for(ck::index_t z = 0; z < arg.window_spatial_lengths_[0]; ++z)
|
||||||
|
{
|
||||||
|
ck::index_t di = do_ * arg.window_strides_[0] + z - arg.in_left_pads_[0];
|
||||||
|
for(ck::index_t y = 0; y < arg.window_spatial_lengths_[1]; ++y)
|
||||||
|
{
|
||||||
|
ck::index_t hi = ho * arg.window_strides_[1] + y - arg.in_left_pads_[1];
|
||||||
|
for(ck::index_t x = 0; x < arg.window_spatial_lengths_[2]; ++x)
|
||||||
|
{
|
||||||
|
ck::index_t wi =
|
||||||
|
wo * arg.window_strides_[2] + x - arg.in_left_pads_[2];
|
||||||
|
if(di >= 0 &&
|
||||||
|
di < static_cast<ck::index_t>(arg.in_.mDesc.GetLengths()[2]) &&
|
||||||
|
hi >= 0 &&
|
||||||
|
hi < static_cast<ck::index_t>(arg.in_.mDesc.GetLengths()[3]) &&
|
||||||
|
wi >= 0 &&
|
||||||
|
wi < static_cast<ck::index_t>(arg.in_.mDesc.GetLengths()[4]))
|
||||||
|
{
|
||||||
|
ComputeDataType currVal =
|
||||||
|
static_cast<ComputeDataType>(arg.in_(n, c, di, hi, wi));
|
||||||
|
|
||||||
|
in_elementwise_op(currVal, currVal);
|
||||||
|
|
||||||
|
Accumulation::Calculate(accuVal, currVal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
acc_elementwise_op(accuVal, accuVal);
|
||||||
|
|
||||||
|
arg.out_(n, c, do_, ho, wo) = accuVal;
|
||||||
|
};
|
||||||
|
|
||||||
|
make_ParallelTensorFunctor(f_ncdhw,
|
||||||
|
arg.out_.mDesc.GetLengths()[0],
|
||||||
|
arg.out_.mDesc.GetLengths()[1],
|
||||||
|
arg.out_.mDesc.GetLengths()[2],
|
||||||
|
arg.out_.mDesc.GetLengths()[3],
|
||||||
|
arg.out_.mDesc.GetLengths()[4])(
|
||||||
|
std::thread::hardware_concurrency());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
using Accumulation = ck::detail::AccumulateWithIndexAndNanCheck<PropagateNan,
|
||||||
|
ReduceOperation,
|
||||||
|
ComputeDataType,
|
||||||
|
IndexDataType>;
|
||||||
|
|
||||||
|
auto f_ncdhw = [&](auto n, auto c, auto do_, auto ho, auto wo) {
|
||||||
|
auto accuVal = ReduceOperation::template GetIdentityValue<ComputeDataType>();
|
||||||
|
IndexDataType accuIndex = 0;
|
||||||
|
|
||||||
|
for(ck::index_t z = 0; z < arg.window_spatial_lengths_[0]; ++z)
|
||||||
|
{
|
||||||
|
ck::index_t di = do_ * arg.window_strides_[0] + z - arg.in_left_pads_[0];
|
||||||
|
for(ck::index_t y = 0; y < arg.window_spatial_lengths_[1]; ++y)
|
||||||
|
{
|
||||||
|
ck::index_t hi = ho * arg.window_strides_[1] + y - arg.in_left_pads_[1];
|
||||||
|
for(ck::index_t x = 0; x < arg.window_spatial_lengths_[2]; ++x)
|
||||||
|
{
|
||||||
|
ck::index_t wi =
|
||||||
|
wo * arg.window_strides_[2] + x - arg.in_left_pads_[2];
|
||||||
|
if(di >= 0 &&
|
||||||
|
di < static_cast<ck::index_t>(arg.in_.mDesc.GetLengths()[2]) &&
|
||||||
|
hi >= 0 &&
|
||||||
|
hi < static_cast<ck::index_t>(arg.in_.mDesc.GetLengths()[3]) &&
|
||||||
|
wi >= 0 &&
|
||||||
|
wi < static_cast<ck::index_t>(arg.in_.mDesc.GetLengths()[4]))
|
||||||
|
{
|
||||||
|
ComputeDataType currVal =
|
||||||
|
static_cast<ComputeDataType>(arg.in_(n, c, di, hi, wi));
|
||||||
|
IndexDataType currIndex =
|
||||||
|
arg.in_.GetOffsetFromMultiIndex(n, c, di, hi, wi);
|
||||||
|
|
||||||
|
in_elementwise_op(currVal, currVal);
|
||||||
|
|
||||||
|
Accumulation::Calculate(accuVal, currVal, accuIndex, currIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
acc_elementwise_op(accuVal, accuVal);
|
||||||
|
|
||||||
|
arg.out_(n, c, do_, ho, wo) = accuVal;
|
||||||
|
arg.out_indices_(n, c, do_, ho, wo) = accuIndex;
|
||||||
|
};
|
||||||
|
|
||||||
|
make_ParallelTensorFunctor(f_ncdhw,
|
||||||
|
arg.out_.mDesc.GetLengths()[0],
|
||||||
|
arg.out_.mDesc.GetLengths()[1],
|
||||||
|
arg.out_.mDesc.GetLengths()[2],
|
||||||
|
arg.out_.mDesc.GetLengths()[3],
|
||||||
|
arg.out_.mDesc.GetLengths()[4])(
|
||||||
|
std::thread::hardware_concurrency());
|
||||||
|
};
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
float RunPooling2dFwd(const Argument& arg)
|
||||||
|
{
|
||||||
|
|
||||||
|
auto elementwise_ops =
|
||||||
|
ck::reduce_unary_operator<ReduceOpId, true, true>::GetElementwiseOperator(
|
||||||
|
arg.reduceLength_);
|
||||||
|
|
||||||
|
auto in_elementwise_op = std::get<0>(elementwise_ops);
|
||||||
|
auto acc_elementwise_op = std::get<1>(elementwise_ops);
|
||||||
|
|
||||||
|
if constexpr(!OutputIndex)
|
||||||
|
{
|
||||||
|
using Accumulation = ck::detail::
|
||||||
|
AccumulateWithNanCheck<PropagateNan, ReduceOperation, ComputeDataType>;
|
||||||
|
|
||||||
|
auto f_nchw = [&](auto n, auto c, auto ho, auto wo) {
|
||||||
|
auto accuVal = ReduceOperation::template GetIdentityValue<ComputeDataType>();
|
||||||
|
|
||||||
|
for(ck::index_t y = 0; y < arg.window_spatial_lengths_[0]; ++y)
|
||||||
|
{
|
||||||
|
ck::index_t hi = ho * arg.window_strides_[0] + y - arg.in_left_pads_[0];
|
||||||
|
for(ck::index_t x = 0; x < arg.window_spatial_lengths_[1]; ++x)
|
||||||
|
{
|
||||||
|
ck::index_t wi = wo * arg.window_strides_[1] + x - arg.in_left_pads_[1];
|
||||||
|
if(hi >= 0 &&
|
||||||
|
hi < static_cast<ck::index_t>(arg.in_.mDesc.GetLengths()[2]) &&
|
||||||
|
wi >= 0 &&
|
||||||
|
wi < static_cast<ck::index_t>(arg.in_.mDesc.GetLengths()[3]))
|
||||||
|
{
|
||||||
|
ComputeDataType currVal =
|
||||||
|
static_cast<ComputeDataType>(arg.in_(n, c, hi, wi));
|
||||||
|
|
||||||
|
in_elementwise_op(currVal, currVal);
|
||||||
|
|
||||||
|
Accumulation::Calculate(accuVal, currVal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
acc_elementwise_op(accuVal, accuVal);
|
||||||
|
arg.out_(n, c, ho, wo) = accuVal;
|
||||||
|
};
|
||||||
|
|
||||||
|
make_ParallelTensorFunctor(f_nchw,
|
||||||
|
arg.out_.mDesc.GetLengths()[0],
|
||||||
|
arg.out_.mDesc.GetLengths()[1],
|
||||||
|
arg.out_.mDesc.GetLengths()[2],
|
||||||
|
arg.out_.mDesc.GetLengths()[3])(
|
||||||
|
std::thread::hardware_concurrency());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
using Accumulation = ck::detail::AccumulateWithIndexAndNanCheck<PropagateNan,
|
||||||
|
ReduceOperation,
|
||||||
|
ComputeDataType,
|
||||||
|
IndexDataType>;
|
||||||
|
|
||||||
|
auto f_nchw = [&](auto n, auto c, auto ho, auto wo) {
|
||||||
|
auto accuVal = ReduceOperation::template GetIdentityValue<ComputeDataType>();
|
||||||
|
IndexDataType accuIndex = 0;
|
||||||
|
|
||||||
|
for(ck::index_t y = 0; y < arg.window_spatial_lengths_[0]; ++y)
|
||||||
|
{
|
||||||
|
ck::index_t hi = ho * arg.window_strides_[0] + y - arg.in_left_pads_[0];
|
||||||
|
for(ck::index_t x = 0; x < arg.window_spatial_lengths_[1]; ++x)
|
||||||
|
{
|
||||||
|
ck::index_t wi = wo * arg.window_strides_[1] + x - arg.in_left_pads_[1];
|
||||||
|
if(hi >= 0 &&
|
||||||
|
hi < static_cast<ck::index_t>(arg.in_.mDesc.GetLengths()[2]) &&
|
||||||
|
wi >= 0 &&
|
||||||
|
wi < static_cast<ck::index_t>(arg.in_.mDesc.GetLengths()[3]))
|
||||||
|
{
|
||||||
|
ComputeDataType currVal =
|
||||||
|
static_cast<ComputeDataType>(arg.in_(n, c, hi, wi));
|
||||||
|
|
||||||
|
IndexDataType currIndex =
|
||||||
|
arg.in_.GetOffsetFromMultiIndex(n, c, hi, wi);
|
||||||
|
|
||||||
|
in_elementwise_op(currVal, currVal);
|
||||||
|
|
||||||
|
Accumulation::Calculate(accuVal, currVal, accuIndex, currIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
acc_elementwise_op(accuVal, accuVal);
|
||||||
|
arg.out_(n, c, ho, wo) = accuVal;
|
||||||
|
arg.out_indices_(n, c, ho, wo) = accuIndex;
|
||||||
|
};
|
||||||
|
|
||||||
|
make_ParallelTensorFunctor(f_nchw,
|
||||||
|
arg.out_.mDesc.GetLengths()[0],
|
||||||
|
arg.out_.mDesc.GetLengths()[1],
|
||||||
|
arg.out_.mDesc.GetLengths()[2],
|
||||||
|
arg.out_.mDesc.GetLengths()[3])(
|
||||||
|
std::thread::hardware_concurrency());
|
||||||
|
};
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
float Run(const Argument& arg)
|
||||||
|
{
|
||||||
|
// TODO - support generic pooling
|
||||||
|
if constexpr(InOutRank == 5 && WindowRank == 3)
|
||||||
|
return RunPooling3dFwd(arg);
|
||||||
|
else if constexpr(InOutRank == 4 && WindowRank == 2)
|
||||||
|
return RunPooling2dFwd(arg);
|
||||||
|
else
|
||||||
|
throw std::runtime_error("Only support pooling3d or pooling2d so far");
|
||||||
|
}
|
||||||
|
|
||||||
|
float Run(const device::BaseArgument* p_arg,
|
||||||
|
const StreamConfig& /* stream_config */ = StreamConfig{}) override
|
||||||
|
{
|
||||||
|
return Run(*dynamic_cast<const Argument*>(p_arg));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
bool IsSupportedArgument(const device::BaseArgument*) override { return true; }
|
||||||
|
|
||||||
|
static auto MakeArgument(const Tensor<InDataType>& in,
|
||||||
|
Tensor<OutDataType>& out,
|
||||||
|
Tensor<IndexDataType>& out_indices,
|
||||||
|
const std::vector<ck::index_t>& window_spatial_lengths,
|
||||||
|
const std::vector<ck::index_t>& window_strides,
|
||||||
|
const std::vector<ck::index_t>& in_left_pads,
|
||||||
|
const std::vector<ck::index_t>& in_right_pads)
|
||||||
|
{
|
||||||
|
return Argument{in,
|
||||||
|
out,
|
||||||
|
out_indices,
|
||||||
|
window_spatial_lengths,
|
||||||
|
window_strides,
|
||||||
|
in_left_pads,
|
||||||
|
in_right_pads};
|
||||||
|
}
|
||||||
|
|
||||||
|
static auto MakeInvoker() { return Invoker{}; }
|
||||||
|
|
||||||
|
virtual std::unique_ptr<device::BaseInvoker> MakeInvokerPointer()
|
||||||
|
{
|
||||||
|
return std::make_unique<Invoker>(Invoker{});
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string GetTypeString() const override
|
||||||
|
{
|
||||||
|
auto str = std::stringstream();
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
|
str << "ReferencePoolingFwd"
|
||||||
|
<< std::endl;
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
|
return str.str();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace host
|
||||||
|
} // namespace tensor_operation
|
||||||
|
} // namespace ck
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
|
#include "ck/ck.hpp"
|
||||||
|
#include "ck/tensor_operation/gpu/device/tensor_layout.hpp"
|
||||||
|
#include "ck/tensor_operation/gpu/device/device_pool_fwd.hpp"
|
||||||
|
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp"
|
||||||
|
|
||||||
|
#include "ck/library/tensor_operation_instance/device_operation_instance_factory.hpp"
|
||||||
|
|
||||||
|
namespace ck {
|
||||||
|
namespace tensor_operation {
|
||||||
|
namespace device {
|
||||||
|
namespace instance {
|
||||||
|
|
||||||
|
static constexpr auto InOutRank = 4;
|
||||||
|
static constexpr auto WindowRank = 2;
|
||||||
|
|
||||||
|
static constexpr auto MaxOp = ck::ReduceTensorOp::MAX;
|
||||||
|
static constexpr auto AvgOp = ck::ReduceTensorOp::AVG;
|
||||||
|
|
||||||
|
// FP16
|
||||||
|
void add_device_pool2d_fwd_nhwc_f16_instances(
|
||||||
|
std::vector<
|
||||||
|
std::unique_ptr<DevicePoolFwd<InOutRank, WindowRank, F16, F16, I32, MaxOp, false>>>&);
|
||||||
|
|
||||||
|
void add_device_pool2d_fwd_nhwc_f16_instances(
|
||||||
|
std::vector<
|
||||||
|
std::unique_ptr<DevicePoolFwd<InOutRank, WindowRank, F16, F16, I32, AvgOp, false>>>&);
|
||||||
|
|
||||||
|
// FP16 - return index
|
||||||
|
void add_device_pool2d_fwd_nhwc_index_f16_instances(
|
||||||
|
std::vector<
|
||||||
|
std::unique_ptr<DevicePoolFwd<InOutRank, WindowRank, F16, F16, I32, MaxOp, true>>>&);
|
||||||
|
|
||||||
|
// FP32
|
||||||
|
void add_device_pool2d_fwd_nhwc_f32_instances(
|
||||||
|
std::vector<
|
||||||
|
std::unique_ptr<DevicePoolFwd<InOutRank, WindowRank, F32, F32, I32, MaxOp, false>>>&);
|
||||||
|
|
||||||
|
void add_device_pool2d_fwd_nhwc_f32_instances(
|
||||||
|
std::vector<
|
||||||
|
std::unique_ptr<DevicePoolFwd<InOutRank, WindowRank, F32, F32, I32, AvgOp, false>>>&);
|
||||||
|
|
||||||
|
// FP32 - return index
|
||||||
|
void add_device_pool2d_fwd_nhwc_index_f32_instances(
|
||||||
|
std::vector<
|
||||||
|
std::unique_ptr<DevicePoolFwd<InOutRank, WindowRank, F32, F32, I32, MaxOp, true>>>&);
|
||||||
|
|
||||||
|
template <typename InDataType,
|
||||||
|
typename OutDataType,
|
||||||
|
typename IndexDataType,
|
||||||
|
ck::ReduceTensorOp ReduceOpId,
|
||||||
|
bool OutputIndex>
|
||||||
|
struct DeviceOperationInstanceFactory<ck::tensor_operation::device::DevicePoolFwd<InOutRank,
|
||||||
|
WindowRank,
|
||||||
|
InDataType,
|
||||||
|
OutDataType,
|
||||||
|
IndexDataType,
|
||||||
|
ReduceOpId,
|
||||||
|
OutputIndex>>
|
||||||
|
{
|
||||||
|
using DeviceOp = DevicePoolFwd<InOutRank,
|
||||||
|
WindowRank,
|
||||||
|
InDataType,
|
||||||
|
OutDataType,
|
||||||
|
IndexDataType,
|
||||||
|
ReduceOpId,
|
||||||
|
OutputIndex>;
|
||||||
|
|
||||||
|
static auto GetInstances()
|
||||||
|
{
|
||||||
|
std::vector<std::unique_ptr<DeviceOp>> op_ptrs;
|
||||||
|
|
||||||
|
if constexpr(is_same_v<InDataType, F16> && is_same_v<OutDataType, F16> &&
|
||||||
|
is_same_v<IndexDataType, I32>)
|
||||||
|
{
|
||||||
|
if constexpr(OutputIndex && ReduceOpId == MaxOp)
|
||||||
|
{
|
||||||
|
add_device_pool2d_fwd_nhwc_index_f16_instances(op_ptrs);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
add_device_pool2d_fwd_nhwc_f16_instances(op_ptrs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if constexpr(is_same_v<InDataType, F32> && is_same_v<OutDataType, F32> &&
|
||||||
|
is_same_v<IndexDataType, I32>)
|
||||||
|
{
|
||||||
|
if constexpr(OutputIndex && ReduceOpId == MaxOp)
|
||||||
|
{
|
||||||
|
add_device_pool2d_fwd_nhwc_index_f32_instances(op_ptrs);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
add_device_pool2d_fwd_nhwc_f32_instances(op_ptrs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return op_ptrs;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace instance
|
||||||
|
} // namespace device
|
||||||
|
} // namespace tensor_operation
|
||||||
|
} // namespace ck
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
|
#include "ck/ck.hpp"
|
||||||
|
#include "ck/tensor_operation/gpu/device/tensor_layout.hpp"
|
||||||
|
#include "ck/tensor_operation/gpu/device/device_pool_fwd.hpp"
|
||||||
|
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp"
|
||||||
|
|
||||||
|
#include "ck/library/tensor_operation_instance/device_operation_instance_factory.hpp"
|
||||||
|
|
||||||
|
namespace ck {
|
||||||
|
namespace tensor_operation {
|
||||||
|
namespace device {
|
||||||
|
namespace instance {
|
||||||
|
|
||||||
|
static constexpr auto InOutRank = 5;
|
||||||
|
static constexpr auto WindowRank = 3;
|
||||||
|
|
||||||
|
static constexpr auto MaxOp = ck::ReduceTensorOp::MAX;
|
||||||
|
static constexpr auto AvgOp = ck::ReduceTensorOp::AVG;
|
||||||
|
|
||||||
|
// FP16
|
||||||
|
void add_device_pool3d_fwd_ndhwc_f16_instances(
|
||||||
|
std::vector<
|
||||||
|
std::unique_ptr<DevicePoolFwd<InOutRank, WindowRank, F16, F16, I32, MaxOp, false>>>&);
|
||||||
|
|
||||||
|
void add_device_pool3d_fwd_ndhwc_f16_instances(
|
||||||
|
std::vector<
|
||||||
|
std::unique_ptr<DevicePoolFwd<InOutRank, WindowRank, F16, F16, I32, AvgOp, false>>>&);
|
||||||
|
|
||||||
|
// FP16 - return index
|
||||||
|
void add_device_pool3d_fwd_ndhwc_index_f16_instances(
|
||||||
|
std::vector<
|
||||||
|
std::unique_ptr<DevicePoolFwd<InOutRank, WindowRank, F16, F16, I32, MaxOp, true>>>&);
|
||||||
|
|
||||||
|
// FP32
|
||||||
|
void add_device_pool3d_fwd_ndhwc_f32_instances(
|
||||||
|
std::vector<
|
||||||
|
std::unique_ptr<DevicePoolFwd<InOutRank, WindowRank, F32, F32, I32, MaxOp, false>>>&);
|
||||||
|
|
||||||
|
void add_device_pool3d_fwd_ndhwc_f32_instances(
|
||||||
|
std::vector<
|
||||||
|
std::unique_ptr<DevicePoolFwd<InOutRank, WindowRank, F32, F32, I32, AvgOp, false>>>&);
|
||||||
|
|
||||||
|
// FP32 - return index
|
||||||
|
void add_device_pool3d_fwd_ndhwc_index_f32_instances(
|
||||||
|
std::vector<
|
||||||
|
std::unique_ptr<DevicePoolFwd<InOutRank, WindowRank, F32, F32, I32, MaxOp, true>>>&);
|
||||||
|
|
||||||
|
template <typename InDataType,
|
||||||
|
typename OutDataType,
|
||||||
|
typename IndexDataType,
|
||||||
|
ck::ReduceTensorOp ReduceOpId,
|
||||||
|
bool OutputIndex>
|
||||||
|
struct DeviceOperationInstanceFactory<ck::tensor_operation::device::DevicePoolFwd<InOutRank,
|
||||||
|
WindowRank,
|
||||||
|
InDataType,
|
||||||
|
OutDataType,
|
||||||
|
IndexDataType,
|
||||||
|
ReduceOpId,
|
||||||
|
OutputIndex>>
|
||||||
|
{
|
||||||
|
using DeviceOp = DevicePoolFwd<InOutRank,
|
||||||
|
WindowRank,
|
||||||
|
InDataType,
|
||||||
|
OutDataType,
|
||||||
|
IndexDataType,
|
||||||
|
ReduceOpId,
|
||||||
|
OutputIndex>;
|
||||||
|
|
||||||
|
static auto GetInstances()
|
||||||
|
{
|
||||||
|
std::vector<std::unique_ptr<DeviceOp>> op_ptrs;
|
||||||
|
|
||||||
|
if constexpr(is_same_v<InDataType, F16> && is_same_v<OutDataType, F16> &&
|
||||||
|
is_same_v<IndexDataType, I32>)
|
||||||
|
{
|
||||||
|
if constexpr(OutputIndex && ReduceOpId == MaxOp)
|
||||||
|
{
|
||||||
|
add_device_pool3d_fwd_ndhwc_index_f16_instances(op_ptrs);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
add_device_pool3d_fwd_ndhwc_f16_instances(op_ptrs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if constexpr(is_same_v<InDataType, F32> && is_same_v<OutDataType, F32> &&
|
||||||
|
is_same_v<IndexDataType, I32>)
|
||||||
|
{
|
||||||
|
if constexpr(OutputIndex && ReduceOpId == MaxOp)
|
||||||
|
{
|
||||||
|
add_device_pool3d_fwd_ndhwc_index_f32_instances(op_ptrs);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
add_device_pool3d_fwd_ndhwc_f32_instances(op_ptrs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return op_ptrs;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace instance
|
||||||
|
} // namespace device
|
||||||
|
} // namespace tensor_operation
|
||||||
|
} // namespace ck
|
||||||
@@ -90,6 +90,7 @@ void add_device_reduce_instance_threadwise(
|
|||||||
AccElementwiseOp,
|
AccElementwiseOp,
|
||||||
PropagateNan,
|
PropagateNan,
|
||||||
OutputIndex,
|
OutputIndex,
|
||||||
|
false,
|
||||||
false, // HaveIndexInputIfOutputIndex
|
false, // HaveIndexInputIfOutputIndex
|
||||||
cfg1::BlockSize_,
|
cfg1::BlockSize_,
|
||||||
cfg2::MThreadSliceSize_,
|
cfg2::MThreadSliceSize_,
|
||||||
|
|||||||
@@ -411,6 +411,12 @@ struct Tensor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename... Is>
|
||||||
|
std::size_t GetOffsetFromMultiIndex(Is... is) const
|
||||||
|
{
|
||||||
|
return mDesc.GetOffsetFromMultiIndex(is...);
|
||||||
|
}
|
||||||
|
|
||||||
template <typename... Is>
|
template <typename... Is>
|
||||||
T& operator()(Is... is)
|
T& operator()(Is... is)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
add_instance_library(device_pool_fwd_instance
|
||||||
|
device_avg_pool2d_fwd_nhwc_f16_instance.cpp
|
||||||
|
device_avg_pool2d_fwd_nhwc_f32_instance.cpp
|
||||||
|
device_avg_pool3d_fwd_ndhwc_f16_instance.cpp
|
||||||
|
device_avg_pool3d_fwd_ndhwc_f32_instance.cpp
|
||||||
|
device_max_pool2d_fwd_nhwc_f16_instance.cpp
|
||||||
|
device_max_pool2d_fwd_nhwc_f32_instance.cpp
|
||||||
|
device_max_pool3d_fwd_ndhwc_f16_instance.cpp
|
||||||
|
device_max_pool3d_fwd_ndhwc_f32_instance.cpp
|
||||||
|
)
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
|
||||||
|
|
||||||
|
#include "pool_fwd_instance_common.hpp"
|
||||||
|
|
||||||
|
namespace ck {
|
||||||
|
namespace tensor_operation {
|
||||||
|
namespace device {
|
||||||
|
namespace instance {
|
||||||
|
|
||||||
|
static constexpr auto ReduceOpId = ck::ReduceTensorOp::AVG;
|
||||||
|
|
||||||
|
void add_device_pool2d_fwd_nhwc_f16_instances(
|
||||||
|
std::vector<std::unique_ptr<DevicePoolFwd<4, 2, F16, F16, I32, ReduceOpId, false>>>& instances)
|
||||||
|
{
|
||||||
|
add_device_operation_instances(
|
||||||
|
instances, device_pool2d_fwd_nhwc_instances<F16, F16, I32, F32, ReduceOpId, false>{});
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace instance
|
||||||
|
} // namespace device
|
||||||
|
} // namespace tensor_operation
|
||||||
|
} // namespace ck
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
|
||||||
|
|
||||||
|
#include "pool_fwd_instance_common.hpp"
|
||||||
|
|
||||||
|
namespace ck {
|
||||||
|
namespace tensor_operation {
|
||||||
|
namespace device {
|
||||||
|
namespace instance {
|
||||||
|
|
||||||
|
static constexpr auto ReduceOpId = ck::ReduceTensorOp::AVG;
|
||||||
|
|
||||||
|
void add_device_pool2d_fwd_nhwc_f32_instances(
|
||||||
|
std::vector<std::unique_ptr<DevicePoolFwd<4, 2, F32, F32, I32, ReduceOpId, false>>>& instances)
|
||||||
|
{
|
||||||
|
add_device_operation_instances(
|
||||||
|
instances, device_pool2d_fwd_nhwc_instances<F32, F32, I32, F32, ReduceOpId, false>{});
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace instance
|
||||||
|
} // namespace device
|
||||||
|
} // namespace tensor_operation
|
||||||
|
} // namespace ck
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
|
||||||
|
|
||||||
|
#include "pool_fwd_instance_common.hpp"
|
||||||
|
|
||||||
|
namespace ck {
|
||||||
|
namespace tensor_operation {
|
||||||
|
namespace device {
|
||||||
|
namespace instance {
|
||||||
|
|
||||||
|
static constexpr auto ReduceOpId = ck::ReduceTensorOp::AVG;
|
||||||
|
|
||||||
|
void add_device_pool3d_fwd_ndhwc_f16_instances(
|
||||||
|
std::vector<std::unique_ptr<DevicePoolFwd<5, 3, F16, F16, I32, ReduceOpId, false>>>& instances)
|
||||||
|
{
|
||||||
|
add_device_operation_instances(
|
||||||
|
instances, device_pool3d_fwd_ndhwc_instances<F16, F16, I32, F32, ReduceOpId, false>{});
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace instance
|
||||||
|
} // namespace device
|
||||||
|
} // namespace tensor_operation
|
||||||
|
} // namespace ck
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
|
||||||
|
|
||||||
|
#include "pool_fwd_instance_common.hpp"
|
||||||
|
|
||||||
|
namespace ck {
|
||||||
|
namespace tensor_operation {
|
||||||
|
namespace device {
|
||||||
|
namespace instance {
|
||||||
|
|
||||||
|
static constexpr auto ReduceOpId = ck::ReduceTensorOp::AVG;
|
||||||
|
|
||||||
|
void add_device_pool3d_fwd_ndhwc_f32_instances(
|
||||||
|
std::vector<std::unique_ptr<DevicePoolFwd<5, 3, F32, F32, I32, ReduceOpId, false>>>& instances)
|
||||||
|
{
|
||||||
|
add_device_operation_instances(
|
||||||
|
instances, device_pool3d_fwd_ndhwc_instances<F32, F32, I32, F32, ReduceOpId, false>{});
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace instance
|
||||||
|
} // namespace device
|
||||||
|
} // namespace tensor_operation
|
||||||
|
} // namespace ck
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
|
||||||
|
|
||||||
|
#include "pool_fwd_instance_common.hpp"
|
||||||
|
|
||||||
|
namespace ck {
|
||||||
|
namespace tensor_operation {
|
||||||
|
namespace device {
|
||||||
|
namespace instance {
|
||||||
|
|
||||||
|
static constexpr auto ReduceOpId = ck::ReduceTensorOp::MAX;
|
||||||
|
|
||||||
|
void add_device_pool2d_fwd_nhwc_f16_instances(
|
||||||
|
std::vector<std::unique_ptr<DevicePoolFwd<4, 2, F16, F16, I32, ReduceOpId, false>>>& instances)
|
||||||
|
{
|
||||||
|
add_device_operation_instances(
|
||||||
|
instances, device_pool2d_fwd_nhwc_instances<F16, F16, I32, F16, ReduceOpId, false>{});
|
||||||
|
}
|
||||||
|
|
||||||
|
void add_device_pool2d_fwd_nhwc_index_f16_instances(
|
||||||
|
std::vector<std::unique_ptr<DevicePoolFwd<4, 2, F16, F16, I32, ReduceOpId, true>>>& instances)
|
||||||
|
{
|
||||||
|
add_device_operation_instances(
|
||||||
|
instances, device_pool2d_fwd_nhwc_instances<F16, F16, I32, F16, ReduceOpId, true>{});
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace instance
|
||||||
|
} // namespace device
|
||||||
|
} // namespace tensor_operation
|
||||||
|
} // namespace ck
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
|
||||||
|
|
||||||
|
#include "pool_fwd_instance_common.hpp"
|
||||||
|
|
||||||
|
namespace ck {
|
||||||
|
namespace tensor_operation {
|
||||||
|
namespace device {
|
||||||
|
namespace instance {
|
||||||
|
|
||||||
|
static constexpr auto ReduceOpId = ck::ReduceTensorOp::MAX;
|
||||||
|
|
||||||
|
void add_device_pool2d_fwd_nhwc_f32_instances(
|
||||||
|
std::vector<std::unique_ptr<DevicePoolFwd<4, 2, F32, F32, I32, ReduceOpId, false>>>& instances)
|
||||||
|
{
|
||||||
|
add_device_operation_instances(
|
||||||
|
instances, device_pool2d_fwd_nhwc_instances<F32, F32, I32, F32, ReduceOpId, false>{});
|
||||||
|
}
|
||||||
|
|
||||||
|
void add_device_pool2d_fwd_nhwc_index_f32_instances(
|
||||||
|
std::vector<std::unique_ptr<DevicePoolFwd<4, 2, F32, F32, I32, ReduceOpId, true>>>& instances)
|
||||||
|
{
|
||||||
|
add_device_operation_instances(
|
||||||
|
instances, device_pool2d_fwd_nhwc_instances<F32, F32, I32, F32, ReduceOpId, true>{});
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace instance
|
||||||
|
} // namespace device
|
||||||
|
} // namespace tensor_operation
|
||||||
|
} // namespace ck
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
|
||||||
|
|
||||||
|
#include "pool_fwd_instance_common.hpp"
|
||||||
|
|
||||||
|
namespace ck {
|
||||||
|
namespace tensor_operation {
|
||||||
|
namespace device {
|
||||||
|
namespace instance {
|
||||||
|
|
||||||
|
static constexpr auto ReduceOpId = ck::ReduceTensorOp::MAX;
|
||||||
|
|
||||||
|
void add_device_pool3d_fwd_ndhwc_f16_instances(
|
||||||
|
std::vector<std::unique_ptr<DevicePoolFwd<5, 3, F16, F16, I32, ReduceOpId, false>>>& instances)
|
||||||
|
{
|
||||||
|
add_device_operation_instances(
|
||||||
|
instances, device_pool3d_fwd_ndhwc_instances<F16, F16, I32, F16, ReduceOpId, false>{});
|
||||||
|
}
|
||||||
|
|
||||||
|
void add_device_pool3d_fwd_ndhwc_index_f16_instances(
|
||||||
|
std::vector<std::unique_ptr<DevicePoolFwd<5, 3, F16, F16, I32, ReduceOpId, true>>>& instances)
|
||||||
|
{
|
||||||
|
add_device_operation_instances(
|
||||||
|
instances, device_pool3d_fwd_ndhwc_instances<F16, F16, I32, F16, ReduceOpId, true>{});
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace instance
|
||||||
|
} // namespace device
|
||||||
|
} // namespace tensor_operation
|
||||||
|
} // namespace ck
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
|
||||||
|
|
||||||
|
#include "pool_fwd_instance_common.hpp"
|
||||||
|
|
||||||
|
namespace ck {
|
||||||
|
namespace tensor_operation {
|
||||||
|
namespace device {
|
||||||
|
namespace instance {
|
||||||
|
|
||||||
|
static constexpr auto ReduceOpId = ck::ReduceTensorOp::MAX;
|
||||||
|
|
||||||
|
void add_device_pool3d_fwd_ndhwc_f32_instances(
|
||||||
|
std::vector<std::unique_ptr<DevicePoolFwd<5, 3, F32, F32, I32, ReduceOpId, false>>>& instances)
|
||||||
|
{
|
||||||
|
add_device_operation_instances(
|
||||||
|
instances, device_pool3d_fwd_ndhwc_instances<F32, F32, I32, F32, ReduceOpId, false>{});
|
||||||
|
}
|
||||||
|
|
||||||
|
void add_device_pool3d_fwd_ndhwc_index_f32_instances(
|
||||||
|
std::vector<std::unique_ptr<DevicePoolFwd<5, 3, F32, F32, I32, ReduceOpId, true>>>& instances)
|
||||||
|
{
|
||||||
|
add_device_operation_instances(
|
||||||
|
instances, device_pool3d_fwd_ndhwc_instances<F32, F32, I32, F32, ReduceOpId, true>{});
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace instance
|
||||||
|
} // namespace device
|
||||||
|
} // namespace tensor_operation
|
||||||
|
} // namespace ck
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "ck/ck.hpp"
|
||||||
|
#include "ck/tensor_operation/gpu/device/impl/device_pool2d_fwd_nhwc_nhwc.hpp"
|
||||||
|
#include "ck/tensor_operation/gpu/device/impl/device_pool3d_fwd_ndhwc_ndhwc.hpp"
|
||||||
|
#include "ck/utility/data_type.hpp"
|
||||||
|
|
||||||
|
#include "ck/library/tensor_operation_instance/add_device_operation_instance.hpp"
|
||||||
|
|
||||||
|
namespace ck {
|
||||||
|
namespace tensor_operation {
|
||||||
|
namespace device {
|
||||||
|
namespace instance {
|
||||||
|
|
||||||
|
using I32 = int32_t;
|
||||||
|
using F16 = ck::half_t;
|
||||||
|
using F32 = float;
|
||||||
|
|
||||||
|
template <typename InDataType,
|
||||||
|
typename OutDataType,
|
||||||
|
typename IndexDataType,
|
||||||
|
typename ComputeDataType,
|
||||||
|
ReduceTensorOp ReduceOpId,
|
||||||
|
bool OutputIndex>
|
||||||
|
using device_pool2d_fwd_nhwc_instances =
|
||||||
|
// clang-format off
|
||||||
|
std::tuple <
|
||||||
|
DevicePool2dFwd_Input_N_Hi_Wi_C_Output_N_Ho_Wo_C<InDataType, OutDataType, IndexDataType, ComputeDataType, ReduceOpId, OutputIndex, 256, 256, 1, 1, 1, 1>,
|
||||||
|
DevicePool2dFwd_Input_N_Hi_Wi_C_Output_N_Ho_Wo_C<InDataType, OutDataType, IndexDataType, ComputeDataType, ReduceOpId, OutputIndex, 256, 256, 1, 2, 1, 2>,
|
||||||
|
DevicePool2dFwd_Input_N_Hi_Wi_C_Output_N_Ho_Wo_C<InDataType, OutDataType, IndexDataType, ComputeDataType, ReduceOpId, OutputIndex, 256, 256, 1, 4, 1, 4>
|
||||||
|
// clang-format on
|
||||||
|
>;
|
||||||
|
|
||||||
|
template <typename InDataType,
|
||||||
|
typename OutDataType,
|
||||||
|
typename IndexDataType,
|
||||||
|
typename ComputeDataType,
|
||||||
|
ReduceTensorOp ReduceOpId,
|
||||||
|
bool OutputIndex>
|
||||||
|
using device_pool3d_fwd_ndhwc_instances =
|
||||||
|
// clang-format off
|
||||||
|
std::tuple <
|
||||||
|
DevicePool3dFwd_Input_N_Di_Hi_Wi_C_Output_N_Do_Ho_Wo_C<InDataType, OutDataType, IndexDataType, ComputeDataType, ReduceOpId, OutputIndex, 256, 256, 1, 1, 1, 1>,
|
||||||
|
DevicePool3dFwd_Input_N_Di_Hi_Wi_C_Output_N_Do_Ho_Wo_C<InDataType, OutDataType, IndexDataType, ComputeDataType, ReduceOpId, OutputIndex, 256, 256, 1, 2, 1, 2>,
|
||||||
|
DevicePool3dFwd_Input_N_Di_Hi_Wi_C_Output_N_Do_Ho_Wo_C<InDataType, OutDataType, IndexDataType, ComputeDataType, ReduceOpId, OutputIndex, 256, 256, 1, 4, 1, 4>
|
||||||
|
// clang-format on
|
||||||
|
>;
|
||||||
|
|
||||||
|
} // namespace instance
|
||||||
|
} // namespace device
|
||||||
|
} // namespace tensor_operation
|
||||||
|
} // namespace ck
|
||||||
264
profiler/include/profiler/profile_pool2d_fwd_impl.hpp
Normal file
264
profiler/include/profiler/profile_pool2d_fwd_impl.hpp
Normal file
@@ -0,0 +1,264 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
|
#include "ck/ck.hpp"
|
||||||
|
#include "ck/library/tensor_operation_instance/gpu/pool2d_fwd.hpp"
|
||||||
|
#include "ck/library/utility/check_err.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/utility/literals.hpp"
|
||||||
|
#include "ck/library/reference_tensor_operation/cpu/reference_pool_fwd.hpp"
|
||||||
|
|
||||||
|
namespace ck {
|
||||||
|
namespace profiler {
|
||||||
|
|
||||||
|
template <typename InDataType,
|
||||||
|
typename OutDataType,
|
||||||
|
typename ComputeDataType,
|
||||||
|
typename IndexDataType,
|
||||||
|
ck::ReduceTensorOp ReduceOpId,
|
||||||
|
bool PropagateNan,
|
||||||
|
bool OutputIndex>
|
||||||
|
bool profile_pool2d_fwd_impl(int do_verification,
|
||||||
|
int init_method,
|
||||||
|
bool do_log,
|
||||||
|
bool time_kernel,
|
||||||
|
std::vector<index_t> in_length, // NCHW
|
||||||
|
std::vector<index_t> window_spatial_lengths,
|
||||||
|
std::vector<index_t> window_strides,
|
||||||
|
std::vector<index_t> input_left_pads,
|
||||||
|
std::vector<index_t> input_right_pads)
|
||||||
|
{
|
||||||
|
constexpr index_t InOutRank = 4;
|
||||||
|
constexpr index_t WindowRank = 2;
|
||||||
|
|
||||||
|
if(in_length.size() != InOutRank || window_spatial_lengths.size() != WindowRank ||
|
||||||
|
window_strides.size() != WindowRank || input_left_pads.size() != WindowRank ||
|
||||||
|
input_right_pads.size() != WindowRank)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
std::vector<index_t> out_length(InOutRank);
|
||||||
|
|
||||||
|
int N = in_length[0];
|
||||||
|
int C = in_length[1];
|
||||||
|
|
||||||
|
out_length[0] = N;
|
||||||
|
out_length[1] = C;
|
||||||
|
|
||||||
|
// Calculate Ho, Wo
|
||||||
|
for(int i = 2; i < InOutRank; ++i)
|
||||||
|
{
|
||||||
|
auto pad1 = input_left_pads[i - 2];
|
||||||
|
auto pad2 = input_right_pads[i - 2];
|
||||||
|
auto windows_size = window_spatial_lengths[i - 2];
|
||||||
|
auto windows_stride = window_strides[i - 2];
|
||||||
|
out_length[i] = (in_length[i] + pad1 + pad2 - windows_size) / windows_stride + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Hi = in_length[2];
|
||||||
|
int Wi = in_length[3];
|
||||||
|
int Ho = out_length[2];
|
||||||
|
int Wo = out_length[3];
|
||||||
|
|
||||||
|
auto f_host_tensor_descriptor =
|
||||||
|
[](std::size_t N_, std::size_t C_, std::size_t H, std::size_t W) {
|
||||||
|
using namespace ck::literals;
|
||||||
|
return HostTensorDescriptor({N_, C_, H, W}, {C_ * H * W, 1_uz, W * C_, C_});
|
||||||
|
};
|
||||||
|
|
||||||
|
Tensor<InDataType> in_n_c_hi_wi(f_host_tensor_descriptor(N, C, Hi, Wi));
|
||||||
|
Tensor<OutDataType> out_n_c_ho_wo_host(f_host_tensor_descriptor(N, C, Ho, Wo));
|
||||||
|
Tensor<IndexDataType> out_indices_n_c_ho_wo_host(f_host_tensor_descriptor(N, C, Ho, Wo));
|
||||||
|
|
||||||
|
Tensor<OutDataType> out_n_c_ho_wo_device(f_host_tensor_descriptor(N, C, Ho, Wo));
|
||||||
|
Tensor<IndexDataType> out_indices_n_c_ho_wo_device(f_host_tensor_descriptor(N, C, Ho, Wo));
|
||||||
|
|
||||||
|
switch(init_method)
|
||||||
|
{
|
||||||
|
case 0: in_n_c_hi_wi.GenerateTensorValue(GeneratorTensor_1<InDataType>{}); break;
|
||||||
|
case 1: in_n_c_hi_wi.GenerateTensorValue(GeneratorTensor_2<InDataType>{-5, 5}); break;
|
||||||
|
default: in_n_c_hi_wi.GenerateTensorValue(GeneratorTensor_3<InDataType>{-0.5, 0.5});
|
||||||
|
}
|
||||||
|
|
||||||
|
DeviceMem in_device_buf(sizeof(InDataType) * in_n_c_hi_wi.mDesc.GetElementSpaceSize());
|
||||||
|
DeviceMem out_device_buf(sizeof(OutDataType) *
|
||||||
|
out_n_c_ho_wo_device.mDesc.GetElementSpaceSize());
|
||||||
|
DeviceMem out_indices_device_buf(sizeof(IndexDataType) *
|
||||||
|
out_indices_n_c_ho_wo_device.mDesc.GetElementSpaceSize());
|
||||||
|
|
||||||
|
in_device_buf.ToDevice(in_n_c_hi_wi.mData.data());
|
||||||
|
|
||||||
|
// add device normalization instances
|
||||||
|
using DeviceOp = ck::tensor_operation::device::DevicePoolFwd<InOutRank,
|
||||||
|
WindowRank,
|
||||||
|
InDataType,
|
||||||
|
OutDataType,
|
||||||
|
IndexDataType,
|
||||||
|
ReduceOpId,
|
||||||
|
OutputIndex>;
|
||||||
|
|
||||||
|
// get device op instances
|
||||||
|
const auto instance_ptrs =
|
||||||
|
ck::tensor_operation::device::instance::DeviceOperationInstanceFactory<
|
||||||
|
DeviceOp>::GetInstances();
|
||||||
|
|
||||||
|
std::cout << "found " << instance_ptrs.size() << " instances" << std::endl;
|
||||||
|
|
||||||
|
std::string best_instance_name;
|
||||||
|
float best_avg_time = std::numeric_limits<float>::max();
|
||||||
|
float best_gb_per_sec = 0;
|
||||||
|
|
||||||
|
if(do_verification)
|
||||||
|
{
|
||||||
|
using ReferenceInstance = ck::tensor_operation::host::ReferencePoolingFwd<InOutRank,
|
||||||
|
WindowRank,
|
||||||
|
InDataType,
|
||||||
|
OutDataType,
|
||||||
|
ComputeDataType,
|
||||||
|
IndexDataType,
|
||||||
|
ReduceOpId,
|
||||||
|
PropagateNan,
|
||||||
|
OutputIndex>;
|
||||||
|
|
||||||
|
ReferenceInstance ref;
|
||||||
|
auto ref_argument = ref.MakeArgument(in_n_c_hi_wi,
|
||||||
|
out_n_c_ho_wo_host,
|
||||||
|
out_indices_n_c_ho_wo_host,
|
||||||
|
window_spatial_lengths,
|
||||||
|
window_strides,
|
||||||
|
input_left_pads,
|
||||||
|
input_right_pads);
|
||||||
|
auto ref_invoker = ref.MakeInvoker();
|
||||||
|
ref_invoker.Run(ref_argument);
|
||||||
|
}
|
||||||
|
|
||||||
|
int num_kernel = 0;
|
||||||
|
|
||||||
|
for(auto& inst_ptr : instance_ptrs)
|
||||||
|
{
|
||||||
|
auto argument_ptr = inst_ptr->MakeArgumentPointer(
|
||||||
|
static_cast<InDataType*>(in_device_buf.GetDeviceBuffer()),
|
||||||
|
static_cast<OutDataType*>(out_device_buf.GetDeviceBuffer()),
|
||||||
|
static_cast<IndexDataType*>(out_indices_device_buf.GetDeviceBuffer()),
|
||||||
|
in_length,
|
||||||
|
window_spatial_lengths,
|
||||||
|
out_length,
|
||||||
|
{C * Hi * Wi, 1, Wi * C, C},
|
||||||
|
{C * Ho * Wo, 1, Wo * C, C},
|
||||||
|
{C * Ho * Wo, 1, Wo * C, C},
|
||||||
|
window_strides,
|
||||||
|
input_left_pads,
|
||||||
|
input_right_pads,
|
||||||
|
{2, 3});
|
||||||
|
|
||||||
|
if(inst_ptr->IsSupportedArgument(argument_ptr.get()))
|
||||||
|
{
|
||||||
|
++num_kernel;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(time_kernel)
|
||||||
|
{
|
||||||
|
std::cout << inst_ptr->GetTypeString() << " skipped due to unsupported argument: ";
|
||||||
|
LogRange(std::cout << "input lengths = ", in_length, ", ") << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto invoker_ptr = inst_ptr->MakeInvokerPointer();
|
||||||
|
|
||||||
|
float avg_time = invoker_ptr->Run(argument_ptr.get(), StreamConfig{nullptr, time_kernel});
|
||||||
|
|
||||||
|
std::size_t num_bytes = in_n_c_hi_wi.mDesc.GetElementSize() * sizeof(InDataType) +
|
||||||
|
out_n_c_ho_wo_host.mDesc.GetElementSize() * sizeof(OutDataType);
|
||||||
|
|
||||||
|
if constexpr(OutputIndex)
|
||||||
|
num_bytes += out_indices_n_c_ho_wo_host.mDesc.GetElementSize() * sizeof(IndexDataType);
|
||||||
|
|
||||||
|
float gb_per_sec = num_bytes / 1.E6 / avg_time;
|
||||||
|
|
||||||
|
if(time_kernel)
|
||||||
|
std::cout << "Perf: " << std::setw(10) << avg_time << " ms, " << gb_per_sec << " GB/s, "
|
||||||
|
<< inst_ptr->GetTypeString() << std::endl;
|
||||||
|
|
||||||
|
if(avg_time < best_avg_time)
|
||||||
|
{
|
||||||
|
best_instance_name = inst_ptr->GetTypeString();
|
||||||
|
best_avg_time = avg_time;
|
||||||
|
best_gb_per_sec = gb_per_sec;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(do_verification)
|
||||||
|
{
|
||||||
|
out_device_buf.FromDevice(out_n_c_ho_wo_device.mData.data());
|
||||||
|
|
||||||
|
bool pass = ck::utils::check_err(out_n_c_ho_wo_device.mData,
|
||||||
|
out_n_c_ho_wo_host.mData,
|
||||||
|
"Error: Incorrect results",
|
||||||
|
1e-3,
|
||||||
|
1e-3);
|
||||||
|
|
||||||
|
if constexpr(OutputIndex)
|
||||||
|
{
|
||||||
|
out_indices_device_buf.FromDevice(out_indices_n_c_ho_wo_device.mData.data());
|
||||||
|
|
||||||
|
pass = pass && ck::utils::check_err(out_indices_n_c_ho_wo_device,
|
||||||
|
out_indices_n_c_ho_wo_host);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(do_log)
|
||||||
|
{
|
||||||
|
LogRangeAsType<float>(std::cout << "in_n_c_hi_wi : ", in_n_c_hi_wi.mData, ",")
|
||||||
|
<< std::endl;
|
||||||
|
LogRangeAsType<float>(
|
||||||
|
std::cout << "out_n_c_ho_wo_host : ", out_n_c_ho_wo_host.mData, ",")
|
||||||
|
<< std::endl;
|
||||||
|
LogRangeAsType<float>(
|
||||||
|
std::cout << "out_n_c_ho_wo_device : ", out_n_c_ho_wo_device.mData, ",")
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
|
if constexpr(OutputIndex)
|
||||||
|
LogRangeAsType<float>(std::cout << "out_indices_n_c_ho_wo_device : ",
|
||||||
|
out_indices_n_c_ho_wo_device.mData,
|
||||||
|
",")
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!pass)
|
||||||
|
{
|
||||||
|
std::cout << inst_ptr->GetTypeString() << " failed verification: ";
|
||||||
|
LogRange(std::cout << "lengths = [", in_length, ", ") << "]." << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(time_kernel)
|
||||||
|
std::cout << "pass" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(time_kernel)
|
||||||
|
{
|
||||||
|
LogRange(std::cout << "length = ", in_length, ",") << std::endl;
|
||||||
|
std::cout << "best perf = " << best_avg_time << " ms, " << best_gb_per_sec << " GB/s, "
|
||||||
|
<< best_instance_name << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(num_kernel == 0)
|
||||||
|
{
|
||||||
|
std::cout << "Error: No kernel is applicable" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace profiler
|
||||||
|
} // namespace ck
|
||||||
271
profiler/include/profiler/profile_pool3d_fwd_impl.hpp
Normal file
271
profiler/include/profiler/profile_pool3d_fwd_impl.hpp
Normal file
@@ -0,0 +1,271 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
|
#include "ck/ck.hpp"
|
||||||
|
#include "ck/library/tensor_operation_instance/gpu/pool3d_fwd.hpp"
|
||||||
|
#include "ck/library/utility/check_err.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/utility/literals.hpp"
|
||||||
|
#include "ck/library/reference_tensor_operation/cpu/reference_pool_fwd.hpp"
|
||||||
|
|
||||||
|
namespace ck {
|
||||||
|
namespace profiler {
|
||||||
|
|
||||||
|
template <typename InDataType,
|
||||||
|
typename OutDataType,
|
||||||
|
typename ComputeDataType,
|
||||||
|
typename IndexDataType,
|
||||||
|
ck::ReduceTensorOp ReduceOpId,
|
||||||
|
bool PropagateNan,
|
||||||
|
bool OutputIndex>
|
||||||
|
bool profile_pool3d_fwd_impl(int do_verification,
|
||||||
|
int init_method,
|
||||||
|
bool do_log,
|
||||||
|
bool time_kernel,
|
||||||
|
std::vector<index_t> in_length, // NCDHW
|
||||||
|
std::vector<index_t> window_spatial_lengths,
|
||||||
|
std::vector<index_t> window_strides,
|
||||||
|
std::vector<index_t> input_left_pads,
|
||||||
|
std::vector<index_t> input_right_pads)
|
||||||
|
{
|
||||||
|
constexpr index_t InOutRank = 5;
|
||||||
|
constexpr index_t WindowRank = 3;
|
||||||
|
|
||||||
|
if(in_length.size() != InOutRank || window_spatial_lengths.size() != WindowRank ||
|
||||||
|
window_strides.size() != WindowRank || input_left_pads.size() != WindowRank ||
|
||||||
|
input_right_pads.size() != WindowRank)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
std::vector<index_t> out_length(InOutRank);
|
||||||
|
|
||||||
|
int N = in_length[0];
|
||||||
|
int C = in_length[1];
|
||||||
|
|
||||||
|
out_length[0] = N;
|
||||||
|
out_length[1] = C;
|
||||||
|
|
||||||
|
// Calculate Do, Ho, Wo
|
||||||
|
for(int i = 2; i < InOutRank; ++i)
|
||||||
|
{
|
||||||
|
auto pad1 = input_left_pads[i - 2];
|
||||||
|
auto pad2 = input_right_pads[i - 2];
|
||||||
|
auto windows_size = window_spatial_lengths[i - 2];
|
||||||
|
auto windows_stride = window_strides[i - 2];
|
||||||
|
out_length[i] = (in_length[i] + pad1 + pad2 - windows_size) / windows_stride + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Di = in_length[2];
|
||||||
|
int Hi = in_length[3];
|
||||||
|
int Wi = in_length[4];
|
||||||
|
int Do = out_length[2];
|
||||||
|
int Ho = out_length[3];
|
||||||
|
int Wo = out_length[4];
|
||||||
|
|
||||||
|
auto f_host_tensor_descriptor =
|
||||||
|
[](std::size_t N_, std::size_t C_, std::size_t D, std::size_t H, std::size_t W) {
|
||||||
|
using namespace ck::literals;
|
||||||
|
|
||||||
|
return HostTensorDescriptor({N_, C_, D, H, W},
|
||||||
|
{D * C_ * H * W, 1_uz, C_ * H * W, W * C_, C_});
|
||||||
|
};
|
||||||
|
|
||||||
|
Tensor<InDataType> in_n_c_di_hi_wi(f_host_tensor_descriptor(N, C, Di, Hi, Wi));
|
||||||
|
Tensor<OutDataType> out_n_c_do_ho_wo_host(f_host_tensor_descriptor(N, C, Do, Ho, Wo));
|
||||||
|
Tensor<IndexDataType> out_indices_n_c_do_ho_wo_host(f_host_tensor_descriptor(N, C, Do, Ho, Wo));
|
||||||
|
|
||||||
|
Tensor<OutDataType> out_n_c_do_ho_wo_device(f_host_tensor_descriptor(N, C, Do, Ho, Wo));
|
||||||
|
Tensor<IndexDataType> out_indices_n_c_do_ho_wo_device(
|
||||||
|
f_host_tensor_descriptor(N, C, Do, Ho, Wo));
|
||||||
|
|
||||||
|
switch(init_method)
|
||||||
|
{
|
||||||
|
case 0: in_n_c_di_hi_wi.GenerateTensorValue(GeneratorTensor_1<InDataType>{}); break;
|
||||||
|
case 1: in_n_c_di_hi_wi.GenerateTensorValue(GeneratorTensor_2<InDataType>{-5, 5}); break;
|
||||||
|
default: in_n_c_di_hi_wi.GenerateTensorValue(GeneratorTensor_3<InDataType>{-0.5, 0.5});
|
||||||
|
}
|
||||||
|
|
||||||
|
DeviceMem in_device_buf(sizeof(InDataType) * in_n_c_di_hi_wi.mDesc.GetElementSpaceSize());
|
||||||
|
DeviceMem out_device_buf(sizeof(OutDataType) *
|
||||||
|
out_n_c_do_ho_wo_device.mDesc.GetElementSpaceSize());
|
||||||
|
DeviceMem out_indices_device_buf(sizeof(IndexDataType) *
|
||||||
|
out_indices_n_c_do_ho_wo_device.mDesc.GetElementSpaceSize());
|
||||||
|
|
||||||
|
in_device_buf.ToDevice(in_n_c_di_hi_wi.mData.data());
|
||||||
|
|
||||||
|
// add device normalization instances
|
||||||
|
using DeviceOp = ck::tensor_operation::device::DevicePoolFwd<InOutRank,
|
||||||
|
WindowRank,
|
||||||
|
InDataType,
|
||||||
|
OutDataType,
|
||||||
|
IndexDataType,
|
||||||
|
ReduceOpId,
|
||||||
|
OutputIndex>;
|
||||||
|
|
||||||
|
// get device op instances
|
||||||
|
const auto instance_ptrs =
|
||||||
|
ck::tensor_operation::device::instance::DeviceOperationInstanceFactory<
|
||||||
|
DeviceOp>::GetInstances();
|
||||||
|
|
||||||
|
std::cout << "found " << instance_ptrs.size() << " instances" << std::endl;
|
||||||
|
|
||||||
|
std::string best_instance_name;
|
||||||
|
float best_avg_time = std::numeric_limits<float>::max();
|
||||||
|
float best_gb_per_sec = 0;
|
||||||
|
|
||||||
|
if(do_verification)
|
||||||
|
{
|
||||||
|
using ReferenceInstance = ck::tensor_operation::host::ReferencePoolingFwd<InOutRank,
|
||||||
|
WindowRank,
|
||||||
|
InDataType,
|
||||||
|
OutDataType,
|
||||||
|
ComputeDataType,
|
||||||
|
IndexDataType,
|
||||||
|
ReduceOpId,
|
||||||
|
PropagateNan,
|
||||||
|
OutputIndex>;
|
||||||
|
|
||||||
|
ReferenceInstance ref;
|
||||||
|
auto ref_argument = ref.MakeArgument(in_n_c_di_hi_wi,
|
||||||
|
out_n_c_do_ho_wo_host,
|
||||||
|
out_indices_n_c_do_ho_wo_host,
|
||||||
|
window_spatial_lengths,
|
||||||
|
window_strides,
|
||||||
|
input_left_pads,
|
||||||
|
input_right_pads);
|
||||||
|
auto ref_invoker = ref.MakeInvoker();
|
||||||
|
ref_invoker.Run(ref_argument);
|
||||||
|
}
|
||||||
|
|
||||||
|
int num_kernel = 0;
|
||||||
|
|
||||||
|
for(auto& inst_ptr : instance_ptrs)
|
||||||
|
{
|
||||||
|
auto argument_ptr = inst_ptr->MakeArgumentPointer(
|
||||||
|
static_cast<InDataType*>(in_device_buf.GetDeviceBuffer()),
|
||||||
|
static_cast<OutDataType*>(out_device_buf.GetDeviceBuffer()),
|
||||||
|
static_cast<IndexDataType*>(out_indices_device_buf.GetDeviceBuffer()),
|
||||||
|
in_length,
|
||||||
|
window_spatial_lengths,
|
||||||
|
out_length,
|
||||||
|
{Di * C * Hi * Wi, 1, C * Hi * Wi, Wi * 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,
|
||||||
|
input_left_pads,
|
||||||
|
input_right_pads,
|
||||||
|
{2, 3, 4});
|
||||||
|
|
||||||
|
if(inst_ptr->IsSupportedArgument(argument_ptr.get()))
|
||||||
|
{
|
||||||
|
++num_kernel;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(time_kernel)
|
||||||
|
{
|
||||||
|
std::cout << inst_ptr->GetTypeString() << " skipped due to unsupported argument: ";
|
||||||
|
LogRange(std::cout << "input lengths = ", in_length, ", ") << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto invoker_ptr = inst_ptr->MakeInvokerPointer();
|
||||||
|
|
||||||
|
float avg_time = invoker_ptr->Run(argument_ptr.get(), StreamConfig{nullptr, time_kernel});
|
||||||
|
|
||||||
|
std::size_t num_bytes = in_n_c_di_hi_wi.mDesc.GetElementSize() * sizeof(InDataType) +
|
||||||
|
out_n_c_do_ho_wo_host.mDesc.GetElementSize() * sizeof(OutDataType);
|
||||||
|
|
||||||
|
if constexpr(OutputIndex)
|
||||||
|
num_bytes +=
|
||||||
|
out_indices_n_c_do_ho_wo_host.mDesc.GetElementSize() * sizeof(IndexDataType);
|
||||||
|
|
||||||
|
float gb_per_sec = num_bytes / 1.E6 / avg_time;
|
||||||
|
|
||||||
|
if(time_kernel)
|
||||||
|
std::cout << "Perf: " << std::setw(10) << avg_time << " ms, " << gb_per_sec << " GB/s, "
|
||||||
|
<< inst_ptr->GetTypeString() << std::endl;
|
||||||
|
|
||||||
|
if(avg_time < best_avg_time)
|
||||||
|
{
|
||||||
|
best_instance_name = inst_ptr->GetTypeString();
|
||||||
|
best_avg_time = avg_time;
|
||||||
|
best_gb_per_sec = gb_per_sec;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(do_verification)
|
||||||
|
{
|
||||||
|
out_device_buf.FromDevice(out_n_c_do_ho_wo_device.mData.data());
|
||||||
|
|
||||||
|
bool pass = ck::utils::check_err(out_n_c_do_ho_wo_device.mData,
|
||||||
|
out_n_c_do_ho_wo_host.mData,
|
||||||
|
"Error: Incorrect results",
|
||||||
|
1e-3,
|
||||||
|
1e-3);
|
||||||
|
|
||||||
|
if constexpr(OutputIndex)
|
||||||
|
{
|
||||||
|
out_indices_device_buf.FromDevice(out_indices_n_c_do_ho_wo_device.mData.data());
|
||||||
|
|
||||||
|
pass = pass && ck::utils::check_err(out_indices_n_c_do_ho_wo_device,
|
||||||
|
out_indices_n_c_do_ho_wo_host);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(do_log)
|
||||||
|
{
|
||||||
|
LogRangeAsType<float>(
|
||||||
|
std::cout << "in_n_c_di_hi_wi : ", in_n_c_di_hi_wi.mData, ",")
|
||||||
|
<< std::endl;
|
||||||
|
LogRangeAsType<float>(
|
||||||
|
std::cout << "out_n_c_do_ho_wo_host : ", out_n_c_do_ho_wo_host.mData, ",")
|
||||||
|
<< std::endl;
|
||||||
|
LogRangeAsType<float>(
|
||||||
|
std::cout << "out_n_c_do_ho_wo_device : ", out_n_c_do_ho_wo_device.mData, ",")
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
|
if constexpr(OutputIndex)
|
||||||
|
LogRangeAsType<float>(std::cout << "out_indices_n_c_do_ho_wo_device : ",
|
||||||
|
out_indices_n_c_do_ho_wo_device.mData,
|
||||||
|
",")
|
||||||
|
<< std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!pass)
|
||||||
|
{
|
||||||
|
std::cout << inst_ptr->GetTypeString() << " failed verification: ";
|
||||||
|
LogRange(std::cout << "lengths = [", in_length, ", ") << "]." << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(time_kernel)
|
||||||
|
std::cout << "pass" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(time_kernel)
|
||||||
|
{
|
||||||
|
LogRange(std::cout << "length = ", in_length, ",") << std::endl;
|
||||||
|
std::cout << "best perf = " << best_avg_time << " ms, " << best_gb_per_sec << " GB/s, "
|
||||||
|
<< best_instance_name << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(num_kernel == 0)
|
||||||
|
{
|
||||||
|
std::cout << "Error: No kernel is applicable" << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace profiler
|
||||||
|
} // namespace ck
|
||||||
@@ -25,6 +25,8 @@ set(PROFILER_SOURCES
|
|||||||
profile_reduce.cpp
|
profile_reduce.cpp
|
||||||
profile_groupnorm.cpp
|
profile_groupnorm.cpp
|
||||||
profile_layernorm.cpp
|
profile_layernorm.cpp
|
||||||
|
profile_avg_pool2d_fwd.cpp
|
||||||
|
profile_max_pool3d_fwd.cpp
|
||||||
profile_softmax.cpp
|
profile_softmax.cpp
|
||||||
profile_batchnorm_fwd.cpp
|
profile_batchnorm_fwd.cpp
|
||||||
profile_batchnorm_bwd.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_grouped_gemm_fastgelu_instance)
|
||||||
target_link_libraries(${PROFILER_EXECUTABLE} PRIVATE device_contraction_bilinear_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_contraction_scale_instance)
|
||||||
|
target_link_libraries(${PROFILER_EXECUTABLE} PRIVATE device_pool_fwd_instance)
|
||||||
|
|
||||||
rocm_install(TARGETS ${PROFILER_EXECUTABLE} COMPONENT profiler)
|
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;
|
ck::DataTypeEnum data_type = ck::DataTypeEnum::Half;
|
||||||
bool do_verification = false;
|
bool do_verification = false;
|
||||||
int init_method = 0;
|
int init_method = 0;
|
||||||
bool do_log = 0;
|
bool do_log = false;
|
||||||
bool time_kernel = 1;
|
bool time_kernel = 1;
|
||||||
std::vector<index_t> length = {64, 16, 16, 32, 40};
|
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);
|
||||||
@@ -57,6 +57,7 @@ add_subdirectory(data_type)
|
|||||||
add_subdirectory(elementwise_normalization)
|
add_subdirectory(elementwise_normalization)
|
||||||
add_subdirectory(batchnorm)
|
add_subdirectory(batchnorm)
|
||||||
add_subdirectory(contraction)
|
add_subdirectory(contraction)
|
||||||
|
add_subdirectory(pool_fwd)
|
||||||
if(GPU_TARGETS MATCHES "gfx1100")
|
if(GPU_TARGETS MATCHES "gfx1100")
|
||||||
add_subdirectory(wmma_op)
|
add_subdirectory(wmma_op)
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
16
test/pool_fwd/CMakeLists.txt
Normal file
16
test/pool_fwd/CMakeLists.txt
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
add_custom_target(test_pool_fwd)
|
||||||
|
|
||||||
|
add_gtest_executable(test_avg_pool2d_fwd test_avg_pool2d_fwd.cpp)
|
||||||
|
add_gtest_executable(test_avg_pool3d_fwd test_avg_pool3d_fwd.cpp)
|
||||||
|
add_gtest_executable(test_max_pool2d_fwd test_max_pool2d_fwd.cpp)
|
||||||
|
add_gtest_executable(test_max_pool3d_fwd test_max_pool3d_fwd.cpp)
|
||||||
|
|
||||||
|
target_link_libraries(test_avg_pool2d_fwd PRIVATE utility device_pool_fwd_instance)
|
||||||
|
target_link_libraries(test_avg_pool3d_fwd PRIVATE utility device_pool_fwd_instance)
|
||||||
|
target_link_libraries(test_max_pool2d_fwd PRIVATE utility device_pool_fwd_instance)
|
||||||
|
target_link_libraries(test_max_pool3d_fwd PRIVATE utility device_pool_fwd_instance)
|
||||||
|
|
||||||
|
add_dependencies(test_pool_fwd test_avg_pool2d_fwd)
|
||||||
|
add_dependencies(test_pool_fwd test_avg_pool3d_fwd)
|
||||||
|
add_dependencies(test_pool_fwd test_max_pool2d_fwd)
|
||||||
|
add_dependencies(test_pool_fwd test_max_pool3d_fwd)
|
||||||
56
test/pool_fwd/test_avg_pool2d_fwd.cpp
Normal file
56
test/pool_fwd/test_avg_pool2d_fwd.cpp
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
|
||||||
|
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
#include "profiler/profile_pool2d_fwd_impl.hpp"
|
||||||
|
#include "test_pool_fwd_common.hpp"
|
||||||
|
|
||||||
|
template <typename Tuple>
|
||||||
|
class TestAvgPool2dFwd : public ::testing::Test
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
using InDataType = std::tuple_element_t<0, Tuple>;
|
||||||
|
using OutDataType = std::tuple_element_t<1, Tuple>;
|
||||||
|
using ComputeDataType = std::tuple_element_t<2, Tuple>;
|
||||||
|
using IndexDataType = std::tuple_element_t<3, Tuple>;
|
||||||
|
|
||||||
|
std::vector<PoolingParam> params;
|
||||||
|
|
||||||
|
void Run()
|
||||||
|
{
|
||||||
|
for(auto param : params)
|
||||||
|
{
|
||||||
|
bool success =
|
||||||
|
ck::profiler::profile_pool2d_fwd_impl<InDataType,
|
||||||
|
OutDataType,
|
||||||
|
ComputeDataType,
|
||||||
|
IndexDataType,
|
||||||
|
ck::ReduceTensorOp::AVG,
|
||||||
|
false,
|
||||||
|
false>(true,
|
||||||
|
2,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
param.length_,
|
||||||
|
param.window_spatial_lengths_,
|
||||||
|
param.window_strides_,
|
||||||
|
param.input_left_pads_,
|
||||||
|
param.input_right_pads_);
|
||||||
|
EXPECT_TRUE(success);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
using KernelTypes =
|
||||||
|
::testing::Types<std::tuple<F16, F16, F32, I32>, std::tuple<F32, F32, F32, I32>>;
|
||||||
|
|
||||||
|
TYPED_TEST_SUITE(TestAvgPool2dFwd, KernelTypes);
|
||||||
|
TYPED_TEST(TestAvgPool2dFwd, Test_Pool)
|
||||||
|
{
|
||||||
|
// length, window_length, window_stride, left_pad, right_pad
|
||||||
|
this->params = {{{1, 1, 1, 1}, {1, 1}, {1, 1}, {0, 0}, {0, 0}},
|
||||||
|
{{2, 16, 64, 64}, {64, 64}, {1, 1}, {0, 0}, {0, 0}},
|
||||||
|
{{2, 32, 30, 30}, {2, 2}, {2, 2}, {1, 1}, {1, 1}}};
|
||||||
|
|
||||||
|
this->Run();
|
||||||
|
}
|
||||||
56
test/pool_fwd/test_avg_pool3d_fwd.cpp
Normal file
56
test/pool_fwd/test_avg_pool3d_fwd.cpp
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
|
||||||
|
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
#include "profiler/profile_pool3d_fwd_impl.hpp"
|
||||||
|
#include "test_pool_fwd_common.hpp"
|
||||||
|
|
||||||
|
template <typename Tuple>
|
||||||
|
class TestAvgPool3dFwd : public ::testing::Test
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
using InDataType = std::tuple_element_t<0, Tuple>;
|
||||||
|
using OutDataType = std::tuple_element_t<1, Tuple>;
|
||||||
|
using ComputeDataType = std::tuple_element_t<2, Tuple>;
|
||||||
|
using IndexDataType = std::tuple_element_t<3, Tuple>;
|
||||||
|
|
||||||
|
std::vector<PoolingParam> params;
|
||||||
|
|
||||||
|
void Run()
|
||||||
|
{
|
||||||
|
for(auto param : params)
|
||||||
|
{
|
||||||
|
bool success =
|
||||||
|
ck::profiler::profile_pool3d_fwd_impl<InDataType,
|
||||||
|
OutDataType,
|
||||||
|
ComputeDataType,
|
||||||
|
IndexDataType,
|
||||||
|
ck::ReduceTensorOp::AVG,
|
||||||
|
false,
|
||||||
|
false>(true,
|
||||||
|
2,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
param.length_,
|
||||||
|
param.window_spatial_lengths_,
|
||||||
|
param.window_strides_,
|
||||||
|
param.input_left_pads_,
|
||||||
|
param.input_right_pads_);
|
||||||
|
EXPECT_TRUE(success);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
using KernelTypes =
|
||||||
|
::testing::Types<std::tuple<F16, F16, F32, I32>, std::tuple<F32, F32, F32, I32>>;
|
||||||
|
|
||||||
|
TYPED_TEST_SUITE(TestAvgPool3dFwd, KernelTypes);
|
||||||
|
TYPED_TEST(TestAvgPool3dFwd, Test_Pool)
|
||||||
|
{
|
||||||
|
// length, window_length, window_stride, left_pad, right_pad
|
||||||
|
this->params = {{{1, 1, 1, 1, 1}, {1, 1, 1}, {1, 1, 1}, {0, 0, 0}, {0, 0, 0}},
|
||||||
|
{{2, 16, 64, 64, 64}, {64, 64, 64}, {1, 1, 1}, {0, 0, 0}, {0, 0, 0}},
|
||||||
|
{{2, 32, 30, 30, 30}, {2, 2, 2}, {2, 2, 2}, {1, 1, 1}, {1, 1, 1}}};
|
||||||
|
|
||||||
|
this->Run();
|
||||||
|
}
|
||||||
75
test/pool_fwd/test_max_pool2d_fwd.cpp
Normal file
75
test/pool_fwd/test_max_pool2d_fwd.cpp
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
|
||||||
|
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
#include "profiler/profile_pool2d_fwd_impl.hpp"
|
||||||
|
#include "test_pool_fwd_common.hpp"
|
||||||
|
|
||||||
|
template <typename Tuple>
|
||||||
|
class TestMaxPool2dFwd : public ::testing::Test
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
using InDataType = std::tuple_element_t<0, Tuple>;
|
||||||
|
using OutDataType = std::tuple_element_t<1, Tuple>;
|
||||||
|
using ComputeDataType = std::tuple_element_t<2, Tuple>;
|
||||||
|
using IndexDataType = std::tuple_element_t<3, Tuple>;
|
||||||
|
|
||||||
|
std::vector<PoolingParam> params;
|
||||||
|
|
||||||
|
void Run()
|
||||||
|
{
|
||||||
|
for(auto param : params)
|
||||||
|
{
|
||||||
|
// max pool
|
||||||
|
bool success =
|
||||||
|
ck::profiler::profile_pool2d_fwd_impl<InDataType,
|
||||||
|
OutDataType,
|
||||||
|
ComputeDataType,
|
||||||
|
IndexDataType,
|
||||||
|
ck::ReduceTensorOp::MAX,
|
||||||
|
false,
|
||||||
|
false>(true,
|
||||||
|
2,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
param.length_,
|
||||||
|
param.window_spatial_lengths_,
|
||||||
|
param.window_strides_,
|
||||||
|
param.input_left_pads_,
|
||||||
|
param.input_right_pads_);
|
||||||
|
EXPECT_TRUE(success);
|
||||||
|
|
||||||
|
// max pool + index
|
||||||
|
success = ck::profiler::profile_pool2d_fwd_impl<InDataType,
|
||||||
|
OutDataType,
|
||||||
|
ComputeDataType,
|
||||||
|
IndexDataType,
|
||||||
|
ck::ReduceTensorOp::MAX,
|
||||||
|
false,
|
||||||
|
true>(true,
|
||||||
|
2,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
param.length_,
|
||||||
|
param.window_spatial_lengths_,
|
||||||
|
param.window_strides_,
|
||||||
|
param.input_left_pads_,
|
||||||
|
param.input_right_pads_);
|
||||||
|
EXPECT_TRUE(success);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
using KernelTypes =
|
||||||
|
::testing::Types<std::tuple<F16, F16, F16, I32>, std::tuple<F32, F32, F32, I32>>;
|
||||||
|
|
||||||
|
TYPED_TEST_SUITE(TestMaxPool2dFwd, KernelTypes);
|
||||||
|
TYPED_TEST(TestMaxPool2dFwd, Test_Pool)
|
||||||
|
{
|
||||||
|
// length, window_length, window_stride, left_pad, right_pad
|
||||||
|
this->params = {{{1, 1, 1, 1}, {1, 1}, {1, 1}, {0, 0}, {0, 0}},
|
||||||
|
{{2, 16, 64, 64}, {64, 64}, {1, 1}, {0, 0}, {0, 0}},
|
||||||
|
{{2, 32, 30, 30}, {2, 2}, {2, 2}, {1, 1}, {1, 1}}};
|
||||||
|
|
||||||
|
this->Run();
|
||||||
|
}
|
||||||
75
test/pool_fwd/test_max_pool3d_fwd.cpp
Normal file
75
test/pool_fwd/test_max_pool3d_fwd.cpp
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
|
||||||
|
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
#include "profiler/profile_pool3d_fwd_impl.hpp"
|
||||||
|
#include "test_pool_fwd_common.hpp"
|
||||||
|
|
||||||
|
template <typename Tuple>
|
||||||
|
class TestMaxPool3dFwd : public ::testing::Test
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
using InDataType = std::tuple_element_t<0, Tuple>;
|
||||||
|
using OutDataType = std::tuple_element_t<1, Tuple>;
|
||||||
|
using ComputeDataType = std::tuple_element_t<2, Tuple>;
|
||||||
|
using IndexDataType = std::tuple_element_t<3, Tuple>;
|
||||||
|
|
||||||
|
std::vector<PoolingParam> params;
|
||||||
|
|
||||||
|
void Run()
|
||||||
|
{
|
||||||
|
for(auto param : params)
|
||||||
|
{
|
||||||
|
// max pool
|
||||||
|
bool success =
|
||||||
|
ck::profiler::profile_pool3d_fwd_impl<InDataType,
|
||||||
|
OutDataType,
|
||||||
|
ComputeDataType,
|
||||||
|
IndexDataType,
|
||||||
|
ck::ReduceTensorOp::MAX,
|
||||||
|
false,
|
||||||
|
false>(true,
|
||||||
|
2,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
param.length_,
|
||||||
|
param.window_spatial_lengths_,
|
||||||
|
param.window_strides_,
|
||||||
|
param.input_left_pads_,
|
||||||
|
param.input_right_pads_);
|
||||||
|
EXPECT_TRUE(success);
|
||||||
|
|
||||||
|
// max pool + index
|
||||||
|
success = ck::profiler::profile_pool3d_fwd_impl<InDataType,
|
||||||
|
OutDataType,
|
||||||
|
ComputeDataType,
|
||||||
|
IndexDataType,
|
||||||
|
ck::ReduceTensorOp::MAX,
|
||||||
|
false,
|
||||||
|
true>(true,
|
||||||
|
2,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
param.length_,
|
||||||
|
param.window_spatial_lengths_,
|
||||||
|
param.window_strides_,
|
||||||
|
param.input_left_pads_,
|
||||||
|
param.input_right_pads_);
|
||||||
|
EXPECT_TRUE(success);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
using KernelTypes =
|
||||||
|
::testing::Types<std::tuple<F16, F16, F16, I32>, std::tuple<F32, F32, F32, I32>>;
|
||||||
|
|
||||||
|
TYPED_TEST_SUITE(TestMaxPool3dFwd, KernelTypes);
|
||||||
|
TYPED_TEST(TestMaxPool3dFwd, Test_Pool)
|
||||||
|
{
|
||||||
|
// length, window_length, window_stride, left_pad, right_pad
|
||||||
|
this->params = {{{1, 1, 1, 1, 1}, {1, 1, 1}, {1, 1, 1}, {0, 0, 0}, {0, 0, 0}},
|
||||||
|
{{2, 16, 64, 64, 64}, {64, 64, 64}, {1, 1, 1}, {0, 0, 0}, {0, 0, 0}},
|
||||||
|
{{2, 32, 30, 30, 30}, {2, 2, 2}, {2, 2, 2}, {1, 1, 1}, {1, 1, 1}}};
|
||||||
|
|
||||||
|
this->Run();
|
||||||
|
}
|
||||||
31
test/pool_fwd/test_pool_fwd_common.hpp
Normal file
31
test/pool_fwd/test_pool_fwd_common.hpp
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
|
||||||
|
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
#include "ck/ck.hpp"
|
||||||
|
|
||||||
|
using F16 = ck::half_t;
|
||||||
|
using F32 = float;
|
||||||
|
using I32 = int32_t;
|
||||||
|
using ck::index_t;
|
||||||
|
|
||||||
|
struct PoolingParam
|
||||||
|
{
|
||||||
|
PoolingParam(const std::vector<index_t>& length,
|
||||||
|
const std::vector<index_t>& window_spatial_lengths,
|
||||||
|
const std::vector<index_t>& window_strides,
|
||||||
|
const std::vector<index_t>& input_left_pads,
|
||||||
|
const std::vector<index_t>& input_right_pads)
|
||||||
|
: length_(length),
|
||||||
|
window_spatial_lengths_(window_spatial_lengths),
|
||||||
|
window_strides_(window_strides),
|
||||||
|
input_left_pads_(input_left_pads),
|
||||||
|
input_right_pads_(input_right_pads)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
std::vector<index_t> length_;
|
||||||
|
std::vector<index_t> window_spatial_lengths_;
|
||||||
|
std::vector<index_t> window_strides_;
|
||||||
|
std::vector<index_t> input_left_pads_;
|
||||||
|
std::vector<index_t> input_right_pads_;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user