memcpy.h 3.3 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 15 16

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

17
#include "paddle/fluid/platform/device/gpu/gpu_info.h"
Y
Yi Wang 已提交
18
#include "paddle/fluid/platform/place.h"
F
fwenguang 已提交
19 20 21
#ifdef PADDLE_WITH_MLU
#include "paddle/fluid/platform/device/mlu/device_context.h"
#endif
22 23 24 25

namespace paddle {
namespace memory {

26 27 28 29 30 31 32 33 34 35
/**
 * \brief   Copy memory from one place to another place.
 *
 * \param[in]  DstPlace Destination allocation place (CPU).
 * \param[in]  dst      Destination memory address.
 * \param[in]  SrcPlace Source allocation place (CPU).
 * \param[in]  src      Source memory address.
 * \param[in]  num      memory size in bytes to copy.
 *
 */
36 37 38
template <typename DstPlace, typename SrcPlace>
void Copy(DstPlace, void* dst, SrcPlace, const void* src, size_t num);

39
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54

/**
 * \brief   Copy memory from one place to another place.
 *
 * \param[in]  DstPlace Destination allocation place (CPU or GPU).
 * \param[in]  dst      Destination memory address.
 * \param[in]  SrcPlace Source allocation place (CPU or GPU).
 * \param[in]  src      Source memory address.
 * \param[in]  num      memory size in bytes to copy.
 * \param[in]  stream   CUDA stream.
 *
 * \note    For GPU memory copy, CUDA stream need to be specified
 *          for asynchronously memory copy.
 *
 */
55 56
template <typename DstPlace, typename SrcPlace>
void Copy(DstPlace, void* dst, SrcPlace, const void* src, size_t num,
57
          gpuStream_t stream);
58
#endif
59

60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
#ifdef PADDLE_WITH_ASCEND_CL
/**
 * \brief   Copy memory from one place to another place.
 *
 * \param[in]  DstPlace Destination allocation place (CPU or NPU).
 * \param[in]  dst      Destination memory address.
 * \param[in]  SrcPlace Source allocation place (CPU or NPU).
 * \param[in]  src      Source memory address.
 * \param[in]  num      memory size in bytes to copy.
 * \param[in]  stream   NPU stream.
 *
 * \note    For NPU memory copy, NPU stream need to be specified
 *          for asynchronously memory copy.
 *
 */
template <typename DstPlace, typename SrcPlace>
void Copy(DstPlace, void* dst, SrcPlace, const void* src, size_t num,
          aclrtStream stream);
L
Luo Tao 已提交
78
#endif
79

F
fwenguang 已提交
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
#ifdef PADDLE_WITH_MLU
/**
 * \brief   Copy memory from one place to another place.
 *
 * \param[in]  DstPlace Destination allocation place (CPU or MLU).
 * \param[in]  dst      Destination memory address.
 * \param[in]  SrcPlace Source allocation place (CPU or MLU).
 * \param[in]  src      Source memory address.
 * \param[in]  num      memory size in bytes to copy.
 * \param[in]  stream   MLU stream.
 *
 * \note    For MLU memory copy, MLU stream need to be specified
 *          for asynchronously memory copy.
 *
 */
template <typename DstPlace, typename SrcPlace>
void Copy(DstPlace, void* dst, SrcPlace, const void* src, size_t num,
          mluStream stream);
#endif

100 101
}  // namespace memory
}  // namespace paddle