26 #ifndef LBANN_LAYERS_OPERATOR_LAYER_IMPL_HPP_INCLUDED 27 #define LBANN_LAYERS_OPERATOR_LAYER_IMPL_HPP_INCLUDED 37 #include "lbann/proto/layers.pb.h" 38 #include <cereal/types/base_class.hpp> 43 template <
typename InputT,
typename OutputT, data_layout Layout, El::Device D>
50 m_ops.emplace_back(std::move(op));
54 template <
typename InputT,
typename OutputT, data_layout Layout, El::Device D>
57 std::vector<OperatorPtr> operators)
65 template <
typename InputT,
typename OutputT, data_layout Layout, El::Device D>
71 template <
typename InputT,
typename OutputT, data_layout Layout, El::Device D>
81 template <
typename InputT,
typename OutputT, data_layout Layout, El::Device D>
87 template <
typename InputT,
typename OutputT, data_layout Layout, El::Device D>
93 template <
typename InputT,
typename OutputT, data_layout Layout, El::Device D>
99 template <
typename InputT,
typename OutputT, data_layout Layout, El::Device D>
106 template <
typename InputT,
typename OutputT, data_layout Layout, El::Device D>
112 template <
typename InputT,
typename OutputT, data_layout Layout, El::Device D>
117 for (
const auto& op :
m_ops) {
118 result |= op->get_backprop_requirements();
123 template <
typename InputT,
typename OutputT, data_layout Layout, El::Device D>
129 template <
typename InputT,
typename OutputT, data_layout Layout, El::Device D>
137 template <
typename InputT,
typename OutputT, data_layout Layout, El::Device D>
141 for (
auto const& op :
m_ops)
142 desc.add(op->get_description());
146 template <
typename InputT,
typename OutputT, data_layout Layout, El::Device D>
147 template <
typename ArchiveT>
150 ar(cereal::base_class<DataTypeLayer>(
this),
m_ops);
153 template <
typename InputT,
typename OutputT, data_layout Layout, El::Device D>
160 template <
typename InputT,
typename OutputT, data_layout Layout, El::Device D>
162 std::vector<OperatorPtr>
const& ops) -> std::vector<OperatorPtr>
164 std::vector<OperatorPtr> out;
165 out.reserve(ops.size());
166 for (
auto const& x : ops) {
167 out.emplace_back(x->clone());
172 template <
typename InputT,
typename OutputT, data_layout Layout, El::Device D>
176 return std::vector<size_t>{cbegin(in), cend(in)};
182 template <
typename InputT,
typename OutputT, data_layout Layout, El::Device D>
183 std::vector<utils::ConstDistTensorView<InputT, D>>
187 std::vector<utils::ConstDistTensorView<InputT, D>> out;
188 out.reserve(n_parents);
189 for (
int p = 0; p < n_parents; ++p) {
191 out.emplace_back(prev_acts,
197 template <
typename InputT,
typename OutputT, data_layout Layout, El::Device D>
198 std::vector<utils::DistTensorView<OutputT, D>>
202 std::vector<utils::DistTensorView<OutputT, D>> out;
203 out.reserve(n_children);
204 for (
int c = 0; c < n_children; ++c) {
211 template <
typename InputT,
typename OutputT, data_layout Layout, El::Device D>
212 std::vector<utils::ConstDistTensorView<OutputT, D>>
216 std::vector<utils::ConstDistTensorView<OutputT, D>> out;
217 out.reserve(n_children);
218 for (
int c = 0; c < n_children; ++c) {
220 out.emplace_back(prev_sigs,
226 template <
typename InputT,
typename OutputT, data_layout Layout, El::Device D>
227 std::vector<utils::DistTensorView<InputT, D>>
231 std::vector<utils::DistTensorView<InputT, D>> out;
232 out.reserve(n_parents);
233 for (
int p = 0; p < n_parents; ++p) {
235 out.emplace_back(error_sigs,
243 template <
typename InputT,
248 lbann_data::Layer
const& msg)
249 -> std::unique_ptr<Layer>
258 auto const& params = msg.operator_layer();
260 auto const num_ops = params.ops_size();
261 std::vector<OperatorPtr> ops;
262 ops.reserve(num_ops);
263 for (
int ii = 0; ii < num_ops; ++ii) {
265 LBANN_ASSERT(msg.datatype() == params.ops(ii).input_datatype());
266 LBANN_ASSERT(msg.datatype() == params.ops(ii).output_datatype());
269 proto::construct_operator<InputT, OutputT, D>(params.ops(ii)));
271 return std::make_unique<LayerType>(*comm, std::move(ops));
274 #ifndef LBANN_INSTANTIATE_OPERATOR_LAYER 277 #define PROTO_DEVICE(T, D) \ 278 extern template class OperatorLayer<T, T, data_layout::DATA_PARALLEL, D>; \ 279 extern template class OperatorLayer<T, T, data_layout::MODEL_PARALLEL, D>; \ 280 extern template std::unique_ptr<Layer> \ 281 build_operator_layer_from_pbuf<T, T, data_layout::DATA_PARALLEL, D>( \ 283 lbann_data::Layer const&); \ 284 extern template std::unique_ptr<Layer> \ 285 build_operator_layer_from_pbuf<T, T, data_layout::MODEL_PARALLEL, D>( \ 287 lbann_data::Layer const&) 292 #endif // LBANN_INSTANTIATE_OPERATOR_LAYER 293 #endif // LBANN_LAYERS_OPERATOR_LAYER_IMPL_HPP_INCLUDED
std::vector< size_t > splice_dims(ArgTs &&... args)
std::string get_type() const final
Get the layer type's name.
std::vector< utils::ConstDistTensorView< OutputT, D > > get_grad_wrt_outputs() const
std::vector< OperatorPtr > m_ops
static std::vector< size_t > fix_type(std::vector< int > const &in)
El::Device get_device_allocation() const final
Get the device allocation for the data tensors. We assume that the decice allocation of the previous ...
int get_num_parents() const noexcept
Get number of parent layers.
OperatorLayer & operator=(OperatorLayer const &other)
Copy assignment.
description get_description() const final
Human-readable description.
std::vector< int > get_input_dims(size_t input_index=0) const
Get input tensor dimensions.
Generates nicely formatted description messages.
virtual description get_description() const
Human-readable description.
constexpr El::Device Device
OutputAbsDistMatrixType & get_prev_error_signals(int child_index=0)
InputAbsDistMatrixType & get_prev_activations(int parent_index=0)
#define LBANN_ASSERT(cond)
const OutputAbsDistMatrixType & get_activations(const Layer &child) const override
std::unique_ptr< Layer > build_operator_layer_from_pbuf(lbann_comm *, lbann_data::Layer const &)
std::vector< utils::ConstDistTensorView< InputT, D > > get_inputs() const
void serialize(ArchiveT &)
int get_num_children() const noexcept
Get number of child layers.
void bp_compute() final
Compute objective funciton gradients. Called by the 'back_prop' function. Given the input...
static std::vector< OperatorPtr > clone_ops(std::vector< OperatorPtr > const &ops)
OperatorLayer * copy() const final
Polymorphic copy.
int get_backprop_requirements() const final
Returns the necessary tensors for computing backpropagation.
data_layout
Data layout that is optimized for different modes of parallelism.
void fp_compute() final
Apply layer operation. Called by the 'forward_prop' function. Given the input tensors, the output tensors are populated with computed values.
data_layout get_data_layout() const final
Get data layout of the data tensors. We assume that the data layouts of the previous activations...
Neural network tensor operation.
std::vector< utils::DistTensorView< OutputT, D > > get_outputs()
bool can_run_inplace() const final
If True, the computation can run in-place (feeding each input activations tensor as the corresponding...
std::unique_ptr< OperatorType > OperatorPtr
std::vector< int > get_output_dims(size_t output_index=0) const
Get output tensor dimensions.
Layer composed of one or more operator objects.
std::vector< utils::DistTensorView< InputT, D > > get_grad_wrt_inputs()
int m_expected_num_parent_layers
data_type_layer & operator=(data_type_layer &&other)=default
const InputAbsDistMatrixType & get_error_signals(const Layer &parent) const override