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_float_kernels;
90 extern const std::string sort_common_kernels;
91 extern const std::string sort_by_key_kernels;
92 extern const std::string sort_by_key_int_kernels;
93 extern const std::string sort_by_key_uint_kernels;
94 extern const std::string transform_kernels;
95 extern const std::string transform_reduce_kernels;
96 extern const std::string transform_scan_kernels;
109 virtual const ::std::string operator() (const ::std::vector< ::std::string >& typeNames)
const
110 {
return "Error; virtual function not overloaded"; }
113 void addKernelName(
const std::string& kernelName) { kernelNames.push_back(kernelName); }
116 const ::std::string name(
int kernelIndex )
const {
return kernelNames[ kernelIndex ]; }
119 size_t numKernels()
const {
return kernelNames.size(); }
122 const ::std::vector< ::std::string > getKernelNames()
const {
return kernelNames; }
125 ::std::vector< ::std::string > kernelNames;
131 extern std::string fileToString(
const std::string &fileName);
140 ::std::vector< ::cl::Kernel > getKernels(
142 const ::std::vector< ::std::string >& typeNames,
144 const ::std::vector< ::std::string >& typeDefinitions,
145 const std::string& baseKernelString,
146 const std::string& compileOptions =
""
155 void getVersion( cl_uint& major, cl_uint& minor, cl_uint& patch );
175 inline cl_int
V_OpenCL( cl_int res,
const std::string& msg,
size_t lineno )
184 tmp.append(
"V_OpenCL< " );
186 tmp.append(
" >: " );
189 throw ::cl::Error( res, tmp.c_str( ) );
195 #define V_OPENCL( status, message ) V_OpenCL( status, message, __LINE__ )
206 ::cl::Context context;
207 ::std::string device;
208 ::std::string compileOptions;
209 ::std::string kernelSource;
214 ::cl::Program program;
224 if( lhs.context() < rhs.context() )
226 else if( lhs.context() > rhs.context() )
231 comparison = lhs.device.compare(rhs.device);
237 else if( comparison > 0 )
244 comparison = lhs.compileOptions.compare(rhs.compileOptions);
250 else if( comparison > 0 )
259 comparison = lhs.kernelSource.compare(rhs.kernelSource);
263 else if( comparison > 0 )
274 typedef ::std::map< ProgramMapKey, ProgramMapValue, ProgramMapKeyComp > ProgramMap;
278 extern boost::mutex programMapMutex;
279 extern ProgramMap programMap;
284 #if defined( _WIN32 )
285 #define ALIGNED( bound ) __declspec( align( bound ) )
287 #define ALIGNED( bound ) __attribute__ ( (aligned( bound ) ) )