QMCPACK
CUDAfill.cpp
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2021 QMCPACK developers.
6 //
7 // File developed by: Ye Luo, yeluo@anl.gov, Argonne National Laboratory
8 //
9 // File created by: Ye Luo, yeluo@anl.gov, Argonne National Laboratory
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #include "CUDAfill.hpp"
14 #include <stdexcept>
15 #include "CUDAruntime.hpp"
16 
17 namespace qmcplusplus
18 {
19 template<typename T>
20 void CUDAfill_n(T* ptr, size_t n, const T& value)
21 {
22  if (value != T())
23  throw std::runtime_error("CUDAfill_n doesn't support fill non T() values!");
24  // setting 0 value on each byte should be 0 for int, float and double.
25  cudaErrorCheck(cudaMemset(ptr, 0, n * sizeof(T)), "Memset failed in CUDAfill_n!");
26 }
27 
28 template void CUDAfill_n<int>(int* ptr, size_t n, const int& value);
29 template void CUDAfill_n<size_t>(size_t* ptr, size_t n, const size_t& value);
30 
31 template void CUDAfill_n<float>(float* ptr, size_t n, const float& value);
32 template void CUDAfill_n<double>(double* ptr, size_t n, const double& value);
33 
34 template void CUDAfill_n<std::complex<float>>(std::complex<float>* ptr, size_t n, const std::complex<float>& value);
35 template void CUDAfill_n<std::complex<double>>(std::complex<double>* ptr, size_t n, const std::complex<double>& value);
36 } // namespace qmcplusplus
#define cudaMemset
Definition: cuda2hip.h:144
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
handle CUDA/HIP runtime selection.
template void CUDAfill_n< double >(double *ptr, size_t n, const double &value)
template void CUDAfill_n< float >(float *ptr, size_t n, const float &value)
template void CUDAfill_n< size_t >(size_t *ptr, size_t n, const size_t &value)
cudaErrorCheck(cudaMemcpyAsync(dev_lu.data(), lu.data(), sizeof(decltype(lu)::value_type) *lu.size(), cudaMemcpyHostToDevice, hstream), "cudaMemcpyAsync failed copying log_values to device")
void CUDAfill_n(T *ptr, size_t n, const T &value)
fill device memory with a given value.
Definition: CUDAfill.cpp:20
template void CUDAfill_n< int >(int *ptr, size_t n, const int &value)