You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.7 KiB
59 lines
1.7 KiB
8 years ago
|
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
|
||
|
|
||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
you may not use this file except in compliance with the License.
|
||
|
You may obtain a copy of the License at
|
||
|
|
||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||
|
|
||
|
Unless required by applicable law or agreed to in writing, software
|
||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
See the License for the specific language governing permissions and
|
||
|
limitations under the License. */
|
||
|
|
||
|
#pragma once
|
||
|
|
||
8 years ago
|
#include <stddef.h> // for size_t
|
||
8 years ago
|
|
||
8 years ago
|
namespace paddle {
|
||
|
namespace memory {
|
||
|
namespace detail {
|
||
|
|
||
8 years ago
|
/**
|
||
|
* \brief SystemAllocator is the parent class of CPUAllocator and GPUAllocator.
|
||
|
* A BuddyAllocator object uses a SystemAllocator* pointing to the
|
||
|
* underlying system allocator.
|
||
|
*/
|
||
8 years ago
|
class SystemAllocator {
|
||
8 years ago
|
public:
|
||
8 years ago
|
virtual ~SystemAllocator() {}
|
||
8 years ago
|
virtual void* Alloc(size_t& index, size_t size) = 0;
|
||
|
virtual void Free(void* p, size_t size, size_t index) = 0;
|
||
8 years ago
|
virtual bool UseGpu() const = 0;
|
||
8 years ago
|
};
|
||
|
|
||
8 years ago
|
class CPUAllocator : public SystemAllocator {
|
||
8 years ago
|
public:
|
||
8 years ago
|
virtual void* Alloc(size_t& index, size_t size);
|
||
|
virtual void Free(void* p, size_t size, size_t index);
|
||
8 years ago
|
virtual bool UseGpu() const;
|
||
8 years ago
|
};
|
||
|
|
||
7 years ago
|
#ifdef PADDLE_WITH_CUDA
|
||
8 years ago
|
class GPUAllocator : public SystemAllocator {
|
||
|
public:
|
||
8 years ago
|
virtual void* Alloc(size_t& index, size_t size);
|
||
|
virtual void Free(void* p, size_t size, size_t index);
|
||
8 years ago
|
virtual bool UseGpu() const;
|
||
8 years ago
|
|
||
8 years ago
|
private:
|
||
8 years ago
|
size_t gpu_alloc_size_ = 0;
|
||
|
size_t fallback_alloc_size_ = 0;
|
||
8 years ago
|
};
|
||
7 years ago
|
#endif
|
||
8 years ago
|
|
||
|
} // namespace detail
|
||
|
} // namespace memory
|
||
|
} // namespace paddle
|