LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
im2col.hpp
Go to the documentation of this file.
1 // Copyright (c) 2014-2023, Lawrence Livermore National Security, LLC.
3 // Produced at the Lawrence Livermore National Laboratory.
4 // Written by the LBANN Research Team (B. Van Essen, et al.) listed in
5 // the CONTRIBUTORS file. <lbann-dev@llnl.gov>
6 //
7 // LLNL-CODE-697807.
8 // All rights reserved.
9 //
10 // This file is part of LBANN: Livermore Big Artificial Neural Network
11 // Toolkit. For details, see http://software.llnl.gov/LBANN or
12 // https://github.com/LLNL/LBANN.
13 //
14 // Licensed under the Apache License, Version 2.0 (the "Licensee"); you
15 // may not use this file except in compliance with the License. You may
16 // obtain a copy of the License at:
17 //
18 // http://www.apache.org/licenses/LICENSE-2.0
19 //
20 // Unless required by applicable law or agreed to in writing, software
21 // distributed under the License is distributed on an "AS IS" BASIS,
22 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
23 // implied. See the License for the specific language governing
24 // permissions and limitations under the license.
26 
27 #ifndef LBANN_UTILS_IM2COL_HPP
28 #define LBANN_UTILS_IM2COL_HPP
29 
30 #include "lbann/base.hpp"
31 
32 namespace lbann {
33 
35 
49 template <typename TensorDataType>
50 void im2col(const CPUMatDT<TensorDataType>& im,
51  CPUMatDT<TensorDataType>& col,
52  int num_channels,
53  int im_num_dims,
54  const int* im_dims,
55  const int* im_pads,
56  const int* window_dims,
57  const int* window_strides);
58 
59 #ifdef LBANN_HAS_GPU
60 template <typename TensorDataType>
61 void im2col(const El::Matrix<TensorDataType, El::Device::GPU>& im,
62  El::Matrix<TensorDataType, El::Device::GPU>& col,
63  const int num_channels,
64  const int im_num_dims,
65  const int* im_dims,
66  const int* im_pads,
67  const int* window_dims,
68  const int* window_strides,
69  const El::SyncInfo<El::Device::GPU>& sync_info);
70 #endif // LBANN_HAS_GPU
71 
74 std::pair<size_t, size_t> get_im2col_output_size(const int num_samples,
75  const int num_channels,
76  const int im_num_dims,
77  const int* im_dims,
78  const int* im_pads,
79  const int* window_dims,
80  const int* window_strides);
81 
83 
98 template <typename TensorDataType>
99 void col2im(const CPUMatDT<TensorDataType>& col,
100  CPUMatDT<TensorDataType>& im,
101  int num_channels,
102  int im_num_dims,
103  const int* im_dims,
104  const int* im_pads,
105  const int* window_dims,
106  const int* window_strides);
107 
109 
125 template <typename TensorDataType>
126 void col2im(const CPUMatDT<TensorDataType>& col,
127  CPUMatDT<TensorDataType>& im,
128  int num_channels,
129  int im_num_dims,
130  const int* im_dims,
131  const int* im_pads,
132  const int* window_dims,
133  const int* window_strides,
134  std::function<TensorDataType(const TensorDataType&,
135  const TensorDataType&)> reduction_op);
136 
138 
143 template <typename TensorDataType>
144 void im2col_1x1(const TensorDataType* input_buffer,
145  TensorDataType* output_buffer,
146  int num_channels,
147  int num_input_dims,
148  const int* input_dims);
149 
151 
154 template <typename TensorDataType>
155 void im2col_2d(const TensorDataType* __restrict__ input_buffer,
156  TensorDataType* __restrict__ output_buffer,
157  int input_dim_x,
158  int input_dim_y,
159  int input_pad_x,
160  int input_pad_y,
161  int num_channels,
162  int window_dim_x,
163  int window_dim_y,
164  int offset_stride_x,
165  int offset_stride_y);
166 
168 
173 template <typename TensorDataType>
174 void col2im_1x1(const TensorDataType* input_buffer,
175  TensorDataType* output_buffer,
176  const int num_channels,
177  const int num_output_dims,
178  const int* output_dims);
179 
181 
184 template <typename TensorDataType>
185 void col2im_2d(const TensorDataType* __restrict__ input_buffer,
186  TensorDataType* __restrict__ output_buffer,
187  int output_dim_x,
188  int output_dim_y,
189  int output_pad_x,
190  int output_pad_y,
191  int num_channels,
192  int window_dim_x,
193  int window_dim_y,
194  int offset_stride_x,
195  int offset_stride_y);
196 
197 } // namespace lbann
198 
199 #endif // LBANN_UTILS_IM2COL_HPP
void col2im(const CPUMatDT< TensorDataType > &col, CPUMatDT< TensorDataType > &im, int num_channels, int im_num_dims, const int *im_dims, const int *im_pads, const int *window_dims, const int *window_strides)
Rearrange matrix columns into image blocks.
void col2im_2d(const TensorDataType *__restrict__ input_buffer, TensorDataType *__restrict__ output_buffer, int output_dim_x, int output_dim_y, int output_pad_x, int output_pad_y, int num_channels, int window_dim_x, int window_dim_y, int offset_stride_x, int offset_stride_y)
Rearrange matrix columns into 2D image blocks.
void im2col_1x1(const TensorDataType *input_buffer, TensorDataType *output_buffer, int num_channels, int num_input_dims, const int *input_dims)
Rearrange 1x1 image blocks into matrix columns.
void im2col(const CPUMatDT< TensorDataType > &im, CPUMatDT< TensorDataType > &col, int num_channels, int im_num_dims, const int *im_dims, const int *im_pads, const int *window_dims, const int *window_strides)
Rearrange image blocks into matrix columns.
std::pair< size_t, size_t > get_im2col_output_size(const int num_samples, const int num_channels, const int im_num_dims, const int *im_dims, const int *im_pads, const int *window_dims, const int *window_strides)
void col2im_1x1(const TensorDataType *input_buffer, TensorDataType *output_buffer, const int num_channels, const int num_output_dims, const int *output_dims)
Rearrange matrix columns into 1x1 image blocks.
void im2col_2d(const TensorDataType *__restrict__ input_buffer, TensorDataType *__restrict__ output_buffer, int input_dim_x, int input_dim_y, int input_pad_x, int input_pad_y, int num_channels, int window_dim_x, int window_dim_y, int offset_stride_x, int offset_stride_y)
Rearrange 2D image blocks into matrix columns.