SkePU  1.2
 All Classes Namespaces Files Functions Variables 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, size_t n, CONST_TYPE const1)\n"
33  "{\n"
34  " size_t i = get_global_id(0);\n"
35  " size_t 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], const1);\n"
39  " i += gridSize;\n"
40  " }\n"
41  "}\n"
42 );
43 
44 
45 
46 
47 
53 static std::string MapArrayKernel_CL_Matrix_Blockwise(
54  "__kernel void MapArrayKernel_Matrix_Blockwise_KERNELNAME(__global TYPE* input1, __global TYPE* input2, __global TYPE* output, size_t outSize, size_t p2BlockSize, CONST_TYPE const1)\n"
55  "{\n"
56  " size_t i = get_global_id(0);\n"
57  " size_t gridSize = get_local_size(0)*get_num_groups(0);\n"
58  " if(i < outSize)\n"
59  " {\n"
60  " output[i] = FUNCTIONNAME(&input1[0], &input2[i*p2BlockSize], const1);\n"
61  " i += gridSize;\n"
62  " }\n"
63  "}\n"
64 );
65 
66 
73  "__kernel void MapArrayKernel_Sparse_Matrix_Blockwise_KERNELNAME(__global TYPE* input1, __global TYPE* in2_values, __global size_t *in2_row_offsets, __global size_t *in2_col_indices, __global TYPE* output, size_t outSize, size_t indexOffset, CONST_TYPE const1)\n"
74  "{\n"
75  " size_t i = get_global_id(0);\n"
76  " size_t gridSize = get_local_size(0)*get_num_groups(0);\n"
77  " if(i < outSize)\n"
78  " {\n"
79  " size_t rowId = in2_row_offsets[i] - indexOffset;\n"
80  " size_t row2Id = in2_row_offsets[i+1] - indexOffset;\n"
81  " output[i] = FUNCTIONNAME(&input1[0], &in2_values[rowId], (row2Id-rowId), &in2_col_indices[rowId], const1);\n"
82  " i += gridSize;\n"
83  " }\n"
84  "}\n"
85 );
86 
87 
93 static std::string MapArrayKernel_CL_Matrix(
94  "__kernel void MapArrayKernel_Matrix_KERNELNAME(__global TYPE* input1, __global TYPE* input2, __global TYPE* output, size_t n, size_t xsize, size_t ysize, size_t yoffset, CONST_TYPE const1)\n"
95  "{\n"
96  " size_t xindex = get_global_id(0);\n"
97  " size_t yindex = get_global_id(1);\n"
98  " size_t i = yindex*xsize + xindex; \n"
99  " if(i < n && xindex<xsize && yindex <ysize)\n"
100  " {\n"
101  " output[i] = FUNCTIONNAME(&input1[0], input2[i], xindex, yindex+yoffset, const1);\n"
102  " }\n"
103  "}\n"
104 );
105 
106 
111 }
112 
113 #endif
114 
115 #ifdef SKEPU_CUDA
116 
117 namespace skepu
118 {
119 
132 template <typename in,typename out, typename ArrayFunc>
133 __global__ void MapArrayKernel_VAR(ArrayFunc mapArrayFunc, in* input,MultiVector P, out* output, size_t n)
134 {
135  size_t i = blockIdx.x * blockDim.x + threadIdx.x;
136  size_t gridSize = blockDim.x*gridDim.x;
137 
138  while(i < n)
139  {
140  output[i] = mapArrayFunc.CU(input[i], P);
141  i += gridSize;
142  }
143 }
144 
150 template <typename T, typename ArrayFunc>
151 __global__ void MapArrayKernel_CU(ArrayFunc mapArrayFunc, T* input1, T* input2, T* output, size_t n)
152 {
153  size_t i = blockIdx.x * blockDim.x + threadIdx.x;
154  size_t gridSize = blockDim.x*gridDim.x;
155 
156  while(i < n)
157  {
158  output[i] = mapArrayFunc.CU(&input1[0], input2[i]);
159  i += gridSize;
160  }
161 }
162 
163 
164 
165 
171 template <typename T, typename ArrayFunc>
172 __global__ void MapArrayKernel_CU_Matrix_Blockwise(ArrayFunc mapArrayFunc, T* input1, T* input2, T* output, size_t outSize, size_t p2BlockSize)
173 {
174  size_t i = blockIdx.x * blockDim.x + threadIdx.x;
175  size_t gridSize = blockDim.x*gridDim.x;
176 
177  if(i < outSize)
178  {
179  output[i] = mapArrayFunc.CU(&input1[0], &input2[i*p2BlockSize]);
180  i += gridSize;
181  }
182 }
183 
184 
190 template <typename T, typename ArrayFunc>
191 __global__ void MapArrayKernel_CU_Sparse_Matrix_Blockwise(ArrayFunc mapArrayFunc, T* input1, T* in2_values, size_t *in2_row_offsets, size_t *in2_col_indices, T* output, size_t outSize, size_t indexOffset)
192 {
193  size_t i = blockIdx.x * blockDim.x + threadIdx.x;
194  size_t gridSize = blockDim.x*gridDim.x;
195 
196  if(i < outSize) //m_mapArrayFunc->CPU(&input1[0], &values[rowIdx], rowSize, &col_indices[rowIdx]);
197  {
198  size_t rowId = in2_row_offsets[i] - indexOffset;
199  size_t row2Id = in2_row_offsets[i+1] - indexOffset;
200  output[i] = mapArrayFunc.CU(&input1[0], &in2_values[rowId], (row2Id-rowId), &in2_col_indices[rowId]);
201  i += gridSize;
202  }
203 }
204 
205 
206 
212 template <typename T, typename ArrayFunc>
213 __global__ void MapArrayKernel_CU_Matrix(ArrayFunc mapArrayFunc, T* input1, T* input2, T* output, size_t n, size_t xsize, size_t ysize, size_t yoffset)
214 {
215  size_t xindex = blockIdx.x * blockDim.x + threadIdx.x;
216  size_t yindex = blockIdx.y * blockDim.y + threadIdx.y;
217  size_t outaddr = yindex*xsize + xindex; //(gridDim.x * blockDim.x) * yindex + xindex;
218 
219  if(outaddr < n && xindex<xsize && yindex <ysize)
220  {
221  output[outaddr] = mapArrayFunc.CU(&input1[0], input2[outaddr], xindex, yindex+yoffset);
222  }
223 }
224 
225 
226 
231 }
232 
233 #endif
234 
235 #endif
236 
237 
static std::string MapArrayKernel_CL("__kernel void MapArrayKernel_KERNELNAME(__global TYPE* input1, __global TYPE* input2, __global TYPE* output, size_t n, CONST_TYPE const1)\n""{\n"" size_t i = get_global_id(0);\n"" size_t gridSize = get_local_size(0)*get_num_groups(0);\n"" while(i < n)\n"" {\n"" output[i] = FUNCTIONNAME(&input1[0], input2[i], const1);\n"" i += gridSize;\n"" }\n""}\n")
__global__ void MapArrayKernel_CU_Matrix_Blockwise(ArrayFunc mapArrayFunc, T *input1, T *input2, T *output, size_t outSize, size_t p2BlockSize)
Definition: maparray_kernels.h:172
static std::string MapArrayKernel_CL_Matrix("__kernel void MapArrayKernel_Matrix_KERNELNAME(__global TYPE* input1, __global TYPE* input2, __global TYPE* output, size_t n, size_t xsize, size_t ysize, size_t yoffset, CONST_TYPE const1)\n""{\n"" size_t xindex = get_global_id(0);\n"" size_t yindex = get_global_id(1);\n"" size_t 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")
static std::string MapArrayKernel_CL_Matrix_Blockwise("__kernel void MapArrayKernel_Matrix_Blockwise_KERNELNAME(__global TYPE* input1, __global TYPE* input2, __global TYPE* output, size_t outSize, size_t p2BlockSize, CONST_TYPE const1)\n""{\n"" size_t i = get_global_id(0);\n"" size_t 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_Sparse_Matrix_Blockwise(ArrayFunc mapArrayFunc, T *input1, T *in2_values, size_t *in2_row_offsets, size_t *in2_col_indices, T *output, size_t outSize, size_t indexOffset)
Definition: maparray_kernels.h:191
static std::string MapArrayKernel_CL_Sparse_Matrix_Blockwise("__kernel void MapArrayKernel_Sparse_Matrix_Blockwise_KERNELNAME(__global TYPE* input1, __global TYPE* in2_values, __global size_t *in2_row_offsets, __global size_t *in2_col_indices, __global TYPE* output, size_t outSize, size_t indexOffset, CONST_TYPE const1)\n""{\n"" size_t i = get_global_id(0);\n"" size_t gridSize = get_local_size(0)*get_num_groups(0);\n"" if(i < outSize)\n"" {\n"" size_t rowId = in2_row_offsets[i] - indexOffset;\n"" size_t 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(ArrayFunc mapArrayFunc, T *input1, T *input2, T *output, size_t n)
Definition: maparray_kernels.h:151
__global__ void MapArrayKernel_CU_Matrix(ArrayFunc mapArrayFunc, T *input1, T *input2, T *output, size_t n, size_t xsize, size_t ysize, size_t yoffset)
Definition: maparray_kernels.h:213