27 #ifndef RESHAPE_HPP_INCLUDED 28 #define RESHAPE_HPP_INCLUDED 41 template <
typename TensorDataType, data_layout T_layout, El::Device Dev>
55 template <
typename ArchiveT>
60 std::string
get_type()
const override {
return "reshape"; }
81 int unspecified_dim = -1;
82 for (
size_t dim = 0; dim < output_dims.size(); ++dim) {
83 if (output_dims[dim] <= 0) {
84 if (unspecified_dim < 0) {
85 unspecified_dim = dim;
90 if (unspecified_dim >= 0) {
92 output_dims[unspecified_dim] = this->
get_input_size() / specified_size;
98 std::stringstream err;
99 err <<
"input tensor dimensions (";
100 for (
size_t i = 0; i < input_dims.size(); ++i) {
101 err << (i > 0 ?
" x " :
"") << input_dims[i];
103 err <<
") do not match output tensor dimensions (";
104 for (
size_t i = 0; i < output_dims.size(); ++i) {
105 err << (i > 0 ?
"x" :
"") << output_dims[i];
108 err <<
" in " << this->
get_type() <<
" layer " 109 <<
"\"" << this->
get_name() <<
"\"";
126 #ifndef LBANN_RESHAPE_LAYER_INSTANTIATE 127 #define PROTO_DEVICE(T, Device) \ 128 extern template class reshape_layer<T, data_layout::DATA_PARALLEL, Device>; \ 129 extern template class reshape_layer<T, data_layout::MODEL_PARALLEL, Device> 133 #endif // LBANN_RESHAPE_LAYER_INSTANTIATE 137 #endif // RESHAPE_HPP_INCLUDED virtual void setup_dims()
Setup tensor dimensions Called by the 'setup' function. If there are any input tensors, the base method sets all uninitialized output tensor dimensions equal to the first input tensor dimensions.
void setup_dims() override
Setup tensor dimensions Called by the 'setup' function. If there are any input tensors, the base method sets all uninitialized output tensor dimensions equal to the first input tensor dimensions.
friend class cereal::access
auto get_linear_size(std::vector< T > const &dims)
int get_output_size(size_t output_index=0) const
Get output tensor size.
void fp_setup_outputs() override
Setup output tensors. Called by the 'forward_prop' function. Each output tensor is resized to match t...
std::vector< int > get_input_dims(size_t input_index=0) const
Get input tensor dimensions.
int get_backprop_requirements() const override
Returns the necessary tensors for computing backpropagation.
constexpr El::Device Device
OutputAbsDistMatrixType & get_prev_error_signals(int child_index=0)
InputAbsDistMatrixType & get_prev_activations(int parent_index=0)
reshape_layer * copy() const override
Copy function. This function dynamically allocates memory for a layer instance and instantiates a cop...
void fp_compute() override
Apply layer operation. Called by the 'forward_prop' function. Given the input tensors, the output tensors are populated with computed values.
const OutputAbsDistMatrixType & get_activations(const Layer &child) const override
int get_input_size(size_t input_index=0) const
Get input tensor size.
void set_output_dims(std::vector< int > dims, size_t output_index=0)
Set output tensor dimensions.
void serialize(ArchiveT &ar)
data_layout get_data_layout() const override
Get data layout of the data tensors. We assume that the data layouts of the previous activations...
El::Device get_device_allocation() const override
Get the device allocation for the data tensors. We assume that the decice allocation of the previous ...
std::string get_name() const
Get the layer instance's name.
void bp_compute() override
Compute objective funciton gradients. Called by the 'back_prop' function. Given the input...
void write_specific_proto(lbann_data::Layer &proto) const final
data_layout
Data layout that is optimized for different modes of parallelism.
Reinterpret tensor with new dimensions.
void bp_setup_gradient_wrt_inputs() override
Setup gradient w.r.t. input tensors. Called by the 'back_prop' function. Each gradient w...
bool can_run_inplace() const override
If True, the computation can run in-place (feeding each input activations tensor as the corresponding...
std::string get_type() const override
Get the layer type's name.
reshape_layer(lbann_comm *comm, std::vector< int > dims)
std::vector< int > get_output_dims(size_t output_index=0) const
Get output tensor dimensions.
const InputAbsDistMatrixType & get_error_signals(const Layer &parent) const override