SkePU(integratedwithStarPU)  0.8.1
 All Classes Namespaces Files Functions Enumerations Friends Macros Groups Pages
maparray_kernels.h
Go to the documentation of this file.
1 
5 #ifndef MAPARRAY_KERNELS_H
6 #define MAPARRAY_KERNELS_H
7 
8 #ifdef SKEPU_OPENCL
9 
10 #include <string>
11 
12 namespace skepu
13 {
14 
31 static std::string MapArrayKernel_CL(
32 "__kernel void MapArrayKernel_KERNELNAME(__global TYPE* input1, __global TYPE* input2, __global TYPE* output, unsigned int n)\n"
33 "{\n"
34 " int i = get_global_id(0);\n"
35 " unsigned int gridSize = get_local_size(0)*get_num_groups(0);\n"
36 " while(i < n)\n"
37 " {\n"
38 " output[i] = FUNCTIONNAME(&input1[0], input2[i]);\n"
39 " i += gridSize;\n"
40 " }\n"
41 "}\n"
42 );
43 
44 
45 //static std::string MapArrayKernel_CL_Matrix(
46 //"__kernel void MapArrayKernel_KERNELNAME_Matrix(__global TYPE* input1, __global TYPE* input2, __global TYPE* output, unsigned int n, unsigned int xsize, unsigned int ysize)\n"
47 //"{\n"
48 //" int xindex = get_global_id(0);\n"
49 //" int yindex = get_global_id(1);\n"
50 //" int i = (get_global_size(0) * get_local_size(0)) * yindex + xindex;\n"
51 //" if(i < n && xindex<xsize && yindex <ysize)\n"
52 //" {\n"
53 //" output[i] = FUNCTIONNAME(&input1[0], input2[i]);\n"
54 //" }\n"
55 //"}\n"
56 //);
57 
63 static std::string MapArrayKernel_CL_Matrix(
64 "__kernel void MapArrayKernel_Matrix_KERNELNAME(__global TYPE* input1, __global TYPE* input2, __global TYPE* output, unsigned int n, unsigned int xsize, unsigned int ysize, int yoffset, CONST_TYPE const1)\n"
65 "{\n"
66 " int xindex = get_global_id(0);\n"
67 " int yindex = get_global_id(1);\n"
68 " int i = yindex*xsize + xindex; \n"
69 " if(i < n && xindex<xsize && yindex <ysize)\n"
70 " {\n"
71 " output[i] = FUNCTIONNAME(&input1[0], input2[i], xindex, yindex+yoffset, const1);\n"
72 " }\n"
73 "}\n"
74 );
75 
76 
82 static std::string MapArrayKernel_CL_Matrix_Blockwise(
83 "__kernel void MapArrayKernel_Matrix_Blockwise_KERNELNAME(__global TYPE* input1, __global TYPE* input2, __global TYPE* output, unsigned int outSize, int p2BlockSize, CONST_TYPE const1)\n"
84 "{\n"
85 " int i = get_global_id(0);\n"
86 " unsigned int gridSize = get_local_size(0)*get_num_groups(0);\n"
87 " if(i < outSize)\n"
88 " {\n"
89 " output[i] = FUNCTIONNAME(&input1[0], &input2[i*p2BlockSize], const1);\n"
90 " i += gridSize;\n"
91 " }\n"
92 "}\n"
93 );
94 
95 
102 "__kernel void MapArrayKernel_Sparse_Matrix_Blockwise_KERNELNAME(__global TYPE* input1, __global TYPE* in2_values, __global unsigned int *in2_row_offsets, __global unsigned int *in2_col_indices, __global TYPE* output, unsigned int outSize, int indexOffset, CONST_TYPE const1)\n"
103 "{\n"
104 " int i = get_global_id(0);\n"
105 " unsigned int gridSize = get_local_size(0)*get_num_groups(0);\n"
106 " if(i < outSize)\n"
107 " {\n"
108 " int rowId = in2_row_offsets[i] - indexOffset;\n"
109 " int row2Id = in2_row_offsets[i+1] - indexOffset;\n"
110 " output[i] = FUNCTIONNAME(&input1[0], &in2_values[rowId], (row2Id-rowId), &in2_col_indices[rowId], const1);\n"
111 " i += gridSize;\n"
112 " }\n"
113 "}\n"
114 );
115 
120 }
121 
122 #endif
123 
124 #ifdef SKEPU_CUDA
125 
126 namespace skepu
127 {
128 
145 template <typename T, typename ArrayFunc>
146 __global__ void MapArrayKernel_CU(ArrayFunc mapArrayFunc, T* input1, T* input2, T* output, unsigned int n)
147 {
148  unsigned int i = blockIdx.x * blockDim.x + threadIdx.x;
149  unsigned int gridSize = blockDim.x*gridDim.x;
150 
151  while(i < n)
152  {
153  output[i] = mapArrayFunc.CU(&input1[0], input2[i]);
154  i += gridSize;
155  }
156 }
157 
158 //
159 //
160 //template <typename T, typename ArrayFunc>
161 //__global__ void MapArrayKernel_CU_Matrix(ArrayFunc mapArrayFunc, T* input1, T* input2, T* output, unsigned int n)
162 //{
163 // unsigned int xindex = blockIdx.x * blockDim.x + threadIdx.x;
164 // unsigned int yindex = blockIdx.y * blockDim.y + threadIdx.y;
165 // unsigned int outaddr = (gridDim.x * blockDim.x) * yindex + xindex;
166 //
167 // if(outaddr < n)
168 // {
169 // output[outaddr] = mapArrayFunc.CU(&input1[0], input2[outaddr], xindex, yindex);
170 // }
171 //}
172 
178 template <typename T, typename ArrayFunc>
179 __global__ void MapArrayKernel_CU_Matrix(ArrayFunc mapArrayFunc, T* input1, T* input2, T* output, unsigned int n, unsigned int xsize, unsigned int ysize, unsigned int yoffset)
180 {
181  unsigned int xindex = blockIdx.x * blockDim.x + threadIdx.x;
182  unsigned int yindex = blockIdx.y * blockDim.y + threadIdx.y;
183  unsigned int outaddr = yindex*xsize + xindex; //(gridDim.x * blockDim.x) * yindex + xindex;
184 
185  if(outaddr < n && xindex<xsize && yindex <ysize)
186  {
187  output[outaddr] = mapArrayFunc.CU(&input1[0], input2[outaddr], xindex, yindex+yoffset);
188  }
189 }
190 
191 
197 template <typename T, typename ArrayFunc>
198 __global__ void MapArrayKernel_CU_Matrix_Blockwise(ArrayFunc mapArrayFunc, T* input1, T* input2, T* output, unsigned int outSize, int p2BlockSize)
199 {
200  unsigned int i = blockIdx.x * blockDim.x + threadIdx.x;
201  unsigned int gridSize = blockDim.x*gridDim.x;
202 
203  if(i < outSize)
204  {
205  output[i] = mapArrayFunc.CU(&input1[0], &input2[i*p2BlockSize]);
206  i += gridSize;
207  }
208 }
209 
210 
216 template <typename T, typename ArrayFunc>
217 __global__ void MapArrayKernel_CU_Sparse_Matrix_Blockwise(ArrayFunc mapArrayFunc, T* input1, T* in2_values, unsigned int *in2_row_offsets, unsigned int *in2_col_indices, T* output, unsigned int outSize, int indexOffset)
218 {
219  unsigned int i = blockIdx.x * blockDim.x + threadIdx.x;
220  unsigned int gridSize = blockDim.x*gridDim.x;
221 
222  if(i < outSize) //m_mapArrayFunc->CPU(&input1[0], &values[rowIdx], rowSize, &col_indices[rowIdx]);
223  {
224  int rowId = in2_row_offsets[i] - indexOffset;
225  int row2Id = in2_row_offsets[i+1] - indexOffset;
226  output[i] = mapArrayFunc.CU(&input1[0], &in2_values[rowId], (row2Id-rowId), &in2_col_indices[rowId]);
227  i += gridSize;
228  }
229 }
230 
231 
232 
233 
234 
239 }
240 
241 #endif
242 
243 #endif
244 
static std::string MapArrayKernel_CL("__kernel void MapArrayKernel_KERNELNAME(__global TYPE* input1, __global TYPE* input2, __global TYPE* output, unsigned int n)\n""{\n"" int i = get_global_id(0);\n"" unsigned int gridSize = get_local_size(0)*get_num_groups(0);\n"" while(i < n)\n"" {\n"" output[i] = FUNCTIONNAME(&input1[0], input2[i]);\n"" i += gridSize;\n"" }\n""}\n")
static std::string MapArrayKernel_CL_Sparse_Matrix_Blockwise("__kernel void MapArrayKernel_Sparse_Matrix_Blockwise_KERNELNAME(__global TYPE* input1, __global TYPE* in2_values, __global unsigned int *in2_row_offsets, __global unsigned int *in2_col_indices, __global TYPE* output, unsigned int outSize, int indexOffset, CONST_TYPE const1)\n""{\n"" int i = get_global_id(0);\n"" unsigned int gridSize = get_local_size(0)*get_num_groups(0);\n"" if(i < outSize)\n"" {\n"" int rowId = in2_row_offsets[i] - indexOffset;\n"" int row2Id = in2_row_offsets[i+1] - indexOffset;\n"" output[i] = FUNCTIONNAME(&input1[0], &in2_values[rowId], (row2Id-rowId), &in2_col_indices[rowId], const1);\n"" i += gridSize;\n"" }\n""}\n")
__global__ void MapArrayKernel_CU_Matrix_Blockwise(ArrayFunc mapArrayFunc, T *input1, T *input2, T *output, unsigned int outSize, int p2BlockSize)
Definition: maparray_kernels.h:198
static std::string MapArrayKernel_CL_Matrix_Blockwise("__kernel void MapArrayKernel_Matrix_Blockwise_KERNELNAME(__global TYPE* input1, __global TYPE* input2, __global TYPE* output, unsigned int outSize, int p2BlockSize, CONST_TYPE const1)\n""{\n"" int i = get_global_id(0);\n"" unsigned int gridSize = get_local_size(0)*get_num_groups(0);\n"" if(i < outSize)\n"" {\n"" output[i] = FUNCTIONNAME(&input1[0], &input2[i*p2BlockSize], const1);\n"" i += gridSize;\n"" }\n""}\n")
__global__ void MapArrayKernel_CU_Matrix(ArrayFunc mapArrayFunc, T *input1, T *input2, T *output, unsigned int n, unsigned int xsize, unsigned int ysize, unsigned int yoffset)
Definition: maparray_kernels.h:179
static std::string MapArrayKernel_CL_Matrix("__kernel void MapArrayKernel_Matrix_KERNELNAME(__global TYPE* input1, __global TYPE* input2, __global TYPE* output, unsigned int n, unsigned int xsize, unsigned int ysize, int yoffset, CONST_TYPE const1)\n""{\n"" int xindex = get_global_id(0);\n"" int yindex = get_global_id(1);\n"" int i = yindex*xsize + xindex; \n"" if(i < n && xindex<xsize && yindex <ysize)\n"" {\n"" output[i] = FUNCTIONNAME(&input1[0], input2[i], xindex, yindex+yoffset, const1);\n"" }\n""}\n")
__global__ void MapArrayKernel_CU(ArrayFunc mapArrayFunc, T *input1, T *input2, T *output, unsigned int n)
Definition: maparray_kernels.h:146
__global__ void MapArrayKernel_CU_Sparse_Matrix_Blockwise(ArrayFunc mapArrayFunc, T *input1, T *in2_values, unsigned int *in2_row_offsets, unsigned int *in2_col_indices, T *output, unsigned int outSize, int indexOffset)
Definition: maparray_kernels.h:217