malloc.cc 2.4 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

20 21
namespace paddle {
namespace memory {
22

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

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

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

36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
std::shared_ptr<Allocation> AllocShared(const platform::CUDAPlace& place,
                                        size_t size,
                                        const gpuStream_t& stream) {
  return allocation::AllocatorFacade::Instance().AllocShared(place, size,
                                                             stream);
}

AllocationPtr Alloc(const platform::CUDAPlace& place, size_t size,
                    const gpuStream_t& stream) {
  return allocation::AllocatorFacade::Instance().Alloc(place, size, stream);
}

uint64_t Release(const platform::CUDAPlace& place, const gpuStream_t& stream) {
  return allocation::AllocatorFacade::Instance().Release(place, stream);
}

53 54
void RecordStream(std::shared_ptr<Allocation> allocation,
                  const gpuStream_t& stream) {
55 56 57
  return allocation::AllocatorFacade::Instance().RecordStream(allocation,
                                                              stream);
}
58 59 60 61 62

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

63
#endif
64 65
}  // namespace memory
}  // namespace paddle