mult_kernel_impl.h
Go to the documentation of this file.
1 /*
2  * This file is a part of TiledArray.
3  * Copyright (C) 2018 Virginia Tech
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * Chong Peng
19  * Department of Chemistry, Virginia Tech
20  * Apir 11, 2018
21  *
22  */
23 
24 #ifndef TILEDARRAY_CUDA_MULT_KERNEL_IMPL_H__INCLUDED
25 #define TILEDARRAY_CUDA_MULT_KERNEL_IMPL_H__INCLUDED
26 
28 #include <thrust/device_vector.h>
29 #include <thrust/execution_policy.h>
30 
31 namespace TiledArray {
32 
34 template <typename T>
35 void mult_to_cuda_kernel_impl(T *result, const T *arg, std::size_t n,
36  cudaStream_t stream, int device_id) {
37  CudaSafeCall(cudaSetDevice(device_id));
38 
39  thrust::multiplies<T> mul_op;
40  thrust::transform(
41  thrust::cuda::par.on(stream), thrust::device_pointer_cast(arg),
42  thrust::device_pointer_cast(arg) + n, thrust::device_pointer_cast(result),
43  thrust::device_pointer_cast(result), mul_op);
44 }
45 
47 template <typename T>
48 void mult_cuda_kernel_impl(T *result, const T *arg1, const T *arg2,
49  std::size_t n, cudaStream_t stream, int device_id) {
50  CudaSafeCall(cudaSetDevice(device_id));
51 
52  thrust::multiplies<T> mul_op;
53  thrust::transform(
54  thrust::cuda::par.on(stream), thrust::device_pointer_cast(arg1),
55  thrust::device_pointer_cast(arg1) + n, thrust::device_pointer_cast(arg2),
56  thrust::device_pointer_cast(result), mul_op);
57 }
58 
59 } // namespace TiledArray
60 
61 #endif // TILEDARRAY_CUDA_MULT_KERNEL_IMPL_H__INCLUDED
void mult_cuda_kernel_impl(T *result, const T *arg1, const T *arg2, std::size_t n, cudaStream_t stream, int device_id)
result[i] = arg1[i] * arg2[i]
void mult_to_cuda_kernel_impl(T *result, const T *arg, std::size_t n, cudaStream_t stream, int device_id)
result[i] = result[i] * arg[i]