copy.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023-2024, NVIDIA CORPORATION.
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 #pragma once
19 
20 #include <stdint.h>
21 #ifdef CUML_ENABLE_GPU
23 #endif
25 
26 namespace raft_proto {
27 template <device_type dst_type, device_type src_type, typename T>
28 void copy(T* dst, T const* src, uint32_t size, uint32_t dst_offset, uint32_t src_offset)
29 {
30  detail::copy<dst_type, src_type, T>(dst + dst_offset, src + src_offset, size, cuda_stream{});
31 }
32 
33 template <device_type dst_type, device_type src_type, typename T>
34 void copy(
35  T* dst, T const* src, uint32_t size, uint32_t dst_offset, uint32_t src_offset, cuda_stream stream)
36 {
37  detail::copy<dst_type, src_type, T>(dst + dst_offset, src + src_offset, size, stream);
38 }
39 
40 template <device_type dst_type, device_type src_type, typename T>
41 void copy(T* dst, T const* src, uint32_t size)
42 {
43  detail::copy<dst_type, src_type, T>(dst, src, size, cuda_stream{});
44 }
45 
46 template <device_type dst_type, device_type src_type, typename T>
47 void copy(T* dst, T const* src, uint32_t size, cuda_stream stream)
48 {
49  detail::copy<dst_type, src_type, T>(dst, src, size, stream);
50 }
51 
52 template <typename T>
53 void copy(T* dst,
54  T const* src,
55  uint32_t size,
56  device_type dst_type,
57  device_type src_type,
58  uint32_t dst_offset,
59  uint32_t src_offset,
60  cuda_stream stream)
61 {
62  if (dst_type == device_type::gpu && src_type == device_type::gpu) {
63  detail::copy<device_type::gpu, device_type::gpu, T>(
64  dst + dst_offset, src + src_offset, size, stream);
65  } else if (dst_type == device_type::cpu && src_type == device_type::cpu) {
66  detail::copy<device_type::cpu, device_type::cpu, T>(
67  dst + dst_offset, src + src_offset, size, stream);
68  } else if (dst_type == device_type::gpu && src_type == device_type::cpu) {
69  detail::copy<device_type::gpu, device_type::cpu, T>(
70  dst + dst_offset, src + src_offset, size, stream);
71  } else if (dst_type == device_type::cpu && src_type == device_type::gpu) {
72  detail::copy<device_type::cpu, device_type::gpu, T>(
73  dst + dst_offset, src + src_offset, size, stream);
74  }
75 }
76 
77 template <typename T>
78 void copy(T* dst, T const* src, uint32_t size, device_type dst_type, device_type src_type)
79 {
80  copy<T>(dst, src, size, dst_type, src_type, 0, 0, cuda_stream{});
81 }
82 
83 template <typename T>
84 void copy(T* dst,
85  T const* src,
86  uint32_t size,
87  device_type dst_type,
88  device_type src_type,
89  cuda_stream stream)
90 {
91  copy<T>(dst, src, size, dst_type, src_type, 0, 0, stream);
92 }
93 
94 } // namespace raft_proto
Definition: buffer.hpp:35
int cuda_stream
Definition: cuda_stream.hpp:25
device_type
Definition: device_type.hpp:18
const_agnostic_same_t< T, U > copy(buffer< T > &dst, buffer< U > const &src, typename buffer< T >::index_type dst_offset, typename buffer< U >::index_type src_offset, typename buffer< T >::index_type size, cuda_stream stream)
Definition: buffer.hpp:327