/*! \file
 * \brief template definition of `__global__` functions InitTestArray_kernel and GPU_InitTestArray
  * 
 */
#ifndef __INITARRAYGPU_CUH__
#define __INITARRAYGPU_CUH__

#include "InitArrayFunc.hpp"

/*! \brief template definition of `__global__` functions InitTestArray_kernel
 * 
 * \param d_X    pointeur sur device GPU
 * \param N      dimension du tableau
 * \param Const  valeur
 * 
 * \tparam T     type `int`, `float` or `double`
 * 
*/
template <class T> __global__ void InitTestArray_kernel(
    T *d_X,
    int N,
    T Const
){
    const int      tid = blockDim.x * blockIdx.x + threadIdx.x;
    const int THREAD_N = blockDim.x * gridDim.x;
    int pos=tid;
    
    while (pos < N){
      d_X[pos] = TestFunc(Const,pos);
      pos+=THREAD_N;
    }
}

/*! \brief template definition of GPU_InitTestArray
 * 
 * \param d_X       pointer to device T array 
 * \param N         size of d_X
 * \param Const     T value
 * \param threads   threads number
 * \param blocks    blocks number
 * 
 * \tparam T      type `int`, `float` or `double`
*/
template <class T> void GPU_InitTestArray(
  T *d_X, int N, T Const,int threads, int blocks
)
{
  dim3 dimBlock(threads, 1, 1);
  dim3 dimGrid(blocks, 1, 1);
  
  InitTestArray_kernel<T><<< dimGrid, dimBlock>>>(d_X,N,Const);
}

#endif
