SkePU  1.2
 All Classes Namespaces Files Functions Variables Enumerations Friends Macros Groups Pages
map_kernels.h
Go to the documentation of this file.
1 
5 #ifndef MAP_KERNELS_H
6 #define MAP_KERNELS_H
7 
8 #ifdef SKEPU_OPENCL
9 
10 #include <string>
11 
12 namespace skepu
13 {
14 
30 static std::string UnaryMapKernel_CL(
31  "__kernel void UnaryMapKernel_KERNELNAME(__global TYPE* input, __global TYPE* output, size_t numElements, CONST_TYPE const1)\n"
32  "{\n"
33  " int i = get_global_id(0);\n"
34  " size_t gridSize = get_local_size(0)*get_num_groups(0);\n"
35  " while(i < numElements)\n"
36  " {\n"
37  " output[i] = FUNCTIONNAME(input[i], const1);\n"
38  " i += gridSize;\n"
39  " }\n"
40  "}\n"
41 );
42 
47 static std::string BinaryMapKernel_CL(
48  "__kernel void BinaryMapKernel_KERNELNAME(__global TYPE* input1, __global TYPE* input2, __global TYPE* output, size_t n, CONST_TYPE const1)\n"
49  "{\n"
50  " int i = get_global_id(0);\n"
51  " size_t gridSize = get_local_size(0)*get_num_groups(0);\n"
52  " while(i < n)\n"
53  " {\n"
54  " output[i] = FUNCTIONNAME(input1[i], input2[i], const1);\n"
55  " i += gridSize;\n"
56  " }\n"
57  "}\n"
58 );
59 
64 static std::string TrinaryMapKernel_CL(
65  "__kernel void TrinaryMapKernel_KERNELNAME(__global TYPE* input1, __global TYPE* input2, __global TYPE* input3, __global TYPE* output, size_t n, CONST_TYPE const1)\n"
66  "{\n"
67  " int i = get_global_id(0);\n"
68  " size_t gridSize = get_local_size(0)*get_num_groups(0);\n"
69  " while(i < n)\n"
70  " {\n"
71  " output[i] = FUNCTIONNAME(input1[i], input2[i], input3[i], const1);\n"
72  " i += gridSize;\n"
73  " }\n"
74  "}\n"
75 );
76 
81 }
82 
83 #endif
84 
85 #ifdef SKEPU_CUDA
86 
87 namespace skepu
88 {
89 
105 template <typename T, typename UnaryFunc>
106 __global__ void MapKernelUnary_CU(UnaryFunc mapFunc, T* input, T* output, size_t n)
107 {
108  size_t i = blockIdx.x * blockDim.x + threadIdx.x;
109  size_t gridSize = blockDim.x*gridDim.x;
110 
111  while(i < n)
112  {
113  output[i] = mapFunc.CU(input[i]);
114  i += gridSize;
115  }
116 }
117 
122 template <typename T, typename BinaryFunc>
123 __global__ void MapKernelBinary_CU(BinaryFunc mapFunc, T* input1, T* input2, T* output, size_t n)
124 {
125  size_t i = blockIdx.x * blockDim.x + threadIdx.x;
126  size_t gridSize = blockDim.x*gridDim.x;
127 
128  while(i < n)
129  {
130  output[i] = mapFunc.CU(input1[i], input2[i]);
131  i += gridSize;
132  }
133 }
134 
139 template <typename T, typename TrinaryFunc>
140 __global__ void MapKernelTrinary_CU(TrinaryFunc mapFunc, T* input1, T* input2, T* input3, T* output, size_t n)
141 {
142  size_t i = blockIdx.x * blockDim.x + threadIdx.x;
143  size_t gridSize = blockDim.x*gridDim.x;
144 
145  while(i < n)
146  {
147  output[i] = mapFunc.CU(input1[i], input2[i], input3[i]);
148  i += gridSize;
149  }
150 }
151 
156 }
157 
158 #endif
159 
160 #endif
161 
162 
static std::string TrinaryMapKernel_CL("__kernel void TrinaryMapKernel_KERNELNAME(__global TYPE* input1, __global TYPE* input2, __global TYPE* input3, __global TYPE* output, size_t n, CONST_TYPE const1)\n""{\n"" int 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[i], input2[i], input3[i], const1);\n"" i += gridSize;\n"" }\n""}\n")
__global__ void MapKernelBinary_CU(BinaryFunc mapFunc, T *input1, T *input2, T *output, size_t n)
Definition: map_kernels.h:123
static std::string BinaryMapKernel_CL("__kernel void BinaryMapKernel_KERNELNAME(__global TYPE* input1, __global TYPE* input2, __global TYPE* output, size_t n, CONST_TYPE const1)\n""{\n"" int 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[i], input2[i], const1);\n"" i += gridSize;\n"" }\n""}\n")
__global__ void MapKernelUnary_CU(UnaryFunc mapFunc, T *input, T *output, size_t n)
Definition: map_kernels.h:106
__global__ void MapKernelTrinary_CU(TrinaryFunc mapFunc, T *input1, T *input2, T *input3, T *output, size_t n)
Definition: map_kernels.h:140
static std::string UnaryMapKernel_CL("__kernel void UnaryMapKernel_KERNELNAME(__global TYPE* input, __global TYPE* output, size_t numElements, CONST_TYPE const1)\n""{\n"" int i = get_global_id(0);\n"" size_t gridSize = get_local_size(0)*get_num_groups(0);\n"" while(i < numElements)\n"" {\n"" output[i] = FUNCTIONNAME(input[i], const1);\n"" i += gridSize;\n"" }\n""}\n")