You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

memory_pool.h 1.9 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * Copyright 2019 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef DATASET_UTIL_MEMORY_POOL_H_
  17. #define DATASET_UTIL_MEMORY_POOL_H_
  18. #include <cstddef>
  19. #include <cstdint>
  20. #include <memory>
  21. #include "dataset/util/status.h"
  22. namespace mindspore {
  23. namespace dataset {
  24. // Abstract class of a memory pool
  25. class MemoryPool {
  26. public:
  27. // Allocate a block of size n
  28. virtual Status Allocate(size_t, void **) = 0;
  29. // Enlarge or shrink a block from oldSz to newSz
  30. virtual Status Reallocate(void **, size_t old_sz, size_t new_sz) = 0;
  31. // Free a pointer
  32. virtual void Deallocate(void *) = 0;
  33. // What is the maximum size I can allocate ?
  34. virtual uint64_t get_max_size() const = 0;
  35. virtual int PercentFree() const = 0;
  36. // Destructor
  37. virtual ~MemoryPool() {}
  38. };
  39. Status DeMalloc(std::size_t s, void **p, bool);
  40. } // namespace dataset
  41. } // namespace mindspore
  42. void *operator new(std::size_t, mindspore::dataset::Status *, std::shared_ptr<mindspore::dataset::MemoryPool>);
  43. void *operator new[](std::size_t, mindspore::dataset::Status *, std::shared_ptr<mindspore::dataset::MemoryPool>);
  44. void operator delete(void *, std::shared_ptr<mindspore::dataset::MemoryPool>);
  45. void operator delete[](void *, std::shared_ptr<mindspore::dataset::MemoryPool>);
  46. #endif // DATASET_UTIL_MEMORY_POOL_H_