27 #ifndef LBANN_LAYERS_TRANSFORM_TESSELLATE_HPP_INCLUDED 28 #define LBANN_LAYERS_TRANSFORM_TESSELLATE_HPP_INCLUDED 33 #include "lbann/proto/layers.pb.h" 58 template <
typename TensorDataType,
101 template <
typename ArchiveT>
106 std::string
get_type()
const override {
return "tessellate"; }
115 std::stringstream err;
120 if (input_dims.size() != output_dims.size()) {
122 <<
"attempted to tessellate a ";
123 for (
size_t i = 0; i < input_dims.size(); ++i) {
124 err << (i > 0 ?
"x" :
"") << input_dims[i];
126 err <<
" tensor into a ";
127 for (
size_t i = 0; i < output_dims.size(); ++i) {
128 err << (i > 0 ?
"x" :
"") << output_dims[i];
135 if (input_dims.size() > 3) {
137 <<
"attempted to tessellate a ";
138 for (
size_t i = 0; i < input_dims.size(); ++i) {
139 err << (i > 0 ?
"x" :
"") << input_dims[i];
141 err <<
" tensor, but tessellation is currently only supported " 142 <<
"with 3 dimensions or less";
150 dist_data.colDist = El::STAR;
151 m_input_v.reset(AbsDistMatrixType::Instantiate(dist_data));
167 while (input_dims.size() < 3) {
168 input_dims.insert(input_dims.begin(), 1);
170 while (output_dims.size() < 3) {
171 output_dims.insert(output_dims.begin(), 1);
179 if (
m_input_v->DistData() == input.DistData()) {
185 const auto& local_input =
m_input_v->LockedMatrix();
189 if (input_dims.size() > 3) {
190 LBANN_ERROR(
"tessellate layer currently only supports 3D tensors");
201 while (input_dims.size() < 3) {
202 input_dims.insert(input_dims.begin(), 1);
204 while (output_dims.size() < 3) {
205 output_dims.insert(output_dims.begin(), 1);
212 m_input_v->AlignWith(gradient_wrt_output);
213 if (
m_input_v->DistData() == gradient_wrt_input.DistData()) {
214 El::View(*
m_input_v, gradient_wrt_input);
217 m_input_v->Resize(gradient_wrt_input.Height(),
218 gradient_wrt_input.Width());
220 auto& local_gradient_wrt_input =
m_input_v->Matrix();
227 local_gradient_wrt_input);
230 if (
m_input_v->DistData() != gradient_wrt_input.DistData()) {
232 El::Copy(*
m_input_v, gradient_wrt_input);
246 const std::vector<int>& output_dims,
254 const std::vector<int>& output_dims,
259 template <
typename T, data_layout L, El::Device D>
261 lbann_data::Layer& proto)
const 263 proto.set_datatype(proto::ProtoDataType<T>);
264 auto* msg = proto.mutable_tessellate();
268 #ifndef LBANN_TESSELLATE_LAYER_INSTANTIATE 269 #define PROTO_DEVICE(T, Device) \ 270 extern template class tessellate_layer<T, \ 271 data_layout::DATA_PARALLEL, \ 273 extern template class tessellate_layer<T, data_layout::MODEL_PARALLEL, Device> 277 #endif // LBANN_TESSELLATE_LAYER_INSTANTIATE 281 #endif // LBANN_LAYERS_TRANSFORM_TESSELLATE_HPP_INCLUDED tessellate_layer * copy() const override
Copy function. This function dynamically allocates memory for a layer instance and instantiates a cop...
void serialize(ArchiveT &ar)
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_data(size_t max_mini_batch_size) override
Setup layer data. Called by the 'setup' function. Memory is allocated for distributed matrices...
tessellate_layer & operator=(const tessellate_layer &other)
void write_specific_proto(lbann_data::Layer &proto) const final
El::AbstractDistMatrix< TensorDataType > AbsDistMatrixType
The tensor type expected in this object.
Repeat a tensor until it matches specified dimensions.
lbann_comm * get_comm() const
std::string get_type() const override
Get the layer type's name.
void bp_compute_3d(const std::vector< int > &input_dims, const std::vector< int > &output_dims, const AbsDistMatrixType &gradient_wrt_output, AbsMatrixType &gradient_wrt_input)
std::unique_ptr< AbsDistMatrixType > m_input_v
El::AbstractMatrix< TensorDataType > AbsMatrixType
The local tensor type expected in this object.
std::vector< int > get_input_dims(size_t input_index=0) const
Get input tensor dimensions.
El::Device get_device_allocation() const override
Get the device allocation for the data tensors. We assume that the decice allocation of the previous ...
constexpr El::Device Device
OutputAbsDistMatrixType & get_prev_error_signals(int child_index=0)
InputAbsDistMatrixType & get_prev_activations(int parent_index=0)
const OutputAbsDistMatrixType & get_activations(const Layer &child) const override
bool can_run_inplace() const override
If True, the computation can run in-place (feeding each input activations tensor as the corresponding...
void set_output_dims(std::vector< int > dims, size_t output_index=0)
Set output tensor dimensions.
void assign_to_repeated(google::protobuf::RepeatedField< T > &field, ContainerT const &values)
Assign a range of values to a repeated protobuf field.
tessellate_layer(lbann_comm *comm, std::vector< int > dims={})
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
int get_backprop_requirements() const override
Returns the necessary tensors for computing backpropagation.
tessellate_layer(const tessellate_layer &other)
T allreduce(T snd, const El::mpi::Comm &c, El::mpi::Op op=El::mpi::SUM) const
std::string get_name() const
Get the layer instance's name.
data_layout get_data_layout() const override
Get data layout of the data tensors. We assume that the data layouts of the previous activations...
data_layout
Data layout that is optimized for different modes of parallelism.
void fp_compute_3d(const std::vector< int > &input_dims, const std::vector< int > &output_dims, const AbsMatrixType &input, AbsDistMatrixType &output)
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.
void setup_data(size_t max_mini_batch_size) override
void bp_compute() override
Compute objective funciton gradients. Called by the 'back_prop' function. Given the input...
std::vector< int > get_output_dims(size_t output_index=0) const
Get output tensor dimensions.
data_type_layer & operator=(data_type_layer &&other)=default
const InputAbsDistMatrixType & get_error_signals(const Layer &parent) const override