$(NNTRAINER_ROOT)/nntrainer/tensor/tensor_pool.cpp \
$(NNTRAINER_ROOT)/nntrainer/tensor/memory_pool.cpp \
$(NNTRAINER_ROOT)/nntrainer/tensor/basic_planner.cpp \
+ $(NNTRAINER_ROOT)/nntrainer/tensor/optimized_v1_planner.cpp \
$(NNTRAINER_ROOT)/nntrainer/tensor/blas_interface.cpp \
$(NNTRAINER_ROOT)/nntrainer/layers/layer_node.cpp \
$(NNTRAINER_ROOT)/nntrainer/layers/layer_context.cpp \
*/
void deallocateWeights() { tensor_manager->deallocateWeights(); }
+ /**
+ * @brief Enable the memory optimizations for the network
+ *
+ * @param val true to enable, else false
+ */
+ void setMemoryOptimizations(bool val) {
+ tensor_manager->setOptimizations(val);
+ }
+
/**
* @brief Create optimizer variable for every weights
*
std::vector<float *> inference(std::vector<float *> &input,
unsigned int batch);
+ /**
+ * @brief Enable the memory optimizations for the network
+ *
+ */
+ void enableMemoryOptimizations() { model_graph.setMemoryOptimizations(true); }
+
+ /**
+ * @brief Enable the memory optimizations for the network
+ *
+ */
+ void disableMemoryOptimizations() {
+ model_graph.setMemoryOptimizations(false);
+ }
+
/**
* @brief Run NeuralNetwork train with callback function by user
* @param[in] dt datatype (mode) where it should be
void Manager::allocateWeights(unsigned int max_exec_order_) {
if (!weight_pool.isAllocated()) {
- weight_pool.finalize(BasicPlanner(), 0, max_exec_order_);
+ finalizeTensorPool(weight_pool, 0, max_exec_order_);
weight_pool.allocate();
}
}
allocateWeights(max_exec_order_);
if (!tensor_pool.isAllocated()) {
- tensor_pool.finalize(BasicPlanner(), 0, max_exec_order_);
+ finalizeTensorPool(tensor_pool, 0, max_exec_order_);
if (tensor_pool.minMemoryRequirement() > 0)
tensor_pool.allocate();
}
return all_weights;
}
+void Manager::finalizeTensorPool(TensorPool &pool, unsigned int start,
+ unsigned int end) {
+ if (enable_optimizations)
+ pool.finalize(OptimizedV1Planner(), start, end);
+ else
+ pool.finalize(BasicPlanner(), start, end);
+}
+
} // namespace nntrainer
/**
* @brief Constructor of Manager
*/
- Manager() = default;
+ Manager() : enable_optimizations(true) {}
/**
* @brief Construct a new Manager object (deleted)
*/
void deallocateWeights();
+ /**
+ * @brief Set optimizations for manager
+ *
+ * @param val true to enable, else false
+ */
+ void setOptimizations(bool val) { enable_optimizations = val; }
+
private:
/** @todo: merge this list to one */
std::vector<std::unique_ptr<Weight>>
TensorPool weight_pool; /**< tensor pool to request tensors */
TensorPool tensor_pool; /**< tensor pool to request tensors */
+
+ bool enable_optimizations; /**< to enable memory optimizations */
+
+ /**
+ * @brief Finalize the given tensor pool
+ *
+ * @param pool Tensor pool to finalize
+ * @param start Start execution order
+ * @param end End execution order
+ */
+ void finalizeTensorPool(TensorPool &pool, unsigned int start,
+ unsigned int end);
};
} // namespace nntrainer
if (pool_size < min_pool_size || !validateLayout())
throw std::runtime_error("Planned layout is not feasible");
- return double(pool_size) / double(min_pool_size);
+ return double(min_pool_size) / double(pool_size);
}
/**
*/
#include <memory_pool.h>
+#include <nntrainer_log.h>
#include <tensor.h>
#include <tensor_pool.h>
#include <tensor_wrap_specs.h>
}
/** 4. finalizeLayout for the memory pool. */
- if (bytes_requested > 0)
- mem_pool.planLayout(planner);
+ if (bytes_requested > 0) {
+ double efficiency = mem_pool.planLayout(planner);
+ ml_logd("Memory layout efficiency = %lf", efficiency);
+ }
}
/**
/** Disable memory optimization as memory being matched for each layer
*/
+ if (!opt)
+ nn.disableMemoryOptimizations();
if (nn.loadFromConfig(config)) {
throw std::invalid_argument("load from config failed!");