24 #if !defined( BOLT_CL_BOLT_H )
25 #define BOLT_CL_BOLT_H
26 #define __CL_ENABLE_EXCEPTIONS
27 #define CL_USE_DEPRECATED_OPENCL_1_1_APIS
37 #include <boost/thread/mutex.hpp>
38 #include "bolt/BoltVersion.h"
42 #define PUSH_BACK_UNIQUE(CONTAINER, ELEMENT) \
43 if (std::find(CONTAINER.begin(), CONTAINER.end(), ELEMENT) == CONTAINER.end()) \
44 CONTAINER.push_back(ELEMENT);
71 extern const std::string binary_search_kernels;
72 extern const std::string copy_kernels;
73 extern const std::string count_kernels;
74 extern const std::string fill_kernels;
75 extern const std::string gather_kernels;
76 extern const std::string generate_kernels;
77 extern const std::string merge_kernels;
78 extern const std::string min_element_kernels;
79 extern const std::string reduce_kernels;
80 extern const std::string reduce_by_key_kernels;
81 extern const std::string scan_kernels;
82 extern const std::string scan_by_key_kernels;
83 extern const std::string scatter_kernels;
84 extern const std::string sort_kernels;
85 extern const std::string stablesort_kernels;
86 extern const std::string stablesort_by_key_kernels;
87 extern const std::string sort_uint_kernels;
88 extern const std::string sort_int_kernels;
89 extern const std::string sort_common_kernels;
90 extern const std::string sort_by_key_kernels;
91 extern const std::string sort_by_key_int_kernels;
92 extern const std::string sort_by_key_uint_kernels;
93 extern const std::string transform_kernels;
94 extern const std::string transform_reduce_kernels;
95 extern const std::string transform_scan_kernels;
108 virtual const ::std::string operator() (const ::std::vector< ::std::string >& typeNames)
const
109 {
return "Error; virtual function not overloaded"; }
112 void addKernelName(
const std::string& kernelName) { kernelNames.push_back(kernelName); }
115 const ::std::string name(
int kernelIndex )
const {
return kernelNames[ kernelIndex ]; }
118 size_t numKernels()
const {
return kernelNames.size(); }
121 const ::std::vector< ::std::string > getKernelNames()
const {
return kernelNames; }
124 ::std::vector< ::std::string > kernelNames;
130 extern std::string fileToString(
const std::string &fileName);
139 ::std::vector< ::cl::Kernel > getKernels(
141 const ::std::vector< ::std::string >& typeNames,
143 const ::std::vector< ::std::string >& typeDefinitions,
144 const std::string& baseKernelString,
145 const std::string& compileOptions =
""
154 void getVersion( cl_uint& major, cl_uint& minor, cl_uint& patch );
174 inline cl_int
V_OpenCL( cl_int res,
const std::string& msg,
size_t lineno )
183 tmp.append(
"V_OpenCL< " );
185 tmp.append(
" >: " );
188 throw ::cl::Error( res, tmp.c_str( ) );
194 #define V_OPENCL( status, message ) V_OpenCL( status, message, __LINE__ )
205 ::cl::Context context;
206 ::std::string device;
207 ::std::string compileOptions;
208 ::std::string kernelSource;
213 ::cl::Program program;
223 if( lhs.context() < rhs.context() )
225 else if( lhs.context() > rhs.context() )
230 comparison = lhs.device.compare(rhs.device);
236 else if( comparison > 0 )
243 comparison = lhs.compileOptions.compare(rhs.compileOptions);
249 else if( comparison > 0 )
258 comparison = lhs.kernelSource.compare(rhs.kernelSource);
262 else if( comparison > 0 )
273 typedef ::std::map< ProgramMapKey, ProgramMapValue, ProgramMapKeyComp > ProgramMap;
277 extern boost::mutex programMapMutex;
278 extern ProgramMap programMap;
283 #if defined( _WIN32 )
284 #define ALIGNED( bound ) __declspec( align( bound ) )
286 #define ALIGNED( bound ) __attribute__ ( (aligned( bound ) ) )