cl.hpp 110 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020
  1. /*******************************************************************************
  2. * Copyright (c) 2008-2010 The Khronos Group Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and/or associated documentation files (the
  6. * "Materials"), to deal in the Materials without restriction, including
  7. * without limitation the rights to use, copy, modify, merge, publish,
  8. * distribute, sublicense, and/or sell copies of the Materials, and to
  9. * permit persons to whom the Materials are furnished to do so, subject to
  10. * the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included
  13. * in all copies or substantial portions of the Materials.
  14. *
  15. * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  18. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  19. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  20. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  21. * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
  22. ******************************************************************************/
  23. #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
  24. #if __GNUC__ >= 6
  25. #pragma GCC diagnostic ignored "-Wignored-attributes"
  26. #endif
  27. /*! \file
  28. *
  29. * \brief C++ bindings for OpenCL 1.0 (rev 48) and OpenCL 1.1 (rev 33)
  30. * \author Benedict R. Gaster and Laurent Morichetti
  31. *
  32. * Additions and fixes from Brian Cole, March 3rd 2010.
  33. *
  34. * \version 1.1
  35. * \date June 2010
  36. *
  37. * Optional extension support
  38. *
  39. * cl
  40. * cl_ext_device_fission
  41. * #define USE_CL_DEVICE_FISSION
  42. */
  43. /*! \mainpage
  44. * \section intro Introduction
  45. * For many large applications C++ is the language of choice and so it seems
  46. * reasonable to define C++ bindings for OpenCL.
  47. *
  48. *
  49. * The interface is contained with a single C++ header file \em cl.hpp and all
  50. * definitions are contained within the namespace \em cl. There is no additional
  51. * requirement to include \em cl.h and to use either the C++ or original C
  52. * bindings it is enough to simply include \em cl.hpp.
  53. *
  54. * The bindings themselves are lightweight and correspond closely to the
  55. * underlying C API. Using the C++ bindings introduces no additional execution
  56. * overhead.
  57. *
  58. * For detail documentation on the bindings see:
  59. *
  60. * The OpenCL C++ Wrapper API 1.1 (revision 04)
  61. * http://www.khronos.org/registry/cl/specs/opencl-cplusplus-1.1.pdf
  62. *
  63. * \section example Example
  64. *
  65. * The following example shows a general use case for the C++
  66. * bindings, including support for the optional exception feature and
  67. * also the supplied vector and string classes, see following sections for
  68. * decriptions of these features.
  69. *
  70. * \code
  71. * #define __CL_ENABLE_EXCEPTIONS
  72. *
  73. * #if defined(__APPLE__) || defined(__MACOSX)
  74. * #include <OpenCL/cl.hpp>
  75. * #else
  76. * #include <CL/cl.hpp>
  77. * #endif
  78. * #include <cstdio>
  79. * #include <cstdlib>
  80. * #include <iostream>
  81. *
  82. * const char * helloStr = "__kernel void "
  83. * "hello(void) "
  84. * "{ "
  85. * " "
  86. * "} ";
  87. *
  88. * int
  89. * main(void)
  90. * {
  91. * cl_int err = CL_SUCCESS;
  92. * try {
  93. *
  94. * std::vector<cl::Platform> platforms;
  95. * cl::Platform::get(&platforms);
  96. * if (platforms.size() == 0) {
  97. * std::cout << "Platform size 0\n";
  98. * return -1;
  99. * }
  100. *
  101. * cl_context_properties properties[] =
  102. * { CL_CONTEXT_PLATFORM, (cl_context_properties)(platforms[0])(), 0};
  103. * cl::Context context(CL_DEVICE_TYPE_CPU, properties);
  104. *
  105. * std::vector<cl::Device> devices = context.getInfo<CL_CONTEXT_DEVICES>();
  106. *
  107. * cl::Program::Sources source(1,
  108. * std::make_pair(helloStr,strlen(helloStr)));
  109. * cl::Program program_ = cl::Program(context, source);
  110. * program_.build(devices);
  111. *
  112. * cl::Kernel kernel(program_, "hello", &err);
  113. *
  114. * cl::Event event;
  115. * cl::CommandQueue queue(context, devices[0], 0, &err);
  116. * queue.enqueueNDRangeKernel(
  117. * kernel,
  118. * cl::NullRange,
  119. * cl::NDRange(4,4),
  120. * cl::NullRange,
  121. * NULL,
  122. * &event);
  123. *
  124. * event.wait();
  125. * }
  126. * catch (cl::Error err) {
  127. * std::cerr
  128. * << "ERROR: "
  129. * << err.what()
  130. * << "("
  131. * << err.err()
  132. * << ")"
  133. * << std::endl;
  134. * }
  135. *
  136. * return EXIT_SUCCESS;
  137. * }
  138. *
  139. * \endcode
  140. *
  141. */
  142. #ifndef CL_HPP_
  143. #define CL_HPP_
  144. #ifdef _WIN32
  145. #include <windows.h>
  146. #include <malloc.h>
  147. #if defined(USE_DX_INTEROP)
  148. #include <CL/cl_d3d10.h>
  149. #endif
  150. #endif // _WIN32
  151. //
  152. #if defined(USE_CL_DEVICE_FISSION)
  153. #include <CL/cl_ext.h>
  154. #endif
  155. #if defined(__APPLE__) || defined(__MACOSX)
  156. #include <OpenGL/OpenGL.h>
  157. #include <OpenCL/opencl.h>
  158. #else
  159. #include <GL/gl.h>
  160. #include <CL/opencl.h>
  161. #endif // !__APPLE__
  162. #if !defined(CL_CALLBACK)
  163. #define CL_CALLBACK
  164. #endif //CL_CALLBACK
  165. #include <utility>
  166. #if !defined(__NO_STD_VECTOR)
  167. #include <vector>
  168. #endif
  169. #if !defined(__NO_STD_STRING)
  170. #include <string>
  171. #endif
  172. #if defined(linux) || defined(__APPLE__) || defined(__MACOSX)
  173. # include <alloca.h>
  174. #endif // linux
  175. #include <cstring>
  176. /*! \namespace cl
  177. *
  178. * \brief The OpenCL C++ bindings are defined within this namespace.
  179. *
  180. */
  181. namespace cl {
  182. #define __INIT_CL_EXT_FCN_PTR(name) \
  183. if(!pfn_##name) { \
  184. pfn_##name = (PFN_##name) \
  185. clGetExtensionFunctionAddress(#name); \
  186. if(!pfn_##name) { \
  187. } \
  188. }
  189. class Program;
  190. class Device;
  191. class Context;
  192. class CommandQueue;
  193. class Memory;
  194. #if defined(__CL_ENABLE_EXCEPTIONS)
  195. #include <exception>
  196. /*! \class Error
  197. * \brief Exception class
  198. */
  199. class Error : public std::exception
  200. {
  201. private:
  202. cl_int err_;
  203. const char * errStr_;
  204. public:
  205. /*! Create a new CL error exception for a given error code
  206. * and corresponding message.
  207. */
  208. Error(cl_int err, const char * errStr = NULL) : err_(err), errStr_(errStr)
  209. {}
  210. ~Error() throw() {}
  211. /*! \brief Get error string associated with exception
  212. *
  213. * \return A memory pointer to the error message string.
  214. */
  215. virtual const char * what() const throw ()
  216. {
  217. if (errStr_ == NULL) {
  218. return "empty";
  219. }
  220. else {
  221. return errStr_;
  222. }
  223. }
  224. /*! \brief Get error code associated with exception
  225. *
  226. * \return The error code.
  227. */
  228. cl_int err(void) const { return err_; }
  229. };
  230. #define __ERR_STR(x) #x
  231. #else
  232. #define __ERR_STR(x) NULL
  233. #endif // __CL_ENABLE_EXCEPTIONS
  234. //! \cond DOXYGEN_DETAIL
  235. #if !defined(__CL_USER_OVERRIDE_ERROR_STRINGS)
  236. #define __GET_DEVICE_INFO_ERR __ERR_STR(clgetDeviceInfo)
  237. #define __GET_PLATFORM_INFO_ERR __ERR_STR(clGetPlatformInfo)
  238. #define __GET_DEVICE_IDS_ERR __ERR_STR(clGetDeviceIDs)
  239. #define __GET_PLATFORM_IDS_ERR __ERR_STR(clGetPlatformIDs)
  240. #define __GET_CONTEXT_INFO_ERR __ERR_STR(clGetContextInfo)
  241. #define __GET_EVENT_INFO_ERR __ERR_STR(clGetEventInfo)
  242. #define __GET_EVENT_PROFILE_INFO_ERR __ERR_STR(clGetEventProfileInfo)
  243. #define __GET_MEM_OBJECT_INFO_ERR __ERR_STR(clGetMemObjectInfo)
  244. #define __GET_IMAGE_INFO_ERR __ERR_STR(clGetImageInfo)
  245. #define __GET_SAMPLER_INFO_ERR __ERR_STR(clGetSamplerInfo)
  246. #define __GET_KERNEL_INFO_ERR __ERR_STR(clGetKernelInfo)
  247. #define __GET_KERNEL_WORK_GROUP_INFO_ERR __ERR_STR(clGetKernelWorkGroupInfo)
  248. #define __GET_PROGRAM_INFO_ERR __ERR_STR(clGetProgramInfo)
  249. #define __GET_PROGRAM_BUILD_INFO_ERR __ERR_STR(clGetProgramBuildInfo)
  250. #define __GET_COMMAND_QUEUE_INFO_ERR __ERR_STR(clGetCommandQueueInfo)
  251. #define __CREATE_CONTEXT_FROM_TYPE_ERR __ERR_STR(clCreateContextFromType)
  252. #define __GET_SUPPORTED_IMAGE_FORMATS_ERR __ERR_STR(clGetSupportedImageFormats)
  253. #define __CREATE_BUFFER_ERR __ERR_STR(clCreateBuffer)
  254. #define __CREATE_SUBBUFFER_ERR __ERR_STR(clCreateSubBuffer)
  255. #define __CREATE_GL_BUFFER_ERR __ERR_STR(clCreateFromGLBuffer)
  256. #define __GET_GL_OBJECT_INFO_ERR __ERR_STR(clGetGLObjectInfo)
  257. #define __CREATE_IMAGE2D_ERR __ERR_STR(clCreateImage2D)
  258. #define __CREATE_IMAGE3D_ERR __ERR_STR(clCreateImage3D)
  259. #define __CREATE_SAMPLER_ERR __ERR_STR(clCreateSampler)
  260. #define __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR __ERR_STR(clSetMemObjectDestructorCallback)
  261. #define __CREATE_USER_EVENT_ERR __ERR_STR(clCreateUserEvent)
  262. #define __SET_USER_EVENT_STATUS_ERR __ERR_STR(clSetUserEventStatus)
  263. #define __SET_EVENT_CALLBACK_ERR __ERR_STR(clSetEventCallback)
  264. #define __WAIT_FOR_EVENTS_ERR __ERR_STR(clWaitForEvents)
  265. #define __CREATE_KERNEL_ERR __ERR_STR(clCreateKernel)
  266. #define __SET_KERNEL_ARGS_ERR __ERR_STR(clSetKernelArg)
  267. #define __CREATE_PROGRAM_WITH_SOURCE_ERR __ERR_STR(clCreateProgramWithSource)
  268. #define __CREATE_PROGRAM_WITH_BINARY_ERR __ERR_STR(clCreateProgramWithBinary)
  269. #define __BUILD_PROGRAM_ERR __ERR_STR(clBuildProgram)
  270. #define __CREATE_KERNELS_IN_PROGRAM_ERR __ERR_STR(clCreateKernelsInProgram)
  271. #define __CREATE_COMMAND_QUEUE_ERR __ERR_STR(clCreateCommandQueue)
  272. #define __SET_COMMAND_QUEUE_PROPERTY_ERR __ERR_STR(clSetCommandQueueProperty)
  273. #define __ENQUEUE_READ_BUFFER_ERR __ERR_STR(clEnqueueReadBuffer)
  274. #define __ENQUEUE_READ_BUFFER_RECT_ERR __ERR_STR(clEnqueueReadBufferRect)
  275. #define __ENQUEUE_WRITE_BUFFER_ERR __ERR_STR(clEnqueueWriteBuffer)
  276. #define __ENQUEUE_WRITE_BUFFER_RECT_ERR __ERR_STR(clEnqueueWriteBufferRect)
  277. #define __ENQEUE_COPY_BUFFER_ERR __ERR_STR(clEnqueueCopyBuffer)
  278. #define __ENQEUE_COPY_BUFFER_RECT_ERR __ERR_STR(clEnqueueCopyBufferRect)
  279. #define __ENQUEUE_READ_IMAGE_ERR __ERR_STR(clEnqueueReadImage)
  280. #define __ENQUEUE_WRITE_IMAGE_ERR __ERR_STR(clEnqueueWriteImage)
  281. #define __ENQUEUE_COPY_IMAGE_ERR __ERR_STR(clEnqueueCopyImage)
  282. #define __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR __ERR_STR(clEnqueueCopyImageToBuffer)
  283. #define __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR __ERR_STR(clEnqueueCopyBufferToImage)
  284. #define __ENQUEUE_MAP_BUFFER_ERR __ERR_STR(clEnqueueMapBuffer)
  285. #define __ENQUEUE_MAP_IMAGE_ERR __ERR_STR(clEnqueueMapImage)
  286. #define __ENQUEUE_UNMAP_MEM_OBJECT_ERR __ERR_STR(clEnqueueUnMapMemObject)
  287. #define __ENQUEUE_NDRANGE_KERNEL_ERR __ERR_STR(clEnqueueNDRangeKernel)
  288. #define __ENQUEUE_TASK_ERR __ERR_STR(clEnqueueTask)
  289. #define __ENQUEUE_NATIVE_KERNEL __ERR_STR(clEnqueueNativeKernel)
  290. #define __ENQUEUE_MARKER_ERR __ERR_STR(clEnqueueMarker)
  291. #define __ENQUEUE_WAIT_FOR_EVENTS_ERR __ERR_STR(clEnqueueWaitForEvents)
  292. #define __ENQUEUE_BARRIER_ERR __ERR_STR(clEnqueueBarrier)
  293. #define __ENQUEUE_ACQUIRE_GL_ERR __ERR_STR(clEnqueueAcquireGLObjects)
  294. #define __ENQUEUE_RELEASE_GL_ERR __ERR_STR(clEnqueueReleaseGLObjects)
  295. #define __UNLOAD_COMPILER_ERR __ERR_STR(clUnloadCompiler)
  296. #define __FLUSH_ERR __ERR_STR(clFlush)
  297. #define __FINISH_ERR __ERR_STR(clFinish)
  298. #define __CREATE_SUB_DEVICES __ERR_STR(clCreateSubDevicesEXT)
  299. #endif // __CL_USER_OVERRIDE_ERROR_STRINGS
  300. //! \endcond
  301. /*! \class string
  302. * \brief Simple string class, that provides a limited subset of std::string
  303. * functionality but avoids many of the issues that come with that class.
  304. */
  305. class string
  306. {
  307. private:
  308. ::size_t size_;
  309. char * str_;
  310. public:
  311. string(void) : size_(0), str_(NULL)
  312. {
  313. }
  314. string(char * str, ::size_t size) :
  315. size_(size),
  316. str_(NULL)
  317. {
  318. str_ = new char[size_+1];
  319. if (str_ != NULL) {
  320. memcpy(str_, str, size_ * sizeof(char));
  321. str_[size_] = '\0';
  322. }
  323. else {
  324. size_ = 0;
  325. }
  326. }
  327. string(char * str) :
  328. str_(NULL)
  329. {
  330. size_= ::strlen(str);
  331. str_ = new char[size_ + 1];
  332. if (str_ != NULL) {
  333. memcpy(str_, str, (size_ + 1) * sizeof(char));
  334. }
  335. else {
  336. size_ = 0;
  337. }
  338. }
  339. string& operator=(const string& rhs)
  340. {
  341. if (this == &rhs) {
  342. return *this;
  343. }
  344. if (rhs.size_ == 0 || rhs.str_ == NULL) {
  345. size_ = 0;
  346. str_ = NULL;
  347. }
  348. else {
  349. size_ = rhs.size_;
  350. str_ = new char[size_ + 1];
  351. if (str_ != NULL) {
  352. memcpy(str_, rhs.str_, (size_ + 1) * sizeof(char));
  353. }
  354. else {
  355. size_ = 0;
  356. }
  357. }
  358. return *this;
  359. }
  360. string(const string& rhs)
  361. {
  362. *this = rhs;
  363. }
  364. ~string()
  365. {
  366. if (str_ != NULL) {
  367. delete[] str_;
  368. }
  369. }
  370. ::size_t size(void) const { return size_; }
  371. ::size_t length(void) const { return size(); }
  372. const char * c_str(void) const { return (str_) ? str_ : "";}
  373. };
  374. #if !defined(__USE_DEV_STRING) && !defined(__NO_STD_STRING)
  375. #include <string>
  376. typedef std::string STRING_CLASS;
  377. #elif !defined(__USE_DEV_STRING)
  378. typedef cl::string STRING_CLASS;
  379. #endif
  380. #if !defined(__USE_DEV_VECTOR) && !defined(__NO_STD_VECTOR)
  381. #include <vector>
  382. #define VECTOR_CLASS std::vector
  383. #elif !defined(__USE_DEV_VECTOR)
  384. #define VECTOR_CLASS cl::vector
  385. #endif
  386. #if !defined(__MAX_DEFAULT_VECTOR_SIZE)
  387. #define __MAX_DEFAULT_VECTOR_SIZE 10
  388. #endif
  389. /*! \class vector
  390. * \brief Fixed sized vector implementation that mirroring
  391. * std::vector functionality.
  392. */
  393. template <typename T, unsigned int N = __MAX_DEFAULT_VECTOR_SIZE>
  394. class vector
  395. {
  396. private:
  397. T data_[N];
  398. unsigned int size_;
  399. bool empty_;
  400. public:
  401. vector() :
  402. size_(-1),
  403. empty_(true)
  404. {}
  405. ~vector() {}
  406. unsigned int size(void) const
  407. {
  408. return size_ + 1;
  409. }
  410. void clear()
  411. {
  412. size_ = -1;
  413. empty_ = true;
  414. }
  415. void push_back (const T& x)
  416. {
  417. if (size() < N) {
  418. size_++;
  419. data_[size_] = x;
  420. empty_ = false;
  421. }
  422. }
  423. void pop_back(void)
  424. {
  425. if (!empty_) {
  426. data_[size_].~T();
  427. size_--;
  428. if (size_ == -1) {
  429. empty_ = true;
  430. }
  431. }
  432. }
  433. vector(const vector<T, N>& vec) :
  434. size_(vec.size_),
  435. empty_(vec.empty_)
  436. {
  437. if (!empty_) {
  438. memcpy(&data_[0], &vec.data_[0], size() * sizeof(T));
  439. }
  440. }
  441. vector(unsigned int size, const T& val = T()) :
  442. size_(-1),
  443. empty_(true)
  444. {
  445. for (unsigned int i = 0; i < size; i++) {
  446. push_back(val);
  447. }
  448. }
  449. vector<T, N>& operator=(const vector<T, N>& rhs)
  450. {
  451. if (this == &rhs) {
  452. return *this;
  453. }
  454. size_ = rhs.size_;
  455. empty_ = rhs.empty_;
  456. if (!empty_) {
  457. memcpy(&data_[0], &rhs.data_[0], size() * sizeof(T));
  458. }
  459. return *this;
  460. }
  461. bool operator==(vector<T,N> &vec)
  462. {
  463. if (empty_ && vec.empty_) {
  464. return true;
  465. }
  466. if (size() != vec.size()) {
  467. return false;
  468. }
  469. return memcmp(&data_[0], &vec.data_[0], size() * sizeof(T)) == 0 ? true : false;
  470. }
  471. operator T* () { return data_; }
  472. operator const T* () const { return data_; }
  473. bool empty (void) const
  474. {
  475. return empty_;
  476. }
  477. unsigned int max_size (void) const
  478. {
  479. return N;
  480. }
  481. unsigned int capacity () const
  482. {
  483. return sizeof(T) * N;
  484. }
  485. T& operator[](int index)
  486. {
  487. return data_[index];
  488. }
  489. T operator[](int index) const
  490. {
  491. return data_[index];
  492. }
  493. template<class I>
  494. void assign(I start, I end)
  495. {
  496. clear();
  497. while(start < end) {
  498. push_back(*start);
  499. start++;
  500. }
  501. }
  502. /*! \class iterator
  503. * \brief Iterator class for vectors
  504. */
  505. class iterator
  506. {
  507. private:
  508. vector<T,N> vec_;
  509. int index_;
  510. bool initialized_;
  511. public:
  512. iterator(void) :
  513. index_(-1),
  514. initialized_(false)
  515. {
  516. index_ = -1;
  517. initialized_ = false;
  518. }
  519. ~iterator(void) {}
  520. static iterator begin(vector<T,N> &vec)
  521. {
  522. iterator i;
  523. if (!vec.empty()) {
  524. i.index_ = 0;
  525. }
  526. i.vec_ = vec;
  527. i.initialized_ = true;
  528. return i;
  529. }
  530. static iterator end(vector<T,N> &vec)
  531. {
  532. iterator i;
  533. if (!vec.empty()) {
  534. i.index_ = vec.size();
  535. }
  536. i.vec_ = vec;
  537. i.initialized_ = true;
  538. return i;
  539. }
  540. bool operator==(iterator i)
  541. {
  542. return ((vec_ == i.vec_) &&
  543. (index_ == i.index_) &&
  544. (initialized_ == i.initialized_));
  545. }
  546. bool operator!=(iterator i)
  547. {
  548. return (!(*this==i));
  549. }
  550. void operator++()
  551. {
  552. index_++;
  553. }
  554. void operator++(int x)
  555. {
  556. index_ += x;
  557. }
  558. void operator--()
  559. {
  560. index_--;
  561. }
  562. void operator--(int x)
  563. {
  564. index_ -= x;
  565. }
  566. T operator *()
  567. {
  568. return vec_[index_];
  569. }
  570. };
  571. iterator begin(void)
  572. {
  573. return iterator::begin(*this);
  574. }
  575. iterator end(void)
  576. {
  577. return iterator::end(*this);
  578. }
  579. T& front(void)
  580. {
  581. return data_[0];
  582. }
  583. T& back(void)
  584. {
  585. return data_[size_];
  586. }
  587. const T& front(void) const
  588. {
  589. return data_[0];
  590. }
  591. const T& back(void) const
  592. {
  593. return data_[size_];
  594. }
  595. };
  596. /*!
  597. * \brief size_t class used to interface between C++ and
  598. * OpenCL C calls that require arrays of size_t values, who's
  599. * size is known statically.
  600. */
  601. template <int N>
  602. struct size_t : public cl::vector< ::size_t, N> { };
  603. namespace detail {
  604. // GetInfo help struct
  605. template <typename Functor, typename T>
  606. struct GetInfoHelper
  607. {
  608. static cl_int
  609. get(Functor f, cl_uint name, T* param)
  610. {
  611. return f(name, sizeof(T), param, NULL);
  612. }
  613. };
  614. // Specialized GetInfoHelper for VECTOR_CLASS params
  615. template <typename Func, typename T>
  616. struct GetInfoHelper<Func, VECTOR_CLASS<T> >
  617. {
  618. static cl_int get(Func f, cl_uint name, VECTOR_CLASS<T>* param)
  619. {
  620. ::size_t required;
  621. cl_int err = f(name, 0, NULL, &required);
  622. if (err != CL_SUCCESS) {
  623. return err;
  624. }
  625. T* value = (T*) alloca(required);
  626. err = f(name, required, value, NULL);
  627. if (err != CL_SUCCESS) {
  628. return err;
  629. }
  630. param->assign(&value[0], &value[required/sizeof(T)]);
  631. return CL_SUCCESS;
  632. }
  633. };
  634. // Specialized for getInfo<CL_PROGRAM_BINARIES>
  635. template <typename Func>
  636. struct GetInfoHelper<Func, VECTOR_CLASS<char *> >
  637. {
  638. static cl_int
  639. get(Func f, cl_uint name, VECTOR_CLASS<char *>* param)
  640. {
  641. cl_uint err = f(name, param->size() * sizeof(char *), &(*param)[0], NULL);
  642. if (err != CL_SUCCESS) {
  643. return err;
  644. }
  645. return CL_SUCCESS;
  646. }
  647. };
  648. // Specialized GetInfoHelper for STRING_CLASS params
  649. template <typename Func>
  650. struct GetInfoHelper<Func, STRING_CLASS>
  651. {
  652. static cl_int get(Func f, cl_uint name, STRING_CLASS* param)
  653. {
  654. ::size_t required;
  655. cl_int err = f(name, 0, NULL, &required);
  656. if (err != CL_SUCCESS) {
  657. return err;
  658. }
  659. char* value = (char*) alloca(required);
  660. err = f(name, required, value, NULL);
  661. if (err != CL_SUCCESS) {
  662. return err;
  663. }
  664. *param = value;
  665. return CL_SUCCESS;
  666. }
  667. };
  668. #define __GET_INFO_HELPER_WITH_RETAIN(CPP_TYPE) \
  669. namespace detail { \
  670. template <typename Func> \
  671. struct GetInfoHelper<Func, CPP_TYPE> \
  672. { \
  673. static cl_int get(Func f, cl_uint name, CPP_TYPE* param) \
  674. { \
  675. cl_uint err = f(name, sizeof(CPP_TYPE), param, NULL); \
  676. if (err != CL_SUCCESS) { \
  677. return err; \
  678. } \
  679. \
  680. return ReferenceHandler<CPP_TYPE::cl_type>::retain((*param)()); \
  681. } \
  682. }; \
  683. }
  684. #define __PARAM_NAME_INFO_1_0(F) \
  685. F(cl_platform_info, CL_PLATFORM_PROFILE, STRING_CLASS) \
  686. F(cl_platform_info, CL_PLATFORM_VERSION, STRING_CLASS) \
  687. F(cl_platform_info, CL_PLATFORM_NAME, STRING_CLASS) \
  688. F(cl_platform_info, CL_PLATFORM_VENDOR, STRING_CLASS) \
  689. F(cl_platform_info, CL_PLATFORM_EXTENSIONS, STRING_CLASS) \
  690. \
  691. F(cl_device_info, CL_DEVICE_TYPE, cl_device_type) \
  692. F(cl_device_info, CL_DEVICE_VENDOR_ID, cl_uint) \
  693. F(cl_device_info, CL_DEVICE_MAX_COMPUTE_UNITS, cl_uint) \
  694. F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, cl_uint) \
  695. F(cl_device_info, CL_DEVICE_MAX_WORK_GROUP_SIZE, ::size_t) \
  696. F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_SIZES, VECTOR_CLASS< ::size_t>) \
  697. F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, cl_uint) \
  698. F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, cl_uint) \
  699. F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, cl_uint) \
  700. F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, cl_uint) \
  701. F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, cl_uint) \
  702. F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, cl_uint) \
  703. F(cl_device_info, CL_DEVICE_MAX_CLOCK_FREQUENCY, cl_uint) \
  704. F(cl_device_info, CL_DEVICE_ADDRESS_BITS, cl_bitfield) \
  705. F(cl_device_info, CL_DEVICE_MAX_READ_IMAGE_ARGS, cl_uint) \
  706. F(cl_device_info, CL_DEVICE_MAX_WRITE_IMAGE_ARGS, cl_uint) \
  707. F(cl_device_info, CL_DEVICE_MAX_MEM_ALLOC_SIZE, cl_ulong) \
  708. F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_WIDTH, ::size_t) \
  709. F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_HEIGHT, ::size_t) \
  710. F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_WIDTH, ::size_t) \
  711. F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_HEIGHT, ::size_t) \
  712. F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_DEPTH, ::size_t) \
  713. F(cl_device_info, CL_DEVICE_IMAGE_SUPPORT, cl_uint) \
  714. F(cl_device_info, CL_DEVICE_MAX_PARAMETER_SIZE, ::size_t) \
  715. F(cl_device_info, CL_DEVICE_MAX_SAMPLERS, cl_uint) \
  716. F(cl_device_info, CL_DEVICE_MEM_BASE_ADDR_ALIGN, cl_uint) \
  717. F(cl_device_info, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, cl_uint) \
  718. F(cl_device_info, CL_DEVICE_SINGLE_FP_CONFIG, cl_device_fp_config) \
  719. F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, cl_device_mem_cache_type) \
  720. F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, cl_uint)\
  721. F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, cl_ulong) \
  722. F(cl_device_info, CL_DEVICE_GLOBAL_MEM_SIZE, cl_ulong) \
  723. F(cl_device_info, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, cl_ulong) \
  724. F(cl_device_info, CL_DEVICE_MAX_CONSTANT_ARGS, cl_uint) \
  725. F(cl_device_info, CL_DEVICE_LOCAL_MEM_TYPE, cl_device_local_mem_type) \
  726. F(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE, cl_ulong) \
  727. F(cl_device_info, CL_DEVICE_ERROR_CORRECTION_SUPPORT, cl_bool) \
  728. F(cl_device_info, CL_DEVICE_PROFILING_TIMER_RESOLUTION, ::size_t) \
  729. F(cl_device_info, CL_DEVICE_ENDIAN_LITTLE, cl_bool) \
  730. F(cl_device_info, CL_DEVICE_AVAILABLE, cl_bool) \
  731. F(cl_device_info, CL_DEVICE_COMPILER_AVAILABLE, cl_bool) \
  732. F(cl_device_info, CL_DEVICE_EXECUTION_CAPABILITIES, cl_device_exec_capabilities) \
  733. F(cl_device_info, CL_DEVICE_QUEUE_PROPERTIES, cl_command_queue_properties) \
  734. F(cl_device_info, CL_DEVICE_PLATFORM, cl_platform_id) \
  735. F(cl_device_info, CL_DEVICE_NAME, STRING_CLASS) \
  736. F(cl_device_info, CL_DEVICE_VENDOR, STRING_CLASS) \
  737. F(cl_device_info, CL_DRIVER_VERSION, STRING_CLASS) \
  738. F(cl_device_info, CL_DEVICE_PROFILE, STRING_CLASS) \
  739. F(cl_device_info, CL_DEVICE_VERSION, STRING_CLASS) \
  740. F(cl_device_info, CL_DEVICE_EXTENSIONS, STRING_CLASS) \
  741. \
  742. F(cl_context_info, CL_CONTEXT_REFERENCE_COUNT, cl_uint) \
  743. F(cl_context_info, CL_CONTEXT_DEVICES, VECTOR_CLASS<Device>) \
  744. F(cl_context_info, CL_CONTEXT_PROPERTIES, VECTOR_CLASS<cl_context_properties>) \
  745. \
  746. F(cl_event_info, CL_EVENT_COMMAND_QUEUE, cl::CommandQueue) \
  747. F(cl_event_info, CL_EVENT_COMMAND_TYPE, cl_command_type) \
  748. F(cl_event_info, CL_EVENT_REFERENCE_COUNT, cl_uint) \
  749. F(cl_event_info, CL_EVENT_COMMAND_EXECUTION_STATUS, cl_uint) \
  750. \
  751. F(cl_profiling_info, CL_PROFILING_COMMAND_QUEUED, cl_ulong) \
  752. F(cl_profiling_info, CL_PROFILING_COMMAND_SUBMIT, cl_ulong) \
  753. F(cl_profiling_info, CL_PROFILING_COMMAND_START, cl_ulong) \
  754. F(cl_profiling_info, CL_PROFILING_COMMAND_END, cl_ulong) \
  755. \
  756. F(cl_mem_info, CL_MEM_TYPE, cl_mem_object_type) \
  757. F(cl_mem_info, CL_MEM_FLAGS, cl_mem_flags) \
  758. F(cl_mem_info, CL_MEM_SIZE, ::size_t) \
  759. F(cl_mem_info, CL_MEM_HOST_PTR, void*) \
  760. F(cl_mem_info, CL_MEM_MAP_COUNT, cl_uint) \
  761. F(cl_mem_info, CL_MEM_REFERENCE_COUNT, cl_uint) \
  762. F(cl_mem_info, CL_MEM_CONTEXT, cl::Context) \
  763. \
  764. F(cl_image_info, CL_IMAGE_FORMAT, cl_image_format) \
  765. F(cl_image_info, CL_IMAGE_ELEMENT_SIZE, ::size_t) \
  766. F(cl_image_info, CL_IMAGE_ROW_PITCH, ::size_t) \
  767. F(cl_image_info, CL_IMAGE_SLICE_PITCH, ::size_t) \
  768. F(cl_image_info, CL_IMAGE_WIDTH, ::size_t) \
  769. F(cl_image_info, CL_IMAGE_HEIGHT, ::size_t) \
  770. F(cl_image_info, CL_IMAGE_DEPTH, ::size_t) \
  771. \
  772. F(cl_sampler_info, CL_SAMPLER_REFERENCE_COUNT, cl_uint) \
  773. F(cl_sampler_info, CL_SAMPLER_CONTEXT, cl::Context) \
  774. F(cl_sampler_info, CL_SAMPLER_NORMALIZED_COORDS, cl_addressing_mode) \
  775. F(cl_sampler_info, CL_SAMPLER_ADDRESSING_MODE, cl_filter_mode) \
  776. F(cl_sampler_info, CL_SAMPLER_FILTER_MODE, cl_bool) \
  777. \
  778. F(cl_program_info, CL_PROGRAM_REFERENCE_COUNT, cl_uint) \
  779. F(cl_program_info, CL_PROGRAM_CONTEXT, cl::Context) \
  780. F(cl_program_info, CL_PROGRAM_NUM_DEVICES, cl_uint) \
  781. F(cl_program_info, CL_PROGRAM_DEVICES, VECTOR_CLASS<cl_device_id>) \
  782. F(cl_program_info, CL_PROGRAM_SOURCE, STRING_CLASS) \
  783. F(cl_program_info, CL_PROGRAM_BINARY_SIZES, VECTOR_CLASS< ::size_t>) \
  784. F(cl_program_info, CL_PROGRAM_BINARIES, VECTOR_CLASS<char *>) \
  785. \
  786. F(cl_program_build_info, CL_PROGRAM_BUILD_STATUS, cl_build_status) \
  787. F(cl_program_build_info, CL_PROGRAM_BUILD_OPTIONS, STRING_CLASS) \
  788. F(cl_program_build_info, CL_PROGRAM_BUILD_LOG, STRING_CLASS) \
  789. \
  790. F(cl_kernel_info, CL_KERNEL_FUNCTION_NAME, STRING_CLASS) \
  791. F(cl_kernel_info, CL_KERNEL_NUM_ARGS, cl_uint) \
  792. F(cl_kernel_info, CL_KERNEL_REFERENCE_COUNT, cl_uint) \
  793. F(cl_kernel_info, CL_KERNEL_CONTEXT, cl::Context) \
  794. F(cl_kernel_info, CL_KERNEL_PROGRAM, cl::Program) \
  795. \
  796. F(cl_kernel_work_group_info, CL_KERNEL_WORK_GROUP_SIZE, ::size_t) \
  797. F(cl_kernel_work_group_info, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, cl::size_t<3>) \
  798. F(cl_kernel_work_group_info, CL_KERNEL_LOCAL_MEM_SIZE, cl_ulong) \
  799. \
  800. F(cl_command_queue_info, CL_QUEUE_CONTEXT, cl::Context) \
  801. F(cl_command_queue_info, CL_QUEUE_DEVICE, cl::Device) \
  802. F(cl_command_queue_info, CL_QUEUE_REFERENCE_COUNT, cl_uint) \
  803. F(cl_command_queue_info, CL_QUEUE_PROPERTIES, cl_command_queue_properties)
  804. #if defined(CL_VERSION_1_1)
  805. #define __PARAM_NAME_INFO_1_1(F) \
  806. F(cl_context_info, CL_CONTEXT_NUM_DEVICES, cl_uint)\
  807. F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF, cl_uint) \
  808. F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR, cl_uint) \
  809. F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT, cl_uint) \
  810. F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, cl_uint) \
  811. F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, cl_uint) \
  812. F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, cl_uint) \
  813. F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, cl_uint) \
  814. F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, cl_uint) \
  815. F(cl_device_info, CL_DEVICE_DOUBLE_FP_CONFIG, cl_device_fp_config) \
  816. F(cl_device_info, CL_DEVICE_HALF_FP_CONFIG, cl_device_fp_config) \
  817. F(cl_device_info, CL_DEVICE_HOST_UNIFIED_MEMORY, cl_bool) \
  818. \
  819. F(cl_mem_info, CL_MEM_ASSOCIATED_MEMOBJECT, cl::Memory) \
  820. F(cl_mem_info, CL_MEM_OFFSET, ::size_t) \
  821. \
  822. F(cl_kernel_work_group_info, CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, ::size_t) \
  823. F(cl_kernel_work_group_info, CL_KERNEL_PRIVATE_MEM_SIZE, cl_ulong) \
  824. \
  825. F(cl_event_info, CL_EVENT_CONTEXT, cl::Context)
  826. #endif // CL_VERSION_1_1
  827. #if defined(USE_CL_DEVICE_FISSION)
  828. #define __PARAM_NAME_DEVICE_FISSION(F) \
  829. F(cl_device_info, CL_DEVICE_PARENT_DEVICE_EXT, cl_device_id) \
  830. F(cl_device_info, CL_DEVICE_PARTITION_TYPES_EXT, VECTOR_CLASS<cl_device_partition_property_ext>) \
  831. F(cl_device_info, CL_DEVICE_AFFINITY_DOMAINS_EXT, VECTOR_CLASS<cl_device_partition_property_ext>) \
  832. F(cl_device_info, CL_DEVICE_REFERENCE_COUNT_EXT , cl_uint) \
  833. F(cl_device_info, CL_DEVICE_PARTITION_STYLE_EXT, VECTOR_CLASS<cl_device_partition_property_ext>)
  834. #endif // USE_CL_DEVICE_FISSION
  835. template <typename enum_type, cl_int Name>
  836. struct param_traits {};
  837. #define __DECLARE_PARAM_TRAITS(token, param_name, T) \
  838. struct token; \
  839. template<> \
  840. struct param_traits<detail:: token,param_name> \
  841. { \
  842. enum { value = param_name }; \
  843. typedef T param_type; \
  844. };
  845. __PARAM_NAME_INFO_1_0(__DECLARE_PARAM_TRAITS)
  846. #if defined(CL_VERSION_1_1)
  847. __PARAM_NAME_INFO_1_1(__DECLARE_PARAM_TRAITS)
  848. #endif // CL_VERSION_1_1
  849. #if defined(USE_CL_DEVICE_FISSION)
  850. __PARAM_NAME_DEVICE_FISSION(__DECLARE_PARAM_TRAITS);
  851. #endif // USE_CL_DEVICE_FISSION
  852. #undef __DECLARE_PARAM_TRAITS
  853. // Convenience functions
  854. template <typename Func, typename T>
  855. inline cl_int
  856. getInfo(Func f, cl_uint name, T* param)
  857. {
  858. return GetInfoHelper<Func, T>::get(f, name, param);
  859. }
  860. template <typename Func, typename Arg0>
  861. struct GetInfoFunctor0
  862. {
  863. Func f_; const Arg0& arg0_;
  864. cl_int operator ()(
  865. cl_uint param, ::size_t size, void* value, ::size_t* size_ret)
  866. { return f_(arg0_, param, size, value, size_ret); }
  867. };
  868. template <typename Func, typename Arg0, typename Arg1>
  869. struct GetInfoFunctor1
  870. {
  871. Func f_; const Arg0& arg0_; const Arg1& arg1_;
  872. cl_int operator ()(
  873. cl_uint param, ::size_t size, void* value, ::size_t* size_ret)
  874. { return f_(arg0_, arg1_, param, size, value, size_ret); }
  875. };
  876. template <typename Func, typename Arg0, typename T>
  877. inline cl_int
  878. getInfo(Func f, const Arg0& arg0, cl_uint name, T* param)
  879. {
  880. GetInfoFunctor0<Func, Arg0> f0 = { f, arg0 };
  881. return GetInfoHelper<GetInfoFunctor0<Func, Arg0>, T>
  882. ::get(f0, name, param);
  883. }
  884. template <typename Func, typename Arg0, typename Arg1, typename T>
  885. inline cl_int
  886. getInfo(Func f, const Arg0& arg0, const Arg1& arg1, cl_uint name, T* param)
  887. {
  888. GetInfoFunctor1<Func, Arg0, Arg1> f0 = { f, arg0, arg1 };
  889. return GetInfoHelper<GetInfoFunctor1<Func, Arg0, Arg1>, T>
  890. ::get(f0, name, param);
  891. }
  892. template<typename T>
  893. struct ReferenceHandler
  894. { };
  895. template <>
  896. struct ReferenceHandler<cl_device_id>
  897. {
  898. // cl_device_id does not have retain().
  899. static cl_int retain(cl_device_id)
  900. { return CL_INVALID_DEVICE; }
  901. // cl_device_id does not have release().
  902. static cl_int release(cl_device_id)
  903. { return CL_INVALID_DEVICE; }
  904. };
  905. template <>
  906. struct ReferenceHandler<cl_platform_id>
  907. {
  908. // cl_platform_id does not have retain().
  909. static cl_int retain(cl_platform_id)
  910. { return CL_INVALID_PLATFORM; }
  911. // cl_platform_id does not have release().
  912. static cl_int release(cl_platform_id)
  913. { return CL_INVALID_PLATFORM; }
  914. };
  915. template <>
  916. struct ReferenceHandler<cl_context>
  917. {
  918. static cl_int retain(cl_context context)
  919. { return ::clRetainContext(context); }
  920. static cl_int release(cl_context context)
  921. { return ::clReleaseContext(context); }
  922. };
  923. template <>
  924. struct ReferenceHandler<cl_command_queue>
  925. {
  926. static cl_int retain(cl_command_queue queue)
  927. { return ::clRetainCommandQueue(queue); }
  928. static cl_int release(cl_command_queue queue)
  929. { return ::clReleaseCommandQueue(queue); }
  930. };
  931. template <>
  932. struct ReferenceHandler<cl_mem>
  933. {
  934. static cl_int retain(cl_mem memory)
  935. { return ::clRetainMemObject(memory); }
  936. static cl_int release(cl_mem memory)
  937. { return ::clReleaseMemObject(memory); }
  938. };
  939. template <>
  940. struct ReferenceHandler<cl_sampler>
  941. {
  942. static cl_int retain(cl_sampler sampler)
  943. { return ::clRetainSampler(sampler); }
  944. static cl_int release(cl_sampler sampler)
  945. { return ::clReleaseSampler(sampler); }
  946. };
  947. template <>
  948. struct ReferenceHandler<cl_program>
  949. {
  950. static cl_int retain(cl_program program)
  951. { return ::clRetainProgram(program); }
  952. static cl_int release(cl_program program)
  953. { return ::clReleaseProgram(program); }
  954. };
  955. template <>
  956. struct ReferenceHandler<cl_kernel>
  957. {
  958. static cl_int retain(cl_kernel kernel)
  959. { return ::clRetainKernel(kernel); }
  960. static cl_int release(cl_kernel kernel)
  961. { return ::clReleaseKernel(kernel); }
  962. };
  963. template <>
  964. struct ReferenceHandler<cl_event>
  965. {
  966. static cl_int retain(cl_event event)
  967. { return ::clRetainEvent(event); }
  968. static cl_int release(cl_event event)
  969. { return ::clReleaseEvent(event); }
  970. };
  971. template <typename T>
  972. class Wrapper
  973. {
  974. public:
  975. typedef T cl_type;
  976. protected:
  977. cl_type object_;
  978. public:
  979. Wrapper() : object_(NULL) { }
  980. ~Wrapper()
  981. {
  982. if (object_ != NULL) { release(); }
  983. }
  984. Wrapper(const Wrapper<cl_type>& rhs)
  985. {
  986. object_ = rhs.object_;
  987. if (object_ != NULL) { retain(); }
  988. }
  989. Wrapper<cl_type>& operator = (const Wrapper<cl_type>& rhs)
  990. {
  991. if (object_ != NULL) { release(); }
  992. object_ = rhs.object_;
  993. if (object_ != NULL) { retain(); }
  994. return *this;
  995. }
  996. cl_type operator ()() const { return object_; }
  997. cl_type& operator ()() { return object_; }
  998. protected:
  999. cl_int retain() const
  1000. {
  1001. return ReferenceHandler<cl_type>::retain(object_);
  1002. }
  1003. cl_int release() const
  1004. {
  1005. return ReferenceHandler<cl_type>::release(object_);
  1006. }
  1007. };
  1008. #if defined(__CL_ENABLE_EXCEPTIONS)
  1009. static inline cl_int errHandler (
  1010. cl_int err,
  1011. const char * errStr = NULL)
  1012. //this fails with " throw(Error) " as culprit. can we just remove the declaration? @bug
  1013. {
  1014. if (err != CL_SUCCESS) {
  1015. throw Error(err, errStr);
  1016. }
  1017. return err;
  1018. }
  1019. #else
  1020. static inline cl_int errHandler (cl_int err, const char * errStr = NULL)
  1021. {
  1022. return err;
  1023. }
  1024. #endif // __CL_ENABLE_EXCEPTIONS
  1025. } // namespace detail
  1026. //! \endcond
  1027. /*! \stuct ImageFormat
  1028. * \brief ImageFormat interface fro cl_image_format.
  1029. */
  1030. struct ImageFormat : public cl_image_format
  1031. {
  1032. ImageFormat(){}
  1033. ImageFormat(cl_channel_order order, cl_channel_type type)
  1034. {
  1035. image_channel_order = order;
  1036. image_channel_data_type = type;
  1037. }
  1038. ImageFormat& operator = (const ImageFormat& rhs)
  1039. {
  1040. if (this != &rhs) {
  1041. this->image_channel_data_type = rhs.image_channel_data_type;
  1042. this->image_channel_order = rhs.image_channel_order;
  1043. }
  1044. return *this;
  1045. }
  1046. };
  1047. /*! \class Device
  1048. * \brief Device interface for cl_device_id.
  1049. */
  1050. class Device : public detail::Wrapper<cl_device_id>
  1051. {
  1052. public:
  1053. Device(cl_device_id device) { object_ = device; }
  1054. Device() : detail::Wrapper<cl_type>() { }
  1055. Device(const Device& device) : detail::Wrapper<cl_type>(device) { }
  1056. Device& operator = (const Device& rhs)
  1057. {
  1058. if (this != &rhs) {
  1059. detail::Wrapper<cl_type>::operator=(rhs);
  1060. }
  1061. return *this;
  1062. }
  1063. template <typename T>
  1064. cl_int getInfo(cl_device_info name, T* param) const
  1065. {
  1066. return detail::errHandler(
  1067. detail::getInfo(&::clGetDeviceInfo, object_, name, param),
  1068. __GET_DEVICE_INFO_ERR);
  1069. }
  1070. template <cl_int name> typename
  1071. detail::param_traits<detail::cl_device_info, name>::param_type
  1072. getInfo(cl_int* err = NULL) const
  1073. {
  1074. typename detail::param_traits<
  1075. detail::cl_device_info, name>::param_type param;
  1076. cl_int result = getInfo(name, &param);
  1077. if (err != NULL) {
  1078. *err = result;
  1079. }
  1080. return param;
  1081. }
  1082. #if defined(USE_CL_DEVICE_FISSION)
  1083. cl_int createSubDevices(
  1084. const cl_device_partition_property_ext * properties,
  1085. VECTOR_CLASS<Device>* devices)
  1086. {
  1087. typedef CL_API_ENTRY cl_int
  1088. ( CL_API_CALL * PFN_clCreateSubDevicesEXT)(
  1089. cl_device_id /*in_device*/,
  1090. const cl_device_partition_property_ext * /* properties */,
  1091. cl_uint /*num_entries*/,
  1092. cl_device_id * /*out_devices*/,
  1093. cl_uint * /*num_devices*/ ) CL_EXT_SUFFIX__VERSION_1_1;
  1094. static PFN_clCreateSubDevicesEXT pfn_clCreateSubDevicesEXT = NULL;
  1095. __INIT_CL_EXT_FCN_PTR(clCreateSubDevicesEXT);
  1096. cl_uint n = 0;
  1097. cl_int err = pfn_clCreateSubDevicesEXT(object_, properties, 0, NULL, &n);
  1098. if (err != CL_SUCCESS) {
  1099. return detail::errHandler(err, __CREATE_SUB_DEVICES);
  1100. }
  1101. cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id));
  1102. err = pfn_clCreateSubDevicesEXT(object_, properties, n, ids, NULL);
  1103. if (err != CL_SUCCESS) {
  1104. return detail::errHandler(err, __CREATE_SUB_DEVICES);
  1105. }
  1106. devices->assign(&ids[0], &ids[n]);
  1107. return CL_SUCCESS;
  1108. }
  1109. #endif
  1110. };
  1111. /*! \class Platform
  1112. * \brief Platform interface.
  1113. */
  1114. class Platform : public detail::Wrapper<cl_platform_id>
  1115. {
  1116. public:
  1117. static const Platform null();
  1118. Platform(cl_platform_id platform) { object_ = platform; }
  1119. Platform() : detail::Wrapper<cl_type>() { }
  1120. Platform(const Platform& platform) : detail::Wrapper<cl_type>(platform) { }
  1121. Platform& operator = (const Platform& rhs)
  1122. {
  1123. if (this != &rhs) {
  1124. detail::Wrapper<cl_type>::operator=(rhs);
  1125. }
  1126. return *this;
  1127. }
  1128. cl_int getInfo(cl_platform_info name, STRING_CLASS* param) const
  1129. {
  1130. return detail::errHandler(
  1131. detail::getInfo(&::clGetPlatformInfo, object_, name, param),
  1132. __GET_PLATFORM_INFO_ERR);
  1133. }
  1134. template <cl_int name> typename
  1135. detail::param_traits<detail::cl_platform_info, name>::param_type
  1136. getInfo(cl_int* err = NULL) const
  1137. {
  1138. typename detail::param_traits<
  1139. detail::cl_platform_info, name>::param_type param;
  1140. cl_int result = getInfo(name, &param);
  1141. if (err != NULL) {
  1142. *err = result;
  1143. }
  1144. return param;
  1145. }
  1146. cl_int getDevices(
  1147. cl_device_type type,
  1148. VECTOR_CLASS<Device>* devices) const
  1149. {
  1150. cl_uint n = 0;
  1151. cl_int err = ::clGetDeviceIDs(object_, type, 0, NULL, &n);
  1152. if (err != CL_SUCCESS) {
  1153. return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
  1154. }
  1155. cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id));
  1156. err = ::clGetDeviceIDs(object_, type, n, ids, NULL);
  1157. if (err != CL_SUCCESS) {
  1158. return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
  1159. }
  1160. devices->assign(&ids[0], &ids[n]);
  1161. return CL_SUCCESS;
  1162. }
  1163. #if defined(USE_DX_INTEROP)
  1164. /*! \brief Get the list of available D3D10 devices.
  1165. *
  1166. * \param d3d_device_source.
  1167. *
  1168. * \param d3d_object.
  1169. *
  1170. * \param d3d_device_set.
  1171. *
  1172. * \param devices returns a vector of OpenCL D3D10 devices found. The cl::Device
  1173. * values returned in devices can be used to identify a specific OpenCL
  1174. * device. If \a devices argument is NULL, this argument is ignored.
  1175. *
  1176. * \return One of the following values:
  1177. * - CL_SUCCESS if the function is executed successfully.
  1178. *
  1179. * The application can query specific capabilities of the OpenCL device(s)
  1180. * returned by cl::getDevices. This can be used by the application to
  1181. * determine which device(s) to use.
  1182. *
  1183. * \note In the case that exceptions are enabled and a return value
  1184. * other than CL_SUCCESS is generated, then cl::Error exception is
  1185. * generated.
  1186. */
  1187. cl_int getDevices(
  1188. cl_d3d10_device_source_khr d3d_device_source,
  1189. void * d3d_object,
  1190. cl_d3d10_device_set_khr d3d_device_set,
  1191. VECTOR_CLASS<Device>* devices) const
  1192. {
  1193. typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clGetDeviceIDsFromD3D10KHR)(
  1194. cl_platform_id platform,
  1195. cl_d3d10_device_source_khr d3d_device_source,
  1196. void * d3d_object,
  1197. cl_d3d10_device_set_khr d3d_device_set,
  1198. cl_uint num_entries,
  1199. cl_device_id * devices,
  1200. cl_uint* num_devices);
  1201. static PFN_clGetDeviceIDsFromD3D10KHR pfn_clGetDeviceIDsFromD3D10KHR = NULL;
  1202. __INIT_CL_EXT_FCN_PTR(clGetDeviceIDsFromD3D10KHR);
  1203. cl_uint n = 0;
  1204. cl_int err = pfn_clGetDeviceIDsFromD3D10KHR(
  1205. object_,
  1206. d3d_device_source,
  1207. d3d_object,
  1208. d3d_device_set,
  1209. 0,
  1210. NULL,
  1211. &n);
  1212. if (err != CL_SUCCESS) {
  1213. return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
  1214. }
  1215. cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id));
  1216. err = pfn_clGetDeviceIDsFromD3D10KHR(
  1217. object_,
  1218. d3d_device_source,
  1219. d3d_object,
  1220. d3d_device_set,
  1221. n,
  1222. ids,
  1223. NULL);
  1224. if (err != CL_SUCCESS) {
  1225. return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
  1226. }
  1227. devices->assign(&ids[0], &ids[n]);
  1228. return CL_SUCCESS;
  1229. }
  1230. #endif
  1231. static cl_int get(
  1232. VECTOR_CLASS<Platform>* platforms)
  1233. {
  1234. cl_uint n = 0;
  1235. cl_int err = ::clGetPlatformIDs(0, NULL, &n);
  1236. if (err != CL_SUCCESS) {
  1237. return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
  1238. }
  1239. cl_platform_id* ids = (cl_platform_id*) alloca(
  1240. n * sizeof(cl_platform_id));
  1241. err = ::clGetPlatformIDs(n, ids, NULL);
  1242. if (err != CL_SUCCESS) {
  1243. return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
  1244. }
  1245. platforms->assign(&ids[0], &ids[n]);
  1246. return CL_SUCCESS;
  1247. }
  1248. };
  1249. static inline cl_int
  1250. UnloadCompiler()
  1251. {
  1252. return ::clUnloadCompiler();
  1253. }
  1254. class Context : public detail::Wrapper<cl_context>
  1255. {
  1256. public:
  1257. Context(
  1258. const VECTOR_CLASS<Device>& devices,
  1259. cl_context_properties* properties = NULL,
  1260. void (CL_CALLBACK * notifyFptr)(
  1261. const char *,
  1262. const void *,
  1263. ::size_t,
  1264. void *) = NULL,
  1265. void* data = NULL,
  1266. cl_int* err = NULL)
  1267. {
  1268. cl_int error;
  1269. object_ = ::clCreateContext(
  1270. properties, (cl_uint) devices.size(),
  1271. (cl_device_id*) &devices.front(),
  1272. notifyFptr, data, &error);
  1273. detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
  1274. if (err != NULL) {
  1275. *err = error;
  1276. }
  1277. }
  1278. Context(
  1279. cl_device_type type,
  1280. cl_context_properties* properties = NULL,
  1281. void (CL_CALLBACK * notifyFptr)(
  1282. const char *,
  1283. const void *,
  1284. ::size_t,
  1285. void *) = NULL,
  1286. void* data = NULL,
  1287. cl_int* err = NULL)
  1288. {
  1289. cl_int error;
  1290. object_ = ::clCreateContextFromType(
  1291. properties, type, notifyFptr, data, &error);
  1292. detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
  1293. if (err != NULL) {
  1294. *err = error;
  1295. }
  1296. }
  1297. Context() : detail::Wrapper<cl_type>() { }
  1298. Context(const Context& context) : detail::Wrapper<cl_type>(context) { }
  1299. Context& operator = (const Context& rhs)
  1300. {
  1301. if (this != &rhs) {
  1302. detail::Wrapper<cl_type>::operator=(rhs);
  1303. }
  1304. return *this;
  1305. }
  1306. template <typename T>
  1307. cl_int getInfo(cl_context_info name, T* param) const
  1308. {
  1309. return detail::errHandler(
  1310. detail::getInfo(&::clGetContextInfo, object_, name, param),
  1311. __GET_CONTEXT_INFO_ERR);
  1312. }
  1313. template <cl_int name> typename
  1314. detail::param_traits<detail::cl_context_info, name>::param_type
  1315. getInfo(cl_int* err = NULL) const
  1316. {
  1317. typename detail::param_traits<
  1318. detail::cl_context_info, name>::param_type param;
  1319. cl_int result = getInfo(name, &param);
  1320. if (err != NULL) {
  1321. *err = result;
  1322. }
  1323. return param;
  1324. }
  1325. cl_int getSupportedImageFormats(
  1326. cl_mem_flags flags,
  1327. cl_mem_object_type type,
  1328. VECTOR_CLASS<ImageFormat>* formats) const
  1329. {
  1330. cl_uint numEntries;
  1331. cl_int err = ::clGetSupportedImageFormats(
  1332. object_,
  1333. flags,
  1334. type,
  1335. 0,
  1336. NULL,
  1337. &numEntries);
  1338. if (err != CL_SUCCESS) {
  1339. return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
  1340. }
  1341. ImageFormat* value = (ImageFormat*)
  1342. alloca(numEntries * sizeof(ImageFormat));
  1343. err = ::clGetSupportedImageFormats(
  1344. object_,
  1345. flags,
  1346. type,
  1347. numEntries,
  1348. (cl_image_format*) value,
  1349. NULL);
  1350. if (err != CL_SUCCESS) {
  1351. return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
  1352. }
  1353. formats->assign(&value[0], &value[numEntries]);
  1354. return CL_SUCCESS;
  1355. }
  1356. };
  1357. __GET_INFO_HELPER_WITH_RETAIN(cl::Context)
  1358. /*! \class Event
  1359. * \brief Event interface for cl_event.
  1360. */
  1361. class Event : public detail::Wrapper<cl_event>
  1362. {
  1363. public:
  1364. Event() : detail::Wrapper<cl_type>() { }
  1365. Event(const Event& event) : detail::Wrapper<cl_type>(event) { }
  1366. Event& operator = (const Event& rhs)
  1367. {
  1368. if (this != &rhs) {
  1369. detail::Wrapper<cl_type>::operator=(rhs);
  1370. }
  1371. return *this;
  1372. }
  1373. template <typename T>
  1374. cl_int getInfo(cl_event_info name, T* param) const
  1375. {
  1376. return detail::errHandler(
  1377. detail::getInfo(&::clGetEventInfo, object_, name, param),
  1378. __GET_EVENT_INFO_ERR);
  1379. }
  1380. template <cl_int name> typename
  1381. detail::param_traits<detail::cl_event_info, name>::param_type
  1382. getInfo(cl_int* err = NULL) const
  1383. {
  1384. typename detail::param_traits<
  1385. detail::cl_event_info, name>::param_type param;
  1386. cl_int result = getInfo(name, &param);
  1387. if (err != NULL) {
  1388. *err = result;
  1389. }
  1390. return param;
  1391. }
  1392. template <typename T>
  1393. cl_int getProfilingInfo(cl_profiling_info name, T* param) const
  1394. {
  1395. return detail::errHandler(detail::getInfo(
  1396. &::clGetEventProfilingInfo, object_, name, param),
  1397. __GET_EVENT_PROFILE_INFO_ERR);
  1398. }
  1399. template <cl_int name> typename
  1400. detail::param_traits<detail::cl_profiling_info, name>::param_type
  1401. getProfilingInfo(cl_int* err = NULL) const
  1402. {
  1403. typename detail::param_traits<
  1404. detail::cl_profiling_info, name>::param_type param;
  1405. cl_int result = getProfilingInfo(name, &param);
  1406. if (err != NULL) {
  1407. *err = result;
  1408. }
  1409. return param;
  1410. }
  1411. cl_int wait() const
  1412. {
  1413. return detail::errHandler(
  1414. ::clWaitForEvents(1, &object_),
  1415. __WAIT_FOR_EVENTS_ERR);
  1416. }
  1417. #if defined(CL_VERSION_1_1)
  1418. cl_int setCallback(
  1419. cl_int type,
  1420. void (CL_CALLBACK * pfn_notify)(cl_event, cl_int, void *),
  1421. void * user_data = NULL)
  1422. {
  1423. return detail::errHandler(
  1424. ::clSetEventCallback(
  1425. object_,
  1426. type,
  1427. pfn_notify,
  1428. user_data),
  1429. __SET_EVENT_CALLBACK_ERR);
  1430. }
  1431. #endif
  1432. static cl_int
  1433. waitForEvents(const VECTOR_CLASS<Event>& events)
  1434. {
  1435. return detail::errHandler(
  1436. ::clWaitForEvents(
  1437. (cl_uint) events.size(), (cl_event*)&events.front()),
  1438. __WAIT_FOR_EVENTS_ERR);
  1439. }
  1440. };
  1441. __GET_INFO_HELPER_WITH_RETAIN(cl::Event)
  1442. #if defined(CL_VERSION_1_1)
  1443. /*! \class UserEvent
  1444. * \brief User event interface for cl_event.
  1445. */
  1446. class UserEvent : public Event
  1447. {
  1448. public:
  1449. UserEvent(
  1450. const Context& context,
  1451. cl_int * err = NULL)
  1452. {
  1453. cl_int error;
  1454. object_ = ::clCreateUserEvent(
  1455. context(),
  1456. &error);
  1457. detail::errHandler(error, __CREATE_USER_EVENT_ERR);
  1458. if (err != NULL) {
  1459. *err = error;
  1460. }
  1461. }
  1462. UserEvent() : Event() { }
  1463. UserEvent(const UserEvent& event) : Event(event) { }
  1464. UserEvent& operator = (const UserEvent& rhs)
  1465. {
  1466. if (this != &rhs) {
  1467. Event::operator=(rhs);
  1468. }
  1469. return *this;
  1470. }
  1471. cl_int setStatus(cl_int status)
  1472. {
  1473. return detail::errHandler(
  1474. ::clSetUserEventStatus(object_,status),
  1475. __SET_USER_EVENT_STATUS_ERR);
  1476. }
  1477. };
  1478. #endif
  1479. inline static cl_int
  1480. WaitForEvents(const VECTOR_CLASS<Event>& events)
  1481. {
  1482. return detail::errHandler(
  1483. ::clWaitForEvents(
  1484. (cl_uint) events.size(), (cl_event*)&events.front()),
  1485. __WAIT_FOR_EVENTS_ERR);
  1486. }
  1487. /*! \class Memory
  1488. * \brief Memory interface for cl_mem.
  1489. */
  1490. class Memory : public detail::Wrapper<cl_mem>
  1491. {
  1492. public:
  1493. Memory() : detail::Wrapper<cl_type>() { }
  1494. Memory(const Memory& memory) : detail::Wrapper<cl_type>(memory) { }
  1495. Memory& operator = (const Memory& rhs)
  1496. {
  1497. if (this != &rhs) {
  1498. detail::Wrapper<cl_type>::operator=(rhs);
  1499. }
  1500. return *this;
  1501. }
  1502. template <typename T>
  1503. cl_int getInfo(cl_mem_info name, T* param) const
  1504. {
  1505. return detail::errHandler(
  1506. detail::getInfo(&::clGetMemObjectInfo, object_, name, param),
  1507. __GET_MEM_OBJECT_INFO_ERR);
  1508. }
  1509. template <cl_int name> typename
  1510. detail::param_traits<detail::cl_mem_info, name>::param_type
  1511. getInfo(cl_int* err = NULL) const
  1512. {
  1513. typename detail::param_traits<
  1514. detail::cl_mem_info, name>::param_type param;
  1515. cl_int result = getInfo(name, &param);
  1516. if (err != NULL) {
  1517. *err = result;
  1518. }
  1519. return param;
  1520. }
  1521. #if defined(CL_VERSION_1_1)
  1522. cl_int setDestructorCallback(
  1523. void (CL_CALLBACK * pfn_notify)(cl_mem, void *),
  1524. void * user_data = NULL)
  1525. {
  1526. return detail::errHandler(
  1527. ::clSetMemObjectDestructorCallback(
  1528. object_,
  1529. pfn_notify,
  1530. user_data),
  1531. __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR);
  1532. }
  1533. #endif
  1534. };
  1535. __GET_INFO_HELPER_WITH_RETAIN(cl::Memory)
  1536. /*! \class Buffer
  1537. * \brief Memory buffer interface.
  1538. */
  1539. class Buffer : public Memory
  1540. {
  1541. public:
  1542. Buffer(
  1543. const Context& context,
  1544. cl_mem_flags flags,
  1545. ::size_t size,
  1546. void* host_ptr = NULL,
  1547. cl_int* err = NULL)
  1548. {
  1549. cl_int error;
  1550. object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error);
  1551. detail::errHandler(error, __CREATE_BUFFER_ERR);
  1552. if (err != NULL) {
  1553. *err = error;
  1554. }
  1555. }
  1556. Buffer() : Memory() { }
  1557. Buffer(const Buffer& buffer) : Memory(buffer) { }
  1558. Buffer& operator = (const Buffer& rhs)
  1559. {
  1560. if (this != &rhs) {
  1561. Memory::operator=(rhs);
  1562. }
  1563. return *this;
  1564. }
  1565. #if defined(CL_VERSION_1_1)
  1566. Buffer createSubBuffer(
  1567. cl_mem_flags flags,
  1568. cl_buffer_create_type buffer_create_type,
  1569. const void * buffer_create_info,
  1570. cl_int * err = NULL)
  1571. {
  1572. Buffer result;
  1573. cl_int error;
  1574. result.object_ = ::clCreateSubBuffer(
  1575. object_,
  1576. flags,
  1577. buffer_create_type,
  1578. buffer_create_info,
  1579. &error);
  1580. detail::errHandler(error, __CREATE_SUBBUFFER_ERR);
  1581. if (err != NULL) {
  1582. *err = error;
  1583. }
  1584. return result;
  1585. }
  1586. #endif
  1587. };
  1588. #if defined (USE_DX_INTEROP)
  1589. class BufferD3D10 : public Buffer
  1590. {
  1591. public:
  1592. typedef CL_API_ENTRY cl_mem (CL_API_CALL *PFN_clCreateFromD3D10BufferKHR)(
  1593. cl_context context, cl_mem_flags flags, ID3D10Buffer* buffer,
  1594. cl_int* errcode_ret);
  1595. BufferD3D10(
  1596. const Context& context,
  1597. cl_mem_flags flags,
  1598. ID3D10Buffer* bufobj,
  1599. cl_int * err = NULL)
  1600. {
  1601. static PFN_clCreateFromD3D10BufferKHR pfn_clCreateFromD3D10BufferKHR = NULL;
  1602. __INIT_CL_EXT_FCN_PTR(clCreateFromD3D10BufferKHR);
  1603. cl_int error;
  1604. object_ = pfn_clCreateFromD3D10BufferKHR(
  1605. context(),
  1606. flags,
  1607. bufobj,
  1608. &error);
  1609. detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
  1610. if (err != NULL) {
  1611. *err = error;
  1612. }
  1613. }
  1614. BufferD3D10() : Buffer() { }
  1615. BufferD3D10(const BufferD3D10& buffer) : Buffer(buffer) { }
  1616. BufferD3D10& operator = (const BufferD3D10& rhs)
  1617. {
  1618. if (this != &rhs) {
  1619. Buffer::operator=(rhs);
  1620. }
  1621. return *this;
  1622. }
  1623. };
  1624. #endif
  1625. /*! \class BufferGL
  1626. * \brief Memory buffer interface for GL interop.
  1627. */
  1628. class BufferGL : public Buffer
  1629. {
  1630. public:
  1631. BufferGL(
  1632. const Context& context,
  1633. cl_mem_flags flags,
  1634. GLuint bufobj,
  1635. cl_int * err = NULL)
  1636. {
  1637. cl_int error;
  1638. object_ = ::clCreateFromGLBuffer(
  1639. context(),
  1640. flags,
  1641. bufobj,
  1642. &error);
  1643. detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
  1644. if (err != NULL) {
  1645. *err = error;
  1646. }
  1647. }
  1648. BufferGL() : Buffer() { }
  1649. BufferGL(const BufferGL& buffer) : Buffer(buffer) { }
  1650. BufferGL& operator = (const BufferGL& rhs)
  1651. {
  1652. if (this != &rhs) {
  1653. Buffer::operator=(rhs);
  1654. }
  1655. return *this;
  1656. }
  1657. cl_int getObjectInfo(
  1658. cl_gl_object_type *type,
  1659. GLuint * gl_object_name)
  1660. {
  1661. return detail::errHandler(
  1662. ::clGetGLObjectInfo(object_,type,gl_object_name),
  1663. __GET_GL_OBJECT_INFO_ERR);
  1664. }
  1665. };
  1666. /*! \class BufferRenderGL
  1667. * \brief Memory buffer interface for GL interop with renderbuffer.
  1668. */
  1669. class BufferRenderGL : public Buffer
  1670. {
  1671. public:
  1672. BufferRenderGL(
  1673. const Context& context,
  1674. cl_mem_flags flags,
  1675. GLuint bufobj,
  1676. cl_int * err = NULL)
  1677. {
  1678. cl_int error;
  1679. object_ = ::clCreateFromGLRenderbuffer(
  1680. context(),
  1681. flags,
  1682. bufobj,
  1683. &error);
  1684. detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
  1685. if (err != NULL) {
  1686. *err = error;
  1687. }
  1688. }
  1689. BufferRenderGL() : Buffer() { }
  1690. BufferRenderGL(const BufferGL& buffer) : Buffer(buffer) { }
  1691. BufferRenderGL& operator = (const BufferRenderGL& rhs)
  1692. {
  1693. if (this != &rhs) {
  1694. Buffer::operator=(rhs);
  1695. }
  1696. return *this;
  1697. }
  1698. cl_int getObjectInfo(
  1699. cl_gl_object_type *type,
  1700. GLuint * gl_object_name)
  1701. {
  1702. return detail::errHandler(
  1703. ::clGetGLObjectInfo(object_,type,gl_object_name),
  1704. __GET_GL_OBJECT_INFO_ERR);
  1705. }
  1706. };
  1707. /*! \class Image
  1708. * \brief Base class interface for all images.
  1709. */
  1710. class Image : public Memory
  1711. {
  1712. protected:
  1713. Image() : Memory() { }
  1714. Image(const Image& image) : Memory(image) { }
  1715. Image& operator = (const Image& rhs)
  1716. {
  1717. if (this != &rhs) {
  1718. Memory::operator=(rhs);
  1719. }
  1720. return *this;
  1721. }
  1722. public:
  1723. template <typename T>
  1724. cl_int getImageInfo(cl_image_info name, T* param) const
  1725. {
  1726. return detail::errHandler(
  1727. detail::getInfo(&::clGetImageInfo, object_, name, param),
  1728. __GET_IMAGE_INFO_ERR);
  1729. }
  1730. template <cl_int name> typename
  1731. detail::param_traits<detail::cl_image_info, name>::param_type
  1732. getImageInfo(cl_int* err = NULL) const
  1733. {
  1734. typename detail::param_traits<
  1735. detail::cl_image_info, name>::param_type param;
  1736. cl_int result = getImageInfo(name, &param);
  1737. if (err != NULL) {
  1738. *err = result;
  1739. }
  1740. return param;
  1741. }
  1742. };
  1743. /*! \class Image2D
  1744. * \brief Image interface for 2D images.
  1745. */
  1746. class Image2D : public Image
  1747. {
  1748. public:
  1749. Image2D(
  1750. const Context& context,
  1751. cl_mem_flags flags,
  1752. ImageFormat format,
  1753. ::size_t width,
  1754. ::size_t height,
  1755. ::size_t row_pitch = 0,
  1756. void* host_ptr = NULL,
  1757. cl_int* err = NULL)
  1758. {
  1759. cl_int error;
  1760. object_ = ::clCreateImage2D(
  1761. context(), flags,&format, width, height, row_pitch, host_ptr, &error);
  1762. detail::errHandler(error, __CREATE_IMAGE2D_ERR);
  1763. if (err != NULL) {
  1764. *err = error;
  1765. }
  1766. }
  1767. Image2D() { }
  1768. Image2D(const Image2D& image2D) : Image(image2D) { }
  1769. Image2D& operator = (const Image2D& rhs)
  1770. {
  1771. if (this != &rhs) {
  1772. Image::operator=(rhs);
  1773. }
  1774. return *this;
  1775. }
  1776. };
  1777. /*! \class Image2DGL
  1778. * \brief 2D image interface for GL interop.
  1779. */
  1780. class Image2DGL : public Image2D
  1781. {
  1782. public:
  1783. Image2DGL(
  1784. const Context& context,
  1785. cl_mem_flags flags,
  1786. GLenum target,
  1787. GLint miplevel,
  1788. GLuint texobj,
  1789. cl_int * err = NULL)
  1790. {
  1791. cl_int error;
  1792. object_ = ::clCreateFromGLTexture2D(
  1793. context(),
  1794. flags,
  1795. target,
  1796. miplevel,
  1797. texobj,
  1798. &error);
  1799. detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
  1800. if (err != NULL) {
  1801. *err = error;
  1802. }
  1803. }
  1804. Image2DGL() : Image2D() { }
  1805. Image2DGL(const Image2DGL& image) : Image2D(image) { }
  1806. Image2DGL& operator = (const Image2DGL& rhs)
  1807. {
  1808. if (this != &rhs) {
  1809. Image2D::operator=(rhs);
  1810. }
  1811. return *this;
  1812. }
  1813. };
  1814. /*! \class Image3D
  1815. * \brief Image interface for 3D images.
  1816. */
  1817. class Image3D : public Image
  1818. {
  1819. public:
  1820. Image3D(
  1821. const Context& context,
  1822. cl_mem_flags flags,
  1823. ImageFormat format,
  1824. ::size_t width,
  1825. ::size_t height,
  1826. ::size_t depth,
  1827. ::size_t row_pitch = 0,
  1828. ::size_t slice_pitch = 0,
  1829. void* host_ptr = NULL,
  1830. cl_int* err = NULL)
  1831. {
  1832. cl_int error;
  1833. object_ = ::clCreateImage3D(
  1834. context(), flags, &format, width, height, depth, row_pitch,
  1835. slice_pitch, host_ptr, &error);
  1836. detail::errHandler(error, __CREATE_IMAGE3D_ERR);
  1837. if (err != NULL) {
  1838. *err = error;
  1839. }
  1840. }
  1841. Image3D() { }
  1842. Image3D(const Image3D& image3D) : Image(image3D) { }
  1843. Image3D& operator = (const Image3D& rhs)
  1844. {
  1845. if (this != &rhs) {
  1846. Image::operator=(rhs);
  1847. }
  1848. return *this;
  1849. }
  1850. };
  1851. /*! \class Image2DGL
  1852. * \brief 2D image interface for GL interop.
  1853. */
  1854. class Image3DGL : public Image3D
  1855. {
  1856. public:
  1857. Image3DGL(
  1858. const Context& context,
  1859. cl_mem_flags flags,
  1860. GLenum target,
  1861. GLint miplevel,
  1862. GLuint texobj,
  1863. cl_int * err = NULL)
  1864. {
  1865. cl_int error;
  1866. object_ = ::clCreateFromGLTexture3D(
  1867. context(),
  1868. flags,
  1869. target,
  1870. miplevel,
  1871. texobj,
  1872. &error);
  1873. detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
  1874. if (err != NULL) {
  1875. *err = error;
  1876. }
  1877. }
  1878. Image3DGL() : Image3D() { }
  1879. Image3DGL(const Image3DGL& image) : Image3D(image) { }
  1880. Image3DGL& operator = (const Image3DGL& rhs)
  1881. {
  1882. if (this != &rhs) {
  1883. Image3D::operator=(rhs);
  1884. }
  1885. return *this;
  1886. }
  1887. };
  1888. /*! \class Sampler
  1889. * \brief Sampler interface for cl_sampler.
  1890. */
  1891. class Sampler : public detail::Wrapper<cl_sampler>
  1892. {
  1893. public:
  1894. Sampler() { }
  1895. Sampler(
  1896. const Context& context,
  1897. cl_bool normalized_coords,
  1898. cl_addressing_mode addressing_mode,
  1899. cl_filter_mode filter_mode,
  1900. cl_int* err = NULL)
  1901. {
  1902. cl_int error;
  1903. object_ = ::clCreateSampler(
  1904. context(),
  1905. normalized_coords,
  1906. addressing_mode,
  1907. filter_mode,
  1908. &error);
  1909. detail::errHandler(error, __CREATE_SAMPLER_ERR);
  1910. if (err != NULL) {
  1911. *err = error;
  1912. }
  1913. }
  1914. Sampler(const Sampler& sampler) : detail::Wrapper<cl_type>(sampler) { }
  1915. Sampler& operator = (const Sampler& rhs)
  1916. {
  1917. if (this != &rhs) {
  1918. detail::Wrapper<cl_type>::operator=(rhs);
  1919. }
  1920. return *this;
  1921. }
  1922. template <typename T>
  1923. cl_int getInfo(cl_sampler_info name, T* param) const
  1924. {
  1925. return detail::errHandler(
  1926. detail::getInfo(&::clGetSamplerInfo, object_, name, param),
  1927. __GET_SAMPLER_INFO_ERR);
  1928. }
  1929. template <cl_int name> typename
  1930. detail::param_traits<detail::cl_sampler_info, name>::param_type
  1931. getInfo(cl_int* err = NULL) const
  1932. {
  1933. typename detail::param_traits<
  1934. detail::cl_sampler_info, name>::param_type param;
  1935. cl_int result = getInfo(name, &param);
  1936. if (err != NULL) {
  1937. *err = result;
  1938. }
  1939. return param;
  1940. }
  1941. };
  1942. __GET_INFO_HELPER_WITH_RETAIN(cl::Sampler)
  1943. class Program;
  1944. class CommandQueue;
  1945. class Kernel;
  1946. /*! \class NDRange
  1947. * \brief NDRange interface
  1948. */
  1949. class NDRange
  1950. {
  1951. private:
  1952. size_t<3> sizes_;
  1953. cl_uint dimensions_;
  1954. public:
  1955. NDRange()
  1956. : dimensions_(0)
  1957. { }
  1958. NDRange(::size_t size0)
  1959. : dimensions_(1)
  1960. {
  1961. sizes_.push_back(size0);
  1962. }
  1963. NDRange(::size_t size0, ::size_t size1)
  1964. : dimensions_(2)
  1965. {
  1966. sizes_.push_back(size0);
  1967. sizes_.push_back(size1);
  1968. }
  1969. NDRange(::size_t size0, ::size_t size1, ::size_t size2)
  1970. : dimensions_(3)
  1971. {
  1972. sizes_.push_back(size0);
  1973. sizes_.push_back(size1);
  1974. sizes_.push_back(size2);
  1975. }
  1976. operator const ::size_t*() const { return (const ::size_t*) sizes_; }
  1977. ::size_t dimensions() const { return dimensions_; }
  1978. };
  1979. static const NDRange NullRange;
  1980. /*!
  1981. * \struct LocalSpaceArg
  1982. * \brief Local address raper for use with Kernel::setArg
  1983. */
  1984. struct LocalSpaceArg
  1985. {
  1986. ::size_t size_;
  1987. };
  1988. namespace detail {
  1989. template <typename T>
  1990. struct KernelArgumentHandler
  1991. {
  1992. static ::size_t size(const T&) { return sizeof(T); }
  1993. static T* ptr(T& value) { return &value; }
  1994. };
  1995. template <>
  1996. struct KernelArgumentHandler<LocalSpaceArg>
  1997. {
  1998. static ::size_t size(const LocalSpaceArg& value) { return value.size_; }
  1999. static void* ptr(LocalSpaceArg&) { return NULL; }
  2000. };
  2001. }
  2002. //! \endcond
  2003. inline LocalSpaceArg
  2004. __local(::size_t size)
  2005. {
  2006. LocalSpaceArg ret = { size };
  2007. return ret;
  2008. }
  2009. class KernelFunctor;
  2010. /*! \class Kernel
  2011. * \brief Kernel interface that implements cl_kernel
  2012. */
  2013. class Kernel : public detail::Wrapper<cl_kernel>
  2014. {
  2015. public:
  2016. inline Kernel(const Program& program, const char* name, cl_int* err = NULL);
  2017. Kernel() { }
  2018. Kernel(const Kernel& kernel) : detail::Wrapper<cl_type>(kernel) { }
  2019. Kernel& operator = (const Kernel& rhs)
  2020. {
  2021. if (this != &rhs) {
  2022. detail::Wrapper<cl_type>::operator=(rhs);
  2023. }
  2024. return *this;
  2025. }
  2026. template <typename T>
  2027. cl_int getInfo(cl_kernel_info name, T* param) const
  2028. {
  2029. return detail::errHandler(
  2030. detail::getInfo(&::clGetKernelInfo, object_, name, param),
  2031. __GET_KERNEL_INFO_ERR);
  2032. }
  2033. template <cl_int name> typename
  2034. detail::param_traits<detail::cl_kernel_info, name>::param_type
  2035. getInfo(cl_int* err = NULL) const
  2036. {
  2037. typename detail::param_traits<
  2038. detail::cl_kernel_info, name>::param_type param;
  2039. cl_int result = getInfo(name, &param);
  2040. if (err != NULL) {
  2041. *err = result;
  2042. }
  2043. return param;
  2044. }
  2045. template <typename T>
  2046. cl_int getWorkGroupInfo(
  2047. const Device& device, cl_kernel_work_group_info name, T* param) const
  2048. {
  2049. return detail::errHandler(
  2050. detail::getInfo(
  2051. &::clGetKernelWorkGroupInfo, object_, device(), name, param),
  2052. __GET_KERNEL_WORK_GROUP_INFO_ERR);
  2053. }
  2054. template <cl_int name> typename
  2055. detail::param_traits<detail::cl_kernel_work_group_info, name>::param_type
  2056. getWorkGroupInfo(const Device& device, cl_int* err = NULL) const
  2057. {
  2058. typename detail::param_traits<
  2059. detail::cl_kernel_work_group_info, name>::param_type param;
  2060. cl_int result = getWorkGroupInfo(device, name, &param);
  2061. if (err != NULL) {
  2062. *err = result;
  2063. }
  2064. return param;
  2065. }
  2066. template <typename T>
  2067. cl_int setArg(cl_uint index, T value)
  2068. {
  2069. return detail::errHandler(
  2070. ::clSetKernelArg(
  2071. object_,
  2072. index,
  2073. detail::KernelArgumentHandler<T>::size(value),
  2074. detail::KernelArgumentHandler<T>::ptr(value)),
  2075. __SET_KERNEL_ARGS_ERR);
  2076. }
  2077. cl_int setArg(cl_uint index, ::size_t size, void* argPtr)
  2078. {
  2079. return detail::errHandler(
  2080. ::clSetKernelArg(object_, index, size, argPtr),
  2081. __SET_KERNEL_ARGS_ERR);
  2082. }
  2083. KernelFunctor bind(
  2084. const CommandQueue& queue,
  2085. const NDRange& offset,
  2086. const NDRange& global,
  2087. const NDRange& local);
  2088. KernelFunctor bind(
  2089. const CommandQueue& queue,
  2090. const NDRange& global,
  2091. const NDRange& local);
  2092. };
  2093. __GET_INFO_HELPER_WITH_RETAIN(cl::Kernel)
  2094. /*! \class Program
  2095. * \brief Program interface that implements cl_program.
  2096. */
  2097. class Program : public detail::Wrapper<cl_program>
  2098. {
  2099. public:
  2100. typedef VECTOR_CLASS<std::pair<const void*, ::size_t> > Binaries;
  2101. typedef VECTOR_CLASS<std::pair<const char*, ::size_t> > Sources;
  2102. Program(
  2103. const Context& context,
  2104. const Sources& sources,
  2105. cl_int* err = NULL)
  2106. {
  2107. cl_int error;
  2108. const ::size_t n = (::size_t)sources.size();
  2109. ::size_t* lengths = (::size_t*) alloca(n * sizeof(::size_t));
  2110. const char** strings = (const char**) alloca(n * sizeof(const char*));
  2111. for (::size_t i = 0; i < n; ++i) {
  2112. strings[i] = sources[(int)i].first;
  2113. lengths[i] = sources[(int)i].second;
  2114. }
  2115. object_ = ::clCreateProgramWithSource(
  2116. context(), (cl_uint)n, strings, lengths, &error);
  2117. detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
  2118. if (err != NULL) {
  2119. *err = error;
  2120. }
  2121. }
  2122. Program(
  2123. const Context& context,
  2124. const VECTOR_CLASS<Device>& devices,
  2125. const Binaries& binaries,
  2126. VECTOR_CLASS<cl_int>* binaryStatus = NULL,
  2127. cl_int* err = NULL)
  2128. {
  2129. cl_int error;
  2130. const ::size_t n = binaries.size();
  2131. ::size_t* lengths = (::size_t*) alloca(n * sizeof(::size_t));
  2132. const unsigned char** images = (const unsigned char**) alloca(n * sizeof(const void*));
  2133. for (::size_t i = 0; i < n; ++i) {
  2134. images[i] = (const unsigned char*)binaries[(int)i].first;
  2135. lengths[i] = binaries[(int)i].second;
  2136. }
  2137. object_ = ::clCreateProgramWithBinary(
  2138. context(), (cl_uint) devices.size(),
  2139. (cl_device_id*)&devices.front(),
  2140. lengths, images, binaryStatus != NULL
  2141. ? (cl_int*) &binaryStatus->front()
  2142. : NULL, &error);
  2143. detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
  2144. if (err != NULL) {
  2145. *err = error;
  2146. }
  2147. }
  2148. Program() { }
  2149. Program(const Program& program) : detail::Wrapper<cl_type>(program) { }
  2150. Program& operator = (const Program& rhs)
  2151. {
  2152. if (this != &rhs) {
  2153. detail::Wrapper<cl_type>::operator=(rhs);
  2154. }
  2155. return *this;
  2156. }
  2157. cl_int build(
  2158. const VECTOR_CLASS<Device>& devices,
  2159. const char* options = NULL,
  2160. void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
  2161. void* data = NULL) const
  2162. {
  2163. return detail::errHandler(
  2164. ::clBuildProgram(
  2165. object_,
  2166. (cl_uint)
  2167. devices.size(),
  2168. (cl_device_id*)&devices.front(),
  2169. options,
  2170. notifyFptr,
  2171. data),
  2172. __BUILD_PROGRAM_ERR);
  2173. }
  2174. template <typename T>
  2175. cl_int getInfo(cl_program_info name, T* param) const
  2176. {
  2177. return detail::errHandler(
  2178. detail::getInfo(&::clGetProgramInfo, object_, name, param),
  2179. __GET_PROGRAM_INFO_ERR);
  2180. }
  2181. template <cl_int name> typename
  2182. detail::param_traits<detail::cl_program_info, name>::param_type
  2183. getInfo(cl_int* err = NULL) const
  2184. {
  2185. typename detail::param_traits<
  2186. detail::cl_program_info, name>::param_type param;
  2187. cl_int result = getInfo(name, &param);
  2188. if (err != NULL) {
  2189. *err = result;
  2190. }
  2191. return param;
  2192. }
  2193. template <typename T>
  2194. cl_int getBuildInfo(
  2195. const Device& device, cl_program_build_info name, T* param) const
  2196. {
  2197. return detail::errHandler(
  2198. detail::getInfo(
  2199. &::clGetProgramBuildInfo, object_, device(), name, param),
  2200. __GET_PROGRAM_BUILD_INFO_ERR);
  2201. }
  2202. template <cl_int name> typename
  2203. detail::param_traits<detail::cl_program_build_info, name>::param_type
  2204. getBuildInfo(const Device& device, cl_int* err = NULL) const
  2205. {
  2206. typename detail::param_traits<
  2207. detail::cl_program_build_info, name>::param_type param;
  2208. cl_int result = getBuildInfo(device, name, &param);
  2209. if (err != NULL) {
  2210. *err = result;
  2211. }
  2212. return param;
  2213. }
  2214. cl_int createKernels(VECTOR_CLASS<Kernel>* kernels)
  2215. {
  2216. cl_uint numKernels;
  2217. cl_int err = ::clCreateKernelsInProgram(object_, 0, NULL, &numKernels);
  2218. if (err != CL_SUCCESS) {
  2219. return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
  2220. }
  2221. Kernel* value = (Kernel*) alloca(numKernels * sizeof(Kernel));
  2222. err = ::clCreateKernelsInProgram(
  2223. object_, numKernels, (cl_kernel*) value, NULL);
  2224. if (err != CL_SUCCESS) {
  2225. return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
  2226. }
  2227. kernels->assign(&value[0], &value[numKernels]);
  2228. return CL_SUCCESS;
  2229. }
  2230. };
  2231. __GET_INFO_HELPER_WITH_RETAIN(cl::Program)
  2232. inline Kernel::Kernel(const Program& program, const char* name, cl_int* err)
  2233. {
  2234. cl_int error;
  2235. object_ = ::clCreateKernel(program(), name, &error);
  2236. detail::errHandler(error, __CREATE_KERNEL_ERR);
  2237. if (err != NULL) {
  2238. *err = error;
  2239. }
  2240. }
  2241. /*! \class CommandQueue
  2242. * \brief CommandQueue interface for cl_command_queue.
  2243. */
  2244. class CommandQueue : public detail::Wrapper<cl_command_queue>
  2245. {
  2246. public:
  2247. CommandQueue(
  2248. const Context& context,
  2249. const Device& device,
  2250. cl_command_queue_properties properties = 0,
  2251. cl_int* err = NULL)
  2252. {
  2253. cl_int error;
  2254. object_ = ::clCreateCommandQueue(
  2255. context(), device(), properties, &error);
  2256. detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
  2257. if (err != NULL) {
  2258. *err = error;
  2259. }
  2260. }
  2261. CommandQueue() { }
  2262. CommandQueue(const CommandQueue& commandQueue) : detail::Wrapper<cl_type>(commandQueue) { }
  2263. CommandQueue& operator = (const CommandQueue& rhs)
  2264. {
  2265. if (this != &rhs) {
  2266. detail::Wrapper<cl_type>::operator=(rhs);
  2267. }
  2268. return *this;
  2269. }
  2270. template <typename T>
  2271. cl_int getInfo(cl_command_queue_info name, T* param) const
  2272. {
  2273. return detail::errHandler(
  2274. detail::getInfo(
  2275. &::clGetCommandQueueInfo, object_, name, param),
  2276. __GET_COMMAND_QUEUE_INFO_ERR);
  2277. }
  2278. template <cl_int name> typename
  2279. detail::param_traits<detail::cl_command_queue_info, name>::param_type
  2280. getInfo(cl_int* err = NULL) const
  2281. {
  2282. typename detail::param_traits<
  2283. detail::cl_command_queue_info, name>::param_type param;
  2284. cl_int result = getInfo(name, &param);
  2285. if (err != NULL) {
  2286. *err = result;
  2287. }
  2288. return param;
  2289. }
  2290. cl_int enqueueReadBuffer(
  2291. const Buffer& buffer,
  2292. cl_bool blocking,
  2293. ::size_t offset,
  2294. ::size_t size,
  2295. void* ptr,
  2296. const VECTOR_CLASS<Event>* events = NULL,
  2297. Event* event = NULL) const
  2298. {
  2299. return detail::errHandler(
  2300. ::clEnqueueReadBuffer(
  2301. object_, buffer(), blocking, offset, size,
  2302. ptr,
  2303. (events != NULL) ? (cl_uint) events->size() : 0,
  2304. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  2305. (cl_event*) event),
  2306. __ENQUEUE_READ_BUFFER_ERR);
  2307. }
  2308. cl_int enqueueWriteBuffer(
  2309. const Buffer& buffer,
  2310. cl_bool blocking,
  2311. ::size_t offset,
  2312. ::size_t size,
  2313. const void* ptr,
  2314. const VECTOR_CLASS<Event>* events = NULL,
  2315. Event* event = NULL) const
  2316. {
  2317. return detail::errHandler(
  2318. ::clEnqueueWriteBuffer(
  2319. object_, buffer(), blocking, offset, size,
  2320. ptr,
  2321. (events != NULL) ? (cl_uint) events->size() : 0,
  2322. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  2323. (cl_event*) event),
  2324. __ENQUEUE_WRITE_BUFFER_ERR);
  2325. }
  2326. cl_int enqueueCopyBuffer(
  2327. const Buffer& src,
  2328. const Buffer& dst,
  2329. ::size_t src_offset,
  2330. ::size_t dst_offset,
  2331. ::size_t size,
  2332. const VECTOR_CLASS<Event>* events = NULL,
  2333. Event* event = NULL) const
  2334. {
  2335. return detail::errHandler(
  2336. ::clEnqueueCopyBuffer(
  2337. object_, src(), dst(), src_offset, dst_offset, size,
  2338. (events != NULL) ? (cl_uint) events->size() : 0,
  2339. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  2340. (cl_event*) event),
  2341. __ENQEUE_COPY_BUFFER_ERR);
  2342. }
  2343. #if defined(CL_VERSION_1_1)
  2344. cl_int enqueueReadBufferRect(
  2345. const Buffer& buffer,
  2346. cl_bool blocking,
  2347. const size_t<3>& buffer_offset,
  2348. const size_t<3>& host_offset,
  2349. const size_t<3>& region,
  2350. ::size_t buffer_row_pitch,
  2351. ::size_t buffer_slice_pitch,
  2352. ::size_t host_row_pitch,
  2353. ::size_t host_slice_pitch,
  2354. void *ptr,
  2355. const VECTOR_CLASS<Event>* events = NULL,
  2356. Event* event = NULL) const
  2357. {
  2358. return detail::errHandler(
  2359. ::clEnqueueReadBufferRect(
  2360. object_,
  2361. buffer(),
  2362. blocking,
  2363. (const ::size_t *)buffer_offset,
  2364. (const ::size_t *)host_offset,
  2365. (const ::size_t *)region,
  2366. buffer_row_pitch,
  2367. buffer_slice_pitch,
  2368. host_row_pitch,
  2369. host_slice_pitch,
  2370. ptr,
  2371. (events != NULL) ? (cl_uint) events->size() : 0,
  2372. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  2373. (cl_event*) event),
  2374. __ENQUEUE_READ_BUFFER_RECT_ERR);
  2375. }
  2376. cl_int enqueueWriteBufferRect(
  2377. const Buffer& buffer,
  2378. cl_bool blocking,
  2379. const size_t<3>& buffer_offset,
  2380. const size_t<3>& host_offset,
  2381. const size_t<3>& region,
  2382. ::size_t buffer_row_pitch,
  2383. ::size_t buffer_slice_pitch,
  2384. ::size_t host_row_pitch,
  2385. ::size_t host_slice_pitch,
  2386. void *ptr,
  2387. const VECTOR_CLASS<Event>* events = NULL,
  2388. Event* event = NULL) const
  2389. {
  2390. return detail::errHandler(
  2391. ::clEnqueueWriteBufferRect(
  2392. object_,
  2393. buffer(),
  2394. blocking,
  2395. (const ::size_t *)buffer_offset,
  2396. (const ::size_t *)host_offset,
  2397. (const ::size_t *)region,
  2398. buffer_row_pitch,
  2399. buffer_slice_pitch,
  2400. host_row_pitch,
  2401. host_slice_pitch,
  2402. ptr,
  2403. (events != NULL) ? (cl_uint) events->size() : 0,
  2404. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  2405. (cl_event*) event),
  2406. __ENQUEUE_WRITE_BUFFER_RECT_ERR);
  2407. }
  2408. cl_int enqueueCopyBufferRect(
  2409. const Buffer& src,
  2410. const Buffer& dst,
  2411. const size_t<3>& src_origin,
  2412. const size_t<3>& dst_origin,
  2413. const size_t<3>& region,
  2414. ::size_t src_row_pitch,
  2415. ::size_t src_slice_pitch,
  2416. ::size_t dst_row_pitch,
  2417. ::size_t dst_slice_pitch,
  2418. const VECTOR_CLASS<Event>* events = NULL,
  2419. Event* event = NULL) const
  2420. {
  2421. return detail::errHandler(
  2422. ::clEnqueueCopyBufferRect(
  2423. object_,
  2424. src(),
  2425. dst(),
  2426. (const ::size_t *)src_origin,
  2427. (const ::size_t *)dst_origin,
  2428. (const ::size_t *)region,
  2429. src_row_pitch,
  2430. src_slice_pitch,
  2431. dst_row_pitch,
  2432. dst_slice_pitch,
  2433. (events != NULL) ? (cl_uint) events->size() : 0,
  2434. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  2435. (cl_event*) event),
  2436. __ENQEUE_COPY_BUFFER_RECT_ERR);
  2437. }
  2438. #endif
  2439. cl_int enqueueReadImage(
  2440. const Image& image,
  2441. cl_bool blocking,
  2442. const size_t<3>& origin,
  2443. const size_t<3>& region,
  2444. ::size_t row_pitch,
  2445. ::size_t slice_pitch,
  2446. void* ptr,
  2447. const VECTOR_CLASS<Event>* events = NULL,
  2448. Event* event = NULL) const
  2449. {
  2450. return detail::errHandler(
  2451. ::clEnqueueReadImage(
  2452. object_, image(), blocking, (const ::size_t *) origin,
  2453. (const ::size_t *) region, row_pitch, slice_pitch, ptr,
  2454. (events != NULL) ? (cl_uint) events->size() : 0,
  2455. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  2456. (cl_event*) event),
  2457. __ENQUEUE_READ_IMAGE_ERR);
  2458. }
  2459. cl_int enqueueWriteImage(
  2460. const Image& image,
  2461. cl_bool blocking,
  2462. const size_t<3>& origin,
  2463. const size_t<3>& region,
  2464. ::size_t row_pitch,
  2465. ::size_t slice_pitch,
  2466. void* ptr,
  2467. const VECTOR_CLASS<Event>* events = NULL,
  2468. Event* event = NULL) const
  2469. {
  2470. return detail::errHandler(
  2471. ::clEnqueueWriteImage(
  2472. object_, image(), blocking, (const ::size_t *) origin,
  2473. (const ::size_t *) region, row_pitch, slice_pitch, ptr,
  2474. (events != NULL) ? (cl_uint) events->size() : 0,
  2475. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  2476. (cl_event*) event),
  2477. __ENQUEUE_WRITE_IMAGE_ERR);
  2478. }
  2479. cl_int enqueueCopyImage(
  2480. const Image& src,
  2481. const Image& dst,
  2482. const size_t<3>& src_origin,
  2483. const size_t<3>& dst_origin,
  2484. const size_t<3>& region,
  2485. const VECTOR_CLASS<Event>* events = NULL,
  2486. Event* event = NULL) const
  2487. {
  2488. return detail::errHandler(
  2489. ::clEnqueueCopyImage(
  2490. object_, src(), dst(), (const ::size_t *) src_origin,
  2491. (const ::size_t *)dst_origin, (const ::size_t *) region,
  2492. (events != NULL) ? (cl_uint) events->size() : 0,
  2493. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  2494. (cl_event*) event),
  2495. __ENQUEUE_COPY_IMAGE_ERR);
  2496. }
  2497. cl_int enqueueCopyImageToBuffer(
  2498. const Image& src,
  2499. const Buffer& dst,
  2500. const size_t<3>& src_origin,
  2501. const size_t<3>& region,
  2502. ::size_t dst_offset,
  2503. const VECTOR_CLASS<Event>* events = NULL,
  2504. Event* event = NULL) const
  2505. {
  2506. return detail::errHandler(
  2507. ::clEnqueueCopyImageToBuffer(
  2508. object_, src(), dst(), (const ::size_t *) src_origin,
  2509. (const ::size_t *) region, dst_offset,
  2510. (events != NULL) ? (cl_uint) events->size() : 0,
  2511. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  2512. (cl_event*) event),
  2513. __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR);
  2514. }
  2515. cl_int enqueueCopyBufferToImage(
  2516. const Buffer& src,
  2517. const Image& dst,
  2518. ::size_t src_offset,
  2519. const size_t<3>& dst_origin,
  2520. const size_t<3>& region,
  2521. const VECTOR_CLASS<Event>* events = NULL,
  2522. Event* event = NULL) const
  2523. {
  2524. return detail::errHandler(
  2525. ::clEnqueueCopyBufferToImage(
  2526. object_, src(), dst(), src_offset,
  2527. (const ::size_t *) dst_origin, (const ::size_t *) region,
  2528. (events != NULL) ? (cl_uint) events->size() : 0,
  2529. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  2530. (cl_event*) event),
  2531. __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR);
  2532. }
  2533. void* enqueueMapBuffer(
  2534. const Buffer& buffer,
  2535. cl_bool blocking,
  2536. cl_map_flags flags,
  2537. ::size_t offset,
  2538. ::size_t size,
  2539. const VECTOR_CLASS<Event>* events = NULL,
  2540. Event* event = NULL,
  2541. cl_int* err = NULL) const
  2542. {
  2543. cl_int error;
  2544. void * result = ::clEnqueueMapBuffer(
  2545. object_, buffer(), blocking, flags, offset, size,
  2546. (events != NULL) ? (cl_uint) events->size() : 0,
  2547. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  2548. (cl_event*) event,
  2549. &error);
  2550. detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
  2551. if (err != NULL) {
  2552. *err = error;
  2553. }
  2554. return result;
  2555. }
  2556. void* enqueueMapImage(
  2557. const Image& buffer,
  2558. cl_bool blocking,
  2559. cl_map_flags flags,
  2560. const size_t<3>& origin,
  2561. const size_t<3>& region,
  2562. ::size_t * row_pitch,
  2563. ::size_t * slice_pitch,
  2564. const VECTOR_CLASS<Event>* events = NULL,
  2565. Event* event = NULL,
  2566. cl_int* err = NULL) const
  2567. {
  2568. cl_int error;
  2569. void * result = ::clEnqueueMapImage(
  2570. object_, buffer(), blocking, flags,
  2571. (const ::size_t *) origin, (const ::size_t *) region,
  2572. row_pitch, slice_pitch,
  2573. (events != NULL) ? (cl_uint) events->size() : 0,
  2574. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  2575. (cl_event*) event,
  2576. &error);
  2577. detail::errHandler(error, __ENQUEUE_MAP_IMAGE_ERR);
  2578. if (err != NULL) {
  2579. *err = error;
  2580. }
  2581. return result;
  2582. }
  2583. cl_int enqueueUnmapMemObject(
  2584. const Memory& memory,
  2585. void* mapped_ptr,
  2586. const VECTOR_CLASS<Event>* events = NULL,
  2587. Event* event = NULL) const
  2588. {
  2589. return detail::errHandler(
  2590. ::clEnqueueUnmapMemObject(
  2591. object_, memory(), mapped_ptr,
  2592. (events != NULL) ? (cl_uint) events->size() : 0,
  2593. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  2594. (cl_event*) event),
  2595. __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
  2596. }
  2597. cl_int enqueueNDRangeKernel(
  2598. const Kernel& kernel,
  2599. const NDRange& offset,
  2600. const NDRange& global,
  2601. const NDRange& local,
  2602. const VECTOR_CLASS<Event>* events = NULL,
  2603. Event* event = NULL) const
  2604. {
  2605. return detail::errHandler(
  2606. ::clEnqueueNDRangeKernel(
  2607. object_, kernel(), (cl_uint) global.dimensions(),
  2608. offset.dimensions() != 0 ? (const ::size_t*) offset : NULL,
  2609. (const ::size_t*) global,
  2610. local.dimensions() != 0 ? (const ::size_t*) local : NULL,
  2611. (events != NULL) ? (cl_uint) events->size() : 0,
  2612. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  2613. (cl_event*) event),
  2614. __ENQUEUE_NDRANGE_KERNEL_ERR);
  2615. }
  2616. cl_int enqueueTask(
  2617. const Kernel& kernel,
  2618. const VECTOR_CLASS<Event>* events = NULL,
  2619. Event* event = NULL) const
  2620. {
  2621. return detail::errHandler(
  2622. ::clEnqueueTask(
  2623. object_, kernel(),
  2624. (events != NULL) ? (cl_uint) events->size() : 0,
  2625. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  2626. (cl_event*) event),
  2627. __ENQUEUE_TASK_ERR);
  2628. }
  2629. cl_int enqueueNativeKernel(
  2630. void (*userFptr)(void *),
  2631. std::pair<void*, ::size_t> args,
  2632. const VECTOR_CLASS<Memory>* mem_objects = NULL,
  2633. const VECTOR_CLASS<const void*>* mem_locs = NULL,
  2634. const VECTOR_CLASS<Event>* events = NULL,
  2635. Event* event = NULL) const
  2636. {
  2637. cl_mem * mems = (mem_objects != NULL && mem_objects->size() > 0)
  2638. ? (cl_mem*) alloca(mem_objects->size() * sizeof(cl_mem))
  2639. : NULL;
  2640. if (mems != NULL) {
  2641. for (unsigned int i = 0; i < mem_objects->size(); i++) {
  2642. mems[i] = ((*mem_objects)[i])();
  2643. }
  2644. }
  2645. return detail::errHandler(
  2646. ::clEnqueueNativeKernel(
  2647. object_, userFptr, args.first, args.second,
  2648. (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
  2649. mems,
  2650. (mem_locs != NULL) ? (const void **) &mem_locs->front() : NULL,
  2651. (events != NULL) ? (cl_uint) events->size() : 0,
  2652. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  2653. (cl_event*) event),
  2654. __ENQUEUE_NATIVE_KERNEL);
  2655. }
  2656. cl_int enqueueMarker(Event* event = NULL) const
  2657. {
  2658. return detail::errHandler(
  2659. ::clEnqueueMarker(object_, (cl_event*) event),
  2660. __ENQUEUE_MARKER_ERR);
  2661. }
  2662. cl_int enqueueWaitForEvents(const VECTOR_CLASS<Event>& events) const
  2663. {
  2664. return detail::errHandler(
  2665. ::clEnqueueWaitForEvents(
  2666. object_,
  2667. (cl_uint) events.size(),
  2668. (const cl_event*) &events.front()),
  2669. __ENQUEUE_WAIT_FOR_EVENTS_ERR);
  2670. }
  2671. cl_int enqueueAcquireGLObjects(
  2672. const VECTOR_CLASS<Memory>* mem_objects = NULL,
  2673. const VECTOR_CLASS<Event>* events = NULL,
  2674. Event* event = NULL) const
  2675. {
  2676. return detail::errHandler(
  2677. ::clEnqueueAcquireGLObjects(
  2678. object_,
  2679. (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
  2680. (mem_objects != NULL) ? (const cl_mem *) &mem_objects->front(): NULL,
  2681. (events != NULL) ? (cl_uint) events->size() : 0,
  2682. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  2683. (cl_event*) event),
  2684. __ENQUEUE_ACQUIRE_GL_ERR);
  2685. }
  2686. cl_int enqueueReleaseGLObjects(
  2687. const VECTOR_CLASS<Memory>* mem_objects = NULL,
  2688. const VECTOR_CLASS<Event>* events = NULL,
  2689. Event* event = NULL) const
  2690. {
  2691. return detail::errHandler(
  2692. ::clEnqueueReleaseGLObjects(
  2693. object_,
  2694. (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
  2695. (mem_objects != NULL) ? (const cl_mem *) &mem_objects->front(): NULL,
  2696. (events != NULL) ? (cl_uint) events->size() : 0,
  2697. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  2698. (cl_event*) event),
  2699. __ENQUEUE_RELEASE_GL_ERR);
  2700. }
  2701. #if defined (USE_DX_INTEROP)
  2702. typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueAcquireD3D10ObjectsKHR)(
  2703. cl_command_queue command_queue, cl_uint num_objects,
  2704. const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
  2705. const cl_event* event_wait_list, cl_event* event);
  2706. typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueReleaseD3D10ObjectsKHR)(
  2707. cl_command_queue command_queue, cl_uint num_objects,
  2708. const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
  2709. const cl_event* event_wait_list, cl_event* event);
  2710. cl_int enqueueAcquireD3D10Objects(
  2711. const VECTOR_CLASS<Memory>* mem_objects = NULL,
  2712. const VECTOR_CLASS<Event>* events = NULL,
  2713. Event* event = NULL) const
  2714. {
  2715. static PFN_clEnqueueAcquireD3D10ObjectsKHR pfn_clEnqueueAcquireD3D10ObjectsKHR = NULL;
  2716. __INIT_CL_EXT_FCN_PTR(clEnqueueAcquireD3D10ObjectsKHR);
  2717. return detail::errHandler(
  2718. pfn_clEnqueueAcquireD3D10ObjectsKHR(
  2719. object_,
  2720. (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
  2721. (mem_objects != NULL) ? (const cl_mem *) &mem_objects->front(): NULL,
  2722. (events != NULL) ? (cl_uint) events->size() : 0,
  2723. (events != NULL) ? (cl_event*) &events->front() : NULL,
  2724. (cl_event*) event),
  2725. __ENQUEUE_ACQUIRE_GL_ERR);
  2726. }
  2727. cl_int enqueueReleaseD3D10Objects(
  2728. const VECTOR_CLASS<Memory>* mem_objects = NULL,
  2729. const VECTOR_CLASS<Event>* events = NULL,
  2730. Event* event = NULL) const
  2731. {
  2732. static PFN_clEnqueueReleaseD3D10ObjectsKHR pfn_clEnqueueReleaseD3D10ObjectsKHR = NULL;
  2733. __INIT_CL_EXT_FCN_PTR(clEnqueueReleaseD3D10ObjectsKHR);
  2734. return detail::errHandler(
  2735. pfn_clEnqueueReleaseD3D10ObjectsKHR(
  2736. object_,
  2737. (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
  2738. (mem_objects != NULL) ? (const cl_mem *) &mem_objects->front(): NULL,
  2739. (events != NULL) ? (cl_uint) events->size() : 0,
  2740. (events != NULL) ? (cl_event*) &events->front() : NULL,
  2741. (cl_event*) event),
  2742. __ENQUEUE_RELEASE_GL_ERR);
  2743. }
  2744. #endif
  2745. cl_int enqueueBarrier() const
  2746. {
  2747. return detail::errHandler(
  2748. ::clEnqueueBarrier(object_),
  2749. __ENQUEUE_BARRIER_ERR);
  2750. }
  2751. cl_int flush() const
  2752. {
  2753. return detail::errHandler(::clFlush(object_), __FLUSH_ERR);
  2754. }
  2755. cl_int finish() const
  2756. {
  2757. return detail::errHandler(::clFinish(object_), __FINISH_ERR);
  2758. }
  2759. };
  2760. __GET_INFO_HELPER_WITH_RETAIN(cl::CommandQueue)
  2761. /*! \class KernelFunctor
  2762. * \brief Kernel functor interface
  2763. *
  2764. * \note Currently only functors of zero to ten arguments are supported. It
  2765. * is straightforward to add more and a more general solution, similar to
  2766. * Boost.Lambda could be followed if required in the future.
  2767. */
  2768. class KernelFunctor
  2769. {
  2770. private:
  2771. Kernel kernel_;
  2772. CommandQueue queue_;
  2773. NDRange offset_;
  2774. NDRange global_;
  2775. NDRange local_;
  2776. cl_int err_;
  2777. public:
  2778. KernelFunctor() { }
  2779. KernelFunctor(
  2780. const Kernel& kernel,
  2781. const CommandQueue& queue,
  2782. const NDRange& offset,
  2783. const NDRange& global,
  2784. const NDRange& local) :
  2785. kernel_(kernel),
  2786. queue_(queue),
  2787. offset_(offset),
  2788. global_(global),
  2789. local_(local),
  2790. err_(CL_SUCCESS)
  2791. {}
  2792. KernelFunctor& operator=(const KernelFunctor& rhs);
  2793. KernelFunctor(const KernelFunctor& rhs);
  2794. cl_int getError() { return err_; }
  2795. inline Event operator()(const VECTOR_CLASS<Event>* events = NULL);
  2796. template<typename A1>
  2797. inline Event operator()(
  2798. const A1& a1,
  2799. const VECTOR_CLASS<Event>* events = NULL);
  2800. template<class A1, class A2>
  2801. inline Event operator()(
  2802. const A1& a1,
  2803. const A2& a2,
  2804. const VECTOR_CLASS<Event>* events = NULL);
  2805. template<class A1, class A2, class A3>
  2806. inline Event operator()(
  2807. const A1& a1,
  2808. const A2& a2,
  2809. const A3& a3,
  2810. const VECTOR_CLASS<Event>* events = NULL);
  2811. template<class A1, class A2, class A3, class A4>
  2812. inline Event operator()(
  2813. const A1& a1,
  2814. const A2& a2,
  2815. const A3& a3,
  2816. const A4& a4,
  2817. const VECTOR_CLASS<Event>* events = NULL);
  2818. template<class A1, class A2, class A3, class A4, class A5>
  2819. inline Event operator()(
  2820. const A1& a1,
  2821. const A2& a2,
  2822. const A3& a3,
  2823. const A4& a4,
  2824. const A5& a5,
  2825. const VECTOR_CLASS<Event>* events = NULL);
  2826. template<class A1, class A2, class A3, class A4, class A5, class A6>
  2827. inline Event operator()(
  2828. const A1& a1,
  2829. const A2& a2,
  2830. const A3& a3,
  2831. const A4& a4,
  2832. const A5& a5,
  2833. const A6& a6,
  2834. const VECTOR_CLASS<Event>* events = NULL);
  2835. template<class A1, class A2, class A3, class A4,
  2836. class A5, class A6, class A7>
  2837. inline Event operator()(
  2838. const A1& a1,
  2839. const A2& a2,
  2840. const A3& a3,
  2841. const A4& a4,
  2842. const A5& a5,
  2843. const A6& a6,
  2844. const A7& a7,
  2845. const VECTOR_CLASS<Event>* events = NULL);
  2846. template<class A1, class A2, class A3, class A4, class A5,
  2847. class A6, class A7, class A8>
  2848. inline Event operator()(
  2849. const A1& a1,
  2850. const A2& a2,
  2851. const A3& a3,
  2852. const A4& a4,
  2853. const A5& a5,
  2854. const A6& a6,
  2855. const A7& a7,
  2856. const A8& a8,
  2857. const VECTOR_CLASS<Event>* events = NULL);
  2858. template<class A1, class A2, class A3, class A4, class A5,
  2859. class A6, class A7, class A8, class A9>
  2860. inline Event operator()(
  2861. const A1& a1,
  2862. const A2& a2,
  2863. const A3& a3,
  2864. const A4& a4,
  2865. const A5& a5,
  2866. const A6& a6,
  2867. const A7& a7,
  2868. const A8& a8,
  2869. const A9& a9,
  2870. const VECTOR_CLASS<Event>* events = NULL);
  2871. template<class A1, class A2, class A3, class A4, class A5,
  2872. class A6, class A7, class A8, class A9, class A10>
  2873. inline Event operator()(
  2874. const A1& a1,
  2875. const A2& a2,
  2876. const A3& a3,
  2877. const A4& a4,
  2878. const A5& a5,
  2879. const A6& a6,
  2880. const A7& a7,
  2881. const A8& a8,
  2882. const A9& a9,
  2883. const A10& a10,
  2884. const VECTOR_CLASS<Event>* events = NULL);
  2885. template<class A1, class A2, class A3, class A4, class A5,
  2886. class A6, class A7, class A8, class A9, class A10,
  2887. class A11>
  2888. inline Event operator()(
  2889. const A1& a1,
  2890. const A2& a2,
  2891. const A3& a3,
  2892. const A4& a4,
  2893. const A5& a5,
  2894. const A6& a6,
  2895. const A7& a7,
  2896. const A8& a8,
  2897. const A9& a9,
  2898. const A10& a10,
  2899. const A11& a11,
  2900. const VECTOR_CLASS<Event>* events = NULL);
  2901. template<class A1, class A2, class A3, class A4, class A5,
  2902. class A6, class A7, class A8, class A9, class A10,
  2903. class A11, class A12>
  2904. inline Event operator()(
  2905. const A1& a1,
  2906. const A2& a2,
  2907. const A3& a3,
  2908. const A4& a4,
  2909. const A5& a5,
  2910. const A6& a6,
  2911. const A7& a7,
  2912. const A8& a8,
  2913. const A9& a9,
  2914. const A10& a10,
  2915. const A11& a11,
  2916. const A12& a12,
  2917. const VECTOR_CLASS<Event>* events = NULL);
  2918. template<class A1, class A2, class A3, class A4, class A5,
  2919. class A6, class A7, class A8, class A9, class A10,
  2920. class A11, class A12, class A13>
  2921. inline Event operator()(
  2922. const A1& a1,
  2923. const A2& a2,
  2924. const A3& a3,
  2925. const A4& a4,
  2926. const A5& a5,
  2927. const A6& a6,
  2928. const A7& a7,
  2929. const A8& a8,
  2930. const A9& a9,
  2931. const A10& a10,
  2932. const A11& a11,
  2933. const A12& a12,
  2934. const A13& a13,
  2935. const VECTOR_CLASS<Event>* events = NULL);
  2936. template<class A1, class A2, class A3, class A4, class A5,
  2937. class A6, class A7, class A8, class A9, class A10,
  2938. class A11, class A12, class A13, class A14>
  2939. inline Event operator()(
  2940. const A1& a1,
  2941. const A2& a2,
  2942. const A3& a3,
  2943. const A4& a4,
  2944. const A5& a5,
  2945. const A6& a6,
  2946. const A7& a7,
  2947. const A8& a8,
  2948. const A9& a9,
  2949. const A10& a10,
  2950. const A11& a11,
  2951. const A12& a12,
  2952. const A13& a13,
  2953. const A14& a14,
  2954. const VECTOR_CLASS<Event>* events = NULL);
  2955. template<class A1, class A2, class A3, class A4, class A5,
  2956. class A6, class A7, class A8, class A9, class A10,
  2957. class A11, class A12, class A13, class A14, class A15>
  2958. inline Event operator()(
  2959. const A1& a1,
  2960. const A2& a2,
  2961. const A3& a3,
  2962. const A4& a4,
  2963. const A5& a5,
  2964. const A6& a6,
  2965. const A7& a7,
  2966. const A8& a8,
  2967. const A9& a9,
  2968. const A10& a10,
  2969. const A11& a11,
  2970. const A12& a12,
  2971. const A13& a13,
  2972. const A14& a14,
  2973. const A15& a15,
  2974. const VECTOR_CLASS<Event>* events = NULL);
  2975. };
  2976. inline KernelFunctor Kernel::bind(
  2977. const CommandQueue& queue,
  2978. const NDRange& offset,
  2979. const NDRange& global,
  2980. const NDRange& local)
  2981. {
  2982. return KernelFunctor(*this,queue,offset,global,local);
  2983. }
  2984. inline KernelFunctor Kernel::bind(
  2985. const CommandQueue& queue,
  2986. const NDRange& global,
  2987. const NDRange& local)
  2988. {
  2989. return KernelFunctor(*this,queue,NullRange,global,local);
  2990. }
  2991. inline KernelFunctor& KernelFunctor::operator=(const KernelFunctor& rhs)
  2992. {
  2993. if (this == &rhs) {
  2994. return *this;
  2995. }
  2996. kernel_ = rhs.kernel_;
  2997. queue_ = rhs.queue_;
  2998. offset_ = rhs.offset_;
  2999. global_ = rhs.global_;
  3000. local_ = rhs.local_;
  3001. return *this;
  3002. }
  3003. inline KernelFunctor::KernelFunctor(const KernelFunctor& rhs) :
  3004. kernel_(rhs.kernel_),
  3005. queue_(rhs.queue_),
  3006. offset_(rhs.offset_),
  3007. global_(rhs.global_),
  3008. local_(rhs.local_)
  3009. {
  3010. }
  3011. Event KernelFunctor::operator()(const VECTOR_CLASS<Event>* events)
  3012. {
  3013. (void)events;
  3014. Event event;
  3015. err_ = queue_.enqueueNDRangeKernel(
  3016. kernel_,
  3017. offset_,
  3018. global_,
  3019. local_,
  3020. NULL, // bgaster_fixme - do we want to allow wait event lists?
  3021. &event);
  3022. return event;
  3023. }
  3024. template<typename A1>
  3025. Event KernelFunctor::operator()(
  3026. const A1& a1,
  3027. const VECTOR_CLASS<Event>* events)
  3028. {
  3029. Event event;
  3030. kernel_.setArg(0,a1);
  3031. err_ = queue_.enqueueNDRangeKernel(
  3032. kernel_,
  3033. offset_,
  3034. global_,
  3035. local_,
  3036. NULL, // bgaster_fixme - do we want to allow wait event lists?
  3037. &event);
  3038. return event;
  3039. }
  3040. template<typename A1, typename A2>
  3041. Event KernelFunctor::operator()(
  3042. const A1& a1,
  3043. const A2& a2,
  3044. const VECTOR_CLASS<Event>* events)
  3045. {
  3046. Event event;
  3047. kernel_.setArg(0,a1);
  3048. kernel_.setArg(1,a2);
  3049. err_ = queue_.enqueueNDRangeKernel(
  3050. kernel_,
  3051. offset_,
  3052. global_,
  3053. local_,
  3054. NULL, // bgaster_fixme - do we want to allow wait event lists?
  3055. &event);
  3056. return event;
  3057. }
  3058. template<typename A1, typename A2, typename A3>
  3059. Event KernelFunctor::operator()(
  3060. const A1& a1,
  3061. const A2& a2,
  3062. const A3& a3,
  3063. const VECTOR_CLASS<Event>* events)
  3064. {
  3065. Event event;
  3066. kernel_.setArg(0,a1);
  3067. kernel_.setArg(1,a2);
  3068. kernel_.setArg(2,a3);
  3069. err_ = queue_.enqueueNDRangeKernel(
  3070. kernel_,
  3071. offset_,
  3072. global_,
  3073. local_,
  3074. NULL, // bgaster_fixme - do we want to allow wait event lists?
  3075. &event);
  3076. return event;
  3077. }
  3078. template<typename A1, typename A2, typename A3, typename A4>
  3079. Event KernelFunctor::operator()(
  3080. const A1& a1,
  3081. const A2& a2,
  3082. const A3& a3,
  3083. const A4& a4,
  3084. const VECTOR_CLASS<Event>* events)
  3085. {
  3086. Event event;
  3087. kernel_.setArg(0,a1);
  3088. kernel_.setArg(1,a2);
  3089. kernel_.setArg(2,a3);
  3090. kernel_.setArg(3,a4);
  3091. err_ = queue_.enqueueNDRangeKernel(
  3092. kernel_,
  3093. offset_,
  3094. global_,
  3095. local_,
  3096. NULL, // bgaster_fixme - do we want to allow wait event lists?
  3097. &event);
  3098. return event;
  3099. }
  3100. template<typename A1, typename A2, typename A3, typename A4, typename A5>
  3101. Event KernelFunctor::operator()(
  3102. const A1& a1,
  3103. const A2& a2,
  3104. const A3& a3,
  3105. const A4& a4,
  3106. const A5& a5,
  3107. const VECTOR_CLASS<Event>* events)
  3108. {
  3109. Event event;
  3110. kernel_.setArg(0,a1);
  3111. kernel_.setArg(1,a2);
  3112. kernel_.setArg(2,a3);
  3113. kernel_.setArg(3,a4);
  3114. kernel_.setArg(4,a5);
  3115. err_ = queue_.enqueueNDRangeKernel(
  3116. kernel_,
  3117. offset_,
  3118. global_,
  3119. local_,
  3120. NULL, // bgaster_fixme - do we want to allow wait event lists?
  3121. &event);
  3122. return event;
  3123. }
  3124. template<typename A1, typename A2, typename A3, typename A4, typename A5,
  3125. typename A6>
  3126. Event KernelFunctor::operator()(
  3127. const A1& a1,
  3128. const A2& a2,
  3129. const A3& a3,
  3130. const A4& a4,
  3131. const A5& a5,
  3132. const A6& a6,
  3133. const VECTOR_CLASS<Event>* events)
  3134. {
  3135. Event event;
  3136. kernel_.setArg(0,a1);
  3137. kernel_.setArg(1,a2);
  3138. kernel_.setArg(2,a3);
  3139. kernel_.setArg(3,a4);
  3140. kernel_.setArg(4,a5);
  3141. kernel_.setArg(5,a6);
  3142. err_ = queue_.enqueueNDRangeKernel(
  3143. kernel_,
  3144. offset_,
  3145. global_,
  3146. local_,
  3147. NULL, // bgaster_fixme - do we want to allow wait event lists?
  3148. &event);
  3149. return event;
  3150. }
  3151. template<typename A1, typename A2, typename A3, typename A4,
  3152. typename A5, typename A6, typename A7>
  3153. Event KernelFunctor::operator()(
  3154. const A1& a1,
  3155. const A2& a2,
  3156. const A3& a3,
  3157. const A4& a4,
  3158. const A5& a5,
  3159. const A6& a6,
  3160. const A7& a7,
  3161. const VECTOR_CLASS<Event>* events)
  3162. {
  3163. Event event;
  3164. kernel_.setArg(0,a1);
  3165. kernel_.setArg(1,a2);
  3166. kernel_.setArg(2,a3);
  3167. kernel_.setArg(3,a4);
  3168. kernel_.setArg(4,a5);
  3169. kernel_.setArg(5,a6);
  3170. kernel_.setArg(6,a7);
  3171. err_ = queue_.enqueueNDRangeKernel(
  3172. kernel_,
  3173. offset_,
  3174. global_,
  3175. local_,
  3176. NULL, // bgaster_fixme - do we want to allow wait event lists?
  3177. &event);
  3178. return event;
  3179. }
  3180. template<typename A1, typename A2, typename A3, typename A4, typename A5,
  3181. typename A6, typename A7, typename A8>
  3182. Event KernelFunctor::operator()(
  3183. const A1& a1,
  3184. const A2& a2,
  3185. const A3& a3,
  3186. const A4& a4,
  3187. const A5& a5,
  3188. const A6& a6,
  3189. const A7& a7,
  3190. const A8& a8,
  3191. const VECTOR_CLASS<Event>* events)
  3192. {
  3193. Event event;
  3194. kernel_.setArg(0,a1);
  3195. kernel_.setArg(1,a2);
  3196. kernel_.setArg(2,a3);
  3197. kernel_.setArg(3,a4);
  3198. kernel_.setArg(4,a5);
  3199. kernel_.setArg(5,a6);
  3200. kernel_.setArg(6,a7);
  3201. kernel_.setArg(7,a8);
  3202. err_ = queue_.enqueueNDRangeKernel(
  3203. kernel_,
  3204. offset_,
  3205. global_,
  3206. local_,
  3207. NULL, // bgaster_fixme - do we want to allow wait event lists?
  3208. &event);
  3209. return event;
  3210. }
  3211. template<typename A1, typename A2, typename A3, typename A4, typename A5,
  3212. typename A6, typename A7, typename A8, typename A9>
  3213. Event KernelFunctor::operator()(
  3214. const A1& a1,
  3215. const A2& a2,
  3216. const A3& a3,
  3217. const A4& a4,
  3218. const A5& a5,
  3219. const A6& a6,
  3220. const A7& a7,
  3221. const A8& a8,
  3222. const A9& a9,
  3223. const VECTOR_CLASS<Event>* events)
  3224. {
  3225. Event event;
  3226. kernel_.setArg(0,a1);
  3227. kernel_.setArg(1,a2);
  3228. kernel_.setArg(2,a3);
  3229. kernel_.setArg(3,a4);
  3230. kernel_.setArg(4,a5);
  3231. kernel_.setArg(5,a6);
  3232. kernel_.setArg(6,a7);
  3233. kernel_.setArg(7,a8);
  3234. kernel_.setArg(8,a9);
  3235. err_ = queue_.enqueueNDRangeKernel(
  3236. kernel_,
  3237. offset_,
  3238. global_,
  3239. local_,
  3240. NULL, // bgaster_fixme - do we want to allow wait event lists?
  3241. &event);
  3242. return event;
  3243. }
  3244. template<typename A1, typename A2, typename A3, typename A4, typename A5,
  3245. typename A6, typename A7, typename A8, typename A9, typename A10>
  3246. Event KernelFunctor::operator()(
  3247. const A1& a1,
  3248. const A2& a2,
  3249. const A3& a3,
  3250. const A4& a4,
  3251. const A5& a5,
  3252. const A6& a6,
  3253. const A7& a7,
  3254. const A8& a8,
  3255. const A9& a9,
  3256. const A10& a10,
  3257. const VECTOR_CLASS<Event>* events)
  3258. {
  3259. Event event;
  3260. kernel_.setArg(0,a1);
  3261. kernel_.setArg(1,a2);
  3262. kernel_.setArg(2,a3);
  3263. kernel_.setArg(3,a4);
  3264. kernel_.setArg(4,a5);
  3265. kernel_.setArg(5,a6);
  3266. kernel_.setArg(6,a7);
  3267. kernel_.setArg(7,a8);
  3268. kernel_.setArg(8,a9);
  3269. kernel_.setArg(9,a10);
  3270. err_ = queue_.enqueueNDRangeKernel(
  3271. kernel_,
  3272. offset_,
  3273. global_,
  3274. local_,
  3275. NULL, // bgaster_fixme - do we want to allow wait event lists?
  3276. &event);
  3277. return event;
  3278. }
  3279. template<class A1, class A2, class A3, class A4, class A5,
  3280. class A6, class A7, class A8, class A9, class A10,
  3281. class A11>
  3282. Event KernelFunctor::operator()(
  3283. const A1& a1,
  3284. const A2& a2,
  3285. const A3& a3,
  3286. const A4& a4,
  3287. const A5& a5,
  3288. const A6& a6,
  3289. const A7& a7,
  3290. const A8& a8,
  3291. const A9& a9,
  3292. const A10& a10,
  3293. const A11& a11,
  3294. const VECTOR_CLASS<Event>* events)
  3295. {
  3296. Event event;
  3297. kernel_.setArg(0,a1);
  3298. kernel_.setArg(1,a2);
  3299. kernel_.setArg(2,a3);
  3300. kernel_.setArg(3,a4);
  3301. kernel_.setArg(4,a5);
  3302. kernel_.setArg(5,a6);
  3303. kernel_.setArg(6,a7);
  3304. kernel_.setArg(7,a8);
  3305. kernel_.setArg(8,a9);
  3306. kernel_.setArg(9,a10);
  3307. kernel_.setArg(10,a11);
  3308. err_ = queue_.enqueueNDRangeKernel(
  3309. kernel_,
  3310. offset_,
  3311. global_,
  3312. local_,
  3313. NULL, // bgaster_fixme - do we want to allow wait event lists?
  3314. &event);
  3315. return event;
  3316. }
  3317. template<class A1, class A2, class A3, class A4, class A5,
  3318. class A6, class A7, class A8, class A9, class A10,
  3319. class A11, class A12>
  3320. Event KernelFunctor::operator()(
  3321. const A1& a1,
  3322. const A2& a2,
  3323. const A3& a3,
  3324. const A4& a4,
  3325. const A5& a5,
  3326. const A6& a6,
  3327. const A7& a7,
  3328. const A8& a8,
  3329. const A9& a9,
  3330. const A10& a10,
  3331. const A11& a11,
  3332. const A12& a12,
  3333. const VECTOR_CLASS<Event>* events)
  3334. {
  3335. Event event;
  3336. kernel_.setArg(0,a1);
  3337. kernel_.setArg(1,a2);
  3338. kernel_.setArg(2,a3);
  3339. kernel_.setArg(3,a4);
  3340. kernel_.setArg(4,a5);
  3341. kernel_.setArg(5,a6);
  3342. kernel_.setArg(6,a7);
  3343. kernel_.setArg(7,a8);
  3344. kernel_.setArg(8,a9);
  3345. kernel_.setArg(9,a10);
  3346. kernel_.setArg(10,a11);
  3347. kernel_.setArg(11,a12);
  3348. err_ = queue_.enqueueNDRangeKernel(
  3349. kernel_,
  3350. offset_,
  3351. global_,
  3352. local_,
  3353. NULL, // bgaster_fixme - do we want to allow wait event lists?
  3354. &event);
  3355. return event;
  3356. }
  3357. template<class A1, class A2, class A3, class A4, class A5,
  3358. class A6, class A7, class A8, class A9, class A10,
  3359. class A11, class A12, class A13>
  3360. Event KernelFunctor::operator()(
  3361. const A1& a1,
  3362. const A2& a2,
  3363. const A3& a3,
  3364. const A4& a4,
  3365. const A5& a5,
  3366. const A6& a6,
  3367. const A7& a7,
  3368. const A8& a8,
  3369. const A9& a9,
  3370. const A10& a10,
  3371. const A11& a11,
  3372. const A12& a12,
  3373. const A13& a13,
  3374. const VECTOR_CLASS<Event>* events)
  3375. {
  3376. Event event;
  3377. kernel_.setArg(0,a1);
  3378. kernel_.setArg(1,a2);
  3379. kernel_.setArg(2,a3);
  3380. kernel_.setArg(3,a4);
  3381. kernel_.setArg(4,a5);
  3382. kernel_.setArg(5,a6);
  3383. kernel_.setArg(6,a7);
  3384. kernel_.setArg(7,a8);
  3385. kernel_.setArg(8,a9);
  3386. kernel_.setArg(9,a10);
  3387. kernel_.setArg(10,a11);
  3388. kernel_.setArg(11,a12);
  3389. kernel_.setArg(12,a13);
  3390. err_ = queue_.enqueueNDRangeKernel(
  3391. kernel_,
  3392. offset_,
  3393. global_,
  3394. local_,
  3395. NULL, // bgaster_fixme - do we want to allow wait event lists?
  3396. &event);
  3397. return event;
  3398. }
  3399. template<class A1, class A2, class A3, class A4, class A5,
  3400. class A6, class A7, class A8, class A9, class A10,
  3401. class A11, class A12, class A13, class A14>
  3402. Event KernelFunctor::operator()(
  3403. const A1& a1,
  3404. const A2& a2,
  3405. const A3& a3,
  3406. const A4& a4,
  3407. const A5& a5,
  3408. const A6& a6,
  3409. const A7& a7,
  3410. const A8& a8,
  3411. const A9& a9,
  3412. const A10& a10,
  3413. const A11& a11,
  3414. const A12& a12,
  3415. const A13& a13,
  3416. const A14& a14,
  3417. const VECTOR_CLASS<Event>* events)
  3418. {
  3419. Event event;
  3420. kernel_.setArg(0,a1);
  3421. kernel_.setArg(1,a2);
  3422. kernel_.setArg(2,a3);
  3423. kernel_.setArg(3,a4);
  3424. kernel_.setArg(4,a5);
  3425. kernel_.setArg(5,a6);
  3426. kernel_.setArg(6,a7);
  3427. kernel_.setArg(7,a8);
  3428. kernel_.setArg(8,a9);
  3429. kernel_.setArg(9,a10);
  3430. kernel_.setArg(10,a11);
  3431. kernel_.setArg(11,a12);
  3432. kernel_.setArg(12,a13);
  3433. kernel_.setArg(13,a14);
  3434. err_ = queue_.enqueueNDRangeKernel(
  3435. kernel_,
  3436. offset_,
  3437. global_,
  3438. local_,
  3439. NULL, // bgaster_fixme - do we want to allow wait event lists?
  3440. &event);
  3441. return event;
  3442. }
  3443. template<class A1, class A2, class A3, class A4, class A5,
  3444. class A6, class A7, class A8, class A9, class A10,
  3445. class A11, class A12, class A13, class A14, class A15>
  3446. Event KernelFunctor::operator()(
  3447. const A1& a1,
  3448. const A2& a2,
  3449. const A3& a3,
  3450. const A4& a4,
  3451. const A5& a5,
  3452. const A6& a6,
  3453. const A7& a7,
  3454. const A8& a8,
  3455. const A9& a9,
  3456. const A10& a10,
  3457. const A11& a11,
  3458. const A12& a12,
  3459. const A13& a13,
  3460. const A14& a14,
  3461. const A15& a15,
  3462. const VECTOR_CLASS<Event>* events)
  3463. {
  3464. Event event;
  3465. kernel_.setArg(0,a1);
  3466. kernel_.setArg(1,a2);
  3467. kernel_.setArg(2,a3);
  3468. kernel_.setArg(3,a4);
  3469. kernel_.setArg(4,a5);
  3470. kernel_.setArg(5,a6);
  3471. kernel_.setArg(6,a7);
  3472. kernel_.setArg(7,a8);
  3473. kernel_.setArg(8,a9);
  3474. kernel_.setArg(9,a10);
  3475. kernel_.setArg(10,a11);
  3476. kernel_.setArg(11,a12);
  3477. kernel_.setArg(12,a13);
  3478. kernel_.setArg(13,a14);
  3479. kernel_.setArg(14,a15);
  3480. err_ = queue_.enqueueNDRangeKernel(
  3481. kernel_,
  3482. offset_,
  3483. global_,
  3484. local_,
  3485. NULL, // bgaster_fixme - do we want to allow wait event lists?
  3486. &event);
  3487. return event;
  3488. }
  3489. #undef __ERR_STR
  3490. #if !defined(__CL_USER_OVERRIDE_ERROR_STRINGS)
  3491. #undef __GET_DEVICE_INFO_ERR
  3492. #undef __GET_PLATFORM_INFO_ERR
  3493. #undef __GET_DEVICE_IDS_ERR
  3494. #undef __GET_CONTEXT_INFO_ERR
  3495. #undef __GET_EVENT_INFO_ERR
  3496. #undef __GET_EVENT_PROFILE_INFO_ERR
  3497. #undef __GET_MEM_OBJECT_INFO_ERR
  3498. #undef __GET_IMAGE_INFO_ERR
  3499. #undef __GET_SAMPLER_INFO_ERR
  3500. #undef __GET_KERNEL_INFO_ERR
  3501. #undef __GET_KERNEL_WORK_GROUP_INFO_ERR
  3502. #undef __GET_PROGRAM_INFO_ERR
  3503. #undef __GET_PROGRAM_BUILD_INFO_ERR
  3504. #undef __GET_COMMAND_QUEUE_INFO_ERR
  3505. #undef __CREATE_CONTEXT_FROM_TYPE_ERR
  3506. #undef __GET_SUPPORTED_IMAGE_FORMATS_ERR
  3507. #undef __CREATE_BUFFER_ERR
  3508. #undef __CREATE_SUBBUFFER_ERR
  3509. #undef __CREATE_IMAGE2D_ERR
  3510. #undef __CREATE_IMAGE3D_ERR
  3511. #undef __CREATE_SAMPLER_ERR
  3512. #undef __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR
  3513. #undef __CREATE_USER_EVENT_ERR
  3514. #undef __SET_USER_EVENT_STATUS_ERR
  3515. #undef __SET_EVENT_CALLBACK_ERR
  3516. #undef __WAIT_FOR_EVENTS_ERR
  3517. #undef __CREATE_KERNEL_ERR
  3518. #undef __SET_KERNEL_ARGS_ERR
  3519. #undef __CREATE_PROGRAM_WITH_SOURCE_ERR
  3520. #undef __CREATE_PROGRAM_WITH_BINARY_ERR
  3521. #undef __BUILD_PROGRAM_ERR
  3522. #undef __CREATE_KERNELS_IN_PROGRAM_ERR
  3523. #undef __CREATE_COMMAND_QUEUE_ERR
  3524. #undef __SET_COMMAND_QUEUE_PROPERTY_ERR
  3525. #undef __ENQUEUE_READ_BUFFER_ERR
  3526. #undef __ENQUEUE_WRITE_BUFFER_ERR
  3527. #undef __ENQUEUE_READ_BUFFER_RECT_ERR
  3528. #undef __ENQUEUE_WRITE_BUFFER_RECT_ERR
  3529. #undef __ENQEUE_COPY_BUFFER_ERR
  3530. #undef __ENQEUE_COPY_BUFFER_RECT_ERR
  3531. #undef __ENQUEUE_READ_IMAGE_ERR
  3532. #undef __ENQUEUE_WRITE_IMAGE_ERR
  3533. #undef __ENQUEUE_COPY_IMAGE_ERR
  3534. #undef __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR
  3535. #undef __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR
  3536. #undef __ENQUEUE_MAP_BUFFER_ERR
  3537. #undef __ENQUEUE_MAP_IMAGE_ERR
  3538. #undef __ENQUEUE_UNMAP_MEM_OBJECT_ERR
  3539. #undef __ENQUEUE_NDRANGE_KERNEL_ERR
  3540. #undef __ENQUEUE_TASK_ERR
  3541. #undef __ENQUEUE_NATIVE_KERNEL
  3542. #undef __UNLOAD_COMPILER_ERR
  3543. #endif //__CL_USER_OVERRIDE_ERROR_STRINGS
  3544. #undef __GET_INFO_HELPER_WITH_RETAIN
  3545. // Extensions
  3546. #undef __INIT_CL_EXT_FCN_PTR
  3547. #undef __CREATE_SUB_DEVICES
  3548. #if defined(USE_CL_DEVICE_FISSION)
  3549. #undef __PARAM_NAME_DEVICE_FISSION
  3550. #endif // USE_CL_DEVICE_FISSION
  3551. } // namespace cl
  3552. #endif // CL_HPP_