return;
if (LAYER_V2) {
- for (auto &l_w : weights_v2) {
- for (auto &w : l_w) {
- w->initializeVariable();
- // tensor_map(&w->getVariableRef(), requestMemory(w.getDim().size(), 0,
- // MAX));
- }
+ for (auto &w : weights_v2) {
+ w->initializeVariable();
+ // tensor_map(&w->getVariableRef(), requestMemory(w.getDim().size(), 0,
+ // MAX));
}
} else {
if (total_weight_size == 0) {
return;
if (LAYER_V2) {
- for (auto &l_w : weights_v2) {
- for (auto &w : l_w) {
- w->allocateVariable();
- }
+ for (auto &w : weights_v2) {
+ w->allocateVariable();
}
} else {
for (auto &l_w : weights) {
void Manager::deallocateWeights() {
if (LAYER_V2) {
- for (auto &l_w : weights_v2) {
- for (auto &w : l_w) {
- w->deallocateVariable();
- }
+ for (auto &w : weights_v2) {
+ w->deallocateVariable();
}
} else {
for (auto &l_w : weights) {
shared_grad.allocate();
if (LAYER_V2) {
- for (auto &l_w : weights_v2) {
- for (auto &w : l_w) {
- w->allocateGradient();
- }
+ for (auto &w : weights_v2) {
+ w->allocateGradient();
}
} else {
for (auto &l_w : weights) {
shared_grad.deallocate();
if (LAYER_V2) {
- for (auto &l_w : weights_v2) {
- for (auto &w : l_w) {
- w->deallocateGradient();
- }
+ for (auto &w : weights_v2) {
+ w->deallocateGradient();
}
} else {
for (auto &l_w : weights) {
*/
void Manager::initializeGradients() {
if (LAYER_V2) {
- for (auto &l_w : weights_v2) {
- for (auto &w : l_w) {
- w->initializeGradient();
- // auto exec_order = tensor_exec_order[w.getName()];
- // tensor_map(&w->getGradientRef(), requestMemory(w.getDim().size(),
- // std::get<1>(exec_order), std::get<2>(exec_order) + 1));
- }
+ for (auto &w : weights_v2) {
+ w->initializeGradient();
+ // auto exec_order = tensor_exec_order[w.getName()];
+ // tensor_map(&w->getGradientRef(), requestMemory(w.getDim().size(),
+ // std::get<1>(exec_order), std::get<2>(exec_order) + 1));
}
} else {
if (total_weight_size == 0) {
shared_inout.allocate();
if (LAYER_V2) {
- for (auto &li : inputs_v2) {
- for (auto &in : li) {
- in->allocateVariable();
- }
+ for (auto &in : inputs_v2) {
+ in->allocateVariable();
}
- for (auto &lo : outputs_v2) {
- for (auto &out : lo) {
- out->allocateVariable();
- }
+ for (auto &out : outputs_v2) {
+ out->allocateVariable();
}
- for (auto < : tensors_v2) {
- for (auto &t : lt) {
- t->allocateVariable();
- }
+ for (auto &t : tensors_v2) {
+ t->allocateVariable();
}
} else {
for (auto &l_io : in_outs) {
shared_inout.deallocate();
if (LAYER_V2) {
- for (auto &li : inputs_v2) {
- for (auto &in : li) {
- in->deallocateVariable();
- }
+ for (auto &in : inputs_v2) {
+ in->deallocateVariable();
}
- for (auto &lo : outputs_v2) {
- for (auto &out : lo) {
- out->deallocateVariable();
- }
+ for (auto &out : outputs_v2) {
+ out->deallocateVariable();
}
- for (auto < : tensors_v2) {
- for (auto &t : lt) {
- t->deallocateVariable();
- }
+ for (auto &t : tensors_v2) {
+ t->deallocateVariable();
}
} else {
for (auto &l_io : in_outs) {
shared_deriv.allocate();
if (LAYER_V2) {
- for (auto &li : inputs_v2) {
- for (auto &in : li) {
- in->allocateGradient();
- }
+ for (auto &in : inputs_v2) {
+ in->allocateGradient();
}
- for (auto &lo : outputs_v2) {
- for (auto &out : lo) {
- out->allocateGradient();
- }
+ for (auto &out : outputs_v2) {
+ out->allocateGradient();
}
- for (auto < : tensors_v2) {
- for (auto &t : lt) {
- t->allocateGradient();
- }
+ for (auto &t : tensors_v2) {
+ t->allocateGradient();
}
} else {
for (auto &l_io : in_outs) {
shared_deriv.deallocate();
if (LAYER_V2) {
- for (auto &li : inputs_v2) {
- for (auto &in : li) {
- in->deallocateGradient();
- }
+ for (auto &in : inputs_v2) {
+ in->deallocateGradient();
}
- for (auto &lo : outputs_v2) {
- for (auto &out : lo) {
- out->deallocateGradient();
- }
+ for (auto &out : outputs_v2) {
+ out->deallocateGradient();
}
- for (auto < : tensors_v2) {
- for (auto &t : lt) {
- t->deallocateGradient();
- }
+ for (auto &t : tensors_v2) {
+ t->deallocateGradient();
}
} else {
for (auto &l_io : in_outs) {
}
} else {
// Inference Mode without optimizations
- for (auto &layer_outs : outputs_v2) {
- // TODO:For flatten layer, do not assign new memory
-
- for (auto &outs : layer_outs) {
- outs->initialize(Tensor(), Tensor(), false);
- }
+ for (auto &outs : outputs_v2) {
+ outs->initialize(Tensor(), Tensor(), false);
}
// Inference Mode without optimizations
- for (auto &layer_ts : tensors_v2) {
- for (auto &ts : layer_ts) {
- ts->initialize(Tensor(), Tensor(), false);
- }
+ for (auto &ts : tensors_v2) {
+ ts->initialize(Tensor(), Tensor(), false);
}
// In inference mode, do not allocate the memory for the input of the first
// layer. These is the first entry in the in_outs. Inference() will override
// input tensors of the first layer
- for ([[maybe_unused]] auto &layer_ins : inputs_v2) {
+ for ([[maybe_unused]] auto &ins : inputs_v2) {
// as inputs_v2 are only set for input layers, this can be skipped all the
// way
continue;
}
} else {
// Training Mode without optimizations
- for (auto &layer_outs : outputs_v2) {
- for (auto &outs : layer_outs) {
- outs->initialize(Tensor(), Tensor(), true);
- }
+ for (auto &outs : outputs_v2) {
+ outs->initialize(Tensor(), Tensor(), true);
}
// Training Mode without optimizations
- for (auto &layer_ts : tensors_v2) {
- for (auto &ts : layer_ts) {
- ts->initialize(Tensor(), Tensor(), true);
- }
+ for (auto &ts : tensors_v2) {
+ ts->initialize(Tensor(), Tensor(), true);
}
// Training Mode without optimizations
- for (auto &layer_ins : inputs_v2) {
- for (auto &ins : layer_ins) {
- ins->initialize(Tensor(), Tensor(), true);
- }
+ for (auto &ins : inputs_v2) {
+ ins->initialize(Tensor(), Tensor(), true);
}
}
}
std::vector<Weight *> all_weights;
if (LAYER_V2) {
- for (auto &weight_v2 : weights_v2) {
- for (auto &w : weight_v2) {
- all_weights.push_back(w.get());
- }
+ for (auto &w : weights_v2) {
+ all_weights.push_back(w.get());
}
} else {
throw std::runtime_error("Using deprecated code. Upgrade to LayerV2");
// std::vector<std::unique_ptr<Var_Grad>> tensors; /**< inputs/outputs/tensors
// for the network */
- std::vector<std::vector<std::unique_ptr<Weight>>>
+ std::vector<std::unique_ptr<Weight>>
weights_v2; /**< weights for the layers */
- std::vector<std::vector<std::unique_ptr<Var_Grad>>>
+ std::vector<std::unique_ptr<Var_Grad>>
inputs_v2; /**< inputs for the layers */
- std::vector<std::vector<std::unique_ptr<Var_Grad>>>
+ std::vector<std::unique_ptr<Var_Grad>>
outputs_v2; /**< outputs for the layers */
- std::vector<std::vector<std::unique_ptr<Var_Grad>>>
+ std::vector<std::unique_ptr<Var_Grad>>
tensors_v2; /**< extra tensors required by the layers */
std::unordered_map<std::string, GraphNode::ExecutionOrder>
* @param layer_objs_list list to store the created tensors
*/
template <typename T>
- std::vector<T *> requestTensors(
- const GraphNode &node, const std::vector<typename T::Spec> &tensors_spec,
- std::vector<std::vector<std::unique_ptr<T>>> &layer_objs_list) {
+ std::vector<T *>
+ requestTensors(const GraphNode &node,
+ const std::vector<typename T::Spec> &tensors_spec,
+ std::vector<std::unique_ptr<T>> &layer_objs_list) {
std::vector<T *> ret;
- std::vector<std::unique_ptr<T>> tensors_list;
- tensors_list.reserve(tensors_spec.size());
+ size_t current_size = layer_objs_list.size();
for (auto const &ts : std::as_const(tensors_spec)) {
- tensors_list.emplace_back(std::make_unique<T>(ts));
- auto const &ts_name = tensors_list.back()->getName();
+ layer_objs_list.emplace_back(std::make_unique<T>(ts));
+ auto const &ts_name = layer_objs_list.back()->getName();
/**
* @todo maybe requesting tensor with same name should mean reusing the
* tensor than giving the error
tensor_exec_order[ts_name] = node.getExecutionOrder();
}
- std::transform(tensors_list.begin(), tensors_list.end(),
- std::back_inserter(ret),
+ std::transform(layer_objs_list.begin() + current_size,
+ layer_objs_list.end(), std::back_inserter(ret),
[](auto const &elem) { return elem.get(); });
- layer_objs_list.emplace_back(std::move(tensors_list));
return ret;
}