malloc.cc 2.8 KB
Newer Older
1
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved.
2 3 4 5 6 7 8 9 10 11 12 13 14

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. */

Y
Yu Yang 已提交
15
#include "paddle/fluid/memory/malloc.h"
16

17
#include "paddle/fluid/memory/allocation/allocator_facade.h"
Y
Yu Yang 已提交
18
#include "paddle/fluid/platform/place.h"
19
#include "paddle/phi/core/stream.h"
20

21 22
namespace paddle {
namespace memory {
23

24
std::shared_ptr<Allocation> AllocShared(const platform::Place& place,
25 26
                                        size_t size) {
  return allocation::AllocatorFacade::Instance().AllocShared(place, size);
L
liaogang 已提交
27
}
L
liaogang 已提交
28

29
AllocationPtr Alloc(const platform::Place& place, size_t size) {
30
  return allocation::AllocatorFacade::Instance().Alloc(place, size);
31
}
S
sneaxiy 已提交
32

33
uint64_t Release(const platform::Place& place) {
34 35 36
  return allocation::AllocatorFacade::Instance().Release(place);
}

37
std::shared_ptr<Allocation> AllocShared(const platform::Place& place,
38
                                        size_t size,
39
                                        const phi::Stream& stream) {
40 41 42 43
  return allocation::AllocatorFacade::Instance().AllocShared(place, size,
                                                             stream);
}

44 45 46 47 48
AllocationPtr Alloc(const platform::CUDAPlace& place, size_t size,
                    const phi::Stream& stream) {
  return allocation::AllocatorFacade::Instance().Alloc(place, size, stream);
}

49
bool InSameStream(const std::shared_ptr<Allocation>& allocation,
50
                  const phi::Stream& stream) {
51 52 53 54
  return allocation::AllocatorFacade::Instance().InSameStream(allocation,
                                                              stream);
}

55 56 57 58
void* GetBasePtr(const std::shared_ptr<Allocation>& allocation) {
  return allocation::AllocatorFacade::Instance().GetBasePtr(allocation);
}

59
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
60 61 62 63
uint64_t Release(const platform::CUDAPlace& place, const gpuStream_t& stream) {
  return allocation::AllocatorFacade::Instance().Release(place, stream);
}

64 65
void RecordStream(std::shared_ptr<Allocation> allocation,
                  const gpuStream_t& stream) {
66 67 68
  return allocation::AllocatorFacade::Instance().RecordStream(allocation,
                                                              stream);
}
69 70 71 72 73

const gpuStream_t& GetStream(const std::shared_ptr<Allocation>& allocation) {
  return allocation::AllocatorFacade::Instance().GetStream(allocation);
}

74
#endif
75 76
}  // namespace memory
}  // namespace paddle