Some name changes in im2col code

pull/330/head
Cedric Nugteren 2018-10-22 22:12:58 +02:00
parent ab0178c56b
commit 44b630fc22
4 changed files with 22 additions and 21 deletions

View File

View File

@ -41,23 +41,23 @@ void Xim2col<T>::DoIm2col(const size_t channels, const size_t height, const size
// Makes sure all dimensions are larger than zero
if ((channels == 0) || (height == 0) || (width == 0)) { throw BLASError(StatusCode::kInvalidDimension); }
// Sets the output height and width
// Sets the height and width of the 'col' result
const auto size_h = height + 2 * pad_h;
const auto padding_h = dilation_h * (kernel_h - 1) + 1;
const auto output_h = (size_h >= padding_h) ? (size_h - padding_h) / stride_h + 1 : 1;
const auto col_h = (size_h >= padding_h) ? (size_h - padding_h) / stride_h + 1 : 1;
const auto size_w = width + 2 * pad_w;
const auto padding_w = dilation_w * (kernel_w - 1) + 1;
const auto output_w = (size_w >= padding_w) ? (size_w - padding_w) / stride_w + 1 : 1;
const auto col_w = (size_w >= padding_w) ? (size_w - padding_w) / stride_w + 1 : 1;
// Retrieves the Xcopy kernel from the compiled binary
// Retrieves the kernel from the compiled binary
auto kernel = Kernel(program_, "im2col");
// Sets the kernel arguments
kernel.SetArgument(0, static_cast<int>(height));
kernel.SetArgument(1, static_cast<int>(width));
kernel.SetArgument(2, static_cast<int>(channels));
kernel.SetArgument(3, static_cast<int>(output_h));
kernel.SetArgument(4, static_cast<int>(output_w));
kernel.SetArgument(3, static_cast<int>(col_h));
kernel.SetArgument(4, static_cast<int>(col_w));
kernel.SetArgument(5, static_cast<int>(kernel_h));
kernel.SetArgument(6, static_cast<int>(kernel_w));
kernel.SetArgument(7, static_cast<int>(pad_h));
@ -72,8 +72,8 @@ void Xim2col<T>::DoIm2col(const size_t channels, const size_t height, const size
kernel.SetArgument(16, static_cast<int>(col_offset));
// Launches the kernel
const auto w_ceiled = Ceil(output_w, db_["COPY_DIMX"]);
const auto h_ceiled = Ceil(output_h, db_["COPY_DIMY"]);
const auto w_ceiled = Ceil(col_w, db_["COPY_DIMX"]);
const auto h_ceiled = Ceil(col_h, db_["COPY_DIMY"]);
const auto global = std::vector<size_t>{w_ceiled, h_ceiled * channels};
const auto local = std::vector<size_t>{db_["COPY_DIMX"], db_["COPY_DIMY"]};
RunKernel(kernel, queue_, device_, global, local, event_);

View File

@ -8,6 +8,7 @@
// Cedric Nugteren <www.cedricnugteren.nl>
//
// This file implements the Xim2col routine. The precision is implemented using a template argument.
// Uses the tuning parameters from the regular copy kernel.
//
// =================================================================================================

View File

@ -39,20 +39,20 @@ public:
static std::vector<std::string> BuffersOut() { return {kBufMatB}; }
// Describes how to obtain the sizes of the buffers
static size_t OutputHeight(const Arguments<T> &args) {
static size_t ColHeight(const Arguments<T> &args) {
const auto size = args.height + 2 * args.pad_h;
const auto padding = args.dilation_h * (args.kernel_h - 1) + 1;
if (size >= padding) { return (size - padding) / args.stride_h + 1; }
return 1;
}
static size_t OutputWidth(const Arguments<T> &args) {
static size_t ColWidth(const Arguments<T> &args) {
const auto size = args.width + 2 * args.pad_w;
const auto padding = args.dilation_w * (args.kernel_w - 1) + 1;
if (size >= padding) { return (size - padding) / args.stride_w + 1; }
return 1;
}
static size_t NumPatches(const Arguments<T> &args) {
return OutputHeight(args) * OutputWidth(args) * args.channels;
return ColHeight(args) * ColWidth(args) * args.channels;
}
static size_t GetSizeA(const Arguments<T> &args) {
return args.height * args.width * args.channels + args.a_offset;
@ -156,13 +156,13 @@ public:
template <typename T>
StatusCode RunReference(const Arguments<T> &args, BuffersHost<T> &buffers_host) {
const auto output_h = TestXim2col<T>::OutputHeight(args);
const auto output_w = TestXim2col<T>::OutputWidth(args);
const auto col_h = TestXim2col<T>::ColHeight(args);
const auto col_w = TestXim2col<T>::ColWidth(args);
for (auto c_id = size_t{0}; c_id < args.channels; ++c_id) { // input channels
for (auto kh_id = size_t{0}; kh_id < args.kernel_h; ++kh_id) { // kernel height
for (auto kw_id = size_t{0}; kw_id < args.kernel_w; ++kw_id) { // kernel width
for (auto h_id = size_t{0}; h_id < output_h; ++h_id) { // image height
for (auto w_id = size_t{0}; w_id < output_w; ++w_id) { // image width
for (auto h_id = size_t{0}; h_id < col_h; ++h_id) { // image height
for (auto w_id = size_t{0}; w_id < col_w; ++w_id) { // image width
// Retrieves the input value
const auto h_index = kh_id * args.dilation_h + args.stride_h * h_id - args.pad_h;
@ -170,16 +170,16 @@ StatusCode RunReference(const Arguments<T> &args, BuffersHost<T> &buffers_host)
auto val = ConstantZero<T>();
if (h_index >= 0 && h_index < args.height &&
w_index >= 0 && w_index < args.width) {
const auto input_index = w_index + args.width * (h_index + args.height * c_id);
val = buffers_host.a_mat[input_index + args.a_offset];
const auto im_index = w_index + args.width * (h_index + args.height * c_id);
val = buffers_host.a_mat[im_index + args.a_offset];
}
// Sets the output value
const auto kernel_index = kw_id + args.kernel_w * kh_id;
const auto patch_index = w_id + output_w * h_id;
const auto output_index = patch_index + kernel_index * output_w * output_h +
c_id * output_w * output_h * args.kernel_h * args.kernel_w;
buffers_host.b_mat[output_index + args.b_offset] = val;
const auto patch_index = w_id + col_w * h_id;
const auto col_index = patch_index + kernel_index * col_w * col_h +
c_id * col_w * col_h * args.kernel_h * args.kernel_w;
buffers_host.b_mat[col_index + args.b_offset] = val;
}
}
}