Program Listing for File allocator.h

Return to documentation for file (include/allocator.h)

#ifndef MINDSPORE_INCLUDE_API_ALLOCATOR_H
#define MINDSPORE_INCLUDE_API_ALLOCATOR_H

#include <memory>
#include "include/api/types.h"

namespace mindspore {
class  Allocator {
 public:
  virtual ~Allocator() = default;

  virtual void *Malloc(size_t size) = 0;

  virtual void *Malloc(size_t weight, size_t height, DataType type) {
    return nullptr;
  }

  virtual void Free(void *ptr) = 0;

  virtual int RefCount(void *ptr) = 0;

  virtual int SetRefCount(void *ptr, int ref_count) = 0;

  virtual int DecRefCount(void *ptr, int ref_count) = 0;

  virtual int IncRefCount(void *ptr, int ref_count) = 0;

  static std::shared_ptr<Allocator> Create();

  virtual void *Prepare(void *ptr) { return ptr; }

 protected:
  // memory aligned bytes
  size_t aligned_size_ = 32;
};
}  // namespace mindspore
#endif  // MINDSPORE_INCLUDE_API_ALLOCATOR_H