init.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2022, NVIDIA CORPORATION.
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #pragma once
7 
8 #include <raft/util/cudart_utils.hpp>
9 
10 #include <thrust/copy.h>
11 #include <thrust/device_ptr.h>
12 #include <thrust/execution_policy.h>
13 #include <thrust/iterator/counting_iterator.h>
14 
15 namespace MLCommon {
16 namespace LinAlg {
17 
18 namespace {
19 
30 template <typename T>
31 void range(T* out, int start, int end, cudaStream_t stream)
32 {
33  thrust::counting_iterator<int> first(start);
34  thrust::counting_iterator<int> last = first + (end - start);
35  thrust::device_ptr<T> ptr(out);
36  thrust::copy(thrust::cuda::par.on(stream), first, last, ptr);
37 }
38 
48 template <typename T, int TPB = 256>
49 void range(T* out, int n, cudaStream_t stream)
50 {
51  range(out, 0, n, stream);
52 }
53 
61 template <typename T>
62 void zero(T* out, int n, cudaStream_t stream)
63 {
64  RAFT_CUDA_TRY(cudaMemsetAsync(static_cast<void*>(out), 0, n * sizeof(T), stream));
65 }
66 
67 } // unnamed namespace
68 } // namespace LinAlg
69 } // namespace MLCommon
Definition: Timer.h:9
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:316