init.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022, 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 
17 #pragma once
18 
19 #include <raft/util/cudart_utils.hpp>
20 
21 #include <thrust/copy.h>
22 #include <thrust/device_ptr.h>
23 #include <thrust/execution_policy.h>
24 #include <thrust/iterator/counting_iterator.h>
25 
26 namespace MLCommon {
27 namespace LinAlg {
28 
29 namespace {
30 
41 template <typename T>
42 void range(T* out, int start, int end, cudaStream_t stream)
43 {
44  thrust::counting_iterator<int> first(start);
45  thrust::counting_iterator<int> last = first + (end - start);
46  thrust::device_ptr<T> ptr(out);
47  thrust::copy(thrust::cuda::par.on(stream), first, last, ptr);
48 }
49 
59 template <typename T, int TPB = 256>
60 void range(T* out, int n, cudaStream_t stream)
61 {
62  range(out, 0, n, stream);
63 }
64 
72 template <typename T>
73 void zero(T* out, int n, cudaStream_t stream)
74 {
75  RAFT_CUDA_TRY(cudaMemsetAsync(static_cast<void*>(out), 0, n * sizeof(T), stream));
76 }
77 
78 } // unnamed namespace
79 } // namespace LinAlg
80 } // namespace MLCommon
Definition: kernelparams.h:21
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