grid_dist_id_kernels.cuh 1.48 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
/*
 * grid_dist_id_kernels.cuh
 *
 *  Created on: Jun 25, 2019
 *      Author: i-bird
 */

#ifndef GRID_DIST_ID_KERNELS_CUH_
#define GRID_DIST_ID_KERNELS_CUH_

11
#ifdef CUDA_GPU
12

13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
template<unsigned int dim>
struct ite_gpu_dist
{
	dim3 thr;
	dim3 wthr;

	grid_key_dx<dim,int> start;
	grid_key_dx<dim,int> stop;

	grid_key_dx<dim,int> start_base;

	grid_key_dx<dim,int> origin;

	ite_gpu_dist(ite_gpu<dim> & ite)
	{
		thr = ite.thr;
		wthr = ite.wthr;

		start = ite.start;
		stop = ite.stop;
	}

	size_t nblocks()
	{
		return wthr.x * wthr.y * wthr.z;
	}
};

#define GRID_ID_3_GLOBAL(ite_gpu) grid_key_dx<3,int> key;\
								  grid_key_dx<3,int> keyg;\
							  key.set_d(0,threadIdx.x + blockIdx.x * blockDim.x + ite_gpu.start.get(0));\
    						  key.set_d(1,threadIdx.y + blockIdx.y * blockDim.y + ite_gpu.start.get(1));\
							  key.set_d(2,threadIdx.z + blockIdx.z * blockDim.z + ite_gpu.start.get(2));\
							  \
							  keyg.set_d(0,key.get(0) + ite_gpu.origin.get(0));\
    						  keyg.set_d(1,key.get(1) + ite_gpu.origin.get(1));\
							  keyg.set_d(2,key.get(2) + ite_gpu.origin.get(2));\
										 \
										 if (key.get(0) > ite_gpu.stop.get(0) || key.get(1) > ite_gpu.stop.get(1) || key.get(2) > ite_gpu.stop.get(2))\
    									 {return;}


#endif

template<typename grid_type, typename ite_gpu_type,typename func_t,typename ... args_t>
__global__ void grid_apply_functor(grid_type g, ite_gpu_type ite, func_t f, args_t ... args)
59 60 61 62 63 64 65
{
	f(g,ite,args...);
}



#endif /* GRID_DIST_ID_KERNELS_CUH_ */