27 #ifndef LBANN_LAYER_HADAMARD_HPP_INCLUDED 28 #define LBANN_LAYER_HADAMARD_HPP_INCLUDED 37 template <
typename TensorDataType,
53 template <
typename ArchiveT>
58 std::string
get_type()
const override {
return "Hadamard"; }
80 std::stringstream err;
82 <<
"has no parent layers";
97 std::stringstream err;
99 <<
"has input tensors with incompatible dimensions (";
102 err << (j > 0 ?
", " :
"") <<
"layer \"" << parents[j]->
get_name()
104 for (
size_t k = 0; k < dims.size(); ++k) {
105 err << (k > 0 ?
" x " :
"") << dims[k];
119 El::Fill(output, El::TypeTraits<TensorDataType>::One());
138 switch (num_parents) {
145 for (
int i = 0; i < num_parents; ++i) {
147 El::Copy(gradient_wrt_output, gradient_wrt_input);
148 for (
int j = 0; j < num_parents; ++j) {
160 #ifndef LBANN_HADAMARD_LAYER_INSTANTIATE 161 #define PROTO_DEVICE(T, Device) \ 162 extern template class hadamard_layer<T, data_layout::DATA_PARALLEL, Device>; \ 163 extern template class hadamard_layer<T, data_layout::MODEL_PARALLEL, Device> 167 #endif // LBANN_HADAMARD_LAYER_INSTANTIATE 171 #endif // LBANN_LAYER_HADAMARD_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.
int get_num_parents() const noexcept
Get number of parent layers.
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.
std::string get_type() const override
Get the layer type's name.
constexpr El::Device Device
void serialize(ArchiveT &ar)
OutputAbsDistMatrixType & get_prev_error_signals(int child_index=0)
InputAbsDistMatrixType & get_prev_activations(int parent_index=0)
friend class cereal::access
void setup_pointers() override
Setup layer pointers. Called by the 'setup' function. Pointers to parent/child layers are assumed to ...
const OutputAbsDistMatrixType & get_activations(const Layer &child) const override
hadamard_layer * copy() const override
Copy function. This function dynamically allocates memory for a layer instance and instantiates a cop...
void bp_compute() override
Compute objective funciton gradients. Called by the 'back_prop' function. Given the input...
void set_output_dims(std::vector< int > dims, size_t output_index=0)
Set output tensor dimensions.
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_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.
data_layout get_data_layout() const override
Get data layout of the data tensors. We assume that the data layouts of the previous activations...
std::vector< const Layer * > get_parent_layers() const
std::string get_name() const
Get the layer instance's name.
void write_specific_proto(lbann_data::Layer &proto) const final
data_layout
Data layout that is optimized for different modes of parallelism.
hadamard_layer(lbann_comm *comm)
bool can_run_inplace() const override
If True, the computation can run in-place (feeding each input activations tensor as the corresponding...
El::Device get_device_allocation() const override
Get the device allocation for the data tensors. We assume that the decice allocation of the previous ...
virtual void setup_pointers()
Setup layer pointers. Called by the 'setup' function. Pointers to parent/child layers are assumed to ...
std::vector< int > get_output_dims(size_t output_index=0) const
Get output tensor dimensions.
int m_expected_num_parent_layers
const InputAbsDistMatrixType & get_error_signals(const Layer &parent) const override
Entry-wise tensor product.