* limitations under the License.
*/
+/**
+ * @file MemoryPlanner.h
+ * @brief This file contains Memory Planning related classes
+ */
+
#ifndef __NEURUN_BACKEND_CPU_MEMORY_PLANNER_H__
#define __NEURUN_BACKEND_CPU_MEMORY_PLANNER_H__
namespace cpu
{
+/**
+ * @brief Structure to have memory offset and size
+ */
struct Block
{
uint32_t offset;
uint32_t size;
};
+/**
+ * @brief Class to allocate memory
+ */
class Allocator
{
public:
Allocator(uint32_t capacity);
~Allocator();
+ /**
+ * @brief Get memory base pointer
+ * @return base pointer
+ */
uint8_t *base() const { return _base; }
private:
uint8_t *_base = nullptr;
};
+/**
+ * @brief Interface to plan memory
+ */
struct IMemoryPlanner
{
using MemoryPlans = std::unordered_map<graph::operand::Index, Block>;
+ /**
+ * @brief Claim memory for operand
+ * @param[in] index The operand index
+ * @param[in] size The size of the memory
+ */
virtual void claim(const graph::operand::Index &, size_t) = 0;
+ /**
+ * @brief Release memory for operand
+ * @param[in] index The operand index
+ */
virtual void release(const graph::operand::Index &) = 0;
+ /**
+ * @brief Get capacity for memory planning
+ * @return The value of capacity
+ */
virtual uint32_t capacity() = 0;
+ /**
+ * @brief Get MemoryPlans
+ * @return MemoryPlans
+ */
virtual MemoryPlans &memory_plans() = 0;
};
+/**
+ * @brief Class to plan memory by bump way
+ */
class BumpPlanner : public IMemoryPlanner
{
public:
+ /**
+ * @brief Claim memory for operand by bump way
+ * @param[in] index The operand index
+ * @param[in] size The size of the memory
+ */
virtual void claim(const graph::operand::Index &, size_t) override;
+ /**
+ * @brief Release memory for operand by bump way
+ * @param[in] index The operand index
+ */
virtual void release(const graph::operand::Index &) override;
+ /**
+ * @brief Get capacity for memory planning
+ * @return The value of capacity
+ */
virtual uint32_t capacity() override { return _capacity; }
+ /**
+ * @brief Get MemoryPlans
+ * @return MemoryPlans
+ */
virtual MemoryPlans &memory_plans() override { return _mem_plans; }
private:
MemoryPlans _mem_plans;
};
+/**
+ * @brief Class to plan memory by firstfit way
+ */
class FirstFitPlanner : public IMemoryPlanner
{
public:
+ /**
+ * @brief Claim memory for operand by firstfit way
+ * @param[in] index The operand index
+ * @param[in] size The size of the memory
+ */
virtual void claim(const graph::operand::Index &, size_t) override;
+ /**
+ * @brief Release memory for operand by firstfit way
+ * @param[in] index The operand index
+ */
virtual void release(const graph::operand::Index &) override;
+ /**
+ * @brief Get capacity for memory planning
+ * @return The value of capacity
+ */
virtual uint32_t capacity() override { return _capacity; }
+ /**
+ * @brief Get MemoryPlans
+ * @return MemoryPlans
+ */
virtual MemoryPlans &memory_plans() override { return _mem_plans; }
private: