cl.hpp 271 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305
  1. /*******************************************************************************
  2. * Copyright (c) 2008-2013 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. /*! \file
  24. *
  25. * \brief C++ bindings for OpenCL 1.0 (rev 48), OpenCL 1.1 (rev 33) and
  26. * OpenCL 1.2 (rev 15)
  27. * \author Benedict R. Gaster, Laurent Morichetti and Lee Howes
  28. *
  29. * Additions and fixes from:
  30. * Brian Cole, March 3rd 2010 and April 2012
  31. * Matt Gruenke, April 2012.
  32. * Bruce Merry, February 2013.
  33. *
  34. * \version 1.2.5
  35. * \date June 2013
  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.2 (revision 09)
  61. * http://www.khronos.org/registry/cl/specs/opencl-cplusplus-1.2.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. #include <iterator>
  148. #include <intrin.h>
  149. #if defined(__CL_ENABLE_EXCEPTIONS)
  150. #include <exception>
  151. #endif // #if defined(__CL_ENABLE_EXCEPTIONS)
  152. #pragma push_macro("max")
  153. #undef max
  154. #if defined(USE_DX_INTEROP)
  155. #include <CL/cl_d3d10.h>
  156. #include <CL/cl_dx9_media_sharing.h>
  157. #endif
  158. #endif // _WIN32
  159. //
  160. #if defined(USE_CL_DEVICE_FISSION)
  161. #include <CL/cl_ext.h>
  162. #endif
  163. #if defined(__APPLE__) || defined(__MACOSX)
  164. #include <OpenGL/OpenGL.h>
  165. #include <OpenCL/opencl.h>
  166. #include <libkern/OSAtomic.h>
  167. #else
  168. #include <GL/gl.h>
  169. #include <CL/opencl.h>
  170. #endif // !__APPLE__
  171. // To avoid accidentally taking ownership of core OpenCL types
  172. // such as cl_kernel constructors are made explicit
  173. // under OpenCL 1.2
  174. #if defined(CL_VERSION_1_2) && !defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
  175. #define __CL_EXPLICIT_CONSTRUCTORS explicit
  176. #else // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
  177. #define __CL_EXPLICIT_CONSTRUCTORS
  178. #endif // #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
  179. // Define deprecated prefixes and suffixes to ensure compilation
  180. // in case they are not pre-defined
  181. #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED)
  182. #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
  183. #endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED)
  184. #if !defined(CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED)
  185. #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
  186. #endif // #if !defined(CL_EXT_PREFIX__VERSION_1_1_DEPRECATED)
  187. #if !defined(CL_CALLBACK)
  188. #define CL_CALLBACK
  189. #endif //CL_CALLBACK
  190. #include <utility>
  191. #include <limits>
  192. #if !defined(__NO_STD_VECTOR)
  193. #include <vector>
  194. #endif
  195. #if !defined(__NO_STD_STRING)
  196. #include <string>
  197. #endif
  198. #if defined(__linux__) || defined(__APPLE__) || defined(__MACOSX)
  199. #include <alloca.h>
  200. #include <emmintrin.h>
  201. #include <xmmintrin.h>
  202. #endif // linux
  203. #include <cstring>
  204. /*! \namespace cl
  205. *
  206. * \brief The OpenCL C++ bindings are defined within this namespace.
  207. *
  208. */
  209. namespace cl {
  210. class Memory;
  211. /**
  212. * Deprecated APIs for 1.2
  213. */
  214. #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2))
  215. #define __INIT_CL_EXT_FCN_PTR(name) \
  216. if(!pfn_##name) { \
  217. pfn_##name = (PFN_##name) \
  218. clGetExtensionFunctionAddress(#name); \
  219. if(!pfn_##name) { \
  220. } \
  221. }
  222. #endif // #if defined(CL_VERSION_1_1)
  223. #if defined(CL_VERSION_1_2)
  224. #define __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, name) \
  225. if(!pfn_##name) { \
  226. pfn_##name = (PFN_##name) \
  227. clGetExtensionFunctionAddressForPlatform(platform, #name); \
  228. if(!pfn_##name) { \
  229. } \
  230. }
  231. #endif // #if defined(CL_VERSION_1_1)
  232. class Program;
  233. class Device;
  234. class Context;
  235. class CommandQueue;
  236. class Memory;
  237. class Buffer;
  238. #if defined(__CL_ENABLE_EXCEPTIONS)
  239. /*! \brief Exception class
  240. *
  241. * This may be thrown by API functions when __CL_ENABLE_EXCEPTIONS is defined.
  242. */
  243. class Error : public std::exception
  244. {
  245. private:
  246. cl_int err_;
  247. const char * errStr_;
  248. public:
  249. /*! \brief Create a new CL error exception for a given error code
  250. * and corresponding message.
  251. *
  252. * \param err error code value.
  253. *
  254. * \param errStr a descriptive string that must remain in scope until
  255. * handling of the exception has concluded. If set, it
  256. * will be returned by what().
  257. */
  258. Error(cl_int err, const char * errStr = NULL) : err_(err), errStr_(errStr)
  259. {}
  260. ~Error() throw() {}
  261. /*! \brief Get error string associated with exception
  262. *
  263. * \return A memory pointer to the error message string.
  264. */
  265. virtual const char * what() const throw ()
  266. {
  267. if (errStr_ == NULL) {
  268. return "empty";
  269. }
  270. else {
  271. return errStr_;
  272. }
  273. }
  274. /*! \brief Get error code associated with exception
  275. *
  276. * \return The error code.
  277. */
  278. cl_int err(void) const { return err_; }
  279. };
  280. #define __ERR_STR(x) #x
  281. #else
  282. #define __ERR_STR(x) NULL
  283. #endif // __CL_ENABLE_EXCEPTIONS
  284. namespace detail
  285. {
  286. #if defined(__CL_ENABLE_EXCEPTIONS)
  287. static inline cl_int errHandler (
  288. cl_int err,
  289. const char * errStr = NULL)
  290. {
  291. if (err != CL_SUCCESS) {
  292. throw Error(err, errStr);
  293. }
  294. return err;
  295. }
  296. #else
  297. static inline cl_int errHandler (cl_int err, const char * errStr = NULL)
  298. {
  299. (void) errStr; // suppress unused variable warning
  300. return err;
  301. }
  302. #endif // __CL_ENABLE_EXCEPTIONS
  303. }
  304. //! \cond DOXYGEN_DETAIL
  305. #if !defined(__CL_USER_OVERRIDE_ERROR_STRINGS)
  306. #define __GET_DEVICE_INFO_ERR __ERR_STR(clGetDeviceInfo)
  307. #define __GET_PLATFORM_INFO_ERR __ERR_STR(clGetPlatformInfo)
  308. #define __GET_DEVICE_IDS_ERR __ERR_STR(clGetDeviceIDs)
  309. #define __GET_PLATFORM_IDS_ERR __ERR_STR(clGetPlatformIDs)
  310. #define __GET_CONTEXT_INFO_ERR __ERR_STR(clGetContextInfo)
  311. #define __GET_EVENT_INFO_ERR __ERR_STR(clGetEventInfo)
  312. #define __GET_EVENT_PROFILE_INFO_ERR __ERR_STR(clGetEventProfileInfo)
  313. #define __GET_MEM_OBJECT_INFO_ERR __ERR_STR(clGetMemObjectInfo)
  314. #define __GET_IMAGE_INFO_ERR __ERR_STR(clGetImageInfo)
  315. #define __GET_SAMPLER_INFO_ERR __ERR_STR(clGetSamplerInfo)
  316. #define __GET_KERNEL_INFO_ERR __ERR_STR(clGetKernelInfo)
  317. #if defined(CL_VERSION_1_2)
  318. #define __GET_KERNEL_ARG_INFO_ERR __ERR_STR(clGetKernelArgInfo)
  319. #endif // #if defined(CL_VERSION_1_2)
  320. #define __GET_KERNEL_WORK_GROUP_INFO_ERR __ERR_STR(clGetKernelWorkGroupInfo)
  321. #define __GET_PROGRAM_INFO_ERR __ERR_STR(clGetProgramInfo)
  322. #define __GET_PROGRAM_BUILD_INFO_ERR __ERR_STR(clGetProgramBuildInfo)
  323. #define __GET_COMMAND_QUEUE_INFO_ERR __ERR_STR(clGetCommandQueueInfo)
  324. #define __CREATE_CONTEXT_ERR __ERR_STR(clCreateContext)
  325. #define __CREATE_CONTEXT_FROM_TYPE_ERR __ERR_STR(clCreateContextFromType)
  326. #define __GET_SUPPORTED_IMAGE_FORMATS_ERR __ERR_STR(clGetSupportedImageFormats)
  327. #define __CREATE_BUFFER_ERR __ERR_STR(clCreateBuffer)
  328. #define __COPY_ERR __ERR_STR(cl::copy)
  329. #define __CREATE_SUBBUFFER_ERR __ERR_STR(clCreateSubBuffer)
  330. #define __CREATE_GL_BUFFER_ERR __ERR_STR(clCreateFromGLBuffer)
  331. #define __CREATE_GL_RENDER_BUFFER_ERR __ERR_STR(clCreateFromGLBuffer)
  332. #define __GET_GL_OBJECT_INFO_ERR __ERR_STR(clGetGLObjectInfo)
  333. #if defined(CL_VERSION_1_2)
  334. #define __CREATE_IMAGE_ERR __ERR_STR(clCreateImage)
  335. #define __CREATE_GL_TEXTURE_ERR __ERR_STR(clCreateFromGLTexture)
  336. #define __IMAGE_DIMENSION_ERR __ERR_STR(Incorrect image dimensions)
  337. #endif // #if defined(CL_VERSION_1_2)
  338. #define __CREATE_SAMPLER_ERR __ERR_STR(clCreateSampler)
  339. #define __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR __ERR_STR(clSetMemObjectDestructorCallback)
  340. #define __CREATE_USER_EVENT_ERR __ERR_STR(clCreateUserEvent)
  341. #define __SET_USER_EVENT_STATUS_ERR __ERR_STR(clSetUserEventStatus)
  342. #define __SET_EVENT_CALLBACK_ERR __ERR_STR(clSetEventCallback)
  343. #define __WAIT_FOR_EVENTS_ERR __ERR_STR(clWaitForEvents)
  344. #define __CREATE_KERNEL_ERR __ERR_STR(clCreateKernel)
  345. #define __SET_KERNEL_ARGS_ERR __ERR_STR(clSetKernelArg)
  346. #define __CREATE_PROGRAM_WITH_SOURCE_ERR __ERR_STR(clCreateProgramWithSource)
  347. #define __CREATE_PROGRAM_WITH_BINARY_ERR __ERR_STR(clCreateProgramWithBinary)
  348. #if defined(CL_VERSION_1_2)
  349. #define __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR __ERR_STR(clCreateProgramWithBuiltInKernels)
  350. #endif // #if defined(CL_VERSION_1_2)
  351. #define __BUILD_PROGRAM_ERR __ERR_STR(clBuildProgram)
  352. #if defined(CL_VERSION_1_2)
  353. #define __COMPILE_PROGRAM_ERR __ERR_STR(clCompileProgram)
  354. #endif // #if defined(CL_VERSION_1_2)
  355. #define __CREATE_KERNELS_IN_PROGRAM_ERR __ERR_STR(clCreateKernelsInProgram)
  356. #define __CREATE_COMMAND_QUEUE_ERR __ERR_STR(clCreateCommandQueue)
  357. #define __SET_COMMAND_QUEUE_PROPERTY_ERR __ERR_STR(clSetCommandQueueProperty)
  358. #define __ENQUEUE_READ_BUFFER_ERR __ERR_STR(clEnqueueReadBuffer)
  359. #define __ENQUEUE_READ_BUFFER_RECT_ERR __ERR_STR(clEnqueueReadBufferRect)
  360. #define __ENQUEUE_WRITE_BUFFER_ERR __ERR_STR(clEnqueueWriteBuffer)
  361. #define __ENQUEUE_WRITE_BUFFER_RECT_ERR __ERR_STR(clEnqueueWriteBufferRect)
  362. #define __ENQEUE_COPY_BUFFER_ERR __ERR_STR(clEnqueueCopyBuffer)
  363. #define __ENQEUE_COPY_BUFFER_RECT_ERR __ERR_STR(clEnqueueCopyBufferRect)
  364. #define __ENQUEUE_FILL_BUFFER_ERR __ERR_STR(clEnqueueFillBuffer)
  365. #define __ENQUEUE_READ_IMAGE_ERR __ERR_STR(clEnqueueReadImage)
  366. #define __ENQUEUE_WRITE_IMAGE_ERR __ERR_STR(clEnqueueWriteImage)
  367. #define __ENQUEUE_COPY_IMAGE_ERR __ERR_STR(clEnqueueCopyImage)
  368. #define __ENQUEUE_FILL_IMAGE_ERR __ERR_STR(clEnqueueFillImage)
  369. #define __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR __ERR_STR(clEnqueueCopyImageToBuffer)
  370. #define __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR __ERR_STR(clEnqueueCopyBufferToImage)
  371. #define __ENQUEUE_MAP_BUFFER_ERR __ERR_STR(clEnqueueMapBuffer)
  372. #define __ENQUEUE_MAP_IMAGE_ERR __ERR_STR(clEnqueueMapImage)
  373. #define __ENQUEUE_UNMAP_MEM_OBJECT_ERR __ERR_STR(clEnqueueUnMapMemObject)
  374. #define __ENQUEUE_NDRANGE_KERNEL_ERR __ERR_STR(clEnqueueNDRangeKernel)
  375. #define __ENQUEUE_TASK_ERR __ERR_STR(clEnqueueTask)
  376. #define __ENQUEUE_NATIVE_KERNEL __ERR_STR(clEnqueueNativeKernel)
  377. #if defined(CL_VERSION_1_2)
  378. #define __ENQUEUE_MIGRATE_MEM_OBJECTS_ERR __ERR_STR(clEnqueueMigrateMemObjects)
  379. #endif // #if defined(CL_VERSION_1_2)
  380. #define __ENQUEUE_ACQUIRE_GL_ERR __ERR_STR(clEnqueueAcquireGLObjects)
  381. #define __ENQUEUE_RELEASE_GL_ERR __ERR_STR(clEnqueueReleaseGLObjects)
  382. #define __RETAIN_ERR __ERR_STR(Retain Object)
  383. #define __RELEASE_ERR __ERR_STR(Release Object)
  384. #define __FLUSH_ERR __ERR_STR(clFlush)
  385. #define __FINISH_ERR __ERR_STR(clFinish)
  386. #define __VECTOR_CAPACITY_ERR __ERR_STR(Vector capacity error)
  387. /**
  388. * CL 1.2 version that uses device fission.
  389. */
  390. #if defined(CL_VERSION_1_2)
  391. #define __CREATE_SUB_DEVICES __ERR_STR(clCreateSubDevices)
  392. #else
  393. #define __CREATE_SUB_DEVICES __ERR_STR(clCreateSubDevicesEXT)
  394. #endif // #if defined(CL_VERSION_1_2)
  395. /**
  396. * Deprecated APIs for 1.2
  397. */
  398. #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2))
  399. #define __ENQUEUE_MARKER_ERR __ERR_STR(clEnqueueMarker)
  400. #define __ENQUEUE_WAIT_FOR_EVENTS_ERR __ERR_STR(clEnqueueWaitForEvents)
  401. #define __ENQUEUE_BARRIER_ERR __ERR_STR(clEnqueueBarrier)
  402. #define __UNLOAD_COMPILER_ERR __ERR_STR(clUnloadCompiler)
  403. #define __CREATE_GL_TEXTURE_2D_ERR __ERR_STR(clCreateFromGLTexture2D)
  404. #define __CREATE_GL_TEXTURE_3D_ERR __ERR_STR(clCreateFromGLTexture3D)
  405. #define __CREATE_IMAGE2D_ERR __ERR_STR(clCreateImage2D)
  406. #define __CREATE_IMAGE3D_ERR __ERR_STR(clCreateImage3D)
  407. #endif // #if defined(CL_VERSION_1_1)
  408. #endif // __CL_USER_OVERRIDE_ERROR_STRINGS
  409. //! \endcond
  410. /**
  411. * CL 1.2 marker and barrier commands
  412. */
  413. #if defined(CL_VERSION_1_2)
  414. #define __ENQUEUE_MARKER_WAIT_LIST_ERR __ERR_STR(clEnqueueMarkerWithWaitList)
  415. #define __ENQUEUE_BARRIER_WAIT_LIST_ERR __ERR_STR(clEnqueueBarrierWithWaitList)
  416. #endif // #if defined(CL_VERSION_1_2)
  417. #if !defined(__USE_DEV_STRING) && !defined(__NO_STD_STRING)
  418. typedef std::string STRING_CLASS;
  419. #elif !defined(__USE_DEV_STRING)
  420. /*! \class string
  421. * \brief Simple string class, that provides a limited subset of std::string
  422. * functionality but avoids many of the issues that come with that class.
  423. * \note Deprecated. Please use std::string as default or
  424. * re-define the string class to match the std::string
  425. * interface by defining STRING_CLASS
  426. */
  427. class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED string CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
  428. {
  429. private:
  430. ::size_t size_;
  431. char * str_;
  432. public:
  433. //! \brief Constructs an empty string, allocating no memory.
  434. string(void) : size_(0), str_(NULL)
  435. {
  436. }
  437. /*! \brief Constructs a string populated from an arbitrary value of
  438. * specified size.
  439. *
  440. * An extra '\0' is added, in case none was contained in str.
  441. *
  442. * \param str the initial value of the string instance. Note that '\0'
  443. * characters receive no special treatment. If NULL,
  444. * the string is left empty, with a size of 0.
  445. *
  446. * \param size the number of characters to copy from str.
  447. */
  448. string(const char * str, ::size_t size) :
  449. size_(size),
  450. str_(NULL)
  451. {
  452. if( size > 0 ) {
  453. str_ = new char[size_+1];
  454. if (str_ != NULL) {
  455. memcpy(str_, str, size_ * sizeof(char));
  456. str_[size_] = '\0';
  457. }
  458. else {
  459. size_ = 0;
  460. }
  461. }
  462. }
  463. /*! \brief Constructs a string populated from a null-terminated value.
  464. *
  465. * \param str the null-terminated initial value of the string instance.
  466. * If NULL, the string is left empty, with a size of 0.
  467. */
  468. string(const char * str) :
  469. size_(0),
  470. str_(NULL)
  471. {
  472. if( str ) {
  473. size_= ::strlen(str);
  474. }
  475. if( size_ > 0 ) {
  476. str_ = new char[size_ + 1];
  477. if (str_ != NULL) {
  478. memcpy(str_, str, (size_ + 1) * sizeof(char));
  479. }
  480. }
  481. }
  482. void resize( ::size_t n )
  483. {
  484. if( size_ == n ) {
  485. return;
  486. }
  487. if (n == 0) {
  488. if( str_ ) {
  489. delete [] str_;
  490. }
  491. str_ = NULL;
  492. size_ = 0;
  493. }
  494. else {
  495. char *newString = new char[n + 1];
  496. int copySize = n;
  497. if( size_ < n ) {
  498. copySize = size_;
  499. }
  500. size_ = n;
  501. if(str_) {
  502. memcpy(newString, str_, (copySize + 1) * sizeof(char));
  503. }
  504. if( copySize < size_ ) {
  505. memset(newString + copySize, 0, size_ - copySize);
  506. }
  507. newString[size_] = '\0';
  508. delete [] str_;
  509. str_ = newString;
  510. }
  511. }
  512. const char& operator[] ( ::size_t pos ) const
  513. {
  514. return str_[pos];
  515. }
  516. char& operator[] ( ::size_t pos )
  517. {
  518. return str_[pos];
  519. }
  520. /*! \brief Copies the value of another string to this one.
  521. *
  522. * \param rhs the string to copy.
  523. *
  524. * \returns a reference to the modified instance.
  525. */
  526. string& operator=(const string& rhs)
  527. {
  528. if (this == &rhs) {
  529. return *this;
  530. }
  531. if( str_ != NULL ) {
  532. delete [] str_;
  533. str_ = NULL;
  534. size_ = 0;
  535. }
  536. if (rhs.size_ == 0 || rhs.str_ == NULL) {
  537. str_ = NULL;
  538. size_ = 0;
  539. }
  540. else {
  541. str_ = new char[rhs.size_ + 1];
  542. size_ = rhs.size_;
  543. if (str_ != NULL) {
  544. memcpy(str_, rhs.str_, (size_ + 1) * sizeof(char));
  545. }
  546. else {
  547. size_ = 0;
  548. }
  549. }
  550. return *this;
  551. }
  552. /*! \brief Constructs a string by copying the value of another instance.
  553. *
  554. * \param rhs the string to copy.
  555. */
  556. string(const string& rhs) :
  557. size_(0),
  558. str_(NULL)
  559. {
  560. *this = rhs;
  561. }
  562. //! \brief Destructor - frees memory used to hold the current value.
  563. ~string()
  564. {
  565. delete[] str_;
  566. str_ = NULL;
  567. }
  568. //! \brief Queries the length of the string, excluding any added '\0's.
  569. ::size_t size(void) const { return size_; }
  570. //! \brief Queries the length of the string, excluding any added '\0's.
  571. ::size_t length(void) const { return size(); }
  572. /*! \brief Returns a pointer to the private copy held by this instance,
  573. * or "" if empty/unset.
  574. */
  575. const char * c_str(void) const { return (str_) ? str_ : "";}
  576. };
  577. typedef cl::string STRING_CLASS;
  578. #endif // #elif !defined(__USE_DEV_STRING)
  579. #if !defined(__USE_DEV_VECTOR) && !defined(__NO_STD_VECTOR)
  580. #define VECTOR_CLASS std::vector
  581. #elif !defined(__USE_DEV_VECTOR)
  582. #define VECTOR_CLASS cl::vector
  583. #if !defined(__MAX_DEFAULT_VECTOR_SIZE)
  584. #define __MAX_DEFAULT_VECTOR_SIZE 10
  585. #endif
  586. /*! \class vector
  587. * \brief Fixed sized vector implementation that mirroring
  588. *
  589. * \note Deprecated. Please use std::vector as default or
  590. * re-define the vector class to match the std::vector
  591. * interface by defining VECTOR_CLASS
  592. * \note Not recommended for use with custom objects as
  593. * current implementation will construct N elements
  594. *
  595. * std::vector functionality.
  596. * \brief Fixed sized vector compatible with std::vector.
  597. *
  598. * \note
  599. * This differs from std::vector<> not just in memory allocation,
  600. * but also in terms of when members are constructed, destroyed,
  601. * and assigned instead of being copy constructed.
  602. *
  603. * \param T type of element contained in the vector.
  604. *
  605. * \param N maximum size of the vector.
  606. */
  607. template <typename T, unsigned int N = __MAX_DEFAULT_VECTOR_SIZE>
  608. class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED vector CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
  609. {
  610. private:
  611. T data_[N];
  612. unsigned int size_;
  613. public:
  614. //! \brief Constructs an empty vector with no memory allocated.
  615. vector() :
  616. size_(static_cast<unsigned int>(0))
  617. {}
  618. //! \brief Deallocates the vector's memory and destroys all of its elements.
  619. ~vector()
  620. {
  621. clear();
  622. }
  623. //! \brief Returns the number of elements currently contained.
  624. unsigned int size(void) const
  625. {
  626. return size_;
  627. }
  628. /*! \brief Empties the vector of all elements.
  629. * \note
  630. * This does not deallocate memory but will invoke destructors
  631. * on contained elements.
  632. */
  633. void clear()
  634. {
  635. while(!empty()) {
  636. pop_back();
  637. }
  638. }
  639. /*! \brief Appends an element after the last valid element.
  640. * Calling this on a vector that has reached capacity will throw an
  641. * exception if exceptions are enabled.
  642. */
  643. void push_back (const T& x)
  644. {
  645. if (size() < N) {
  646. new (&data_[size_]) T(x);
  647. size_++;
  648. } else {
  649. detail::errHandler(CL_MEM_OBJECT_ALLOCATION_FAILURE, __VECTOR_CAPACITY_ERR);
  650. }
  651. }
  652. /*! \brief Removes the last valid element from the vector.
  653. * Calling this on an empty vector will throw an exception
  654. * if exceptions are enabled.
  655. */
  656. void pop_back(void)
  657. {
  658. if (size_ != 0) {
  659. --size_;
  660. data_[size_].~T();
  661. } else {
  662. detail::errHandler(CL_MEM_OBJECT_ALLOCATION_FAILURE, __VECTOR_CAPACITY_ERR);
  663. }
  664. }
  665. /*! \brief Constructs with a value copied from another.
  666. *
  667. * \param vec the vector to copy.
  668. */
  669. vector(const vector<T, N>& vec) :
  670. size_(vec.size_)
  671. {
  672. if (size_ != 0) {
  673. assign(vec.begin(), vec.end());
  674. }
  675. }
  676. /*! \brief Constructs with a specified number of initial elements.
  677. *
  678. * \param size number of initial elements.
  679. *
  680. * \param val value of initial elements.
  681. */
  682. vector(unsigned int size, const T& val = T()) :
  683. size_(0)
  684. {
  685. for (unsigned int i = 0; i < size; i++) {
  686. push_back(val);
  687. }
  688. }
  689. /*! \brief Overwrites the current content with that copied from another
  690. * instance.
  691. *
  692. * \param rhs vector to copy.
  693. *
  694. * \returns a reference to this.
  695. */
  696. vector<T, N>& operator=(const vector<T, N>& rhs)
  697. {
  698. if (this == &rhs) {
  699. return *this;
  700. }
  701. if (rhs.size_ != 0) {
  702. assign(rhs.begin(), rhs.end());
  703. } else {
  704. clear();
  705. }
  706. return *this;
  707. }
  708. /*! \brief Tests equality against another instance.
  709. *
  710. * \param vec the vector against which to compare.
  711. */
  712. bool operator==(vector<T,N> &vec)
  713. {
  714. if (size() != vec.size()) {
  715. return false;
  716. }
  717. for( unsigned int i = 0; i < size(); ++i ) {
  718. if( operator[](i) != vec[i] ) {
  719. return false;
  720. }
  721. }
  722. return true;
  723. }
  724. //! \brief Conversion operator to T*.
  725. operator T* () { return data_; }
  726. //! \brief Conversion operator to const T*.
  727. operator const T* () const { return data_; }
  728. //! \brief Tests whether this instance has any elements.
  729. bool empty (void) const
  730. {
  731. return size_==0;
  732. }
  733. //! \brief Returns the maximum number of elements this instance can hold.
  734. unsigned int max_size (void) const
  735. {
  736. return N;
  737. }
  738. //! \brief Returns the maximum number of elements this instance can hold.
  739. unsigned int capacity () const
  740. {
  741. return N;
  742. }
  743. /*! \brief Returns a reference to a given element.
  744. *
  745. * \param index which element to access. *
  746. * \note
  747. * The caller is responsible for ensuring index is >= 0 and < size().
  748. */
  749. T& operator[](int index)
  750. {
  751. return data_[index];
  752. }
  753. /*! \brief Returns a const reference to a given element.
  754. *
  755. * \param index which element to access.
  756. *
  757. * \note
  758. * The caller is responsible for ensuring index is >= 0 and < size().
  759. */
  760. const T& operator[](int index) const
  761. {
  762. return data_[index];
  763. }
  764. /*! \brief Assigns elements of the vector based on a source iterator range.
  765. *
  766. * \param start Beginning iterator of source range
  767. * \param end Enditerator of source range
  768. *
  769. * \note
  770. * Will throw an exception if exceptions are enabled and size exceeded.
  771. */
  772. template<class I>
  773. void assign(I start, I end)
  774. {
  775. clear();
  776. while(start != end) {
  777. push_back(*start);
  778. start++;
  779. }
  780. }
  781. /*! \class iterator
  782. * \brief Const iterator class for vectors
  783. */
  784. class iterator
  785. {
  786. private:
  787. const vector<T,N> *vec_;
  788. int index_;
  789. /**
  790. * Internal iterator constructor to capture reference
  791. * to the vector it iterates over rather than taking
  792. * the vector by copy.
  793. */
  794. iterator (const vector<T,N> &vec, int index) :
  795. vec_(&vec)
  796. {
  797. if( !vec.empty() ) {
  798. index_ = index;
  799. } else {
  800. index_ = -1;
  801. }
  802. }
  803. public:
  804. iterator(void) :
  805. index_(-1),
  806. vec_(NULL)
  807. {
  808. }
  809. iterator(const iterator& rhs) :
  810. vec_(rhs.vec_),
  811. index_(rhs.index_)
  812. {
  813. }
  814. ~iterator(void) {}
  815. static iterator begin(const cl::vector<T,N> &vec)
  816. {
  817. iterator i(vec, 0);
  818. return i;
  819. }
  820. static iterator end(const cl::vector<T,N> &vec)
  821. {
  822. iterator i(vec, vec.size());
  823. return i;
  824. }
  825. bool operator==(iterator i)
  826. {
  827. return ((vec_ == i.vec_) &&
  828. (index_ == i.index_));
  829. }
  830. bool operator!=(iterator i)
  831. {
  832. return (!(*this==i));
  833. }
  834. iterator& operator++()
  835. {
  836. ++index_;
  837. return *this;
  838. }
  839. iterator operator++(int)
  840. {
  841. iterator retVal(*this);
  842. ++index_;
  843. return retVal;
  844. }
  845. iterator& operator--()
  846. {
  847. --index_;
  848. return *this;
  849. }
  850. iterator operator--(int)
  851. {
  852. iterator retVal(*this);
  853. --index_;
  854. return retVal;
  855. }
  856. const T& operator *() const
  857. {
  858. return (*vec_)[index_];
  859. }
  860. };
  861. iterator begin(void)
  862. {
  863. return iterator::begin(*this);
  864. }
  865. iterator begin(void) const
  866. {
  867. return iterator::begin(*this);
  868. }
  869. iterator end(void)
  870. {
  871. return iterator::end(*this);
  872. }
  873. iterator end(void) const
  874. {
  875. return iterator::end(*this);
  876. }
  877. T& front(void)
  878. {
  879. return data_[0];
  880. }
  881. T& back(void)
  882. {
  883. return data_[size_];
  884. }
  885. const T& front(void) const
  886. {
  887. return data_[0];
  888. }
  889. const T& back(void) const
  890. {
  891. return data_[size_-1];
  892. }
  893. };
  894. #endif // #if !defined(__USE_DEV_VECTOR) && !defined(__NO_STD_VECTOR)
  895. namespace detail {
  896. #define __DEFAULT_NOT_INITIALIZED 1
  897. #define __DEFAULT_BEING_INITIALIZED 2
  898. #define __DEFAULT_INITIALIZED 4
  899. /*
  900. * Compare and exchange primitives are needed for handling of defaults
  901. */
  902. inline int compare_exchange(volatile int * dest, int exchange, int comparand)
  903. {
  904. #ifdef _WIN32
  905. return (int)(InterlockedCompareExchange(
  906. (volatile long*)dest,
  907. (long)exchange,
  908. (long)comparand));
  909. #elif defined(__APPLE__) || defined(__MACOSX)
  910. return OSAtomicOr32Orig((uint32_t)exchange, (volatile uint32_t*)dest);
  911. #else // !_WIN32 || defined(__APPLE__) || defined(__MACOSX)
  912. return (__sync_val_compare_and_swap(
  913. dest,
  914. comparand,
  915. exchange));
  916. #endif // !_WIN32
  917. }
  918. inline void fence() { _mm_mfence(); }
  919. }; // namespace detail
  920. /*! \brief class used to interface between C++ and
  921. * OpenCL C calls that require arrays of size_t values, whose
  922. * size is known statically.
  923. */
  924. template <int N>
  925. class size_t
  926. {
  927. private:
  928. ::size_t data_[N];
  929. public:
  930. //! \brief Initialize size_t to all 0s
  931. size_t()
  932. {
  933. for( int i = 0; i < N; ++i ) {
  934. data_[i] = 0;
  935. }
  936. }
  937. ::size_t& operator[](int index)
  938. {
  939. return data_[index];
  940. }
  941. const ::size_t& operator[](int index) const
  942. {
  943. return data_[index];
  944. }
  945. //! \brief Conversion operator to T*.
  946. operator ::size_t* () { return data_; }
  947. //! \brief Conversion operator to const T*.
  948. operator const ::size_t* () const { return data_; }
  949. };
  950. namespace detail {
  951. // Generic getInfoHelper. The final parameter is used to guide overload
  952. // resolution: the actual parameter passed is an int, which makes this
  953. // a worse conversion sequence than a specialization that declares the
  954. // parameter as an int.
  955. template<typename Functor, typename T>
  956. inline cl_int getInfoHelper(Functor f, cl_uint name, T* param, long)
  957. {
  958. return f(name, sizeof(T), param, NULL);
  959. }
  960. // Specialized getInfoHelper for VECTOR_CLASS params
  961. template <typename Func, typename T>
  962. inline cl_int getInfoHelper(Func f, cl_uint name, VECTOR_CLASS<T>* param, long)
  963. {
  964. ::size_t required;
  965. cl_int err = f(name, 0, NULL, &required);
  966. if (err != CL_SUCCESS) {
  967. return err;
  968. }
  969. T* value = (T*) alloca(required);
  970. err = f(name, required, value, NULL);
  971. if (err != CL_SUCCESS) {
  972. return err;
  973. }
  974. param->assign(&value[0], &value[required/sizeof(T)]);
  975. return CL_SUCCESS;
  976. }
  977. /* Specialization for reference-counted types. This depends on the
  978. * existence of Wrapper<T>::cl_type, and none of the other types having the
  979. * cl_type member. Note that simplify specifying the parameter as Wrapper<T>
  980. * does not work, because when using a derived type (e.g. Context) the generic
  981. * template will provide a better match.
  982. */
  983. template <typename Func, typename T>
  984. inline cl_int getInfoHelper(Func f, cl_uint name, VECTOR_CLASS<T>* param, int, typename T::cl_type = 0)
  985. {
  986. ::size_t required;
  987. cl_int err = f(name, 0, NULL, &required);
  988. if (err != CL_SUCCESS) {
  989. return err;
  990. }
  991. typename T::cl_type * value = (typename T::cl_type *) alloca(required);
  992. err = f(name, required, value, NULL);
  993. if (err != CL_SUCCESS) {
  994. return err;
  995. }
  996. ::size_t elements = required / sizeof(typename T::cl_type);
  997. param->assign(&value[0], &value[elements]);
  998. for (::size_t i = 0; i < elements; i++)
  999. {
  1000. if (value[i] != NULL)
  1001. {
  1002. err = (*param)[i].retain();
  1003. if (err != CL_SUCCESS) {
  1004. return err;
  1005. }
  1006. }
  1007. }
  1008. return CL_SUCCESS;
  1009. }
  1010. // Specialized for getInfo<CL_PROGRAM_BINARIES>
  1011. template <typename Func>
  1012. inline cl_int getInfoHelper(Func f, cl_uint name, VECTOR_CLASS<char *>* param, int)
  1013. {
  1014. cl_int err = f(name, param->size() * sizeof(char *), &(*param)[0], NULL);
  1015. if (err != CL_SUCCESS) {
  1016. return err;
  1017. }
  1018. return CL_SUCCESS;
  1019. }
  1020. // Specialized GetInfoHelper for STRING_CLASS params
  1021. template <typename Func>
  1022. inline cl_int getInfoHelper(Func f, cl_uint name, STRING_CLASS* param, long)
  1023. {
  1024. ::size_t required;
  1025. cl_int err = f(name, 0, NULL, &required);
  1026. if (err != CL_SUCCESS) {
  1027. return err;
  1028. }
  1029. char* value = (char*) alloca(required);
  1030. err = f(name, required, value, NULL);
  1031. if (err != CL_SUCCESS) {
  1032. return err;
  1033. }
  1034. *param = value;
  1035. return CL_SUCCESS;
  1036. }
  1037. // Specialized GetInfoHelper for cl::size_t params
  1038. template <typename Func, ::size_t N>
  1039. inline cl_int getInfoHelper(Func f, cl_uint name, size_t<N>* param, long)
  1040. {
  1041. ::size_t required;
  1042. cl_int err = f(name, 0, NULL, &required);
  1043. if (err != CL_SUCCESS) {
  1044. return err;
  1045. }
  1046. ::size_t* value = (::size_t*) alloca(required);
  1047. err = f(name, required, value, NULL);
  1048. if (err != CL_SUCCESS) {
  1049. return err;
  1050. }
  1051. for(int i = 0; i < N; ++i) {
  1052. (*param)[i] = value[i];
  1053. }
  1054. return CL_SUCCESS;
  1055. }
  1056. template<typename T> struct ReferenceHandler;
  1057. /* Specialization for reference-counted types. This depends on the
  1058. * existence of Wrapper<T>::cl_type, and none of the other types having the
  1059. * cl_type member. Note that simplify specifying the parameter as Wrapper<T>
  1060. * does not work, because when using a derived type (e.g. Context) the generic
  1061. * template will provide a better match.
  1062. */
  1063. template<typename Func, typename T>
  1064. inline cl_int getInfoHelper(Func f, cl_uint name, T* param, int, typename T::cl_type = 0)
  1065. {
  1066. typename T::cl_type value;
  1067. cl_int err = f(name, sizeof(value), &value, NULL);
  1068. if (err != CL_SUCCESS) {
  1069. return err;
  1070. }
  1071. *param = value;
  1072. if (value != NULL)
  1073. {
  1074. err = param->retain();
  1075. if (err != CL_SUCCESS) {
  1076. return err;
  1077. }
  1078. }
  1079. return CL_SUCCESS;
  1080. }
  1081. #define __PARAM_NAME_INFO_1_0(F) \
  1082. F(cl_platform_info, CL_PLATFORM_PROFILE, STRING_CLASS) \
  1083. F(cl_platform_info, CL_PLATFORM_VERSION, STRING_CLASS) \
  1084. F(cl_platform_info, CL_PLATFORM_NAME, STRING_CLASS) \
  1085. F(cl_platform_info, CL_PLATFORM_VENDOR, STRING_CLASS) \
  1086. F(cl_platform_info, CL_PLATFORM_EXTENSIONS, STRING_CLASS) \
  1087. \
  1088. F(cl_device_info, CL_DEVICE_TYPE, cl_device_type) \
  1089. F(cl_device_info, CL_DEVICE_VENDOR_ID, cl_uint) \
  1090. F(cl_device_info, CL_DEVICE_MAX_COMPUTE_UNITS, cl_uint) \
  1091. F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, cl_uint) \
  1092. F(cl_device_info, CL_DEVICE_MAX_WORK_GROUP_SIZE, ::size_t) \
  1093. F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_SIZES, VECTOR_CLASS< ::size_t>) \
  1094. F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, cl_uint) \
  1095. F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, cl_uint) \
  1096. F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, cl_uint) \
  1097. F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, cl_uint) \
  1098. F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, cl_uint) \
  1099. F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, cl_uint) \
  1100. F(cl_device_info, CL_DEVICE_MAX_CLOCK_FREQUENCY, cl_uint) \
  1101. F(cl_device_info, CL_DEVICE_ADDRESS_BITS, cl_uint) \
  1102. F(cl_device_info, CL_DEVICE_MAX_READ_IMAGE_ARGS, cl_uint) \
  1103. F(cl_device_info, CL_DEVICE_MAX_WRITE_IMAGE_ARGS, cl_uint) \
  1104. F(cl_device_info, CL_DEVICE_MAX_MEM_ALLOC_SIZE, cl_ulong) \
  1105. F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_WIDTH, ::size_t) \
  1106. F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_HEIGHT, ::size_t) \
  1107. F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_WIDTH, ::size_t) \
  1108. F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_HEIGHT, ::size_t) \
  1109. F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_DEPTH, ::size_t) \
  1110. F(cl_device_info, CL_DEVICE_IMAGE_SUPPORT, cl_bool) \
  1111. F(cl_device_info, CL_DEVICE_MAX_PARAMETER_SIZE, ::size_t) \
  1112. F(cl_device_info, CL_DEVICE_MAX_SAMPLERS, cl_uint) \
  1113. F(cl_device_info, CL_DEVICE_MEM_BASE_ADDR_ALIGN, cl_uint) \
  1114. F(cl_device_info, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, cl_uint) \
  1115. F(cl_device_info, CL_DEVICE_SINGLE_FP_CONFIG, cl_device_fp_config) \
  1116. F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, cl_device_mem_cache_type) \
  1117. F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, cl_uint)\
  1118. F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, cl_ulong) \
  1119. F(cl_device_info, CL_DEVICE_GLOBAL_MEM_SIZE, cl_ulong) \
  1120. F(cl_device_info, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, cl_ulong) \
  1121. F(cl_device_info, CL_DEVICE_MAX_CONSTANT_ARGS, cl_uint) \
  1122. F(cl_device_info, CL_DEVICE_LOCAL_MEM_TYPE, cl_device_local_mem_type) \
  1123. F(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE, cl_ulong) \
  1124. F(cl_device_info, CL_DEVICE_ERROR_CORRECTION_SUPPORT, cl_bool) \
  1125. F(cl_device_info, CL_DEVICE_PROFILING_TIMER_RESOLUTION, ::size_t) \
  1126. F(cl_device_info, CL_DEVICE_ENDIAN_LITTLE, cl_bool) \
  1127. F(cl_device_info, CL_DEVICE_AVAILABLE, cl_bool) \
  1128. F(cl_device_info, CL_DEVICE_COMPILER_AVAILABLE, cl_bool) \
  1129. F(cl_device_info, CL_DEVICE_EXECUTION_CAPABILITIES, cl_device_exec_capabilities) \
  1130. F(cl_device_info, CL_DEVICE_QUEUE_PROPERTIES, cl_command_queue_properties) \
  1131. F(cl_device_info, CL_DEVICE_PLATFORM, cl_platform_id) \
  1132. F(cl_device_info, CL_DEVICE_NAME, STRING_CLASS) \
  1133. F(cl_device_info, CL_DEVICE_VENDOR, STRING_CLASS) \
  1134. F(cl_device_info, CL_DRIVER_VERSION, STRING_CLASS) \
  1135. F(cl_device_info, CL_DEVICE_PROFILE, STRING_CLASS) \
  1136. F(cl_device_info, CL_DEVICE_VERSION, STRING_CLASS) \
  1137. F(cl_device_info, CL_DEVICE_EXTENSIONS, STRING_CLASS) \
  1138. \
  1139. F(cl_context_info, CL_CONTEXT_REFERENCE_COUNT, cl_uint) \
  1140. F(cl_context_info, CL_CONTEXT_DEVICES, VECTOR_CLASS<Device>) \
  1141. F(cl_context_info, CL_CONTEXT_PROPERTIES, VECTOR_CLASS<cl_context_properties>) \
  1142. \
  1143. F(cl_event_info, CL_EVENT_COMMAND_QUEUE, cl::CommandQueue) \
  1144. F(cl_event_info, CL_EVENT_COMMAND_TYPE, cl_command_type) \
  1145. F(cl_event_info, CL_EVENT_REFERENCE_COUNT, cl_uint) \
  1146. F(cl_event_info, CL_EVENT_COMMAND_EXECUTION_STATUS, cl_uint) \
  1147. \
  1148. F(cl_profiling_info, CL_PROFILING_COMMAND_QUEUED, cl_ulong) \
  1149. F(cl_profiling_info, CL_PROFILING_COMMAND_SUBMIT, cl_ulong) \
  1150. F(cl_profiling_info, CL_PROFILING_COMMAND_START, cl_ulong) \
  1151. F(cl_profiling_info, CL_PROFILING_COMMAND_END, cl_ulong) \
  1152. \
  1153. F(cl_mem_info, CL_MEM_TYPE, cl_mem_object_type) \
  1154. F(cl_mem_info, CL_MEM_FLAGS, cl_mem_flags) \
  1155. F(cl_mem_info, CL_MEM_SIZE, ::size_t) \
  1156. F(cl_mem_info, CL_MEM_HOST_PTR, void*) \
  1157. F(cl_mem_info, CL_MEM_MAP_COUNT, cl_uint) \
  1158. F(cl_mem_info, CL_MEM_REFERENCE_COUNT, cl_uint) \
  1159. F(cl_mem_info, CL_MEM_CONTEXT, cl::Context) \
  1160. \
  1161. F(cl_image_info, CL_IMAGE_FORMAT, cl_image_format) \
  1162. F(cl_image_info, CL_IMAGE_ELEMENT_SIZE, ::size_t) \
  1163. F(cl_image_info, CL_IMAGE_ROW_PITCH, ::size_t) \
  1164. F(cl_image_info, CL_IMAGE_SLICE_PITCH, ::size_t) \
  1165. F(cl_image_info, CL_IMAGE_WIDTH, ::size_t) \
  1166. F(cl_image_info, CL_IMAGE_HEIGHT, ::size_t) \
  1167. F(cl_image_info, CL_IMAGE_DEPTH, ::size_t) \
  1168. \
  1169. F(cl_sampler_info, CL_SAMPLER_REFERENCE_COUNT, cl_uint) \
  1170. F(cl_sampler_info, CL_SAMPLER_CONTEXT, cl::Context) \
  1171. F(cl_sampler_info, CL_SAMPLER_NORMALIZED_COORDS, cl_addressing_mode) \
  1172. F(cl_sampler_info, CL_SAMPLER_ADDRESSING_MODE, cl_filter_mode) \
  1173. F(cl_sampler_info, CL_SAMPLER_FILTER_MODE, cl_bool) \
  1174. \
  1175. F(cl_program_info, CL_PROGRAM_REFERENCE_COUNT, cl_uint) \
  1176. F(cl_program_info, CL_PROGRAM_CONTEXT, cl::Context) \
  1177. F(cl_program_info, CL_PROGRAM_NUM_DEVICES, cl_uint) \
  1178. F(cl_program_info, CL_PROGRAM_DEVICES, VECTOR_CLASS<Device>) \
  1179. F(cl_program_info, CL_PROGRAM_SOURCE, STRING_CLASS) \
  1180. F(cl_program_info, CL_PROGRAM_BINARY_SIZES, VECTOR_CLASS< ::size_t>) \
  1181. F(cl_program_info, CL_PROGRAM_BINARIES, VECTOR_CLASS<char *>) \
  1182. \
  1183. F(cl_program_build_info, CL_PROGRAM_BUILD_STATUS, cl_build_status) \
  1184. F(cl_program_build_info, CL_PROGRAM_BUILD_OPTIONS, STRING_CLASS) \
  1185. F(cl_program_build_info, CL_PROGRAM_BUILD_LOG, STRING_CLASS) \
  1186. \
  1187. F(cl_kernel_info, CL_KERNEL_FUNCTION_NAME, STRING_CLASS) \
  1188. F(cl_kernel_info, CL_KERNEL_NUM_ARGS, cl_uint) \
  1189. F(cl_kernel_info, CL_KERNEL_REFERENCE_COUNT, cl_uint) \
  1190. F(cl_kernel_info, CL_KERNEL_CONTEXT, cl::Context) \
  1191. F(cl_kernel_info, CL_KERNEL_PROGRAM, cl::Program) \
  1192. \
  1193. F(cl_kernel_work_group_info, CL_KERNEL_WORK_GROUP_SIZE, ::size_t) \
  1194. F(cl_kernel_work_group_info, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, cl::size_t<3>) \
  1195. F(cl_kernel_work_group_info, CL_KERNEL_LOCAL_MEM_SIZE, cl_ulong) \
  1196. \
  1197. F(cl_command_queue_info, CL_QUEUE_CONTEXT, cl::Context) \
  1198. F(cl_command_queue_info, CL_QUEUE_DEVICE, cl::Device) \
  1199. F(cl_command_queue_info, CL_QUEUE_REFERENCE_COUNT, cl_uint) \
  1200. F(cl_command_queue_info, CL_QUEUE_PROPERTIES, cl_command_queue_properties)
  1201. #if defined(CL_VERSION_1_1)
  1202. #define __PARAM_NAME_INFO_1_1(F) \
  1203. F(cl_context_info, CL_CONTEXT_NUM_DEVICES, cl_uint)\
  1204. F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF, cl_uint) \
  1205. F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR, cl_uint) \
  1206. F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT, cl_uint) \
  1207. F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, cl_uint) \
  1208. F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, cl_uint) \
  1209. F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, cl_uint) \
  1210. F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, cl_uint) \
  1211. F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, cl_uint) \
  1212. F(cl_device_info, CL_DEVICE_DOUBLE_FP_CONFIG, cl_device_fp_config) \
  1213. F(cl_device_info, CL_DEVICE_HALF_FP_CONFIG, cl_device_fp_config) \
  1214. F(cl_device_info, CL_DEVICE_HOST_UNIFIED_MEMORY, cl_bool) \
  1215. F(cl_device_info, CL_DEVICE_OPENCL_C_VERSION, STRING_CLASS) \
  1216. \
  1217. F(cl_mem_info, CL_MEM_ASSOCIATED_MEMOBJECT, cl::Memory) \
  1218. F(cl_mem_info, CL_MEM_OFFSET, ::size_t) \
  1219. \
  1220. F(cl_kernel_work_group_info, CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, ::size_t) \
  1221. F(cl_kernel_work_group_info, CL_KERNEL_PRIVATE_MEM_SIZE, cl_ulong) \
  1222. \
  1223. F(cl_event_info, CL_EVENT_CONTEXT, cl::Context)
  1224. #endif // CL_VERSION_1_1
  1225. #if defined(CL_VERSION_1_2)
  1226. #define __PARAM_NAME_INFO_1_2(F) \
  1227. F(cl_image_info, CL_IMAGE_BUFFER, cl::Buffer) \
  1228. \
  1229. F(cl_program_info, CL_PROGRAM_NUM_KERNELS, ::size_t) \
  1230. F(cl_program_info, CL_PROGRAM_KERNEL_NAMES, STRING_CLASS) \
  1231. \
  1232. F(cl_program_build_info, CL_PROGRAM_BINARY_TYPE, cl_program_binary_type) \
  1233. \
  1234. F(cl_kernel_info, CL_KERNEL_ATTRIBUTES, STRING_CLASS) \
  1235. \
  1236. F(cl_kernel_arg_info, CL_KERNEL_ARG_ADDRESS_QUALIFIER, cl_kernel_arg_address_qualifier) \
  1237. F(cl_kernel_arg_info, CL_KERNEL_ARG_ACCESS_QUALIFIER, cl_kernel_arg_access_qualifier) \
  1238. F(cl_kernel_arg_info, CL_KERNEL_ARG_TYPE_NAME, STRING_CLASS) \
  1239. F(cl_kernel_arg_info, CL_KERNEL_ARG_NAME, STRING_CLASS) \
  1240. \
  1241. F(cl_device_info, CL_DEVICE_PARENT_DEVICE, cl_device_id) \
  1242. F(cl_device_info, CL_DEVICE_PARTITION_PROPERTIES, VECTOR_CLASS<cl_device_partition_property>) \
  1243. F(cl_device_info, CL_DEVICE_PARTITION_TYPE, VECTOR_CLASS<cl_device_partition_property>) \
  1244. F(cl_device_info, CL_DEVICE_REFERENCE_COUNT, cl_uint) \
  1245. F(cl_device_info, CL_DEVICE_PREFERRED_INTEROP_USER_SYNC, ::size_t) \
  1246. F(cl_device_info, CL_DEVICE_PARTITION_AFFINITY_DOMAIN, cl_device_affinity_domain) \
  1247. F(cl_device_info, CL_DEVICE_BUILT_IN_KERNELS, STRING_CLASS)
  1248. #endif // #if defined(CL_VERSION_1_2)
  1249. #if defined(USE_CL_DEVICE_FISSION)
  1250. #define __PARAM_NAME_DEVICE_FISSION(F) \
  1251. F(cl_device_info, CL_DEVICE_PARENT_DEVICE_EXT, cl_device_id) \
  1252. F(cl_device_info, CL_DEVICE_PARTITION_TYPES_EXT, VECTOR_CLASS<cl_device_partition_property_ext>) \
  1253. F(cl_device_info, CL_DEVICE_AFFINITY_DOMAINS_EXT, VECTOR_CLASS<cl_device_partition_property_ext>) \
  1254. F(cl_device_info, CL_DEVICE_REFERENCE_COUNT_EXT , cl_uint) \
  1255. F(cl_device_info, CL_DEVICE_PARTITION_STYLE_EXT, VECTOR_CLASS<cl_device_partition_property_ext>)
  1256. #endif // USE_CL_DEVICE_FISSION
  1257. template <typename enum_type, cl_int Name>
  1258. struct param_traits {};
  1259. #define __CL_DECLARE_PARAM_TRAITS(token, param_name, T) \
  1260. struct token; \
  1261. template<> \
  1262. struct param_traits<detail:: token,param_name> \
  1263. { \
  1264. enum { value = param_name }; \
  1265. typedef T param_type; \
  1266. };
  1267. __PARAM_NAME_INFO_1_0(__CL_DECLARE_PARAM_TRAITS)
  1268. #if defined(CL_VERSION_1_1)
  1269. __PARAM_NAME_INFO_1_1(__CL_DECLARE_PARAM_TRAITS)
  1270. #endif // CL_VERSION_1_1
  1271. #if defined(CL_VERSION_1_2)
  1272. __PARAM_NAME_INFO_1_2(__CL_DECLARE_PARAM_TRAITS)
  1273. #endif // CL_VERSION_1_1
  1274. #if defined(USE_CL_DEVICE_FISSION)
  1275. __PARAM_NAME_DEVICE_FISSION(__CL_DECLARE_PARAM_TRAITS);
  1276. #endif // USE_CL_DEVICE_FISSION
  1277. #ifdef CL_PLATFORM_ICD_SUFFIX_KHR
  1278. __CL_DECLARE_PARAM_TRAITS(cl_platform_info, CL_PLATFORM_ICD_SUFFIX_KHR, STRING_CLASS)
  1279. #endif
  1280. #ifdef CL_DEVICE_PROFILING_TIMER_OFFSET_AMD
  1281. __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_PROFILING_TIMER_OFFSET_AMD, cl_ulong)
  1282. #endif
  1283. #ifdef CL_DEVICE_GLOBAL_FREE_MEMORY_AMD
  1284. __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_FREE_MEMORY_AMD, VECTOR_CLASS< ::size_t>)
  1285. #endif
  1286. #ifdef CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD
  1287. __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_SIMD_PER_COMPUTE_UNIT_AMD, cl_uint)
  1288. #endif
  1289. #ifdef CL_DEVICE_SIMD_WIDTH_AMD
  1290. __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_SIMD_WIDTH_AMD, cl_uint)
  1291. #endif
  1292. #ifdef CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD
  1293. __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_SIMD_INSTRUCTION_WIDTH_AMD, cl_uint)
  1294. #endif
  1295. #ifdef CL_DEVICE_WAVEFRONT_WIDTH_AMD
  1296. __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_WAVEFRONT_WIDTH_AMD, cl_uint)
  1297. #endif
  1298. #ifdef CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD
  1299. __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNELS_AMD, cl_uint)
  1300. #endif
  1301. #ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD
  1302. __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANKS_AMD, cl_uint)
  1303. #endif
  1304. #ifdef CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD
  1305. __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GLOBAL_MEM_CHANNEL_BANK_WIDTH_AMD, cl_uint)
  1306. #endif
  1307. #ifdef CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD
  1308. __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE_PER_COMPUTE_UNIT_AMD, cl_uint)
  1309. #endif
  1310. #ifdef CL_DEVICE_LOCAL_MEM_BANKS_AMD
  1311. __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_LOCAL_MEM_BANKS_AMD, cl_uint)
  1312. #endif
  1313. #ifdef CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV
  1314. __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV, cl_uint)
  1315. #endif
  1316. #ifdef CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV
  1317. __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV, cl_uint)
  1318. #endif
  1319. #ifdef CL_DEVICE_REGISTERS_PER_BLOCK_NV
  1320. __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_REGISTERS_PER_BLOCK_NV, cl_uint)
  1321. #endif
  1322. #ifdef CL_DEVICE_WARP_SIZE_NV
  1323. __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_WARP_SIZE_NV, cl_uint)
  1324. #endif
  1325. #ifdef CL_DEVICE_GPU_OVERLAP_NV
  1326. __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_GPU_OVERLAP_NV, cl_bool)
  1327. #endif
  1328. #ifdef CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV
  1329. __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV, cl_bool)
  1330. #endif
  1331. #ifdef CL_DEVICE_INTEGRATED_MEMORY_NV
  1332. __CL_DECLARE_PARAM_TRAITS(cl_device_info, CL_DEVICE_INTEGRATED_MEMORY_NV, cl_bool)
  1333. #endif
  1334. // Convenience functions
  1335. template <typename Func, typename T>
  1336. inline cl_int
  1337. getInfo(Func f, cl_uint name, T* param)
  1338. {
  1339. return getInfoHelper(f, name, param, 0);
  1340. }
  1341. template <typename Func, typename Arg0>
  1342. struct GetInfoFunctor0
  1343. {
  1344. Func f_; const Arg0& arg0_;
  1345. cl_int operator ()(
  1346. cl_uint param, ::size_t size, void* value, ::size_t* size_ret)
  1347. { return f_(arg0_, param, size, value, size_ret); }
  1348. };
  1349. template <typename Func, typename Arg0, typename Arg1>
  1350. struct GetInfoFunctor1
  1351. {
  1352. Func f_; const Arg0& arg0_; const Arg1& arg1_;
  1353. cl_int operator ()(
  1354. cl_uint param, ::size_t size, void* value, ::size_t* size_ret)
  1355. { return f_(arg0_, arg1_, param, size, value, size_ret); }
  1356. };
  1357. template <typename Func, typename Arg0, typename T>
  1358. inline cl_int
  1359. getInfo(Func f, const Arg0& arg0, cl_uint name, T* param)
  1360. {
  1361. GetInfoFunctor0<Func, Arg0> f0 = { f, arg0 };
  1362. return getInfoHelper(f0, name, param, 0);
  1363. }
  1364. template <typename Func, typename Arg0, typename Arg1, typename T>
  1365. inline cl_int
  1366. getInfo(Func f, const Arg0& arg0, const Arg1& arg1, cl_uint name, T* param)
  1367. {
  1368. GetInfoFunctor1<Func, Arg0, Arg1> f0 = { f, arg0, arg1 };
  1369. return getInfoHelper(f0, name, param, 0);
  1370. }
  1371. template<typename T>
  1372. struct ReferenceHandler
  1373. { };
  1374. #if defined(CL_VERSION_1_2)
  1375. /**
  1376. * OpenCL 1.2 devices do have retain/release.
  1377. */
  1378. template <>
  1379. struct ReferenceHandler<cl_device_id>
  1380. {
  1381. /**
  1382. * Retain the device.
  1383. * \param device A valid device created using createSubDevices
  1384. * \return
  1385. * CL_SUCCESS if the function executed successfully.
  1386. * CL_INVALID_DEVICE if device was not a valid subdevice
  1387. * CL_OUT_OF_RESOURCES
  1388. * CL_OUT_OF_HOST_MEMORY
  1389. */
  1390. static cl_int retain(cl_device_id device)
  1391. { return ::clRetainDevice(device); }
  1392. /**
  1393. * Retain the device.
  1394. * \param device A valid device created using createSubDevices
  1395. * \return
  1396. * CL_SUCCESS if the function executed successfully.
  1397. * CL_INVALID_DEVICE if device was not a valid subdevice
  1398. * CL_OUT_OF_RESOURCES
  1399. * CL_OUT_OF_HOST_MEMORY
  1400. */
  1401. static cl_int release(cl_device_id device)
  1402. { return ::clReleaseDevice(device); }
  1403. };
  1404. #else // #if defined(CL_VERSION_1_2)
  1405. /**
  1406. * OpenCL 1.1 devices do not have retain/release.
  1407. */
  1408. template <>
  1409. struct ReferenceHandler<cl_device_id>
  1410. {
  1411. // cl_device_id does not have retain().
  1412. static cl_int retain(cl_device_id)
  1413. { return CL_SUCCESS; }
  1414. // cl_device_id does not have release().
  1415. static cl_int release(cl_device_id)
  1416. { return CL_SUCCESS; }
  1417. };
  1418. #endif // #if defined(CL_VERSION_1_2)
  1419. template <>
  1420. struct ReferenceHandler<cl_platform_id>
  1421. {
  1422. // cl_platform_id does not have retain().
  1423. static cl_int retain(cl_platform_id)
  1424. { return CL_SUCCESS; }
  1425. // cl_platform_id does not have release().
  1426. static cl_int release(cl_platform_id)
  1427. { return CL_SUCCESS; }
  1428. };
  1429. template <>
  1430. struct ReferenceHandler<cl_context>
  1431. {
  1432. static cl_int retain(cl_context context)
  1433. { return ::clRetainContext(context); }
  1434. static cl_int release(cl_context context)
  1435. { return ::clReleaseContext(context); }
  1436. };
  1437. template <>
  1438. struct ReferenceHandler<cl_command_queue>
  1439. {
  1440. static cl_int retain(cl_command_queue queue)
  1441. { return ::clRetainCommandQueue(queue); }
  1442. static cl_int release(cl_command_queue queue)
  1443. { return ::clReleaseCommandQueue(queue); }
  1444. };
  1445. template <>
  1446. struct ReferenceHandler<cl_mem>
  1447. {
  1448. static cl_int retain(cl_mem memory)
  1449. { return ::clRetainMemObject(memory); }
  1450. static cl_int release(cl_mem memory)
  1451. { return ::clReleaseMemObject(memory); }
  1452. };
  1453. template <>
  1454. struct ReferenceHandler<cl_sampler>
  1455. {
  1456. static cl_int retain(cl_sampler sampler)
  1457. { return ::clRetainSampler(sampler); }
  1458. static cl_int release(cl_sampler sampler)
  1459. { return ::clReleaseSampler(sampler); }
  1460. };
  1461. template <>
  1462. struct ReferenceHandler<cl_program>
  1463. {
  1464. static cl_int retain(cl_program program)
  1465. { return ::clRetainProgram(program); }
  1466. static cl_int release(cl_program program)
  1467. { return ::clReleaseProgram(program); }
  1468. };
  1469. template <>
  1470. struct ReferenceHandler<cl_kernel>
  1471. {
  1472. static cl_int retain(cl_kernel kernel)
  1473. { return ::clRetainKernel(kernel); }
  1474. static cl_int release(cl_kernel kernel)
  1475. { return ::clReleaseKernel(kernel); }
  1476. };
  1477. template <>
  1478. struct ReferenceHandler<cl_event>
  1479. {
  1480. static cl_int retain(cl_event event)
  1481. { return ::clRetainEvent(event); }
  1482. static cl_int release(cl_event event)
  1483. { return ::clReleaseEvent(event); }
  1484. };
  1485. // Extracts version number with major in the upper 16 bits, minor in the lower 16
  1486. static cl_uint getVersion(const char *versionInfo)
  1487. {
  1488. int highVersion = 0;
  1489. int lowVersion = 0;
  1490. int index = 7;
  1491. while(versionInfo[index] != '.' ) {
  1492. highVersion *= 10;
  1493. highVersion += versionInfo[index]-'0';
  1494. ++index;
  1495. }
  1496. ++index;
  1497. while(versionInfo[index] != ' ' ) {
  1498. lowVersion *= 10;
  1499. lowVersion += versionInfo[index]-'0';
  1500. ++index;
  1501. }
  1502. return (highVersion << 16) | lowVersion;
  1503. }
  1504. static cl_uint getPlatformVersion(cl_platform_id platform)
  1505. {
  1506. ::size_t size = 0;
  1507. clGetPlatformInfo(platform, CL_PLATFORM_VERSION, 0, NULL, &size);
  1508. char *versionInfo = (char *) alloca(size);
  1509. clGetPlatformInfo(platform, CL_PLATFORM_VERSION, size, &versionInfo[0], &size);
  1510. return getVersion(versionInfo);
  1511. }
  1512. static cl_uint getDevicePlatformVersion(cl_device_id device)
  1513. {
  1514. cl_platform_id platform;
  1515. clGetDeviceInfo(device, CL_DEVICE_PLATFORM, sizeof(platform), &platform, NULL);
  1516. return getPlatformVersion(platform);
  1517. }
  1518. #if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
  1519. static cl_uint getContextPlatformVersion(cl_context context)
  1520. {
  1521. // The platform cannot be queried directly, so we first have to grab a
  1522. // device and obtain its context
  1523. ::size_t size = 0;
  1524. clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, NULL, &size);
  1525. if (size == 0)
  1526. return 0;
  1527. cl_device_id *devices = (cl_device_id *) alloca(size);
  1528. clGetContextInfo(context, CL_CONTEXT_DEVICES, size, devices, NULL);
  1529. return getDevicePlatformVersion(devices[0]);
  1530. }
  1531. #endif // #if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
  1532. template <typename T>
  1533. class Wrapper
  1534. {
  1535. public:
  1536. typedef T cl_type;
  1537. protected:
  1538. cl_type object_;
  1539. public:
  1540. Wrapper() : object_(NULL) { }
  1541. Wrapper(const cl_type &obj) : object_(obj) { }
  1542. ~Wrapper()
  1543. {
  1544. if (object_ != NULL) { release(); }
  1545. }
  1546. Wrapper(const Wrapper<cl_type>& rhs)
  1547. {
  1548. object_ = rhs.object_;
  1549. if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); }
  1550. }
  1551. Wrapper<cl_type>& operator = (const Wrapper<cl_type>& rhs)
  1552. {
  1553. if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); }
  1554. object_ = rhs.object_;
  1555. if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); }
  1556. return *this;
  1557. }
  1558. Wrapper<cl_type>& operator = (const cl_type &rhs)
  1559. {
  1560. if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); }
  1561. object_ = rhs;
  1562. return *this;
  1563. }
  1564. cl_type operator ()() const { return object_; }
  1565. cl_type& operator ()() { return object_; }
  1566. protected:
  1567. template<typename Func, typename U>
  1568. friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type);
  1569. cl_int retain() const
  1570. {
  1571. return ReferenceHandler<cl_type>::retain(object_);
  1572. }
  1573. cl_int release() const
  1574. {
  1575. return ReferenceHandler<cl_type>::release(object_);
  1576. }
  1577. };
  1578. template <>
  1579. class Wrapper<cl_device_id>
  1580. {
  1581. public:
  1582. typedef cl_device_id cl_type;
  1583. protected:
  1584. cl_type object_;
  1585. bool referenceCountable_;
  1586. static bool isReferenceCountable(cl_device_id device)
  1587. {
  1588. bool retVal = false;
  1589. if (device != NULL) {
  1590. int version = getDevicePlatformVersion(device);
  1591. if(version > ((1 << 16) + 1)) {
  1592. retVal = true;
  1593. }
  1594. }
  1595. return retVal;
  1596. }
  1597. public:
  1598. Wrapper() : object_(NULL), referenceCountable_(false)
  1599. {
  1600. }
  1601. Wrapper(const cl_type &obj) : object_(obj), referenceCountable_(false)
  1602. {
  1603. referenceCountable_ = isReferenceCountable(obj);
  1604. }
  1605. ~Wrapper()
  1606. {
  1607. if (object_ != NULL) { release(); }
  1608. }
  1609. Wrapper(const Wrapper<cl_type>& rhs)
  1610. {
  1611. object_ = rhs.object_;
  1612. referenceCountable_ = isReferenceCountable(object_);
  1613. if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); }
  1614. }
  1615. Wrapper<cl_type>& operator = (const Wrapper<cl_type>& rhs)
  1616. {
  1617. if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); }
  1618. object_ = rhs.object_;
  1619. referenceCountable_ = rhs.referenceCountable_;
  1620. if (object_ != NULL) { detail::errHandler(retain(), __RETAIN_ERR); }
  1621. return *this;
  1622. }
  1623. Wrapper<cl_type>& operator = (const cl_type &rhs)
  1624. {
  1625. if (object_ != NULL) { detail::errHandler(release(), __RELEASE_ERR); }
  1626. object_ = rhs;
  1627. referenceCountable_ = isReferenceCountable(object_);
  1628. return *this;
  1629. }
  1630. cl_type operator ()() const { return object_; }
  1631. cl_type& operator ()() { return object_; }
  1632. protected:
  1633. template<typename Func, typename U>
  1634. friend inline cl_int getInfoHelper(Func, cl_uint, U*, int, typename U::cl_type);
  1635. template<typename Func, typename U>
  1636. friend inline cl_int getInfoHelper(Func, cl_uint, VECTOR_CLASS<U>*, int, typename U::cl_type);
  1637. cl_int retain() const
  1638. {
  1639. if( referenceCountable_ ) {
  1640. return ReferenceHandler<cl_type>::retain(object_);
  1641. }
  1642. else {
  1643. return CL_SUCCESS;
  1644. }
  1645. }
  1646. cl_int release() const
  1647. {
  1648. if( referenceCountable_ ) {
  1649. return ReferenceHandler<cl_type>::release(object_);
  1650. }
  1651. else {
  1652. return CL_SUCCESS;
  1653. }
  1654. }
  1655. };
  1656. } // namespace detail
  1657. //! \endcond
  1658. /*! \stuct ImageFormat
  1659. * \brief Adds constructors and member functions for cl_image_format.
  1660. *
  1661. * \see cl_image_format
  1662. */
  1663. struct ImageFormat : public cl_image_format
  1664. {
  1665. //! \brief Default constructor - performs no initialization.
  1666. ImageFormat(){}
  1667. //! \brief Initializing constructor.
  1668. ImageFormat(cl_channel_order order, cl_channel_type type)
  1669. {
  1670. image_channel_order = order;
  1671. image_channel_data_type = type;
  1672. }
  1673. //! \brief Assignment operator.
  1674. ImageFormat& operator = (const ImageFormat& rhs)
  1675. {
  1676. if (this != &rhs) {
  1677. this->image_channel_data_type = rhs.image_channel_data_type;
  1678. this->image_channel_order = rhs.image_channel_order;
  1679. }
  1680. return *this;
  1681. }
  1682. };
  1683. /*! \brief Class interface for cl_device_id.
  1684. *
  1685. * \note Copies of these objects are inexpensive, since they don't 'own'
  1686. * any underlying resources or data structures.
  1687. *
  1688. * \see cl_device_id
  1689. */
  1690. class Device : public detail::Wrapper<cl_device_id>
  1691. {
  1692. public:
  1693. //! \brief Default constructor - initializes to NULL.
  1694. Device() : detail::Wrapper<cl_type>() { }
  1695. /*! \brief Copy constructor.
  1696. *
  1697. * This simply copies the device ID value, which is an inexpensive operation.
  1698. */
  1699. Device(const Device& device) : detail::Wrapper<cl_type>(device) { }
  1700. /*! \brief Constructor from cl_device_id.
  1701. *
  1702. * This simply copies the device ID value, which is an inexpensive operation.
  1703. */
  1704. Device(const cl_device_id &device) : detail::Wrapper<cl_type>(device) { }
  1705. /*! \brief Returns the first device on the default context.
  1706. *
  1707. * \see Context::getDefault()
  1708. */
  1709. static Device getDefault(cl_int * err = NULL);
  1710. /*! \brief Assignment operator from Device.
  1711. *
  1712. * This simply copies the device ID value, which is an inexpensive operation.
  1713. */
  1714. Device& operator = (const Device& rhs)
  1715. {
  1716. if (this != &rhs) {
  1717. detail::Wrapper<cl_type>::operator=(rhs);
  1718. }
  1719. return *this;
  1720. }
  1721. /*! \brief Assignment operator from cl_device_id.
  1722. *
  1723. * This simply copies the device ID value, which is an inexpensive operation.
  1724. */
  1725. Device& operator = (const cl_device_id& rhs)
  1726. {
  1727. detail::Wrapper<cl_type>::operator=(rhs);
  1728. return *this;
  1729. }
  1730. //! \brief Wrapper for clGetDeviceInfo().
  1731. template <typename T>
  1732. cl_int getInfo(cl_device_info name, T* param) const
  1733. {
  1734. return detail::errHandler(
  1735. detail::getInfo(&::clGetDeviceInfo, object_, name, param),
  1736. __GET_DEVICE_INFO_ERR);
  1737. }
  1738. //! \brief Wrapper for clGetDeviceInfo() that returns by value.
  1739. template <cl_int name> typename
  1740. detail::param_traits<detail::cl_device_info, name>::param_type
  1741. getInfo(cl_int* err = NULL) const
  1742. {
  1743. typename detail::param_traits<
  1744. detail::cl_device_info, name>::param_type param;
  1745. cl_int result = getInfo(name, &param);
  1746. if (err != NULL) {
  1747. *err = result;
  1748. }
  1749. return param;
  1750. }
  1751. /**
  1752. * CL 1.2 version
  1753. */
  1754. #if defined(CL_VERSION_1_2)
  1755. //! \brief Wrapper for clCreateSubDevicesEXT().
  1756. cl_int createSubDevices(
  1757. const cl_device_partition_property * properties,
  1758. VECTOR_CLASS<Device>* devices)
  1759. {
  1760. cl_uint n = 0;
  1761. cl_int err = clCreateSubDevices(object_, properties, 0, NULL, &n);
  1762. if (err != CL_SUCCESS) {
  1763. return detail::errHandler(err, __CREATE_SUB_DEVICES);
  1764. }
  1765. cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id));
  1766. err = clCreateSubDevices(object_, properties, n, ids, NULL);
  1767. if (err != CL_SUCCESS) {
  1768. return detail::errHandler(err, __CREATE_SUB_DEVICES);
  1769. }
  1770. devices->assign(&ids[0], &ids[n]);
  1771. return CL_SUCCESS;
  1772. }
  1773. #endif // #if defined(CL_VERSION_1_2)
  1774. /**
  1775. * CL 1.1 version that uses device fission.
  1776. */
  1777. #if defined(CL_VERSION_1_1)
  1778. #if defined(USE_CL_DEVICE_FISSION)
  1779. cl_int createSubDevices(
  1780. const cl_device_partition_property_ext * properties,
  1781. VECTOR_CLASS<Device>* devices)
  1782. {
  1783. typedef CL_API_ENTRY cl_int
  1784. ( CL_API_CALL * PFN_clCreateSubDevicesEXT)(
  1785. cl_device_id /*in_device*/,
  1786. const cl_device_partition_property_ext * /* properties */,
  1787. cl_uint /*num_entries*/,
  1788. cl_device_id * /*out_devices*/,
  1789. cl_uint * /*num_devices*/ ) CL_EXT_SUFFIX__VERSION_1_1;
  1790. static PFN_clCreateSubDevicesEXT pfn_clCreateSubDevicesEXT = NULL;
  1791. __INIT_CL_EXT_FCN_PTR(clCreateSubDevicesEXT);
  1792. cl_uint n = 0;
  1793. cl_int err = pfn_clCreateSubDevicesEXT(object_, properties, 0, NULL, &n);
  1794. if (err != CL_SUCCESS) {
  1795. return detail::errHandler(err, __CREATE_SUB_DEVICES);
  1796. }
  1797. cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id));
  1798. err = pfn_clCreateSubDevicesEXT(object_, properties, n, ids, NULL);
  1799. if (err != CL_SUCCESS) {
  1800. return detail::errHandler(err, __CREATE_SUB_DEVICES);
  1801. }
  1802. devices->assign(&ids[0], &ids[n]);
  1803. return CL_SUCCESS;
  1804. }
  1805. #endif // #if defined(USE_CL_DEVICE_FISSION)
  1806. #endif // #if defined(CL_VERSION_1_1)
  1807. };
  1808. /*! \brief Class interface for cl_platform_id.
  1809. *
  1810. * \note Copies of these objects are inexpensive, since they don't 'own'
  1811. * any underlying resources or data structures.
  1812. *
  1813. * \see cl_platform_id
  1814. */
  1815. class Platform : public detail::Wrapper<cl_platform_id>
  1816. {
  1817. public:
  1818. //! \brief Default constructor - initializes to NULL.
  1819. Platform() : detail::Wrapper<cl_type>() { }
  1820. /*! \brief Copy constructor.
  1821. *
  1822. * This simply copies the platform ID value, which is an inexpensive operation.
  1823. */
  1824. Platform(const Platform& platform) : detail::Wrapper<cl_type>(platform) { }
  1825. /*! \brief Constructor from cl_platform_id.
  1826. *
  1827. * This simply copies the platform ID value, which is an inexpensive operation.
  1828. */
  1829. Platform(const cl_platform_id &platform) : detail::Wrapper<cl_type>(platform) { }
  1830. /*! \brief Assignment operator from Platform.
  1831. *
  1832. * This simply copies the platform ID value, which is an inexpensive operation.
  1833. */
  1834. Platform& operator = (const Platform& rhs)
  1835. {
  1836. if (this != &rhs) {
  1837. detail::Wrapper<cl_type>::operator=(rhs);
  1838. }
  1839. return *this;
  1840. }
  1841. /*! \brief Assignment operator from cl_platform_id.
  1842. *
  1843. * This simply copies the platform ID value, which is an inexpensive operation.
  1844. */
  1845. Platform& operator = (const cl_platform_id& rhs)
  1846. {
  1847. detail::Wrapper<cl_type>::operator=(rhs);
  1848. return *this;
  1849. }
  1850. //! \brief Wrapper for clGetPlatformInfo().
  1851. cl_int getInfo(cl_platform_info name, STRING_CLASS* param) const
  1852. {
  1853. return detail::errHandler(
  1854. detail::getInfo(&::clGetPlatformInfo, object_, name, param),
  1855. __GET_PLATFORM_INFO_ERR);
  1856. }
  1857. //! \brief Wrapper for clGetPlatformInfo() that returns by value.
  1858. template <cl_int name> typename
  1859. detail::param_traits<detail::cl_platform_info, name>::param_type
  1860. getInfo(cl_int* err = NULL) const
  1861. {
  1862. typename detail::param_traits<
  1863. detail::cl_platform_info, name>::param_type param;
  1864. cl_int result = getInfo(name, &param);
  1865. if (err != NULL) {
  1866. *err = result;
  1867. }
  1868. return param;
  1869. }
  1870. /*! \brief Gets a list of devices for this platform.
  1871. *
  1872. * Wraps clGetDeviceIDs().
  1873. */
  1874. cl_int getDevices(
  1875. cl_device_type type,
  1876. VECTOR_CLASS<Device>* devices) const
  1877. {
  1878. cl_uint n = 0;
  1879. if( devices == NULL ) {
  1880. return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR);
  1881. }
  1882. cl_int err = ::clGetDeviceIDs(object_, type, 0, NULL, &n);
  1883. if (err != CL_SUCCESS) {
  1884. return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
  1885. }
  1886. cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id));
  1887. err = ::clGetDeviceIDs(object_, type, n, ids, NULL);
  1888. if (err != CL_SUCCESS) {
  1889. return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
  1890. }
  1891. devices->assign(&ids[0], &ids[n]);
  1892. return CL_SUCCESS;
  1893. }
  1894. #if defined(USE_DX_INTEROP)
  1895. /*! \brief Get the list of available D3D10 devices.
  1896. *
  1897. * \param d3d_device_source.
  1898. *
  1899. * \param d3d_object.
  1900. *
  1901. * \param d3d_device_set.
  1902. *
  1903. * \param devices returns a vector of OpenCL D3D10 devices found. The cl::Device
  1904. * values returned in devices can be used to identify a specific OpenCL
  1905. * device. If \a devices argument is NULL, this argument is ignored.
  1906. *
  1907. * \return One of the following values:
  1908. * - CL_SUCCESS if the function is executed successfully.
  1909. *
  1910. * The application can query specific capabilities of the OpenCL device(s)
  1911. * returned by cl::getDevices. This can be used by the application to
  1912. * determine which device(s) to use.
  1913. *
  1914. * \note In the case that exceptions are enabled and a return value
  1915. * other than CL_SUCCESS is generated, then cl::Error exception is
  1916. * generated.
  1917. */
  1918. cl_int getDevices(
  1919. cl_d3d10_device_source_khr d3d_device_source,
  1920. void * d3d_object,
  1921. cl_d3d10_device_set_khr d3d_device_set,
  1922. VECTOR_CLASS<Device>* devices) const
  1923. {
  1924. typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clGetDeviceIDsFromD3D10KHR)(
  1925. cl_platform_id platform,
  1926. cl_d3d10_device_source_khr d3d_device_source,
  1927. void * d3d_object,
  1928. cl_d3d10_device_set_khr d3d_device_set,
  1929. cl_uint num_entries,
  1930. cl_device_id * devices,
  1931. cl_uint* num_devices);
  1932. if( devices == NULL ) {
  1933. return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_DEVICE_IDS_ERR);
  1934. }
  1935. static PFN_clGetDeviceIDsFromD3D10KHR pfn_clGetDeviceIDsFromD3D10KHR = NULL;
  1936. __INIT_CL_EXT_FCN_PTR_PLATFORM(object_, clGetDeviceIDsFromD3D10KHR);
  1937. cl_uint n = 0;
  1938. cl_int err = pfn_clGetDeviceIDsFromD3D10KHR(
  1939. object_,
  1940. d3d_device_source,
  1941. d3d_object,
  1942. d3d_device_set,
  1943. 0,
  1944. NULL,
  1945. &n);
  1946. if (err != CL_SUCCESS) {
  1947. return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
  1948. }
  1949. cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id));
  1950. err = pfn_clGetDeviceIDsFromD3D10KHR(
  1951. object_,
  1952. d3d_device_source,
  1953. d3d_object,
  1954. d3d_device_set,
  1955. n,
  1956. ids,
  1957. NULL);
  1958. if (err != CL_SUCCESS) {
  1959. return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
  1960. }
  1961. devices->assign(&ids[0], &ids[n]);
  1962. return CL_SUCCESS;
  1963. }
  1964. #endif
  1965. /*! \brief Gets a list of available platforms.
  1966. *
  1967. * Wraps clGetPlatformIDs().
  1968. */
  1969. static cl_int get(
  1970. VECTOR_CLASS<Platform>* platforms)
  1971. {
  1972. cl_uint n = 0;
  1973. if( platforms == NULL ) {
  1974. return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_PLATFORM_IDS_ERR);
  1975. }
  1976. cl_int err = ::clGetPlatformIDs(0, NULL, &n);
  1977. if (err != CL_SUCCESS) {
  1978. return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
  1979. }
  1980. cl_platform_id* ids = (cl_platform_id*) alloca(
  1981. n * sizeof(cl_platform_id));
  1982. err = ::clGetPlatformIDs(n, ids, NULL);
  1983. if (err != CL_SUCCESS) {
  1984. return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
  1985. }
  1986. platforms->assign(&ids[0], &ids[n]);
  1987. return CL_SUCCESS;
  1988. }
  1989. /*! \brief Gets the first available platform.
  1990. *
  1991. * Wraps clGetPlatformIDs(), returning the first result.
  1992. */
  1993. static cl_int get(
  1994. Platform * platform)
  1995. {
  1996. cl_uint n = 0;
  1997. if( platform == NULL ) {
  1998. return detail::errHandler(CL_INVALID_ARG_VALUE, __GET_PLATFORM_IDS_ERR);
  1999. }
  2000. cl_int err = ::clGetPlatformIDs(0, NULL, &n);
  2001. if (err != CL_SUCCESS) {
  2002. return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
  2003. }
  2004. cl_platform_id* ids = (cl_platform_id*) alloca(
  2005. n * sizeof(cl_platform_id));
  2006. err = ::clGetPlatformIDs(n, ids, NULL);
  2007. if (err != CL_SUCCESS) {
  2008. return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
  2009. }
  2010. *platform = ids[0];
  2011. return CL_SUCCESS;
  2012. }
  2013. /*! \brief Gets the first available platform, returning it by value.
  2014. *
  2015. * Wraps clGetPlatformIDs(), returning the first result.
  2016. */
  2017. static Platform get(
  2018. cl_int * errResult = NULL)
  2019. {
  2020. Platform platform;
  2021. cl_uint n = 0;
  2022. cl_int err = ::clGetPlatformIDs(0, NULL, &n);
  2023. if (err != CL_SUCCESS) {
  2024. detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
  2025. if (errResult != NULL) {
  2026. *errResult = err;
  2027. }
  2028. }
  2029. cl_platform_id* ids = (cl_platform_id*) alloca(
  2030. n * sizeof(cl_platform_id));
  2031. err = ::clGetPlatformIDs(n, ids, NULL);
  2032. if (err != CL_SUCCESS) {
  2033. detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
  2034. }
  2035. if (errResult != NULL) {
  2036. *errResult = err;
  2037. }
  2038. return ids[0];
  2039. }
  2040. static Platform getDefault(
  2041. cl_int *errResult = NULL )
  2042. {
  2043. return get(errResult);
  2044. }
  2045. #if defined(CL_VERSION_1_2)
  2046. //! \brief Wrapper for clUnloadCompiler().
  2047. cl_int
  2048. unloadCompiler()
  2049. {
  2050. return ::clUnloadPlatformCompiler(object_);
  2051. }
  2052. #endif // #if defined(CL_VERSION_1_2)
  2053. }; // class Platform
  2054. /**
  2055. * Deprecated APIs for 1.2
  2056. */
  2057. #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2))
  2058. /**
  2059. * Unload the OpenCL compiler.
  2060. * \note Deprecated for OpenCL 1.2. Use Platform::unloadCompiler instead.
  2061. */
  2062. inline CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int
  2063. UnloadCompiler() CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED;
  2064. inline cl_int
  2065. UnloadCompiler()
  2066. {
  2067. return ::clUnloadCompiler();
  2068. }
  2069. #endif // #if defined(CL_VERSION_1_1)
  2070. /*! \brief Class interface for cl_context.
  2071. *
  2072. * \note Copies of these objects are shallow, meaning that the copy will refer
  2073. * to the same underlying cl_context as the original. For details, see
  2074. * clRetainContext() and clReleaseContext().
  2075. *
  2076. * \see cl_context
  2077. */
  2078. class Context
  2079. : public detail::Wrapper<cl_context>
  2080. {
  2081. private:
  2082. static volatile int default_initialized_;
  2083. static Context default_;
  2084. static volatile cl_int default_error_;
  2085. public:
  2086. /*! \brief Destructor.
  2087. *
  2088. * This calls clReleaseContext() on the value held by this instance.
  2089. */
  2090. ~Context() { }
  2091. /*! \brief Constructs a context including a list of specified devices.
  2092. *
  2093. * Wraps clCreateContext().
  2094. */
  2095. Context(
  2096. const VECTOR_CLASS<Device>& devices,
  2097. cl_context_properties* properties = NULL,
  2098. void (CL_CALLBACK * notifyFptr)(
  2099. const char *,
  2100. const void *,
  2101. ::size_t,
  2102. void *) = NULL,
  2103. void* data = NULL,
  2104. cl_int* err = NULL)
  2105. {
  2106. cl_int error;
  2107. ::size_t numDevices = devices.size();
  2108. cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id));
  2109. for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
  2110. deviceIDs[deviceIndex] = (devices[deviceIndex])();
  2111. }
  2112. object_ = ::clCreateContext(
  2113. properties, (cl_uint) numDevices,
  2114. deviceIDs,
  2115. notifyFptr, data, &error);
  2116. detail::errHandler(error, __CREATE_CONTEXT_ERR);
  2117. if (err != NULL) {
  2118. *err = error;
  2119. }
  2120. }
  2121. Context(
  2122. const Device& device,
  2123. cl_context_properties* properties = NULL,
  2124. void (CL_CALLBACK * notifyFptr)(
  2125. const char *,
  2126. const void *,
  2127. ::size_t,
  2128. void *) = NULL,
  2129. void* data = NULL,
  2130. cl_int* err = NULL)
  2131. {
  2132. cl_int error;
  2133. cl_device_id deviceID = device();
  2134. object_ = ::clCreateContext(
  2135. properties, 1,
  2136. &deviceID,
  2137. notifyFptr, data, &error);
  2138. detail::errHandler(error, __CREATE_CONTEXT_ERR);
  2139. if (err != NULL) {
  2140. *err = error;
  2141. }
  2142. }
  2143. /*! \brief Constructs a context including all devices of a specified type.
  2144. *
  2145. * Wraps clCreateContextFromType().
  2146. */
  2147. Context(
  2148. cl_device_type type,
  2149. cl_context_properties* properties = NULL,
  2150. void (CL_CALLBACK * notifyFptr)(
  2151. const char *,
  2152. const void *,
  2153. ::size_t,
  2154. void *) = NULL,
  2155. void* data = NULL,
  2156. cl_int* err = NULL)
  2157. {
  2158. cl_int error;
  2159. #if !defined(__APPLE__) || !defined(__MACOS)
  2160. cl_context_properties prop[4] = {CL_CONTEXT_PLATFORM, 0, 0, 0 };
  2161. if (properties == NULL) {
  2162. prop[1] = (cl_context_properties)Platform::get(&error)();
  2163. if (error != CL_SUCCESS) {
  2164. detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
  2165. if (err != NULL) {
  2166. *err = error;
  2167. return;
  2168. }
  2169. }
  2170. properties = &prop[0];
  2171. }
  2172. #endif
  2173. object_ = ::clCreateContextFromType(
  2174. properties, type, notifyFptr, data, &error);
  2175. detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
  2176. if (err != NULL) {
  2177. *err = error;
  2178. }
  2179. }
  2180. /*! \brief Returns a singleton context including all devices of CL_DEVICE_TYPE_DEFAULT.
  2181. *
  2182. * \note All calls to this function return the same cl_context as the first.
  2183. */
  2184. static Context getDefault(cl_int * err = NULL)
  2185. {
  2186. int state = detail::compare_exchange(
  2187. &default_initialized_,
  2188. __DEFAULT_BEING_INITIALIZED, __DEFAULT_NOT_INITIALIZED);
  2189. if (state & __DEFAULT_INITIALIZED) {
  2190. if (err != NULL) {
  2191. *err = default_error_;
  2192. }
  2193. return default_;
  2194. }
  2195. if (state & __DEFAULT_BEING_INITIALIZED) {
  2196. // Assume writes will propagate eventually...
  2197. while(default_initialized_ != __DEFAULT_INITIALIZED) {
  2198. detail::fence();
  2199. }
  2200. if (err != NULL) {
  2201. *err = default_error_;
  2202. }
  2203. return default_;
  2204. }
  2205. cl_int error;
  2206. default_ = Context(
  2207. CL_DEVICE_TYPE_DEFAULT,
  2208. NULL,
  2209. NULL,
  2210. NULL,
  2211. &error);
  2212. detail::fence();
  2213. default_error_ = error;
  2214. // Assume writes will propagate eventually...
  2215. default_initialized_ = __DEFAULT_INITIALIZED;
  2216. detail::fence();
  2217. if (err != NULL) {
  2218. *err = default_error_;
  2219. }
  2220. return default_;
  2221. }
  2222. //! \brief Default constructor - initializes to NULL.
  2223. Context() : detail::Wrapper<cl_type>() { }
  2224. /*! \brief Copy constructor.
  2225. *
  2226. * This calls clRetainContext() on the parameter's cl_context.
  2227. */
  2228. Context(const Context& context) : detail::Wrapper<cl_type>(context) { }
  2229. /*! \brief Constructor from cl_context - takes ownership.
  2230. *
  2231. * This effectively transfers ownership of a refcount on the cl_context
  2232. * into the new Context object.
  2233. */
  2234. __CL_EXPLICIT_CONSTRUCTORS Context(const cl_context& context) : detail::Wrapper<cl_type>(context) { }
  2235. /*! \brief Assignment operator from Context.
  2236. *
  2237. * This calls clRetainContext() on the parameter and clReleaseContext() on
  2238. * the previous value held by this instance.
  2239. */
  2240. Context& operator = (const Context& rhs)
  2241. {
  2242. if (this != &rhs) {
  2243. detail::Wrapper<cl_type>::operator=(rhs);
  2244. }
  2245. return *this;
  2246. }
  2247. /*! \brief Assignment operator from cl_context - takes ownership.
  2248. *
  2249. * This effectively transfers ownership of a refcount on the rhs and calls
  2250. * clReleaseContext() on the value previously held by this instance.
  2251. */
  2252. Context& operator = (const cl_context& rhs)
  2253. {
  2254. detail::Wrapper<cl_type>::operator=(rhs);
  2255. return *this;
  2256. }
  2257. //! \brief Wrapper for clGetContextInfo().
  2258. template <typename T>
  2259. cl_int getInfo(cl_context_info name, T* param) const
  2260. {
  2261. return detail::errHandler(
  2262. detail::getInfo(&::clGetContextInfo, object_, name, param),
  2263. __GET_CONTEXT_INFO_ERR);
  2264. }
  2265. //! \brief Wrapper for clGetContextInfo() that returns by value.
  2266. template <cl_int name> typename
  2267. detail::param_traits<detail::cl_context_info, name>::param_type
  2268. getInfo(cl_int* err = NULL) const
  2269. {
  2270. typename detail::param_traits<
  2271. detail::cl_context_info, name>::param_type param;
  2272. cl_int result = getInfo(name, &param);
  2273. if (err != NULL) {
  2274. *err = result;
  2275. }
  2276. return param;
  2277. }
  2278. /*! \brief Gets a list of supported image formats.
  2279. *
  2280. * Wraps clGetSupportedImageFormats().
  2281. */
  2282. cl_int getSupportedImageFormats(
  2283. cl_mem_flags flags,
  2284. cl_mem_object_type type,
  2285. VECTOR_CLASS<ImageFormat>* formats) const
  2286. {
  2287. cl_uint numEntries;
  2288. cl_int err = ::clGetSupportedImageFormats(
  2289. object_,
  2290. flags,
  2291. type,
  2292. 0,
  2293. NULL,
  2294. &numEntries);
  2295. if (err != CL_SUCCESS) {
  2296. return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
  2297. }
  2298. ImageFormat* value = (ImageFormat*)
  2299. alloca(numEntries * sizeof(ImageFormat));
  2300. err = ::clGetSupportedImageFormats(
  2301. object_,
  2302. flags,
  2303. type,
  2304. numEntries,
  2305. (cl_image_format*) value,
  2306. NULL);
  2307. if (err != CL_SUCCESS) {
  2308. return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
  2309. }
  2310. formats->assign(&value[0], &value[numEntries]);
  2311. return CL_SUCCESS;
  2312. }
  2313. };
  2314. inline Device Device::getDefault(cl_int * err)
  2315. {
  2316. cl_int error;
  2317. Device device;
  2318. Context context = Context::getDefault(&error);
  2319. detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
  2320. if (error != CL_SUCCESS) {
  2321. if (err != NULL) {
  2322. *err = error;
  2323. }
  2324. }
  2325. else {
  2326. device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
  2327. if (err != NULL) {
  2328. *err = CL_SUCCESS;
  2329. }
  2330. }
  2331. return device;
  2332. }
  2333. #ifdef _WIN32
  2334. __declspec(selectany) volatile int Context::default_initialized_ = __DEFAULT_NOT_INITIALIZED;
  2335. __declspec(selectany) Context Context::default_;
  2336. __declspec(selectany) volatile cl_int Context::default_error_ = CL_SUCCESS;
  2337. #else
  2338. __attribute__((weak)) volatile int Context::default_initialized_ = __DEFAULT_NOT_INITIALIZED;
  2339. __attribute__((weak)) Context Context::default_;
  2340. __attribute__((weak)) volatile cl_int Context::default_error_ = CL_SUCCESS;
  2341. #endif
  2342. /*! \brief Class interface for cl_event.
  2343. *
  2344. * \note Copies of these objects are shallow, meaning that the copy will refer
  2345. * to the same underlying cl_event as the original. For details, see
  2346. * clRetainEvent() and clReleaseEvent().
  2347. *
  2348. * \see cl_event
  2349. */
  2350. class Event : public detail::Wrapper<cl_event>
  2351. {
  2352. public:
  2353. /*! \brief Destructor.
  2354. *
  2355. * This calls clReleaseEvent() on the value held by this instance.
  2356. */
  2357. ~Event() { }
  2358. //! \brief Default constructor - initializes to NULL.
  2359. Event() : detail::Wrapper<cl_type>() { }
  2360. /*! \brief Copy constructor.
  2361. *
  2362. * This calls clRetainEvent() on the parameter's cl_event.
  2363. */
  2364. Event(const Event& event) : detail::Wrapper<cl_type>(event) { }
  2365. /*! \brief Constructor from cl_event - takes ownership.
  2366. *
  2367. * This effectively transfers ownership of a refcount on the cl_event
  2368. * into the new Event object.
  2369. */
  2370. Event(const cl_event& event) : detail::Wrapper<cl_type>(event) { }
  2371. /*! \brief Assignment operator from cl_event - takes ownership.
  2372. *
  2373. * This effectively transfers ownership of a refcount on the rhs and calls
  2374. * clReleaseEvent() on the value previously held by this instance.
  2375. */
  2376. Event& operator = (const Event& rhs)
  2377. {
  2378. if (this != &rhs) {
  2379. detail::Wrapper<cl_type>::operator=(rhs);
  2380. }
  2381. return *this;
  2382. }
  2383. /*! \brief Assignment operator from cl_event.
  2384. *
  2385. * This calls clRetainEvent() on the parameter and clReleaseEvent() on
  2386. * the previous value held by this instance.
  2387. */
  2388. Event& operator = (const cl_event& rhs)
  2389. {
  2390. detail::Wrapper<cl_type>::operator=(rhs);
  2391. return *this;
  2392. }
  2393. //! \brief Wrapper for clGetEventInfo().
  2394. template <typename T>
  2395. cl_int getInfo(cl_event_info name, T* param) const
  2396. {
  2397. return detail::errHandler(
  2398. detail::getInfo(&::clGetEventInfo, object_, name, param),
  2399. __GET_EVENT_INFO_ERR);
  2400. }
  2401. //! \brief Wrapper for clGetEventInfo() that returns by value.
  2402. template <cl_int name> typename
  2403. detail::param_traits<detail::cl_event_info, name>::param_type
  2404. getInfo(cl_int* err = NULL) const
  2405. {
  2406. typename detail::param_traits<
  2407. detail::cl_event_info, name>::param_type param;
  2408. cl_int result = getInfo(name, &param);
  2409. if (err != NULL) {
  2410. *err = result;
  2411. }
  2412. return param;
  2413. }
  2414. //! \brief Wrapper for clGetEventProfilingInfo().
  2415. template <typename T>
  2416. cl_int getProfilingInfo(cl_profiling_info name, T* param) const
  2417. {
  2418. return detail::errHandler(detail::getInfo(
  2419. &::clGetEventProfilingInfo, object_, name, param),
  2420. __GET_EVENT_PROFILE_INFO_ERR);
  2421. }
  2422. //! \brief Wrapper for clGetEventProfilingInfo() that returns by value.
  2423. template <cl_int name> typename
  2424. detail::param_traits<detail::cl_profiling_info, name>::param_type
  2425. getProfilingInfo(cl_int* err = NULL) const
  2426. {
  2427. typename detail::param_traits<
  2428. detail::cl_profiling_info, name>::param_type param;
  2429. cl_int result = getProfilingInfo(name, &param);
  2430. if (err != NULL) {
  2431. *err = result;
  2432. }
  2433. return param;
  2434. }
  2435. /*! \brief Blocks the calling thread until this event completes.
  2436. *
  2437. * Wraps clWaitForEvents().
  2438. */
  2439. cl_int wait() const
  2440. {
  2441. return detail::errHandler(
  2442. ::clWaitForEvents(1, &object_),
  2443. __WAIT_FOR_EVENTS_ERR);
  2444. }
  2445. #if defined(CL_VERSION_1_1)
  2446. /*! \brief Registers a user callback function for a specific command execution status.
  2447. *
  2448. * Wraps clSetEventCallback().
  2449. */
  2450. cl_int setCallback(
  2451. cl_int type,
  2452. void (CL_CALLBACK * pfn_notify)(cl_event, cl_int, void *),
  2453. void * user_data = NULL)
  2454. {
  2455. return detail::errHandler(
  2456. ::clSetEventCallback(
  2457. object_,
  2458. type,
  2459. pfn_notify,
  2460. user_data),
  2461. __SET_EVENT_CALLBACK_ERR);
  2462. }
  2463. #endif
  2464. /*! \brief Blocks the calling thread until every event specified is complete.
  2465. *
  2466. * Wraps clWaitForEvents().
  2467. */
  2468. static cl_int
  2469. waitForEvents(const VECTOR_CLASS<Event>& events)
  2470. {
  2471. return detail::errHandler(
  2472. ::clWaitForEvents(
  2473. (cl_uint) events.size(), (cl_event*)&events.front()),
  2474. __WAIT_FOR_EVENTS_ERR);
  2475. }
  2476. };
  2477. #if defined(CL_VERSION_1_1)
  2478. /*! \brief Class interface for user events (a subset of cl_event's).
  2479. *
  2480. * See Event for details about copy semantics, etc.
  2481. */
  2482. class UserEvent : public Event
  2483. {
  2484. public:
  2485. /*! \brief Constructs a user event on a given context.
  2486. *
  2487. * Wraps clCreateUserEvent().
  2488. */
  2489. UserEvent(
  2490. const Context& context,
  2491. cl_int * err = NULL)
  2492. {
  2493. cl_int error;
  2494. object_ = ::clCreateUserEvent(
  2495. context(),
  2496. &error);
  2497. detail::errHandler(error, __CREATE_USER_EVENT_ERR);
  2498. if (err != NULL) {
  2499. *err = error;
  2500. }
  2501. }
  2502. //! \brief Default constructor - initializes to NULL.
  2503. UserEvent() : Event() { }
  2504. //! \brief Copy constructor - performs shallow copy.
  2505. UserEvent(const UserEvent& event) : Event(event) { }
  2506. //! \brief Assignment Operator - performs shallow copy.
  2507. UserEvent& operator = (const UserEvent& rhs)
  2508. {
  2509. if (this != &rhs) {
  2510. Event::operator=(rhs);
  2511. }
  2512. return *this;
  2513. }
  2514. /*! \brief Sets the execution status of a user event object.
  2515. *
  2516. * Wraps clSetUserEventStatus().
  2517. */
  2518. cl_int setStatus(cl_int status)
  2519. {
  2520. return detail::errHandler(
  2521. ::clSetUserEventStatus(object_,status),
  2522. __SET_USER_EVENT_STATUS_ERR);
  2523. }
  2524. };
  2525. #endif
  2526. /*! \brief Blocks the calling thread until every event specified is complete.
  2527. *
  2528. * Wraps clWaitForEvents().
  2529. */
  2530. inline static cl_int
  2531. WaitForEvents(const VECTOR_CLASS<Event>& events)
  2532. {
  2533. return detail::errHandler(
  2534. ::clWaitForEvents(
  2535. (cl_uint) events.size(), (cl_event*)&events.front()),
  2536. __WAIT_FOR_EVENTS_ERR);
  2537. }
  2538. /*! \brief Class interface for cl_mem.
  2539. *
  2540. * \note Copies of these objects are shallow, meaning that the copy will refer
  2541. * to the same underlying cl_mem as the original. For details, see
  2542. * clRetainMemObject() and clReleaseMemObject().
  2543. *
  2544. * \see cl_mem
  2545. */
  2546. class Memory : public detail::Wrapper<cl_mem>
  2547. {
  2548. public:
  2549. /*! \brief Destructor.
  2550. *
  2551. * This calls clReleaseMemObject() on the value held by this instance.
  2552. */
  2553. ~Memory() {}
  2554. //! \brief Default constructor - initializes to NULL.
  2555. Memory() : detail::Wrapper<cl_type>() { }
  2556. /*! \brief Copy constructor - performs shallow copy.
  2557. *
  2558. * This calls clRetainMemObject() on the parameter's cl_mem.
  2559. */
  2560. Memory(const Memory& memory) : detail::Wrapper<cl_type>(memory) { }
  2561. /*! \brief Constructor from cl_mem - takes ownership.
  2562. *
  2563. * This effectively transfers ownership of a refcount on the cl_mem
  2564. * into the new Memory object.
  2565. */
  2566. __CL_EXPLICIT_CONSTRUCTORS Memory(const cl_mem& memory) : detail::Wrapper<cl_type>(memory) { }
  2567. /*! \brief Assignment operator from Memory.
  2568. *
  2569. * This calls clRetainMemObject() on the parameter and clReleaseMemObject()
  2570. * on the previous value held by this instance.
  2571. */
  2572. Memory& operator = (const Memory& rhs)
  2573. {
  2574. if (this != &rhs) {
  2575. detail::Wrapper<cl_type>::operator=(rhs);
  2576. }
  2577. return *this;
  2578. }
  2579. /*! \brief Assignment operator from cl_mem - takes ownership.
  2580. *
  2581. * This effectively transfers ownership of a refcount on the rhs and calls
  2582. * clReleaseMemObject() on the value previously held by this instance.
  2583. */
  2584. Memory& operator = (const cl_mem& rhs)
  2585. {
  2586. detail::Wrapper<cl_type>::operator=(rhs);
  2587. return *this;
  2588. }
  2589. //! \brief Wrapper for clGetMemObjectInfo().
  2590. template <typename T>
  2591. cl_int getInfo(cl_mem_info name, T* param) const
  2592. {
  2593. return detail::errHandler(
  2594. detail::getInfo(&::clGetMemObjectInfo, object_, name, param),
  2595. __GET_MEM_OBJECT_INFO_ERR);
  2596. }
  2597. //! \brief Wrapper for clGetMemObjectInfo() that returns by value.
  2598. template <cl_int name> typename
  2599. detail::param_traits<detail::cl_mem_info, name>::param_type
  2600. getInfo(cl_int* err = NULL) const
  2601. {
  2602. typename detail::param_traits<
  2603. detail::cl_mem_info, name>::param_type param;
  2604. cl_int result = getInfo(name, &param);
  2605. if (err != NULL) {
  2606. *err = result;
  2607. }
  2608. return param;
  2609. }
  2610. #if defined(CL_VERSION_1_1)
  2611. /*! \brief Registers a callback function to be called when the memory object
  2612. * is no longer needed.
  2613. *
  2614. * Wraps clSetMemObjectDestructorCallback().
  2615. *
  2616. * Repeated calls to this function, for a given cl_mem value, will append
  2617. * to the list of functions called (in reverse order) when memory object's
  2618. * resources are freed and the memory object is deleted.
  2619. *
  2620. * \note
  2621. * The registered callbacks are associated with the underlying cl_mem
  2622. * value - not the Memory class instance.
  2623. */
  2624. cl_int setDestructorCallback(
  2625. void (CL_CALLBACK * pfn_notify)(cl_mem, void *),
  2626. void * user_data = NULL)
  2627. {
  2628. return detail::errHandler(
  2629. ::clSetMemObjectDestructorCallback(
  2630. object_,
  2631. pfn_notify,
  2632. user_data),
  2633. __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR);
  2634. }
  2635. #endif
  2636. };
  2637. // Pre-declare copy functions
  2638. class Buffer;
  2639. template< typename IteratorType >
  2640. cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer );
  2641. template< typename IteratorType >
  2642. cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator );
  2643. /*! \brief Class interface for Buffer Memory Objects.
  2644. *
  2645. * See Memory for details about copy semantics, etc.
  2646. *
  2647. * \see Memory
  2648. */
  2649. class Buffer : public Memory
  2650. {
  2651. public:
  2652. /*! \brief Constructs a Buffer in a specified context.
  2653. *
  2654. * Wraps clCreateBuffer().
  2655. *
  2656. * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was
  2657. * specified. Note alignment & exclusivity requirements.
  2658. */
  2659. Buffer(
  2660. const Context& context,
  2661. cl_mem_flags flags,
  2662. ::size_t size,
  2663. void* host_ptr = NULL,
  2664. cl_int* err = NULL)
  2665. {
  2666. cl_int error;
  2667. object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error);
  2668. detail::errHandler(error, __CREATE_BUFFER_ERR);
  2669. if (err != NULL) {
  2670. *err = error;
  2671. }
  2672. }
  2673. /*! \brief Constructs a Buffer in the default context.
  2674. *
  2675. * Wraps clCreateBuffer().
  2676. *
  2677. * \param host_ptr Storage to be used if the CL_MEM_USE_HOST_PTR flag was
  2678. * specified. Note alignment & exclusivity requirements.
  2679. *
  2680. * \see Context::getDefault()
  2681. */
  2682. Buffer(
  2683. cl_mem_flags flags,
  2684. ::size_t size,
  2685. void* host_ptr = NULL,
  2686. cl_int* err = NULL)
  2687. {
  2688. cl_int error;
  2689. Context context = Context::getDefault(err);
  2690. object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error);
  2691. detail::errHandler(error, __CREATE_BUFFER_ERR);
  2692. if (err != NULL) {
  2693. *err = error;
  2694. }
  2695. }
  2696. /*!
  2697. * \brief Construct a Buffer from a host container via iterators.
  2698. * If useHostPtr is specified iterators must be random access.
  2699. */
  2700. template< typename IteratorType >
  2701. Buffer(
  2702. IteratorType startIterator,
  2703. IteratorType endIterator,
  2704. bool readOnly,
  2705. bool useHostPtr = false,
  2706. cl_int* err = NULL)
  2707. {
  2708. typedef typename std::iterator_traits<IteratorType>::value_type DataType;
  2709. cl_int error;
  2710. cl_mem_flags flags = 0;
  2711. if( readOnly ) {
  2712. flags |= CL_MEM_READ_ONLY;
  2713. }
  2714. else {
  2715. flags |= CL_MEM_READ_WRITE;
  2716. }
  2717. if( useHostPtr ) {
  2718. flags |= CL_MEM_USE_HOST_PTR;
  2719. }
  2720. ::size_t size = sizeof(DataType)*(endIterator - startIterator);
  2721. Context context = Context::getDefault(err);
  2722. if( useHostPtr ) {
  2723. object_ = ::clCreateBuffer(context(), flags, size, static_cast<DataType*>(&*startIterator), &error);
  2724. } else {
  2725. object_ = ::clCreateBuffer(context(), flags, size, 0, &error);
  2726. }
  2727. detail::errHandler(error, __CREATE_BUFFER_ERR);
  2728. if (err != NULL) {
  2729. *err = error;
  2730. }
  2731. if( !useHostPtr ) {
  2732. error = cl::copy(startIterator, endIterator, *this);
  2733. detail::errHandler(error, __CREATE_BUFFER_ERR);
  2734. if (err != NULL) {
  2735. *err = error;
  2736. }
  2737. }
  2738. }
  2739. //! \brief Default constructor - initializes to NULL.
  2740. Buffer() : Memory() { }
  2741. /*! \brief Copy constructor - performs shallow copy.
  2742. *
  2743. * See Memory for further details.
  2744. */
  2745. Buffer(const Buffer& buffer) : Memory(buffer) { }
  2746. /*! \brief Constructor from cl_mem - takes ownership.
  2747. *
  2748. * See Memory for further details.
  2749. */
  2750. __CL_EXPLICIT_CONSTRUCTORS Buffer(const cl_mem& buffer) : Memory(buffer) { }
  2751. /*! \brief Assignment from Buffer - performs shallow copy.
  2752. *
  2753. * See Memory for further details.
  2754. */
  2755. Buffer& operator = (const Buffer& rhs)
  2756. {
  2757. if (this != &rhs) {
  2758. Memory::operator=(rhs);
  2759. }
  2760. return *this;
  2761. }
  2762. /*! \brief Assignment from cl_mem - performs shallow copy.
  2763. *
  2764. * See Memory for further details.
  2765. */
  2766. Buffer& operator = (const cl_mem& rhs)
  2767. {
  2768. Memory::operator=(rhs);
  2769. return *this;
  2770. }
  2771. #if defined(CL_VERSION_1_1)
  2772. /*! \brief Creates a new buffer object from this.
  2773. *
  2774. * Wraps clCreateSubBuffer().
  2775. */
  2776. Buffer createSubBuffer(
  2777. cl_mem_flags flags,
  2778. cl_buffer_create_type buffer_create_type,
  2779. const void * buffer_create_info,
  2780. cl_int * err = NULL)
  2781. {
  2782. Buffer result;
  2783. cl_int error;
  2784. result.object_ = ::clCreateSubBuffer(
  2785. object_,
  2786. flags,
  2787. buffer_create_type,
  2788. buffer_create_info,
  2789. &error);
  2790. detail::errHandler(error, __CREATE_SUBBUFFER_ERR);
  2791. if (err != NULL) {
  2792. *err = error;
  2793. }
  2794. return result;
  2795. }
  2796. #endif
  2797. };
  2798. #if defined (USE_DX_INTEROP)
  2799. /*! \brief Class interface for creating OpenCL buffers from ID3D10Buffer's.
  2800. *
  2801. * This is provided to facilitate interoperability with Direct3D.
  2802. *
  2803. * See Memory for details about copy semantics, etc.
  2804. *
  2805. * \see Memory
  2806. */
  2807. class BufferD3D10 : public Buffer
  2808. {
  2809. public:
  2810. typedef CL_API_ENTRY cl_mem (CL_API_CALL *PFN_clCreateFromD3D10BufferKHR)(
  2811. cl_context context, cl_mem_flags flags, ID3D10Buffer* buffer,
  2812. cl_int* errcode_ret);
  2813. /*! \brief Constructs a BufferD3D10, in a specified context, from a
  2814. * given ID3D10Buffer.
  2815. *
  2816. * Wraps clCreateFromD3D10BufferKHR().
  2817. */
  2818. BufferD3D10(
  2819. const Context& context,
  2820. cl_mem_flags flags,
  2821. ID3D10Buffer* bufobj,
  2822. cl_int * err = NULL)
  2823. {
  2824. static PFN_clCreateFromD3D10BufferKHR pfn_clCreateFromD3D10BufferKHR = NULL;
  2825. #if defined(CL_VERSION_1_2)
  2826. vector<cl_context_properties> props = context.getInfo<CL_CONTEXT_PROPERTIES>();
  2827. cl_platform platform = -1;
  2828. for( int i = 0; i < props.size(); ++i ) {
  2829. if( props[i] == CL_CONTEXT_PLATFORM ) {
  2830. platform = props[i+1];
  2831. }
  2832. }
  2833. __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, clCreateFromD3D10BufferKHR);
  2834. #endif
  2835. #if defined(CL_VERSION_1_1)
  2836. __INIT_CL_EXT_FCN_PTR(clCreateFromD3D10BufferKHR);
  2837. #endif
  2838. cl_int error;
  2839. object_ = pfn_clCreateFromD3D10BufferKHR(
  2840. context(),
  2841. flags,
  2842. bufobj,
  2843. &error);
  2844. detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
  2845. if (err != NULL) {
  2846. *err = error;
  2847. }
  2848. }
  2849. //! \brief Default constructor - initializes to NULL.
  2850. BufferD3D10() : Buffer() { }
  2851. /*! \brief Copy constructor - performs shallow copy.
  2852. *
  2853. * See Memory for further details.
  2854. */
  2855. BufferD3D10(const BufferD3D10& buffer) : Buffer(buffer) { }
  2856. /*! \brief Constructor from cl_mem - takes ownership.
  2857. *
  2858. * See Memory for further details.
  2859. */
  2860. __CL_EXPLICIT_CONSTRUCTORS BufferD3D10(const cl_mem& buffer) : Buffer(buffer) { }
  2861. /*! \brief Assignment from BufferD3D10 - performs shallow copy.
  2862. *
  2863. * See Memory for further details.
  2864. */
  2865. BufferD3D10& operator = (const BufferD3D10& rhs)
  2866. {
  2867. if (this != &rhs) {
  2868. Buffer::operator=(rhs);
  2869. }
  2870. return *this;
  2871. }
  2872. /*! \brief Assignment from cl_mem - performs shallow copy.
  2873. *
  2874. * See Memory for further details.
  2875. */
  2876. BufferD3D10& operator = (const cl_mem& rhs)
  2877. {
  2878. Buffer::operator=(rhs);
  2879. return *this;
  2880. }
  2881. };
  2882. #endif
  2883. /*! \brief Class interface for GL Buffer Memory Objects.
  2884. *
  2885. * This is provided to facilitate interoperability with OpenGL.
  2886. *
  2887. * See Memory for details about copy semantics, etc.
  2888. *
  2889. * \see Memory
  2890. */
  2891. class BufferGL : public Buffer
  2892. {
  2893. public:
  2894. /*! \brief Constructs a BufferGL in a specified context, from a given
  2895. * GL buffer.
  2896. *
  2897. * Wraps clCreateFromGLBuffer().
  2898. */
  2899. BufferGL(
  2900. const Context& context,
  2901. cl_mem_flags flags,
  2902. GLuint bufobj,
  2903. cl_int * err = NULL)
  2904. {
  2905. cl_int error;
  2906. object_ = ::clCreateFromGLBuffer(
  2907. context(),
  2908. flags,
  2909. bufobj,
  2910. &error);
  2911. detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
  2912. if (err != NULL) {
  2913. *err = error;
  2914. }
  2915. }
  2916. //! \brief Default constructor - initializes to NULL.
  2917. BufferGL() : Buffer() { }
  2918. /*! \brief Copy constructor - performs shallow copy.
  2919. *
  2920. * See Memory for further details.
  2921. */
  2922. BufferGL(const BufferGL& buffer) : Buffer(buffer) { }
  2923. /*! \brief Constructor from cl_mem - takes ownership.
  2924. *
  2925. * See Memory for further details.
  2926. */
  2927. __CL_EXPLICIT_CONSTRUCTORS BufferGL(const cl_mem& buffer) : Buffer(buffer) { }
  2928. /*! \brief Assignment from BufferGL - performs shallow copy.
  2929. *
  2930. * See Memory for further details.
  2931. */
  2932. BufferGL& operator = (const BufferGL& rhs)
  2933. {
  2934. if (this != &rhs) {
  2935. Buffer::operator=(rhs);
  2936. }
  2937. return *this;
  2938. }
  2939. /*! \brief Assignment from cl_mem - performs shallow copy.
  2940. *
  2941. * See Memory for further details.
  2942. */
  2943. BufferGL& operator = (const cl_mem& rhs)
  2944. {
  2945. Buffer::operator=(rhs);
  2946. return *this;
  2947. }
  2948. //! \brief Wrapper for clGetGLObjectInfo().
  2949. cl_int getObjectInfo(
  2950. cl_gl_object_type *type,
  2951. GLuint * gl_object_name)
  2952. {
  2953. return detail::errHandler(
  2954. ::clGetGLObjectInfo(object_,type,gl_object_name),
  2955. __GET_GL_OBJECT_INFO_ERR);
  2956. }
  2957. };
  2958. /*! \brief Class interface for GL Render Buffer Memory Objects.
  2959. *
  2960. * This is provided to facilitate interoperability with OpenGL.
  2961. *
  2962. * See Memory for details about copy semantics, etc.
  2963. *
  2964. * \see Memory
  2965. */
  2966. class BufferRenderGL : public Buffer
  2967. {
  2968. public:
  2969. /*! \brief Constructs a BufferRenderGL in a specified context, from a given
  2970. * GL Renderbuffer.
  2971. *
  2972. * Wraps clCreateFromGLRenderbuffer().
  2973. */
  2974. BufferRenderGL(
  2975. const Context& context,
  2976. cl_mem_flags flags,
  2977. GLuint bufobj,
  2978. cl_int * err = NULL)
  2979. {
  2980. cl_int error;
  2981. object_ = ::clCreateFromGLRenderbuffer(
  2982. context(),
  2983. flags,
  2984. bufobj,
  2985. &error);
  2986. detail::errHandler(error, __CREATE_GL_RENDER_BUFFER_ERR);
  2987. if (err != NULL) {
  2988. *err = error;
  2989. }
  2990. }
  2991. //! \brief Default constructor - initializes to NULL.
  2992. BufferRenderGL() : Buffer() { }
  2993. /*! \brief Copy constructor - performs shallow copy.
  2994. *
  2995. * See Memory for further details.
  2996. */
  2997. BufferRenderGL(const BufferGL& buffer) : Buffer(buffer) { }
  2998. /*! \brief Constructor from cl_mem - takes ownership.
  2999. *
  3000. * See Memory for further details.
  3001. */
  3002. __CL_EXPLICIT_CONSTRUCTORS BufferRenderGL(const cl_mem& buffer) : Buffer(buffer) { }
  3003. /*! \brief Assignment from BufferGL - performs shallow copy.
  3004. *
  3005. * See Memory for further details.
  3006. */
  3007. BufferRenderGL& operator = (const BufferRenderGL& rhs)
  3008. {
  3009. if (this != &rhs) {
  3010. Buffer::operator=(rhs);
  3011. }
  3012. return *this;
  3013. }
  3014. /*! \brief Assignment from cl_mem - performs shallow copy.
  3015. *
  3016. * See Memory for further details.
  3017. */
  3018. BufferRenderGL& operator = (const cl_mem& rhs)
  3019. {
  3020. Buffer::operator=(rhs);
  3021. return *this;
  3022. }
  3023. //! \brief Wrapper for clGetGLObjectInfo().
  3024. cl_int getObjectInfo(
  3025. cl_gl_object_type *type,
  3026. GLuint * gl_object_name)
  3027. {
  3028. return detail::errHandler(
  3029. ::clGetGLObjectInfo(object_,type,gl_object_name),
  3030. __GET_GL_OBJECT_INFO_ERR);
  3031. }
  3032. };
  3033. /*! \brief C++ base class for Image Memory objects.
  3034. *
  3035. * See Memory for details about copy semantics, etc.
  3036. *
  3037. * \see Memory
  3038. */
  3039. class Image : public Memory
  3040. {
  3041. protected:
  3042. //! \brief Default constructor - initializes to NULL.
  3043. Image() : Memory() { }
  3044. /*! \brief Copy constructor - performs shallow copy.
  3045. *
  3046. * See Memory for further details.
  3047. */
  3048. Image(const Image& image) : Memory(image) { }
  3049. /*! \brief Constructor from cl_mem - takes ownership.
  3050. *
  3051. * See Memory for further details.
  3052. */
  3053. __CL_EXPLICIT_CONSTRUCTORS Image(const cl_mem& image) : Memory(image) { }
  3054. /*! \brief Assignment from Image - performs shallow copy.
  3055. *
  3056. * See Memory for further details.
  3057. */
  3058. Image& operator = (const Image& rhs)
  3059. {
  3060. if (this != &rhs) {
  3061. Memory::operator=(rhs);
  3062. }
  3063. return *this;
  3064. }
  3065. /*! \brief Assignment from cl_mem - performs shallow copy.
  3066. *
  3067. * See Memory for further details.
  3068. */
  3069. Image& operator = (const cl_mem& rhs)
  3070. {
  3071. Memory::operator=(rhs);
  3072. return *this;
  3073. }
  3074. public:
  3075. //! \brief Wrapper for clGetImageInfo().
  3076. template <typename T>
  3077. cl_int getImageInfo(cl_image_info name, T* param) const
  3078. {
  3079. return detail::errHandler(
  3080. detail::getInfo(&::clGetImageInfo, object_, name, param),
  3081. __GET_IMAGE_INFO_ERR);
  3082. }
  3083. //! \brief Wrapper for clGetImageInfo() that returns by value.
  3084. template <cl_int name> typename
  3085. detail::param_traits<detail::cl_image_info, name>::param_type
  3086. getImageInfo(cl_int* err = NULL) const
  3087. {
  3088. typename detail::param_traits<
  3089. detail::cl_image_info, name>::param_type param;
  3090. cl_int result = getImageInfo(name, &param);
  3091. if (err != NULL) {
  3092. *err = result;
  3093. }
  3094. return param;
  3095. }
  3096. };
  3097. #if defined(CL_VERSION_1_2)
  3098. /*! \brief Class interface for 1D Image Memory objects.
  3099. *
  3100. * See Memory for details about copy semantics, etc.
  3101. *
  3102. * \see Memory
  3103. */
  3104. class Image1D : public Image
  3105. {
  3106. public:
  3107. /*! \brief Constructs a 1D Image in a specified context.
  3108. *
  3109. * Wraps clCreateImage().
  3110. */
  3111. Image1D(
  3112. const Context& context,
  3113. cl_mem_flags flags,
  3114. ImageFormat format,
  3115. ::size_t width,
  3116. void* host_ptr = NULL,
  3117. cl_int* err = NULL)
  3118. {
  3119. cl_int error;
  3120. cl_image_desc desc;
  3121. desc.image_type = CL_MEM_OBJECT_IMAGE1D;
  3122. desc.image_width = width;
  3123. desc.image_row_pitch = 0;
  3124. desc.num_mip_levels = 0;
  3125. desc.num_samples = 0;
  3126. desc.buffer = 0;
  3127. object_ = ::clCreateImage(
  3128. context(),
  3129. flags,
  3130. &format,
  3131. &desc,
  3132. host_ptr,
  3133. &error);
  3134. detail::errHandler(error, __CREATE_IMAGE_ERR);
  3135. if (err != NULL) {
  3136. *err = error;
  3137. }
  3138. }
  3139. //! \brief Default constructor - initializes to NULL.
  3140. Image1D() { }
  3141. /*! \brief Copy constructor - performs shallow copy.
  3142. *
  3143. * See Memory for further details.
  3144. */
  3145. Image1D(const Image1D& image1D) : Image(image1D) { }
  3146. /*! \brief Constructor from cl_mem - takes ownership.
  3147. *
  3148. * See Memory for further details.
  3149. */
  3150. __CL_EXPLICIT_CONSTRUCTORS Image1D(const cl_mem& image1D) : Image(image1D) { }
  3151. /*! \brief Assignment from Image1D - performs shallow copy.
  3152. *
  3153. * See Memory for further details.
  3154. */
  3155. Image1D& operator = (const Image1D& rhs)
  3156. {
  3157. if (this != &rhs) {
  3158. Image::operator=(rhs);
  3159. }
  3160. return *this;
  3161. }
  3162. /*! \brief Assignment from cl_mem - performs shallow copy.
  3163. *
  3164. * See Memory for further details.
  3165. */
  3166. Image1D& operator = (const cl_mem& rhs)
  3167. {
  3168. Image::operator=(rhs);
  3169. return *this;
  3170. }
  3171. };
  3172. /*! \class Image1DBuffer
  3173. * \brief Image interface for 1D buffer images.
  3174. */
  3175. class Image1DBuffer : public Image
  3176. {
  3177. public:
  3178. Image1DBuffer(
  3179. const Context& context,
  3180. cl_mem_flags flags,
  3181. ImageFormat format,
  3182. ::size_t width,
  3183. const Buffer &buffer,
  3184. cl_int* err = NULL)
  3185. {
  3186. cl_int error;
  3187. cl_image_desc desc;
  3188. desc.image_type = CL_MEM_OBJECT_IMAGE1D_BUFFER;
  3189. desc.image_width = width;
  3190. desc.image_row_pitch = 0;
  3191. desc.num_mip_levels = 0;
  3192. desc.num_samples = 0;
  3193. desc.buffer = buffer();
  3194. object_ = ::clCreateImage(
  3195. context(),
  3196. flags,
  3197. &format,
  3198. &desc,
  3199. NULL,
  3200. &error);
  3201. detail::errHandler(error, __CREATE_IMAGE_ERR);
  3202. if (err != NULL) {
  3203. *err = error;
  3204. }
  3205. }
  3206. Image1DBuffer() { }
  3207. Image1DBuffer(const Image1DBuffer& image1D) : Image(image1D) { }
  3208. __CL_EXPLICIT_CONSTRUCTORS Image1DBuffer(const cl_mem& image1D) : Image(image1D) { }
  3209. Image1DBuffer& operator = (const Image1DBuffer& rhs)
  3210. {
  3211. if (this != &rhs) {
  3212. Image::operator=(rhs);
  3213. }
  3214. return *this;
  3215. }
  3216. Image1DBuffer& operator = (const cl_mem& rhs)
  3217. {
  3218. Image::operator=(rhs);
  3219. return *this;
  3220. }
  3221. };
  3222. /*! \class Image1DArray
  3223. * \brief Image interface for arrays of 1D images.
  3224. */
  3225. class Image1DArray : public Image
  3226. {
  3227. public:
  3228. Image1DArray(
  3229. const Context& context,
  3230. cl_mem_flags flags,
  3231. ImageFormat format,
  3232. ::size_t arraySize,
  3233. ::size_t width,
  3234. ::size_t rowPitch,
  3235. void* host_ptr = NULL,
  3236. cl_int* err = NULL)
  3237. {
  3238. cl_int error;
  3239. cl_image_desc desc;
  3240. desc.image_type = CL_MEM_OBJECT_IMAGE1D_ARRAY;
  3241. desc.image_array_size = arraySize;
  3242. desc.image_width = width;
  3243. desc.image_row_pitch = rowPitch;
  3244. desc.num_mip_levels = 0;
  3245. desc.num_samples = 0;
  3246. desc.buffer = 0;
  3247. object_ = ::clCreateImage(
  3248. context(),
  3249. flags,
  3250. &format,
  3251. &desc,
  3252. host_ptr,
  3253. &error);
  3254. detail::errHandler(error, __CREATE_IMAGE_ERR);
  3255. if (err != NULL) {
  3256. *err = error;
  3257. }
  3258. }
  3259. Image1DArray() { }
  3260. Image1DArray(const Image1DArray& imageArray) : Image(imageArray) { }
  3261. __CL_EXPLICIT_CONSTRUCTORS Image1DArray(const cl_mem& imageArray) : Image(imageArray) { }
  3262. Image1DArray& operator = (const Image1DArray& rhs)
  3263. {
  3264. if (this != &rhs) {
  3265. Image::operator=(rhs);
  3266. }
  3267. return *this;
  3268. }
  3269. Image1DArray& operator = (const cl_mem& rhs)
  3270. {
  3271. Image::operator=(rhs);
  3272. return *this;
  3273. }
  3274. };
  3275. #endif // #if defined(CL_VERSION_1_2)
  3276. /*! \brief Class interface for 2D Image Memory objects.
  3277. *
  3278. * See Memory for details about copy semantics, etc.
  3279. *
  3280. * \see Memory
  3281. */
  3282. class Image2D : public Image
  3283. {
  3284. public:
  3285. /*! \brief Constructs a 1D Image in a specified context.
  3286. *
  3287. * Wraps clCreateImage().
  3288. */
  3289. Image2D(
  3290. const Context& context,
  3291. cl_mem_flags flags,
  3292. ImageFormat format,
  3293. ::size_t width,
  3294. ::size_t height,
  3295. ::size_t row_pitch = 0,
  3296. void* host_ptr = NULL,
  3297. cl_int* err = NULL)
  3298. {
  3299. cl_int error;
  3300. bool useCreateImage;
  3301. #if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
  3302. // Run-time decision based on the actual platform
  3303. {
  3304. cl_uint version = detail::getContextPlatformVersion(context());
  3305. useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above
  3306. }
  3307. #elif defined(CL_VERSION_1_2)
  3308. useCreateImage = true;
  3309. #else
  3310. useCreateImage = false;
  3311. #endif
  3312. #if defined(CL_VERSION_1_2)
  3313. if (useCreateImage)
  3314. {
  3315. cl_image_desc desc;
  3316. desc.image_type = CL_MEM_OBJECT_IMAGE2D;
  3317. desc.image_width = width;
  3318. desc.image_height = height;
  3319. desc.image_row_pitch = row_pitch;
  3320. desc.num_mip_levels = 0;
  3321. desc.num_samples = 0;
  3322. desc.buffer = 0;
  3323. object_ = ::clCreateImage(
  3324. context(),
  3325. flags,
  3326. &format,
  3327. &desc,
  3328. host_ptr,
  3329. &error);
  3330. detail::errHandler(error, __CREATE_IMAGE_ERR);
  3331. if (err != NULL) {
  3332. *err = error;
  3333. }
  3334. }
  3335. #endif // #if defined(CL_VERSION_1_2)
  3336. #if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
  3337. if (!useCreateImage)
  3338. {
  3339. object_ = ::clCreateImage2D(
  3340. context(), flags,&format, width, height, row_pitch, host_ptr, &error);
  3341. detail::errHandler(error, __CREATE_IMAGE2D_ERR);
  3342. if (err != NULL) {
  3343. *err = error;
  3344. }
  3345. }
  3346. #endif // #if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
  3347. }
  3348. //! \brief Default constructor - initializes to NULL.
  3349. Image2D() { }
  3350. /*! \brief Copy constructor - performs shallow copy.
  3351. *
  3352. * See Memory for further details.
  3353. */
  3354. Image2D(const Image2D& image2D) : Image(image2D) { }
  3355. /*! \brief Constructor from cl_mem - takes ownership.
  3356. *
  3357. * See Memory for further details.
  3358. */
  3359. __CL_EXPLICIT_CONSTRUCTORS Image2D(const cl_mem& image2D) : Image(image2D) { }
  3360. /*! \brief Assignment from Image2D - performs shallow copy.
  3361. *
  3362. * See Memory for further details.
  3363. */
  3364. Image2D& operator = (const Image2D& rhs)
  3365. {
  3366. if (this != &rhs) {
  3367. Image::operator=(rhs);
  3368. }
  3369. return *this;
  3370. }
  3371. /*! \brief Assignment from cl_mem - performs shallow copy.
  3372. *
  3373. * See Memory for further details.
  3374. */
  3375. Image2D& operator = (const cl_mem& rhs)
  3376. {
  3377. Image::operator=(rhs);
  3378. return *this;
  3379. }
  3380. };
  3381. #if !defined(CL_VERSION_1_2)
  3382. /*! \brief Class interface for GL 2D Image Memory objects.
  3383. *
  3384. * This is provided to facilitate interoperability with OpenGL.
  3385. *
  3386. * See Memory for details about copy semantics, etc.
  3387. *
  3388. * \see Memory
  3389. * \note Deprecated for OpenCL 1.2. Please use ImageGL instead.
  3390. */
  3391. class CL_EXT_PREFIX__VERSION_1_1_DEPRECATED Image2DGL CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED : public Image2D
  3392. {
  3393. public:
  3394. /*! \brief Constructs an Image2DGL in a specified context, from a given
  3395. * GL Texture.
  3396. *
  3397. * Wraps clCreateFromGLTexture2D().
  3398. */
  3399. Image2DGL(
  3400. const Context& context,
  3401. cl_mem_flags flags,
  3402. GLenum target,
  3403. GLint miplevel,
  3404. GLuint texobj,
  3405. cl_int * err = NULL)
  3406. {
  3407. cl_int error;
  3408. object_ = ::clCreateFromGLTexture2D(
  3409. context(),
  3410. flags,
  3411. target,
  3412. miplevel,
  3413. texobj,
  3414. &error);
  3415. detail::errHandler(error, __CREATE_GL_TEXTURE_2D_ERR);
  3416. if (err != NULL) {
  3417. *err = error;
  3418. }
  3419. }
  3420. //! \brief Default constructor - initializes to NULL.
  3421. Image2DGL() : Image2D() { }
  3422. /*! \brief Copy constructor - performs shallow copy.
  3423. *
  3424. * See Memory for further details.
  3425. */
  3426. Image2DGL(const Image2DGL& image) : Image2D(image) { }
  3427. /*! \brief Constructor from cl_mem - takes ownership.
  3428. *
  3429. * See Memory for further details.
  3430. */
  3431. __CL_EXPLICIT_CONSTRUCTORS Image2DGL(const cl_mem& image) : Image2D(image) { }
  3432. /*! \brief Assignment from Image2DGL - performs shallow copy.
  3433. *
  3434. * See Memory for further details.
  3435. */
  3436. Image2DGL& operator = (const Image2DGL& rhs)
  3437. {
  3438. if (this != &rhs) {
  3439. Image2D::operator=(rhs);
  3440. }
  3441. return *this;
  3442. }
  3443. /*! \brief Assignment from cl_mem - performs shallow copy.
  3444. *
  3445. * See Memory for further details.
  3446. */
  3447. Image2DGL& operator = (const cl_mem& rhs)
  3448. {
  3449. Image2D::operator=(rhs);
  3450. return *this;
  3451. }
  3452. };
  3453. #endif // #if !defined(CL_VERSION_1_2)
  3454. #if defined(CL_VERSION_1_2)
  3455. /*! \class Image2DArray
  3456. * \brief Image interface for arrays of 2D images.
  3457. */
  3458. class Image2DArray : public Image
  3459. {
  3460. public:
  3461. Image2DArray(
  3462. const Context& context,
  3463. cl_mem_flags flags,
  3464. ImageFormat format,
  3465. ::size_t arraySize,
  3466. ::size_t width,
  3467. ::size_t height,
  3468. ::size_t rowPitch,
  3469. ::size_t slicePitch,
  3470. void* host_ptr = NULL,
  3471. cl_int* err = NULL)
  3472. {
  3473. cl_int error;
  3474. cl_image_desc desc;
  3475. desc.image_type = CL_MEM_OBJECT_IMAGE2D_ARRAY;
  3476. desc.image_array_size = arraySize;
  3477. desc.image_width = width;
  3478. desc.image_height = height;
  3479. desc.image_row_pitch = rowPitch;
  3480. desc.image_slice_pitch = slicePitch;
  3481. desc.num_mip_levels = 0;
  3482. desc.num_samples = 0;
  3483. desc.buffer = 0;
  3484. object_ = ::clCreateImage(
  3485. context(),
  3486. flags,
  3487. &format,
  3488. &desc,
  3489. host_ptr,
  3490. &error);
  3491. detail::errHandler(error, __CREATE_IMAGE_ERR);
  3492. if (err != NULL) {
  3493. *err = error;
  3494. }
  3495. }
  3496. Image2DArray() { }
  3497. Image2DArray(const Image2DArray& imageArray) : Image(imageArray) { }
  3498. __CL_EXPLICIT_CONSTRUCTORS Image2DArray(const cl_mem& imageArray) : Image(imageArray) { }
  3499. Image2DArray& operator = (const Image2DArray& rhs)
  3500. {
  3501. if (this != &rhs) {
  3502. Image::operator=(rhs);
  3503. }
  3504. return *this;
  3505. }
  3506. Image2DArray& operator = (const cl_mem& rhs)
  3507. {
  3508. Image::operator=(rhs);
  3509. return *this;
  3510. }
  3511. };
  3512. #endif // #if defined(CL_VERSION_1_2)
  3513. /*! \brief Class interface for 3D Image Memory objects.
  3514. *
  3515. * See Memory for details about copy semantics, etc.
  3516. *
  3517. * \see Memory
  3518. */
  3519. class Image3D : public Image
  3520. {
  3521. public:
  3522. /*! \brief Constructs a 3D Image in a specified context.
  3523. *
  3524. * Wraps clCreateImage().
  3525. */
  3526. Image3D(
  3527. const Context& context,
  3528. cl_mem_flags flags,
  3529. ImageFormat format,
  3530. ::size_t width,
  3531. ::size_t height,
  3532. ::size_t depth,
  3533. ::size_t row_pitch = 0,
  3534. ::size_t slice_pitch = 0,
  3535. void* host_ptr = NULL,
  3536. cl_int* err = NULL)
  3537. {
  3538. cl_int error;
  3539. bool useCreateImage;
  3540. #if defined(CL_VERSION_1_2) && defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
  3541. // Run-time decision based on the actual platform
  3542. {
  3543. cl_uint version = detail::getContextPlatformVersion(context());
  3544. useCreateImage = (version >= 0x10002); // OpenCL 1.2 or above
  3545. }
  3546. #elif defined(CL_VERSION_1_2)
  3547. useCreateImage = true;
  3548. #else
  3549. useCreateImage = false;
  3550. #endif
  3551. #if defined(CL_VERSION_1_2)
  3552. if (useCreateImage)
  3553. {
  3554. cl_image_desc desc;
  3555. desc.image_type = CL_MEM_OBJECT_IMAGE3D;
  3556. desc.image_width = width;
  3557. desc.image_height = height;
  3558. desc.image_depth = depth;
  3559. desc.image_row_pitch = row_pitch;
  3560. desc.image_slice_pitch = slice_pitch;
  3561. desc.num_mip_levels = 0;
  3562. desc.num_samples = 0;
  3563. desc.buffer = 0;
  3564. object_ = ::clCreateImage(
  3565. context(),
  3566. flags,
  3567. &format,
  3568. &desc,
  3569. host_ptr,
  3570. &error);
  3571. detail::errHandler(error, __CREATE_IMAGE_ERR);
  3572. if (err != NULL) {
  3573. *err = error;
  3574. }
  3575. }
  3576. #endif // #if defined(CL_VERSION_1_2)
  3577. #if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
  3578. if (!useCreateImage)
  3579. {
  3580. object_ = ::clCreateImage3D(
  3581. context(), flags, &format, width, height, depth, row_pitch,
  3582. slice_pitch, host_ptr, &error);
  3583. detail::errHandler(error, __CREATE_IMAGE3D_ERR);
  3584. if (err != NULL) {
  3585. *err = error;
  3586. }
  3587. }
  3588. #endif // #if !defined(CL_VERSION_1_2) || defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS)
  3589. }
  3590. //! \brief Default constructor - initializes to NULL.
  3591. Image3D() { }
  3592. /*! \brief Copy constructor - performs shallow copy.
  3593. *
  3594. * See Memory for further details.
  3595. */
  3596. Image3D(const Image3D& image3D) : Image(image3D) { }
  3597. /*! \brief Constructor from cl_mem - takes ownership.
  3598. *
  3599. * See Memory for further details.
  3600. */
  3601. __CL_EXPLICIT_CONSTRUCTORS Image3D(const cl_mem& image3D) : Image(image3D) { }
  3602. /*! \brief Assignment from Image3D - performs shallow copy.
  3603. *
  3604. * See Memory for further details.
  3605. */
  3606. Image3D& operator = (const Image3D& rhs)
  3607. {
  3608. if (this != &rhs) {
  3609. Image::operator=(rhs);
  3610. }
  3611. return *this;
  3612. }
  3613. /*! \brief Assignment from cl_mem - performs shallow copy.
  3614. *
  3615. * See Memory for further details.
  3616. */
  3617. Image3D& operator = (const cl_mem& rhs)
  3618. {
  3619. Image::operator=(rhs);
  3620. return *this;
  3621. }
  3622. };
  3623. #if !defined(CL_VERSION_1_2)
  3624. /*! \brief Class interface for GL 3D Image Memory objects.
  3625. *
  3626. * This is provided to facilitate interoperability with OpenGL.
  3627. *
  3628. * See Memory for details about copy semantics, etc.
  3629. *
  3630. * \see Memory
  3631. */
  3632. class Image3DGL : public Image3D
  3633. {
  3634. public:
  3635. /*! \brief Constructs an Image3DGL in a specified context, from a given
  3636. * GL Texture.
  3637. *
  3638. * Wraps clCreateFromGLTexture3D().
  3639. */
  3640. Image3DGL(
  3641. const Context& context,
  3642. cl_mem_flags flags,
  3643. GLenum target,
  3644. GLint miplevel,
  3645. GLuint texobj,
  3646. cl_int * err = NULL)
  3647. {
  3648. cl_int error;
  3649. object_ = ::clCreateFromGLTexture3D(
  3650. context(),
  3651. flags,
  3652. target,
  3653. miplevel,
  3654. texobj,
  3655. &error);
  3656. detail::errHandler(error, __CREATE_GL_TEXTURE_3D_ERR);
  3657. if (err != NULL) {
  3658. *err = error;
  3659. }
  3660. }
  3661. //! \brief Default constructor - initializes to NULL.
  3662. Image3DGL() : Image3D() { }
  3663. /*! \brief Copy constructor - performs shallow copy.
  3664. *
  3665. * See Memory for further details.
  3666. */
  3667. Image3DGL(const Image3DGL& image) : Image3D(image) { }
  3668. /*! \brief Constructor from cl_mem - takes ownership.
  3669. *
  3670. * See Memory for further details.
  3671. */
  3672. __CL_EXPLICIT_CONSTRUCTORS Image3DGL(const cl_mem& image) : Image3D(image) { }
  3673. /*! \brief Assignment from Image3DGL - performs shallow copy.
  3674. *
  3675. * See Memory for further details.
  3676. */
  3677. Image3DGL& operator = (const Image3DGL& rhs)
  3678. {
  3679. if (this != &rhs) {
  3680. Image3D::operator=(rhs);
  3681. }
  3682. return *this;
  3683. }
  3684. /*! \brief Assignment from cl_mem - performs shallow copy.
  3685. *
  3686. * See Memory for further details.
  3687. */
  3688. Image3DGL& operator = (const cl_mem& rhs)
  3689. {
  3690. Image3D::operator=(rhs);
  3691. return *this;
  3692. }
  3693. };
  3694. #endif // #if !defined(CL_VERSION_1_2)
  3695. #if defined(CL_VERSION_1_2)
  3696. /*! \class ImageGL
  3697. * \brief general image interface for GL interop.
  3698. * We abstract the 2D and 3D GL images into a single instance here
  3699. * that wraps all GL sourced images on the grounds that setup information
  3700. * was performed by OpenCL anyway.
  3701. */
  3702. class ImageGL : public Image
  3703. {
  3704. public:
  3705. ImageGL(
  3706. const Context& context,
  3707. cl_mem_flags flags,
  3708. GLenum target,
  3709. GLint miplevel,
  3710. GLuint texobj,
  3711. cl_int * err = NULL)
  3712. {
  3713. cl_int error;
  3714. object_ = ::clCreateFromGLTexture(
  3715. context(),
  3716. flags,
  3717. target,
  3718. miplevel,
  3719. texobj,
  3720. &error);
  3721. detail::errHandler(error, __CREATE_GL_TEXTURE_ERR);
  3722. if (err != NULL) {
  3723. *err = error;
  3724. }
  3725. }
  3726. ImageGL() : Image() { }
  3727. ImageGL(const ImageGL& image) : Image(image) { }
  3728. __CL_EXPLICIT_CONSTRUCTORS ImageGL(const cl_mem& image) : Image(image) { }
  3729. ImageGL& operator = (const ImageGL& rhs)
  3730. {
  3731. if (this != &rhs) {
  3732. Image::operator=(rhs);
  3733. }
  3734. return *this;
  3735. }
  3736. ImageGL& operator = (const cl_mem& rhs)
  3737. {
  3738. Image::operator=(rhs);
  3739. return *this;
  3740. }
  3741. };
  3742. #endif // #if defined(CL_VERSION_1_2)
  3743. /*! \brief Class interface for cl_sampler.
  3744. *
  3745. * \note Copies of these objects are shallow, meaning that the copy will refer
  3746. * to the same underlying cl_sampler as the original. For details, see
  3747. * clRetainSampler() and clReleaseSampler().
  3748. *
  3749. * \see cl_sampler
  3750. */
  3751. class Sampler : public detail::Wrapper<cl_sampler>
  3752. {
  3753. public:
  3754. /*! \brief Destructor.
  3755. *
  3756. * This calls clReleaseSampler() on the value held by this instance.
  3757. */
  3758. ~Sampler() { }
  3759. //! \brief Default constructor - initializes to NULL.
  3760. Sampler() { }
  3761. /*! \brief Constructs a Sampler in a specified context.
  3762. *
  3763. * Wraps clCreateSampler().
  3764. */
  3765. Sampler(
  3766. const Context& context,
  3767. cl_bool normalized_coords,
  3768. cl_addressing_mode addressing_mode,
  3769. cl_filter_mode filter_mode,
  3770. cl_int* err = NULL)
  3771. {
  3772. cl_int error;
  3773. object_ = ::clCreateSampler(
  3774. context(),
  3775. normalized_coords,
  3776. addressing_mode,
  3777. filter_mode,
  3778. &error);
  3779. detail::errHandler(error, __CREATE_SAMPLER_ERR);
  3780. if (err != NULL) {
  3781. *err = error;
  3782. }
  3783. }
  3784. /*! \brief Copy constructor - performs shallow copy.
  3785. *
  3786. * This calls clRetainSampler() on the parameter's cl_sampler.
  3787. */
  3788. Sampler(const Sampler& sampler) : detail::Wrapper<cl_type>(sampler) { }
  3789. /*! \brief Constructor from cl_sampler - takes ownership.
  3790. *
  3791. * This effectively transfers ownership of a refcount on the cl_sampler
  3792. * into the new Sampler object.
  3793. */
  3794. Sampler(const cl_sampler& sampler) : detail::Wrapper<cl_type>(sampler) { }
  3795. /*! \brief Assignment operator from Sampler.
  3796. *
  3797. * This calls clRetainSampler() on the parameter and clReleaseSampler()
  3798. * on the previous value held by this instance.
  3799. */
  3800. Sampler& operator = (const Sampler& rhs)
  3801. {
  3802. if (this != &rhs) {
  3803. detail::Wrapper<cl_type>::operator=(rhs);
  3804. }
  3805. return *this;
  3806. }
  3807. /*! \brief Assignment operator from cl_sampler - takes ownership.
  3808. *
  3809. * This effectively transfers ownership of a refcount on the rhs and calls
  3810. * clReleaseSampler() on the value previously held by this instance.
  3811. */
  3812. Sampler& operator = (const cl_sampler& rhs)
  3813. {
  3814. detail::Wrapper<cl_type>::operator=(rhs);
  3815. return *this;
  3816. }
  3817. //! \brief Wrapper for clGetSamplerInfo().
  3818. template <typename T>
  3819. cl_int getInfo(cl_sampler_info name, T* param) const
  3820. {
  3821. return detail::errHandler(
  3822. detail::getInfo(&::clGetSamplerInfo, object_, name, param),
  3823. __GET_SAMPLER_INFO_ERR);
  3824. }
  3825. //! \brief Wrapper for clGetSamplerInfo() that returns by value.
  3826. template <cl_int name> typename
  3827. detail::param_traits<detail::cl_sampler_info, name>::param_type
  3828. getInfo(cl_int* err = NULL) const
  3829. {
  3830. typename detail::param_traits<
  3831. detail::cl_sampler_info, name>::param_type param;
  3832. cl_int result = getInfo(name, &param);
  3833. if (err != NULL) {
  3834. *err = result;
  3835. }
  3836. return param;
  3837. }
  3838. };
  3839. class Program;
  3840. class CommandQueue;
  3841. class Kernel;
  3842. //! \brief Class interface for specifying NDRange values.
  3843. class NDRange
  3844. {
  3845. private:
  3846. size_t<3> sizes_;
  3847. cl_uint dimensions_;
  3848. public:
  3849. //! \brief Default constructor - resulting range has zero dimensions.
  3850. NDRange()
  3851. : dimensions_(0)
  3852. { }
  3853. //! \brief Constructs one-dimensional range.
  3854. NDRange(::size_t size0)
  3855. : dimensions_(1)
  3856. {
  3857. sizes_[0] = size0;
  3858. }
  3859. //! \brief Constructs two-dimensional range.
  3860. NDRange(::size_t size0, ::size_t size1)
  3861. : dimensions_(2)
  3862. {
  3863. sizes_[0] = size0;
  3864. sizes_[1] = size1;
  3865. }
  3866. //! \brief Constructs three-dimensional range.
  3867. NDRange(::size_t size0, ::size_t size1, ::size_t size2)
  3868. : dimensions_(3)
  3869. {
  3870. sizes_[0] = size0;
  3871. sizes_[1] = size1;
  3872. sizes_[2] = size2;
  3873. }
  3874. /*! \brief Conversion operator to const ::size_t *.
  3875. *
  3876. * \returns a pointer to the size of the first dimension.
  3877. */
  3878. operator const ::size_t*() const {
  3879. return (const ::size_t*) sizes_;
  3880. }
  3881. //! \brief Queries the number of dimensions in the range.
  3882. ::size_t dimensions() const { return dimensions_; }
  3883. };
  3884. //! \brief A zero-dimensional range.
  3885. static const NDRange NullRange;
  3886. //! \brief Local address wrapper for use with Kernel::setArg
  3887. struct LocalSpaceArg
  3888. {
  3889. ::size_t size_;
  3890. };
  3891. namespace detail {
  3892. template <typename T>
  3893. struct KernelArgumentHandler
  3894. {
  3895. static ::size_t size(const T&) { return sizeof(T); }
  3896. static T* ptr(T& value) { return &value; }
  3897. };
  3898. template <>
  3899. struct KernelArgumentHandler<LocalSpaceArg>
  3900. {
  3901. static ::size_t size(const LocalSpaceArg& value) { return value.size_; }
  3902. static void* ptr(LocalSpaceArg&) { return NULL; }
  3903. };
  3904. }
  3905. //! \endcond
  3906. /*! __local
  3907. * \brief Helper function for generating LocalSpaceArg objects.
  3908. * Deprecated. Replaced with Local.
  3909. */
  3910. inline CL_EXT_PREFIX__VERSION_1_1_DEPRECATED LocalSpaceArg
  3911. __local(::size_t size) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED;
  3912. inline LocalSpaceArg
  3913. __local(::size_t size)
  3914. {
  3915. LocalSpaceArg ret = { size };
  3916. return ret;
  3917. }
  3918. /*! Local
  3919. * \brief Helper function for generating LocalSpaceArg objects.
  3920. */
  3921. inline LocalSpaceArg
  3922. Local(::size_t size)
  3923. {
  3924. LocalSpaceArg ret = { size };
  3925. return ret;
  3926. }
  3927. //class KernelFunctor;
  3928. /*! \brief Class interface for cl_kernel.
  3929. *
  3930. * \note Copies of these objects are shallow, meaning that the copy will refer
  3931. * to the same underlying cl_kernel as the original. For details, see
  3932. * clRetainKernel() and clReleaseKernel().
  3933. *
  3934. * \see cl_kernel
  3935. */
  3936. class Kernel : public detail::Wrapper<cl_kernel>
  3937. {
  3938. public:
  3939. inline Kernel(const Program& program, const char* name, cl_int* err = NULL);
  3940. /*! \brief Destructor.
  3941. *
  3942. * This calls clReleaseKernel() on the value held by this instance.
  3943. */
  3944. ~Kernel() { }
  3945. //! \brief Default constructor - initializes to NULL.
  3946. Kernel() { }
  3947. /*! \brief Copy constructor - performs shallow copy.
  3948. *
  3949. * This calls clRetainKernel() on the parameter's cl_kernel.
  3950. */
  3951. Kernel(const Kernel& kernel) : detail::Wrapper<cl_type>(kernel) { }
  3952. /*! \brief Constructor from cl_kernel - takes ownership.
  3953. *
  3954. * This effectively transfers ownership of a refcount on the cl_kernel
  3955. * into the new Kernel object.
  3956. */
  3957. __CL_EXPLICIT_CONSTRUCTORS Kernel(const cl_kernel& kernel) : detail::Wrapper<cl_type>(kernel) { }
  3958. /*! \brief Assignment operator from Kernel.
  3959. *
  3960. * This calls clRetainKernel() on the parameter and clReleaseKernel()
  3961. * on the previous value held by this instance.
  3962. */
  3963. Kernel& operator = (const Kernel& rhs)
  3964. {
  3965. if (this != &rhs) {
  3966. detail::Wrapper<cl_type>::operator=(rhs);
  3967. }
  3968. return *this;
  3969. }
  3970. /*! \brief Assignment operator from cl_kernel - takes ownership.
  3971. *
  3972. * This effectively transfers ownership of a refcount on the rhs and calls
  3973. * clReleaseKernel() on the value previously held by this instance.
  3974. */
  3975. Kernel& operator = (const cl_kernel& rhs)
  3976. {
  3977. detail::Wrapper<cl_type>::operator=(rhs);
  3978. return *this;
  3979. }
  3980. template <typename T>
  3981. cl_int getInfo(cl_kernel_info name, T* param) const
  3982. {
  3983. return detail::errHandler(
  3984. detail::getInfo(&::clGetKernelInfo, object_, name, param),
  3985. __GET_KERNEL_INFO_ERR);
  3986. }
  3987. template <cl_int name> typename
  3988. detail::param_traits<detail::cl_kernel_info, name>::param_type
  3989. getInfo(cl_int* err = NULL) const
  3990. {
  3991. typename detail::param_traits<
  3992. detail::cl_kernel_info, name>::param_type param;
  3993. cl_int result = getInfo(name, &param);
  3994. if (err != NULL) {
  3995. *err = result;
  3996. }
  3997. return param;
  3998. }
  3999. #if defined(CL_VERSION_1_2)
  4000. template <typename T>
  4001. cl_int getArgInfo(cl_uint argIndex, cl_kernel_arg_info name, T* param) const
  4002. {
  4003. return detail::errHandler(
  4004. detail::getInfo(&::clGetKernelArgInfo, object_, argIndex, name, param),
  4005. __GET_KERNEL_ARG_INFO_ERR);
  4006. }
  4007. template <cl_int name> typename
  4008. detail::param_traits<detail::cl_kernel_arg_info, name>::param_type
  4009. getArgInfo(cl_uint argIndex, cl_int* err = NULL) const
  4010. {
  4011. typename detail::param_traits<
  4012. detail::cl_kernel_arg_info, name>::param_type param;
  4013. cl_int result = getArgInfo(argIndex, name, &param);
  4014. if (err != NULL) {
  4015. *err = result;
  4016. }
  4017. return param;
  4018. }
  4019. #endif // #if defined(CL_VERSION_1_2)
  4020. template <typename T>
  4021. cl_int getWorkGroupInfo(
  4022. const Device& device, cl_kernel_work_group_info name, T* param) const
  4023. {
  4024. return detail::errHandler(
  4025. detail::getInfo(
  4026. &::clGetKernelWorkGroupInfo, object_, device(), name, param),
  4027. __GET_KERNEL_WORK_GROUP_INFO_ERR);
  4028. }
  4029. template <cl_int name> typename
  4030. detail::param_traits<detail::cl_kernel_work_group_info, name>::param_type
  4031. getWorkGroupInfo(const Device& device, cl_int* err = NULL) const
  4032. {
  4033. typename detail::param_traits<
  4034. detail::cl_kernel_work_group_info, name>::param_type param;
  4035. cl_int result = getWorkGroupInfo(device, name, &param);
  4036. if (err != NULL) {
  4037. *err = result;
  4038. }
  4039. return param;
  4040. }
  4041. template <typename T>
  4042. cl_int setArg(cl_uint index, T value)
  4043. {
  4044. return detail::errHandler(
  4045. ::clSetKernelArg(
  4046. object_,
  4047. index,
  4048. detail::KernelArgumentHandler<T>::size(value),
  4049. detail::KernelArgumentHandler<T>::ptr(value)),
  4050. __SET_KERNEL_ARGS_ERR);
  4051. }
  4052. cl_int setArg(cl_uint index, ::size_t size, void* argPtr)
  4053. {
  4054. return detail::errHandler(
  4055. ::clSetKernelArg(object_, index, size, argPtr),
  4056. __SET_KERNEL_ARGS_ERR);
  4057. }
  4058. };
  4059. /*! \class Program
  4060. * \brief Program interface that implements cl_program.
  4061. */
  4062. class Program : public detail::Wrapper<cl_program>
  4063. {
  4064. public:
  4065. typedef VECTOR_CLASS<std::pair<const void*, ::size_t> > Binaries;
  4066. typedef VECTOR_CLASS<std::pair<const char*, ::size_t> > Sources;
  4067. Program(
  4068. const STRING_CLASS& source,
  4069. cl_int* err = NULL)
  4070. {
  4071. cl_int error;
  4072. const char * strings = source.c_str();
  4073. const ::size_t length = source.size();
  4074. Context context = Context::getDefault(err);
  4075. object_ = ::clCreateProgramWithSource(
  4076. context(), (cl_uint)1, &strings, &length, &error);
  4077. detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
  4078. if (error == CL_SUCCESS) {
  4079. error = ::clBuildProgram(
  4080. object_,
  4081. 0,
  4082. NULL,
  4083. "",
  4084. NULL,
  4085. NULL);
  4086. detail::errHandler(error, __BUILD_PROGRAM_ERR);
  4087. }
  4088. if (err != NULL) {
  4089. *err = error;
  4090. }
  4091. }
  4092. Program(
  4093. const STRING_CLASS& source,
  4094. bool build,
  4095. cl_int* err = NULL)
  4096. {
  4097. cl_int error;
  4098. const char * strings = source.c_str();
  4099. const ::size_t length = source.size();
  4100. Context context = Context::getDefault(err);
  4101. object_ = ::clCreateProgramWithSource(
  4102. context(), (cl_uint)1, &strings, &length, &error);
  4103. detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
  4104. if (error == CL_SUCCESS && build) {
  4105. error = ::clBuildProgram(
  4106. object_,
  4107. 0,
  4108. NULL,
  4109. "",
  4110. NULL,
  4111. NULL);
  4112. detail::errHandler(error, __BUILD_PROGRAM_ERR);
  4113. }
  4114. if (err != NULL) {
  4115. *err = error;
  4116. }
  4117. }
  4118. Program(
  4119. const Context& context,
  4120. const STRING_CLASS& source,
  4121. bool build = false,
  4122. cl_int* err = NULL)
  4123. {
  4124. cl_int error;
  4125. const char * strings = source.c_str();
  4126. const ::size_t length = source.size();
  4127. object_ = ::clCreateProgramWithSource(
  4128. context(), (cl_uint)1, &strings, &length, &error);
  4129. detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
  4130. if (error == CL_SUCCESS && build) {
  4131. error = ::clBuildProgram(
  4132. object_,
  4133. 0,
  4134. NULL,
  4135. "",
  4136. NULL,
  4137. NULL);
  4138. detail::errHandler(error, __BUILD_PROGRAM_ERR);
  4139. }
  4140. if (err != NULL) {
  4141. *err = error;
  4142. }
  4143. }
  4144. Program(
  4145. const Context& context,
  4146. const Sources& sources,
  4147. cl_int* err = NULL)
  4148. {
  4149. cl_int error;
  4150. const ::size_t n = (::size_t)sources.size();
  4151. ::size_t* lengths = (::size_t*) alloca(n * sizeof(::size_t));
  4152. const char** strings = (const char**) alloca(n * sizeof(const char*));
  4153. for (::size_t i = 0; i < n; ++i) {
  4154. strings[i] = sources[(int)i].first;
  4155. lengths[i] = sources[(int)i].second;
  4156. }
  4157. object_ = ::clCreateProgramWithSource(
  4158. context(), (cl_uint)n, strings, lengths, &error);
  4159. detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
  4160. if (err != NULL) {
  4161. *err = error;
  4162. }
  4163. }
  4164. /**
  4165. * Construct a program object from a list of devices and a per-device list of binaries.
  4166. * \param context A valid OpenCL context in which to construct the program.
  4167. * \param devices A vector of OpenCL device objects for which the program will be created.
  4168. * \param binaries A vector of pairs of a pointer to a binary object and its length.
  4169. * \param binaryStatus An optional vector that on completion will be resized to
  4170. * match the size of binaries and filled with values to specify if each binary
  4171. * was successfully loaded.
  4172. * Set to CL_SUCCESS if the binary was successfully loaded.
  4173. * Set to CL_INVALID_VALUE if the length is 0 or the binary pointer is NULL.
  4174. * Set to CL_INVALID_BINARY if the binary provided is not valid for the matching device.
  4175. * \param err if non-NULL will be set to CL_SUCCESS on successful operation or one of the following errors:
  4176. * CL_INVALID_CONTEXT if context is not a valid context.
  4177. * CL_INVALID_VALUE if the length of devices is zero; or if the length of binaries does not match the length of devices;
  4178. * or if any entry in binaries is NULL or has length 0.
  4179. * CL_INVALID_DEVICE if OpenCL devices listed in devices are not in the list of devices associated with context.
  4180. * CL_INVALID_BINARY if an invalid program binary was encountered for any device. binaryStatus will return specific status for each device.
  4181. * CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required by the OpenCL implementation on the host.
  4182. */
  4183. Program(
  4184. const Context& context,
  4185. const VECTOR_CLASS<Device>& devices,
  4186. const Binaries& binaries,
  4187. VECTOR_CLASS<cl_int>* binaryStatus = NULL,
  4188. cl_int* err = NULL)
  4189. {
  4190. cl_int error;
  4191. const ::size_t numDevices = devices.size();
  4192. // Catch size mismatch early and return
  4193. if(binaries.size() != numDevices) {
  4194. error = CL_INVALID_VALUE;
  4195. detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
  4196. if (err != NULL) {
  4197. *err = error;
  4198. }
  4199. return;
  4200. }
  4201. ::size_t* lengths = (::size_t*) alloca(numDevices * sizeof(::size_t));
  4202. const unsigned char** images = (const unsigned char**) alloca(numDevices * sizeof(const unsigned char**));
  4203. for (::size_t i = 0; i < numDevices; ++i) {
  4204. images[i] = (const unsigned char*)binaries[i].first;
  4205. lengths[i] = binaries[(int)i].second;
  4206. }
  4207. cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id));
  4208. for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
  4209. deviceIDs[deviceIndex] = (devices[deviceIndex])();
  4210. }
  4211. if(binaryStatus) {
  4212. binaryStatus->resize(numDevices);
  4213. }
  4214. object_ = ::clCreateProgramWithBinary(
  4215. context(), (cl_uint) devices.size(),
  4216. deviceIDs,
  4217. lengths, images, binaryStatus != NULL
  4218. ? &binaryStatus->front()
  4219. : NULL, &error);
  4220. detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
  4221. if (err != NULL) {
  4222. *err = error;
  4223. }
  4224. }
  4225. #if defined(CL_VERSION_1_2)
  4226. /**
  4227. * Create program using builtin kernels.
  4228. * \param kernelNames Semi-colon separated list of builtin kernel names
  4229. */
  4230. Program(
  4231. const Context& context,
  4232. const VECTOR_CLASS<Device>& devices,
  4233. const STRING_CLASS& kernelNames,
  4234. cl_int* err = NULL)
  4235. {
  4236. cl_int error;
  4237. ::size_t numDevices = devices.size();
  4238. cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id));
  4239. for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
  4240. deviceIDs[deviceIndex] = (devices[deviceIndex])();
  4241. }
  4242. object_ = ::clCreateProgramWithBuiltInKernels(
  4243. context(),
  4244. (cl_uint) devices.size(),
  4245. deviceIDs,
  4246. kernelNames.c_str(),
  4247. &error);
  4248. detail::errHandler(error, __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR);
  4249. if (err != NULL) {
  4250. *err = error;
  4251. }
  4252. }
  4253. #endif // #if defined(CL_VERSION_1_2)
  4254. Program() { }
  4255. Program(const Program& program) : detail::Wrapper<cl_type>(program) { }
  4256. __CL_EXPLICIT_CONSTRUCTORS Program(const cl_program& program) : detail::Wrapper<cl_type>(program) { }
  4257. Program& operator = (const Program& rhs)
  4258. {
  4259. if (this != &rhs) {
  4260. detail::Wrapper<cl_type>::operator=(rhs);
  4261. }
  4262. return *this;
  4263. }
  4264. Program& operator = (const cl_program& rhs)
  4265. {
  4266. detail::Wrapper<cl_type>::operator=(rhs);
  4267. return *this;
  4268. }
  4269. cl_int build(
  4270. const VECTOR_CLASS<Device>& devices,
  4271. const char* options = NULL,
  4272. void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
  4273. void* data = NULL) const
  4274. {
  4275. ::size_t numDevices = devices.size();
  4276. cl_device_id* deviceIDs = (cl_device_id*) alloca(numDevices * sizeof(cl_device_id));
  4277. for( ::size_t deviceIndex = 0; deviceIndex < numDevices; ++deviceIndex ) {
  4278. deviceIDs[deviceIndex] = (devices[deviceIndex])();
  4279. }
  4280. return detail::errHandler(
  4281. ::clBuildProgram(
  4282. object_,
  4283. (cl_uint)
  4284. devices.size(),
  4285. deviceIDs,
  4286. options,
  4287. notifyFptr,
  4288. data),
  4289. __BUILD_PROGRAM_ERR);
  4290. }
  4291. cl_int build(
  4292. const char* options = NULL,
  4293. void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
  4294. void* data = NULL) const
  4295. {
  4296. return detail::errHandler(
  4297. ::clBuildProgram(
  4298. object_,
  4299. 0,
  4300. NULL,
  4301. options,
  4302. notifyFptr,
  4303. data),
  4304. __BUILD_PROGRAM_ERR);
  4305. }
  4306. #if defined(CL_VERSION_1_2)
  4307. cl_int compile(
  4308. const char* options = NULL,
  4309. void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
  4310. void* data = NULL) const
  4311. {
  4312. return detail::errHandler(
  4313. ::clCompileProgram(
  4314. object_,
  4315. 0,
  4316. NULL,
  4317. options,
  4318. 0,
  4319. NULL,
  4320. NULL,
  4321. notifyFptr,
  4322. data),
  4323. __COMPILE_PROGRAM_ERR);
  4324. }
  4325. #endif
  4326. template <typename T>
  4327. cl_int getInfo(cl_program_info name, T* param) const
  4328. {
  4329. return detail::errHandler(
  4330. detail::getInfo(&::clGetProgramInfo, object_, name, param),
  4331. __GET_PROGRAM_INFO_ERR);
  4332. }
  4333. template <cl_int name> typename
  4334. detail::param_traits<detail::cl_program_info, name>::param_type
  4335. getInfo(cl_int* err = NULL) const
  4336. {
  4337. typename detail::param_traits<
  4338. detail::cl_program_info, name>::param_type param;
  4339. cl_int result = getInfo(name, &param);
  4340. if (err != NULL) {
  4341. *err = result;
  4342. }
  4343. return param;
  4344. }
  4345. template <typename T>
  4346. cl_int getBuildInfo(
  4347. const Device& device, cl_program_build_info name, T* param) const
  4348. {
  4349. return detail::errHandler(
  4350. detail::getInfo(
  4351. &::clGetProgramBuildInfo, object_, device(), name, param),
  4352. __GET_PROGRAM_BUILD_INFO_ERR);
  4353. }
  4354. template <cl_int name> typename
  4355. detail::param_traits<detail::cl_program_build_info, name>::param_type
  4356. getBuildInfo(const Device& device, cl_int* err = NULL) const
  4357. {
  4358. typename detail::param_traits<
  4359. detail::cl_program_build_info, name>::param_type param;
  4360. cl_int result = getBuildInfo(device, name, &param);
  4361. if (err != NULL) {
  4362. *err = result;
  4363. }
  4364. return param;
  4365. }
  4366. cl_int createKernels(VECTOR_CLASS<Kernel>* kernels)
  4367. {
  4368. cl_uint numKernels;
  4369. cl_int err = ::clCreateKernelsInProgram(object_, 0, NULL, &numKernels);
  4370. if (err != CL_SUCCESS) {
  4371. return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
  4372. }
  4373. Kernel* value = (Kernel*) alloca(numKernels * sizeof(Kernel));
  4374. err = ::clCreateKernelsInProgram(
  4375. object_, numKernels, (cl_kernel*) value, NULL);
  4376. if (err != CL_SUCCESS) {
  4377. return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
  4378. }
  4379. kernels->assign(&value[0], &value[numKernels]);
  4380. return CL_SUCCESS;
  4381. }
  4382. };
  4383. #if defined(CL_VERSION_1_2)
  4384. inline Program linkProgram(
  4385. Program input1,
  4386. Program input2,
  4387. const char* options = NULL,
  4388. void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
  4389. void* data = NULL,
  4390. cl_int* err = NULL)
  4391. {
  4392. cl_int err_local = CL_SUCCESS;
  4393. cl_program programs[2] = { input1(), input2() };
  4394. Context ctx = input1.getInfo<CL_PROGRAM_CONTEXT>();
  4395. cl_program prog = ::clLinkProgram(
  4396. ctx(),
  4397. 0,
  4398. NULL,
  4399. options,
  4400. 2,
  4401. programs,
  4402. notifyFptr,
  4403. data,
  4404. &err_local);
  4405. detail::errHandler(err_local,__COMPILE_PROGRAM_ERR);
  4406. if (err != NULL) {
  4407. *err = err_local;
  4408. }
  4409. return Program(prog);
  4410. }
  4411. inline Program linkProgram(
  4412. VECTOR_CLASS<Program> inputPrograms,
  4413. const char* options = NULL,
  4414. void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
  4415. void* data = NULL,
  4416. cl_int* err = NULL)
  4417. {
  4418. cl_int err_local = CL_SUCCESS;
  4419. cl_program * programs = (cl_program*) alloca(inputPrograms.size() * sizeof(cl_program));
  4420. if (programs != NULL) {
  4421. for (unsigned int i = 0; i < inputPrograms.size(); i++) {
  4422. programs[i] = inputPrograms[i]();
  4423. }
  4424. }
  4425. cl_program prog = ::clLinkProgram(
  4426. Context::getDefault()(),
  4427. 0,
  4428. NULL,
  4429. options,
  4430. (cl_uint)inputPrograms.size(),
  4431. programs,
  4432. notifyFptr,
  4433. data,
  4434. &err_local);
  4435. detail::errHandler(err_local,__COMPILE_PROGRAM_ERR);
  4436. if (err != NULL) {
  4437. *err = err_local;
  4438. }
  4439. return Program(prog);
  4440. }
  4441. #endif
  4442. template<>
  4443. inline VECTOR_CLASS<char *> cl::Program::getInfo<CL_PROGRAM_BINARIES>(cl_int* err) const
  4444. {
  4445. VECTOR_CLASS< ::size_t> sizes = getInfo<CL_PROGRAM_BINARY_SIZES>();
  4446. VECTOR_CLASS<char *> binaries;
  4447. for (VECTOR_CLASS< ::size_t>::iterator s = sizes.begin(); s != sizes.end(); ++s)
  4448. {
  4449. char *ptr = NULL;
  4450. if (*s != 0)
  4451. ptr = new char[*s];
  4452. binaries.push_back(ptr);
  4453. }
  4454. cl_int result = getInfo(CL_PROGRAM_BINARIES, &binaries);
  4455. if (err != NULL) {
  4456. *err = result;
  4457. }
  4458. return binaries;
  4459. }
  4460. inline Kernel::Kernel(const Program& program, const char* name, cl_int* err)
  4461. {
  4462. cl_int error;
  4463. object_ = ::clCreateKernel(program(), name, &error);
  4464. detail::errHandler(error, __CREATE_KERNEL_ERR);
  4465. if (err != NULL) {
  4466. *err = error;
  4467. }
  4468. }
  4469. /*! \class CommandQueue
  4470. * \brief CommandQueue interface for cl_command_queue.
  4471. */
  4472. class CommandQueue : public detail::Wrapper<cl_command_queue>
  4473. {
  4474. private:
  4475. static volatile int default_initialized_;
  4476. static CommandQueue default_;
  4477. static volatile cl_int default_error_;
  4478. public:
  4479. CommandQueue(
  4480. cl_command_queue_properties properties,
  4481. cl_int* err = NULL)
  4482. {
  4483. cl_int error;
  4484. Context context = Context::getDefault(&error);
  4485. detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
  4486. if (error != CL_SUCCESS) {
  4487. if (err != NULL) {
  4488. *err = error;
  4489. }
  4490. }
  4491. else {
  4492. Device device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
  4493. object_ = ::clCreateCommandQueue(
  4494. context(), device(), properties, &error);
  4495. detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
  4496. if (err != NULL) {
  4497. *err = error;
  4498. }
  4499. }
  4500. }
  4501. CommandQueue(
  4502. const Context& context,
  4503. const Device& device,
  4504. cl_command_queue_properties properties = 0,
  4505. cl_int* err = NULL)
  4506. {
  4507. cl_int error;
  4508. object_ = ::clCreateCommandQueue(
  4509. context(), device(), properties, &error);
  4510. detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
  4511. if (err != NULL) {
  4512. *err = error;
  4513. }
  4514. }
  4515. static CommandQueue getDefault(cl_int * err = NULL)
  4516. {
  4517. int state = detail::compare_exchange(
  4518. &default_initialized_,
  4519. __DEFAULT_BEING_INITIALIZED, __DEFAULT_NOT_INITIALIZED);
  4520. if (state & __DEFAULT_INITIALIZED) {
  4521. if (err != NULL) {
  4522. *err = default_error_;
  4523. }
  4524. return default_;
  4525. }
  4526. if (state & __DEFAULT_BEING_INITIALIZED) {
  4527. // Assume writes will propagate eventually...
  4528. while(default_initialized_ != __DEFAULT_INITIALIZED) {
  4529. detail::fence();
  4530. }
  4531. if (err != NULL) {
  4532. *err = default_error_;
  4533. }
  4534. return default_;
  4535. }
  4536. cl_int error;
  4537. Context context = Context::getDefault(&error);
  4538. detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
  4539. if (error != CL_SUCCESS) {
  4540. if (err != NULL) {
  4541. *err = error;
  4542. }
  4543. }
  4544. else {
  4545. Device device = context.getInfo<CL_CONTEXT_DEVICES>()[0];
  4546. default_ = CommandQueue(context, device, 0, &error);
  4547. detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
  4548. if (err != NULL) {
  4549. *err = error;
  4550. }
  4551. }
  4552. detail::fence();
  4553. default_error_ = error;
  4554. // Assume writes will propagate eventually...
  4555. default_initialized_ = __DEFAULT_INITIALIZED;
  4556. detail::fence();
  4557. if (err != NULL) {
  4558. *err = default_error_;
  4559. }
  4560. return default_;
  4561. }
  4562. CommandQueue() { }
  4563. CommandQueue(const CommandQueue& commandQueue) : detail::Wrapper<cl_type>(commandQueue) { }
  4564. CommandQueue(const cl_command_queue& commandQueue) : detail::Wrapper<cl_type>(commandQueue) { }
  4565. CommandQueue& operator = (const CommandQueue& rhs)
  4566. {
  4567. if (this != &rhs) {
  4568. detail::Wrapper<cl_type>::operator=(rhs);
  4569. }
  4570. return *this;
  4571. }
  4572. CommandQueue& operator = (const cl_command_queue& rhs)
  4573. {
  4574. detail::Wrapper<cl_type>::operator=(rhs);
  4575. return *this;
  4576. }
  4577. template <typename T>
  4578. cl_int getInfo(cl_command_queue_info name, T* param) const
  4579. {
  4580. return detail::errHandler(
  4581. detail::getInfo(
  4582. &::clGetCommandQueueInfo, object_, name, param),
  4583. __GET_COMMAND_QUEUE_INFO_ERR);
  4584. }
  4585. template <cl_int name> typename
  4586. detail::param_traits<detail::cl_command_queue_info, name>::param_type
  4587. getInfo(cl_int* err = NULL) const
  4588. {
  4589. typename detail::param_traits<
  4590. detail::cl_command_queue_info, name>::param_type param;
  4591. cl_int result = getInfo(name, &param);
  4592. if (err != NULL) {
  4593. *err = result;
  4594. }
  4595. return param;
  4596. }
  4597. cl_int enqueueReadBuffer(
  4598. const Buffer& buffer,
  4599. cl_bool blocking,
  4600. ::size_t offset,
  4601. ::size_t size,
  4602. void* ptr,
  4603. const VECTOR_CLASS<Event>* events = NULL,
  4604. Event* event = NULL) const
  4605. {
  4606. cl_event tmp;
  4607. cl_int err = detail::errHandler(
  4608. ::clEnqueueReadBuffer(
  4609. object_, buffer(), blocking, offset, size,
  4610. ptr,
  4611. (events != NULL) ? (cl_uint) events->size() : 0,
  4612. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  4613. (event != NULL) ? &tmp : NULL),
  4614. __ENQUEUE_READ_BUFFER_ERR);
  4615. if (event != NULL && err == CL_SUCCESS)
  4616. *event = tmp;
  4617. return err;
  4618. }
  4619. cl_int enqueueWriteBuffer(
  4620. const Buffer& buffer,
  4621. cl_bool blocking,
  4622. ::size_t offset,
  4623. ::size_t size,
  4624. const void* ptr,
  4625. const VECTOR_CLASS<Event>* events = NULL,
  4626. Event* event = NULL) const
  4627. {
  4628. cl_event tmp;
  4629. cl_int err = detail::errHandler(
  4630. ::clEnqueueWriteBuffer(
  4631. object_, buffer(), blocking, offset, size,
  4632. ptr,
  4633. (events != NULL) ? (cl_uint) events->size() : 0,
  4634. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  4635. (event != NULL) ? &tmp : NULL),
  4636. __ENQUEUE_WRITE_BUFFER_ERR);
  4637. if (event != NULL && err == CL_SUCCESS)
  4638. *event = tmp;
  4639. return err;
  4640. }
  4641. cl_int enqueueCopyBuffer(
  4642. const Buffer& src,
  4643. const Buffer& dst,
  4644. ::size_t src_offset,
  4645. ::size_t dst_offset,
  4646. ::size_t size,
  4647. const VECTOR_CLASS<Event>* events = NULL,
  4648. Event* event = NULL) const
  4649. {
  4650. cl_event tmp;
  4651. cl_int err = detail::errHandler(
  4652. ::clEnqueueCopyBuffer(
  4653. object_, src(), dst(), src_offset, dst_offset, size,
  4654. (events != NULL) ? (cl_uint) events->size() : 0,
  4655. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  4656. (event != NULL) ? &tmp : NULL),
  4657. __ENQEUE_COPY_BUFFER_ERR);
  4658. if (event != NULL && err == CL_SUCCESS)
  4659. *event = tmp;
  4660. return err;
  4661. }
  4662. cl_int enqueueReadBufferRect(
  4663. const Buffer& buffer,
  4664. cl_bool blocking,
  4665. const size_t<3>& buffer_offset,
  4666. const size_t<3>& host_offset,
  4667. const size_t<3>& region,
  4668. ::size_t buffer_row_pitch,
  4669. ::size_t buffer_slice_pitch,
  4670. ::size_t host_row_pitch,
  4671. ::size_t host_slice_pitch,
  4672. void *ptr,
  4673. const VECTOR_CLASS<Event>* events = NULL,
  4674. Event* event = NULL) const
  4675. {
  4676. cl_event tmp;
  4677. cl_int err = detail::errHandler(
  4678. ::clEnqueueReadBufferRect(
  4679. object_,
  4680. buffer(),
  4681. blocking,
  4682. (const ::size_t *)buffer_offset,
  4683. (const ::size_t *)host_offset,
  4684. (const ::size_t *)region,
  4685. buffer_row_pitch,
  4686. buffer_slice_pitch,
  4687. host_row_pitch,
  4688. host_slice_pitch,
  4689. ptr,
  4690. (events != NULL) ? (cl_uint) events->size() : 0,
  4691. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  4692. (event != NULL) ? &tmp : NULL),
  4693. __ENQUEUE_READ_BUFFER_RECT_ERR);
  4694. if (event != NULL && err == CL_SUCCESS)
  4695. *event = tmp;
  4696. return err;
  4697. }
  4698. cl_int enqueueWriteBufferRect(
  4699. const Buffer& buffer,
  4700. cl_bool blocking,
  4701. const size_t<3>& buffer_offset,
  4702. const size_t<3>& host_offset,
  4703. const size_t<3>& region,
  4704. ::size_t buffer_row_pitch,
  4705. ::size_t buffer_slice_pitch,
  4706. ::size_t host_row_pitch,
  4707. ::size_t host_slice_pitch,
  4708. void *ptr,
  4709. const VECTOR_CLASS<Event>* events = NULL,
  4710. Event* event = NULL) const
  4711. {
  4712. cl_event tmp;
  4713. cl_int err = detail::errHandler(
  4714. ::clEnqueueWriteBufferRect(
  4715. object_,
  4716. buffer(),
  4717. blocking,
  4718. (const ::size_t *)buffer_offset,
  4719. (const ::size_t *)host_offset,
  4720. (const ::size_t *)region,
  4721. buffer_row_pitch,
  4722. buffer_slice_pitch,
  4723. host_row_pitch,
  4724. host_slice_pitch,
  4725. ptr,
  4726. (events != NULL) ? (cl_uint) events->size() : 0,
  4727. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  4728. (event != NULL) ? &tmp : NULL),
  4729. __ENQUEUE_WRITE_BUFFER_RECT_ERR);
  4730. if (event != NULL && err == CL_SUCCESS)
  4731. *event = tmp;
  4732. return err;
  4733. }
  4734. cl_int enqueueCopyBufferRect(
  4735. const Buffer& src,
  4736. const Buffer& dst,
  4737. const size_t<3>& src_origin,
  4738. const size_t<3>& dst_origin,
  4739. const size_t<3>& region,
  4740. ::size_t src_row_pitch,
  4741. ::size_t src_slice_pitch,
  4742. ::size_t dst_row_pitch,
  4743. ::size_t dst_slice_pitch,
  4744. const VECTOR_CLASS<Event>* events = NULL,
  4745. Event* event = NULL) const
  4746. {
  4747. cl_event tmp;
  4748. cl_int err = detail::errHandler(
  4749. ::clEnqueueCopyBufferRect(
  4750. object_,
  4751. src(),
  4752. dst(),
  4753. (const ::size_t *)src_origin,
  4754. (const ::size_t *)dst_origin,
  4755. (const ::size_t *)region,
  4756. src_row_pitch,
  4757. src_slice_pitch,
  4758. dst_row_pitch,
  4759. dst_slice_pitch,
  4760. (events != NULL) ? (cl_uint) events->size() : 0,
  4761. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  4762. (event != NULL) ? &tmp : NULL),
  4763. __ENQEUE_COPY_BUFFER_RECT_ERR);
  4764. if (event != NULL && err == CL_SUCCESS)
  4765. *event = tmp;
  4766. return err;
  4767. }
  4768. #if defined(CL_VERSION_1_2)
  4769. /**
  4770. * Enqueue a command to fill a buffer object with a pattern
  4771. * of a given size. The pattern is specified a as vector.
  4772. * \tparam PatternType The datatype of the pattern field.
  4773. * The pattern type must be an accepted OpenCL data type.
  4774. */
  4775. template<typename PatternType>
  4776. cl_int enqueueFillBuffer(
  4777. const Buffer& buffer,
  4778. PatternType pattern,
  4779. ::size_t offset,
  4780. ::size_t size,
  4781. const VECTOR_CLASS<Event>* events = NULL,
  4782. Event* event = NULL) const
  4783. {
  4784. cl_event tmp;
  4785. cl_int err = detail::errHandler(
  4786. ::clEnqueueFillBuffer(
  4787. object_,
  4788. buffer(),
  4789. static_cast<void*>(&pattern),
  4790. sizeof(PatternType),
  4791. offset,
  4792. size,
  4793. (events != NULL) ? (cl_uint) events->size() : 0,
  4794. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  4795. (event != NULL) ? &tmp : NULL),
  4796. __ENQUEUE_FILL_BUFFER_ERR);
  4797. if (event != NULL && err == CL_SUCCESS)
  4798. *event = tmp;
  4799. return err;
  4800. }
  4801. #endif // #if defined(CL_VERSION_1_2)
  4802. cl_int enqueueReadImage(
  4803. const Image& image,
  4804. cl_bool blocking,
  4805. const size_t<3>& origin,
  4806. const size_t<3>& region,
  4807. ::size_t row_pitch,
  4808. ::size_t slice_pitch,
  4809. void* ptr,
  4810. const VECTOR_CLASS<Event>* events = NULL,
  4811. Event* event = NULL) const
  4812. {
  4813. cl_event tmp;
  4814. cl_int err = detail::errHandler(
  4815. ::clEnqueueReadImage(
  4816. object_, image(), blocking, (const ::size_t *) origin,
  4817. (const ::size_t *) region, row_pitch, slice_pitch, ptr,
  4818. (events != NULL) ? (cl_uint) events->size() : 0,
  4819. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  4820. (event != NULL) ? &tmp : NULL),
  4821. __ENQUEUE_READ_IMAGE_ERR);
  4822. if (event != NULL && err == CL_SUCCESS)
  4823. *event = tmp;
  4824. return err;
  4825. }
  4826. cl_int enqueueWriteImage(
  4827. const Image& image,
  4828. cl_bool blocking,
  4829. const size_t<3>& origin,
  4830. const size_t<3>& region,
  4831. ::size_t row_pitch,
  4832. ::size_t slice_pitch,
  4833. void* ptr,
  4834. const VECTOR_CLASS<Event>* events = NULL,
  4835. Event* event = NULL) const
  4836. {
  4837. cl_event tmp;
  4838. cl_int err = detail::errHandler(
  4839. ::clEnqueueWriteImage(
  4840. object_, image(), blocking, (const ::size_t *) origin,
  4841. (const ::size_t *) region, row_pitch, slice_pitch, ptr,
  4842. (events != NULL) ? (cl_uint) events->size() : 0,
  4843. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  4844. (event != NULL) ? &tmp : NULL),
  4845. __ENQUEUE_WRITE_IMAGE_ERR);
  4846. if (event != NULL && err == CL_SUCCESS)
  4847. *event = tmp;
  4848. return err;
  4849. }
  4850. cl_int enqueueCopyImage(
  4851. const Image& src,
  4852. const Image& dst,
  4853. const size_t<3>& src_origin,
  4854. const size_t<3>& dst_origin,
  4855. const size_t<3>& region,
  4856. const VECTOR_CLASS<Event>* events = NULL,
  4857. Event* event = NULL) const
  4858. {
  4859. cl_event tmp;
  4860. cl_int err = detail::errHandler(
  4861. ::clEnqueueCopyImage(
  4862. object_, src(), dst(), (const ::size_t *) src_origin,
  4863. (const ::size_t *)dst_origin, (const ::size_t *) region,
  4864. (events != NULL) ? (cl_uint) events->size() : 0,
  4865. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  4866. (event != NULL) ? &tmp : NULL),
  4867. __ENQUEUE_COPY_IMAGE_ERR);
  4868. if (event != NULL && err == CL_SUCCESS)
  4869. *event = tmp;
  4870. return err;
  4871. }
  4872. #if defined(CL_VERSION_1_2)
  4873. /**
  4874. * Enqueue a command to fill an image object with a specified color.
  4875. * \param fillColor is the color to use to fill the image.
  4876. * This is a four component RGBA floating-point color value if
  4877. * the image channel data type is not an unnormalized signed or
  4878. * unsigned data type.
  4879. */
  4880. cl_int enqueueFillImage(
  4881. const Image& image,
  4882. cl_float4 fillColor,
  4883. const size_t<3>& origin,
  4884. const size_t<3>& region,
  4885. const VECTOR_CLASS<Event>* events = NULL,
  4886. Event* event = NULL) const
  4887. {
  4888. cl_event tmp;
  4889. cl_int err = detail::errHandler(
  4890. ::clEnqueueFillImage(
  4891. object_,
  4892. image(),
  4893. static_cast<void*>(&fillColor),
  4894. (const ::size_t *) origin,
  4895. (const ::size_t *) region,
  4896. (events != NULL) ? (cl_uint) events->size() : 0,
  4897. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  4898. (event != NULL) ? &tmp : NULL),
  4899. __ENQUEUE_FILL_IMAGE_ERR);
  4900. if (event != NULL && err == CL_SUCCESS)
  4901. *event = tmp;
  4902. return err;
  4903. }
  4904. /**
  4905. * Enqueue a command to fill an image object with a specified color.
  4906. * \param fillColor is the color to use to fill the image.
  4907. * This is a four component RGBA signed integer color value if
  4908. * the image channel data type is an unnormalized signed integer
  4909. * type.
  4910. */
  4911. cl_int enqueueFillImage(
  4912. const Image& image,
  4913. cl_int4 fillColor,
  4914. const size_t<3>& origin,
  4915. const size_t<3>& region,
  4916. const VECTOR_CLASS<Event>* events = NULL,
  4917. Event* event = NULL) const
  4918. {
  4919. cl_event tmp;
  4920. cl_int err = detail::errHandler(
  4921. ::clEnqueueFillImage(
  4922. object_,
  4923. image(),
  4924. static_cast<void*>(&fillColor),
  4925. (const ::size_t *) origin,
  4926. (const ::size_t *) region,
  4927. (events != NULL) ? (cl_uint) events->size() : 0,
  4928. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  4929. (event != NULL) ? &tmp : NULL),
  4930. __ENQUEUE_FILL_IMAGE_ERR);
  4931. if (event != NULL && err == CL_SUCCESS)
  4932. *event = tmp;
  4933. return err;
  4934. }
  4935. /**
  4936. * Enqueue a command to fill an image object with a specified color.
  4937. * \param fillColor is the color to use to fill the image.
  4938. * This is a four component RGBA unsigned integer color value if
  4939. * the image channel data type is an unnormalized unsigned integer
  4940. * type.
  4941. */
  4942. cl_int enqueueFillImage(
  4943. const Image& image,
  4944. cl_uint4 fillColor,
  4945. const size_t<3>& origin,
  4946. const size_t<3>& region,
  4947. const VECTOR_CLASS<Event>* events = NULL,
  4948. Event* event = NULL) const
  4949. {
  4950. cl_event tmp;
  4951. cl_int err = detail::errHandler(
  4952. ::clEnqueueFillImage(
  4953. object_,
  4954. image(),
  4955. static_cast<void*>(&fillColor),
  4956. (const ::size_t *) origin,
  4957. (const ::size_t *) region,
  4958. (events != NULL) ? (cl_uint) events->size() : 0,
  4959. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  4960. (event != NULL) ? &tmp : NULL),
  4961. __ENQUEUE_FILL_IMAGE_ERR);
  4962. if (event != NULL && err == CL_SUCCESS)
  4963. *event = tmp;
  4964. return err;
  4965. }
  4966. #endif // #if defined(CL_VERSION_1_2)
  4967. cl_int enqueueCopyImageToBuffer(
  4968. const Image& src,
  4969. const Buffer& dst,
  4970. const size_t<3>& src_origin,
  4971. const size_t<3>& region,
  4972. ::size_t dst_offset,
  4973. const VECTOR_CLASS<Event>* events = NULL,
  4974. Event* event = NULL) const
  4975. {
  4976. cl_event tmp;
  4977. cl_int err = detail::errHandler(
  4978. ::clEnqueueCopyImageToBuffer(
  4979. object_, src(), dst(), (const ::size_t *) src_origin,
  4980. (const ::size_t *) region, dst_offset,
  4981. (events != NULL) ? (cl_uint) events->size() : 0,
  4982. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  4983. (event != NULL) ? &tmp : NULL),
  4984. __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR);
  4985. if (event != NULL && err == CL_SUCCESS)
  4986. *event = tmp;
  4987. return err;
  4988. }
  4989. cl_int enqueueCopyBufferToImage(
  4990. const Buffer& src,
  4991. const Image& dst,
  4992. ::size_t src_offset,
  4993. const size_t<3>& dst_origin,
  4994. const size_t<3>& region,
  4995. const VECTOR_CLASS<Event>* events = NULL,
  4996. Event* event = NULL) const
  4997. {
  4998. cl_event tmp;
  4999. cl_int err = detail::errHandler(
  5000. ::clEnqueueCopyBufferToImage(
  5001. object_, src(), dst(), src_offset,
  5002. (const ::size_t *) dst_origin, (const ::size_t *) region,
  5003. (events != NULL) ? (cl_uint) events->size() : 0,
  5004. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  5005. (event != NULL) ? &tmp : NULL),
  5006. __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR);
  5007. if (event != NULL && err == CL_SUCCESS)
  5008. *event = tmp;
  5009. return err;
  5010. }
  5011. void* enqueueMapBuffer(
  5012. const Buffer& buffer,
  5013. cl_bool blocking,
  5014. cl_map_flags flags,
  5015. ::size_t offset,
  5016. ::size_t size,
  5017. const VECTOR_CLASS<Event>* events = NULL,
  5018. Event* event = NULL,
  5019. cl_int* err = NULL) const
  5020. {
  5021. cl_int error;
  5022. void * result = ::clEnqueueMapBuffer(
  5023. object_, buffer(), blocking, flags, offset, size,
  5024. (events != NULL) ? (cl_uint) events->size() : 0,
  5025. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  5026. (cl_event*) event,
  5027. &error);
  5028. detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
  5029. if (err != NULL) {
  5030. *err = error;
  5031. }
  5032. return result;
  5033. }
  5034. void* enqueueMapImage(
  5035. const Image& buffer,
  5036. cl_bool blocking,
  5037. cl_map_flags flags,
  5038. const size_t<3>& origin,
  5039. const size_t<3>& region,
  5040. ::size_t * row_pitch,
  5041. ::size_t * slice_pitch,
  5042. const VECTOR_CLASS<Event>* events = NULL,
  5043. Event* event = NULL,
  5044. cl_int* err = NULL) const
  5045. {
  5046. cl_int error;
  5047. void * result = ::clEnqueueMapImage(
  5048. object_, buffer(), blocking, flags,
  5049. (const ::size_t *) origin, (const ::size_t *) region,
  5050. row_pitch, slice_pitch,
  5051. (events != NULL) ? (cl_uint) events->size() : 0,
  5052. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  5053. (cl_event*) event,
  5054. &error);
  5055. detail::errHandler(error, __ENQUEUE_MAP_IMAGE_ERR);
  5056. if (err != NULL) {
  5057. *err = error;
  5058. }
  5059. return result;
  5060. }
  5061. cl_int enqueueUnmapMemObject(
  5062. const Memory& memory,
  5063. void* mapped_ptr,
  5064. const VECTOR_CLASS<Event>* events = NULL,
  5065. Event* event = NULL) const
  5066. {
  5067. cl_event tmp;
  5068. cl_int err = detail::errHandler(
  5069. ::clEnqueueUnmapMemObject(
  5070. object_, memory(), mapped_ptr,
  5071. (events != NULL) ? (cl_uint) events->size() : 0,
  5072. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  5073. (event != NULL) ? &tmp : NULL),
  5074. __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
  5075. if (event != NULL && err == CL_SUCCESS)
  5076. *event = tmp;
  5077. return err;
  5078. }
  5079. #if defined(CL_VERSION_1_2)
  5080. /**
  5081. * Enqueues a marker command which waits for either a list of events to complete,
  5082. * or all previously enqueued commands to complete.
  5083. *
  5084. * Enqueues a marker command which waits for either a list of events to complete,
  5085. * or if the list is empty it waits for all commands previously enqueued in command_queue
  5086. * to complete before it completes. This command returns an event which can be waited on,
  5087. * i.e. this event can be waited on to insure that all events either in the event_wait_list
  5088. * or all previously enqueued commands, queued before this command to command_queue,
  5089. * have completed.
  5090. */
  5091. cl_int enqueueMarkerWithWaitList(
  5092. const VECTOR_CLASS<Event> *events = 0,
  5093. Event *event = 0)
  5094. {
  5095. cl_event tmp;
  5096. cl_int err = detail::errHandler(
  5097. ::clEnqueueMarkerWithWaitList(
  5098. object_,
  5099. (events != NULL) ? (cl_uint) events->size() : 0,
  5100. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  5101. (event != NULL) ? &tmp : NULL),
  5102. __ENQUEUE_MARKER_WAIT_LIST_ERR);
  5103. if (event != NULL && err == CL_SUCCESS)
  5104. *event = tmp;
  5105. return err;
  5106. }
  5107. /**
  5108. * A synchronization point that enqueues a barrier operation.
  5109. *
  5110. * Enqueues a barrier command which waits for either a list of events to complete,
  5111. * or if the list is empty it waits for all commands previously enqueued in command_queue
  5112. * to complete before it completes. This command blocks command execution, that is, any
  5113. * following commands enqueued after it do not execute until it completes. This command
  5114. * returns an event which can be waited on, i.e. this event can be waited on to insure that
  5115. * all events either in the event_wait_list or all previously enqueued commands, queued
  5116. * before this command to command_queue, have completed.
  5117. */
  5118. cl_int enqueueBarrierWithWaitList(
  5119. const VECTOR_CLASS<Event> *events = 0,
  5120. Event *event = 0)
  5121. {
  5122. cl_event tmp;
  5123. cl_int err = detail::errHandler(
  5124. ::clEnqueueBarrierWithWaitList(
  5125. object_,
  5126. (events != NULL) ? (cl_uint) events->size() : 0,
  5127. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  5128. (event != NULL) ? &tmp : NULL),
  5129. __ENQUEUE_BARRIER_WAIT_LIST_ERR);
  5130. if (event != NULL && err == CL_SUCCESS)
  5131. *event = tmp;
  5132. return err;
  5133. }
  5134. /**
  5135. * Enqueues a command to indicate with which device a set of memory objects
  5136. * should be associated.
  5137. */
  5138. cl_int enqueueMigrateMemObjects(
  5139. const VECTOR_CLASS<Memory> &memObjects,
  5140. cl_mem_migration_flags flags,
  5141. const VECTOR_CLASS<Event>* events = NULL,
  5142. Event* event = NULL
  5143. )
  5144. {
  5145. cl_event tmp;
  5146. cl_mem* localMemObjects = static_cast<cl_mem*>(alloca(memObjects.size() * sizeof(cl_mem)));
  5147. for( int i = 0; i < (int)memObjects.size(); ++i ) {
  5148. localMemObjects[i] = memObjects[i]();
  5149. }
  5150. cl_int err = detail::errHandler(
  5151. ::clEnqueueMigrateMemObjects(
  5152. object_,
  5153. (cl_uint)memObjects.size(),
  5154. static_cast<const cl_mem*>(localMemObjects),
  5155. flags,
  5156. (events != NULL) ? (cl_uint) events->size() : 0,
  5157. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  5158. (event != NULL) ? &tmp : NULL),
  5159. __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
  5160. if (event != NULL && err == CL_SUCCESS)
  5161. *event = tmp;
  5162. return err;
  5163. }
  5164. #endif // #if defined(CL_VERSION_1_2)
  5165. cl_int enqueueNDRangeKernel(
  5166. const Kernel& kernel,
  5167. const NDRange& offset,
  5168. const NDRange& global,
  5169. const NDRange& local = NullRange,
  5170. const VECTOR_CLASS<Event>* events = NULL,
  5171. Event* event = NULL) const
  5172. {
  5173. cl_event tmp;
  5174. cl_int err = detail::errHandler(
  5175. ::clEnqueueNDRangeKernel(
  5176. object_, kernel(), (cl_uint) global.dimensions(),
  5177. offset.dimensions() != 0 ? (const ::size_t*) offset : NULL,
  5178. (const ::size_t*) global,
  5179. local.dimensions() != 0 ? (const ::size_t*) local : NULL,
  5180. (events != NULL) ? (cl_uint) events->size() : 0,
  5181. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  5182. (event != NULL) ? &tmp : NULL),
  5183. __ENQUEUE_NDRANGE_KERNEL_ERR);
  5184. if (event != NULL && err == CL_SUCCESS)
  5185. *event = tmp;
  5186. return err;
  5187. }
  5188. cl_int enqueueTask(
  5189. const Kernel& kernel,
  5190. const VECTOR_CLASS<Event>* events = NULL,
  5191. Event* event = NULL) const
  5192. {
  5193. cl_event tmp;
  5194. cl_int err = detail::errHandler(
  5195. ::clEnqueueTask(
  5196. object_, kernel(),
  5197. (events != NULL) ? (cl_uint) events->size() : 0,
  5198. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  5199. (event != NULL) ? &tmp : NULL),
  5200. __ENQUEUE_TASK_ERR);
  5201. if (event != NULL && err == CL_SUCCESS)
  5202. *event = tmp;
  5203. return err;
  5204. }
  5205. cl_int enqueueNativeKernel(
  5206. void (CL_CALLBACK *userFptr)(void *),
  5207. std::pair<void*, ::size_t> args,
  5208. const VECTOR_CLASS<Memory>* mem_objects = NULL,
  5209. const VECTOR_CLASS<const void*>* mem_locs = NULL,
  5210. const VECTOR_CLASS<Event>* events = NULL,
  5211. Event* event = NULL) const
  5212. {
  5213. cl_mem * mems = (mem_objects != NULL && mem_objects->size() > 0)
  5214. ? (cl_mem*) alloca(mem_objects->size() * sizeof(cl_mem))
  5215. : NULL;
  5216. if (mems != NULL) {
  5217. for (unsigned int i = 0; i < mem_objects->size(); i++) {
  5218. mems[i] = ((*mem_objects)[i])();
  5219. }
  5220. }
  5221. cl_event tmp;
  5222. cl_int err = detail::errHandler(
  5223. ::clEnqueueNativeKernel(
  5224. object_, userFptr, args.first, args.second,
  5225. (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
  5226. mems,
  5227. (mem_locs != NULL) ? (const void **) &mem_locs->front() : NULL,
  5228. (events != NULL) ? (cl_uint) events->size() : 0,
  5229. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  5230. (event != NULL) ? &tmp : NULL),
  5231. __ENQUEUE_NATIVE_KERNEL);
  5232. if (event != NULL && err == CL_SUCCESS)
  5233. *event = tmp;
  5234. return err;
  5235. }
  5236. /**
  5237. * Deprecated APIs for 1.2
  5238. */
  5239. #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2))
  5240. CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
  5241. cl_int enqueueMarker(Event* event = NULL) const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
  5242. {
  5243. return detail::errHandler(
  5244. ::clEnqueueMarker(object_, (cl_event*) event),
  5245. __ENQUEUE_MARKER_ERR);
  5246. }
  5247. CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
  5248. cl_int enqueueWaitForEvents(const VECTOR_CLASS<Event>& events) const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
  5249. {
  5250. return detail::errHandler(
  5251. ::clEnqueueWaitForEvents(
  5252. object_,
  5253. (cl_uint) events.size(),
  5254. (const cl_event*) &events.front()),
  5255. __ENQUEUE_WAIT_FOR_EVENTS_ERR);
  5256. }
  5257. #endif // #if defined(CL_VERSION_1_1)
  5258. cl_int enqueueAcquireGLObjects(
  5259. const VECTOR_CLASS<Memory>* mem_objects = NULL,
  5260. const VECTOR_CLASS<Event>* events = NULL,
  5261. Event* event = NULL) const
  5262. {
  5263. cl_event tmp;
  5264. cl_int err = detail::errHandler(
  5265. ::clEnqueueAcquireGLObjects(
  5266. object_,
  5267. (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
  5268. (mem_objects != NULL) ? (const cl_mem *) &mem_objects->front(): NULL,
  5269. (events != NULL) ? (cl_uint) events->size() : 0,
  5270. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  5271. (event != NULL) ? &tmp : NULL),
  5272. __ENQUEUE_ACQUIRE_GL_ERR);
  5273. if (event != NULL && err == CL_SUCCESS)
  5274. *event = tmp;
  5275. return err;
  5276. }
  5277. cl_int enqueueReleaseGLObjects(
  5278. const VECTOR_CLASS<Memory>* mem_objects = NULL,
  5279. const VECTOR_CLASS<Event>* events = NULL,
  5280. Event* event = NULL) const
  5281. {
  5282. cl_event tmp;
  5283. cl_int err = detail::errHandler(
  5284. ::clEnqueueReleaseGLObjects(
  5285. object_,
  5286. (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
  5287. (mem_objects != NULL) ? (const cl_mem *) &mem_objects->front(): NULL,
  5288. (events != NULL) ? (cl_uint) events->size() : 0,
  5289. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  5290. (event != NULL) ? &tmp : NULL),
  5291. __ENQUEUE_RELEASE_GL_ERR);
  5292. if (event != NULL && err == CL_SUCCESS)
  5293. *event = tmp;
  5294. return err;
  5295. }
  5296. #if defined (USE_DX_INTEROP)
  5297. typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueAcquireD3D10ObjectsKHR)(
  5298. cl_command_queue command_queue, cl_uint num_objects,
  5299. const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
  5300. const cl_event* event_wait_list, cl_event* event);
  5301. typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueReleaseD3D10ObjectsKHR)(
  5302. cl_command_queue command_queue, cl_uint num_objects,
  5303. const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
  5304. const cl_event* event_wait_list, cl_event* event);
  5305. cl_int enqueueAcquireD3D10Objects(
  5306. const VECTOR_CLASS<Memory>* mem_objects = NULL,
  5307. const VECTOR_CLASS<Event>* events = NULL,
  5308. Event* event = NULL) const
  5309. {
  5310. static PFN_clEnqueueAcquireD3D10ObjectsKHR pfn_clEnqueueAcquireD3D10ObjectsKHR = NULL;
  5311. #if defined(CL_VERSION_1_2)
  5312. cl_context context = getInfo<CL_QUEUE_CONTEXT>();
  5313. cl::Device device(getInfo<CL_QUEUE_DEVICE>());
  5314. cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>();
  5315. __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, clEnqueueAcquireD3D10ObjectsKHR);
  5316. #endif
  5317. #if defined(CL_VERSION_1_1)
  5318. __INIT_CL_EXT_FCN_PTR(clEnqueueAcquireD3D10ObjectsKHR);
  5319. #endif
  5320. cl_event tmp;
  5321. cl_int err = detail::errHandler(
  5322. pfn_clEnqueueAcquireD3D10ObjectsKHR(
  5323. object_,
  5324. (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
  5325. (mem_objects != NULL) ? (const cl_mem *) &mem_objects->front(): NULL,
  5326. (events != NULL) ? (cl_uint) events->size() : 0,
  5327. (events != NULL) ? (cl_event*) &events->front() : NULL,
  5328. (event != NULL) ? &tmp : NULL),
  5329. __ENQUEUE_ACQUIRE_GL_ERR);
  5330. if (event != NULL && err == CL_SUCCESS)
  5331. *event = tmp;
  5332. return err;
  5333. }
  5334. cl_int enqueueReleaseD3D10Objects(
  5335. const VECTOR_CLASS<Memory>* mem_objects = NULL,
  5336. const VECTOR_CLASS<Event>* events = NULL,
  5337. Event* event = NULL) const
  5338. {
  5339. static PFN_clEnqueueReleaseD3D10ObjectsKHR pfn_clEnqueueReleaseD3D10ObjectsKHR = NULL;
  5340. #if defined(CL_VERSION_1_2)
  5341. cl_context context = getInfo<CL_QUEUE_CONTEXT>();
  5342. cl::Device device(getInfo<CL_QUEUE_DEVICE>());
  5343. cl_platform_id platform = device.getInfo<CL_DEVICE_PLATFORM>();
  5344. __INIT_CL_EXT_FCN_PTR_PLATFORM(platform, clEnqueueReleaseD3D10ObjectsKHR);
  5345. #endif // #if defined(CL_VERSION_1_2)
  5346. #if defined(CL_VERSION_1_1)
  5347. __INIT_CL_EXT_FCN_PTR(clEnqueueReleaseD3D10ObjectsKHR);
  5348. #endif // #if defined(CL_VERSION_1_1)
  5349. cl_event tmp;
  5350. cl_int err = detail::errHandler(
  5351. pfn_clEnqueueReleaseD3D10ObjectsKHR(
  5352. object_,
  5353. (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
  5354. (mem_objects != NULL) ? (const cl_mem *) &mem_objects->front(): NULL,
  5355. (events != NULL) ? (cl_uint) events->size() : 0,
  5356. (events != NULL) ? (cl_event*) &events->front() : NULL,
  5357. (event != NULL) ? &tmp : NULL),
  5358. __ENQUEUE_RELEASE_GL_ERR);
  5359. if (event != NULL && err == CL_SUCCESS)
  5360. *event = tmp;
  5361. return err;
  5362. }
  5363. #endif
  5364. /**
  5365. * Deprecated APIs for 1.2
  5366. */
  5367. #if defined(CL_USE_DEPRECATED_OPENCL_1_1_APIS) || (defined(CL_VERSION_1_1) && !defined(CL_VERSION_1_2))
  5368. CL_EXT_PREFIX__VERSION_1_1_DEPRECATED
  5369. cl_int enqueueBarrier() const CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED
  5370. {
  5371. return detail::errHandler(
  5372. ::clEnqueueBarrier(object_),
  5373. __ENQUEUE_BARRIER_ERR);
  5374. }
  5375. #endif // #if defined(CL_VERSION_1_1)
  5376. cl_int flush() const
  5377. {
  5378. return detail::errHandler(::clFlush(object_), __FLUSH_ERR);
  5379. }
  5380. cl_int finish() const
  5381. {
  5382. return detail::errHandler(::clFinish(object_), __FINISH_ERR);
  5383. }
  5384. };
  5385. #ifdef _WIN32
  5386. __declspec(selectany) volatile int CommandQueue::default_initialized_ = __DEFAULT_NOT_INITIALIZED;
  5387. __declspec(selectany) CommandQueue CommandQueue::default_;
  5388. __declspec(selectany) volatile cl_int CommandQueue::default_error_ = CL_SUCCESS;
  5389. #else
  5390. __attribute__((weak)) volatile int CommandQueue::default_initialized_ = __DEFAULT_NOT_INITIALIZED;
  5391. __attribute__((weak)) CommandQueue CommandQueue::default_;
  5392. __attribute__((weak)) volatile cl_int CommandQueue::default_error_ = CL_SUCCESS;
  5393. #endif
  5394. inline cl_int enqueueReadBuffer(
  5395. const Buffer& buffer,
  5396. cl_bool blocking,
  5397. ::size_t offset,
  5398. ::size_t size,
  5399. void* ptr,
  5400. const VECTOR_CLASS<Event>* events = NULL,
  5401. Event* event = NULL)
  5402. {
  5403. cl_int error;
  5404. CommandQueue queue = CommandQueue::getDefault(&error);
  5405. if (error != CL_SUCCESS) {
  5406. return error;
  5407. }
  5408. return queue.enqueueReadBuffer(buffer, blocking, offset, size, ptr, events, event);
  5409. }
  5410. inline cl_int enqueueWriteBuffer(
  5411. const Buffer& buffer,
  5412. cl_bool blocking,
  5413. ::size_t offset,
  5414. ::size_t size,
  5415. const void* ptr,
  5416. const VECTOR_CLASS<Event>* events = NULL,
  5417. Event* event = NULL)
  5418. {
  5419. cl_int error;
  5420. CommandQueue queue = CommandQueue::getDefault(&error);
  5421. if (error != CL_SUCCESS) {
  5422. return error;
  5423. }
  5424. return queue.enqueueWriteBuffer(buffer, blocking, offset, size, ptr, events, event);
  5425. }
  5426. inline void* enqueueMapBuffer(
  5427. const Buffer& buffer,
  5428. cl_bool blocking,
  5429. cl_map_flags flags,
  5430. ::size_t offset,
  5431. ::size_t size,
  5432. const VECTOR_CLASS<Event>* events = NULL,
  5433. Event* event = NULL,
  5434. cl_int* err = NULL)
  5435. {
  5436. cl_int error;
  5437. CommandQueue queue = CommandQueue::getDefault(&error);
  5438. detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
  5439. if (err != NULL) {
  5440. *err = error;
  5441. }
  5442. void * result = ::clEnqueueMapBuffer(
  5443. queue(), buffer(), blocking, flags, offset, size,
  5444. (events != NULL) ? (cl_uint) events->size() : 0,
  5445. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  5446. (cl_event*) event,
  5447. &error);
  5448. detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
  5449. if (err != NULL) {
  5450. *err = error;
  5451. }
  5452. return result;
  5453. }
  5454. inline cl_int enqueueUnmapMemObject(
  5455. const Memory& memory,
  5456. void* mapped_ptr,
  5457. const VECTOR_CLASS<Event>* events = NULL,
  5458. Event* event = NULL)
  5459. {
  5460. cl_int error;
  5461. CommandQueue queue = CommandQueue::getDefault(&error);
  5462. detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
  5463. if (error != CL_SUCCESS) {
  5464. return error;
  5465. }
  5466. cl_event tmp;
  5467. cl_int err = detail::errHandler(
  5468. ::clEnqueueUnmapMemObject(
  5469. queue(), memory(), mapped_ptr,
  5470. (events != NULL) ? (cl_uint) events->size() : 0,
  5471. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  5472. (event != NULL) ? &tmp : NULL),
  5473. __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
  5474. if (event != NULL && err == CL_SUCCESS)
  5475. *event = tmp;
  5476. return err;
  5477. }
  5478. inline cl_int enqueueCopyBuffer(
  5479. const Buffer& src,
  5480. const Buffer& dst,
  5481. ::size_t src_offset,
  5482. ::size_t dst_offset,
  5483. ::size_t size,
  5484. const VECTOR_CLASS<Event>* events = NULL,
  5485. Event* event = NULL)
  5486. {
  5487. cl_int error;
  5488. CommandQueue queue = CommandQueue::getDefault(&error);
  5489. if (error != CL_SUCCESS) {
  5490. return error;
  5491. }
  5492. return queue.enqueueCopyBuffer(src, dst, src_offset, dst_offset, size, events, event);
  5493. }
  5494. /**
  5495. * Blocking copy operation between iterators and a buffer.
  5496. */
  5497. template< typename IteratorType >
  5498. inline cl_int copy( IteratorType startIterator, IteratorType endIterator, cl::Buffer &buffer )
  5499. {
  5500. typedef typename std::iterator_traits<IteratorType>::value_type DataType;
  5501. cl_int error;
  5502. ::size_t length = endIterator-startIterator;
  5503. ::size_t byteLength = length*sizeof(DataType);
  5504. DataType *pointer =
  5505. static_cast<DataType*>(enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_WRITE, 0, byteLength, 0, 0, &error));
  5506. // if exceptions enabled, enqueueMapBuffer will throw
  5507. if( error != CL_SUCCESS ) {
  5508. return error;
  5509. }
  5510. #if defined(_MSC_VER)
  5511. std::copy(
  5512. startIterator,
  5513. endIterator,
  5514. stdext::checked_array_iterator<DataType*>(
  5515. pointer, length));
  5516. #else
  5517. std::copy(startIterator, endIterator, pointer);
  5518. #endif
  5519. Event endEvent;
  5520. error = enqueueUnmapMemObject(buffer, pointer, 0, &endEvent);
  5521. // if exceptions enabled, enqueueUnmapMemObject will throw
  5522. if( error != CL_SUCCESS ) {
  5523. return error;
  5524. }
  5525. endEvent.wait();
  5526. return CL_SUCCESS;
  5527. }
  5528. /**
  5529. * Blocking copy operation between iterators and a buffer.
  5530. */
  5531. template< typename IteratorType >
  5532. inline cl_int copy( const cl::Buffer &buffer, IteratorType startIterator, IteratorType endIterator )
  5533. {
  5534. typedef typename std::iterator_traits<IteratorType>::value_type DataType;
  5535. cl_int error;
  5536. ::size_t length = endIterator-startIterator;
  5537. ::size_t byteLength = length*sizeof(DataType);
  5538. DataType *pointer =
  5539. static_cast<DataType*>(enqueueMapBuffer(buffer, CL_TRUE, CL_MAP_READ, 0, byteLength, 0, 0, &error));
  5540. // if exceptions enabled, enqueueMapBuffer will throw
  5541. if( error != CL_SUCCESS ) {
  5542. return error;
  5543. }
  5544. std::copy(pointer, pointer + length, startIterator);
  5545. Event endEvent;
  5546. error = enqueueUnmapMemObject(buffer, pointer, 0, &endEvent);
  5547. // if exceptions enabled, enqueueUnmapMemObject will throw
  5548. if( error != CL_SUCCESS ) {
  5549. return error;
  5550. }
  5551. endEvent.wait();
  5552. return CL_SUCCESS;
  5553. }
  5554. #if defined(CL_VERSION_1_1)
  5555. inline cl_int enqueueReadBufferRect(
  5556. const Buffer& buffer,
  5557. cl_bool blocking,
  5558. const size_t<3>& buffer_offset,
  5559. const size_t<3>& host_offset,
  5560. const size_t<3>& region,
  5561. ::size_t buffer_row_pitch,
  5562. ::size_t buffer_slice_pitch,
  5563. ::size_t host_row_pitch,
  5564. ::size_t host_slice_pitch,
  5565. void *ptr,
  5566. const VECTOR_CLASS<Event>* events = NULL,
  5567. Event* event = NULL)
  5568. {
  5569. cl_int error;
  5570. CommandQueue queue = CommandQueue::getDefault(&error);
  5571. if (error != CL_SUCCESS) {
  5572. return error;
  5573. }
  5574. return queue.enqueueReadBufferRect(
  5575. buffer,
  5576. blocking,
  5577. buffer_offset,
  5578. host_offset,
  5579. region,
  5580. buffer_row_pitch,
  5581. buffer_slice_pitch,
  5582. host_row_pitch,
  5583. host_slice_pitch,
  5584. ptr,
  5585. events,
  5586. event);
  5587. }
  5588. inline cl_int enqueueWriteBufferRect(
  5589. const Buffer& buffer,
  5590. cl_bool blocking,
  5591. const size_t<3>& buffer_offset,
  5592. const size_t<3>& host_offset,
  5593. const size_t<3>& region,
  5594. ::size_t buffer_row_pitch,
  5595. ::size_t buffer_slice_pitch,
  5596. ::size_t host_row_pitch,
  5597. ::size_t host_slice_pitch,
  5598. void *ptr,
  5599. const VECTOR_CLASS<Event>* events = NULL,
  5600. Event* event = NULL)
  5601. {
  5602. cl_int error;
  5603. CommandQueue queue = CommandQueue::getDefault(&error);
  5604. if (error != CL_SUCCESS) {
  5605. return error;
  5606. }
  5607. return queue.enqueueWriteBufferRect(
  5608. buffer,
  5609. blocking,
  5610. buffer_offset,
  5611. host_offset,
  5612. region,
  5613. buffer_row_pitch,
  5614. buffer_slice_pitch,
  5615. host_row_pitch,
  5616. host_slice_pitch,
  5617. ptr,
  5618. events,
  5619. event);
  5620. }
  5621. inline cl_int enqueueCopyBufferRect(
  5622. const Buffer& src,
  5623. const Buffer& dst,
  5624. const size_t<3>& src_origin,
  5625. const size_t<3>& dst_origin,
  5626. const size_t<3>& region,
  5627. ::size_t src_row_pitch,
  5628. ::size_t src_slice_pitch,
  5629. ::size_t dst_row_pitch,
  5630. ::size_t dst_slice_pitch,
  5631. const VECTOR_CLASS<Event>* events = NULL,
  5632. Event* event = NULL)
  5633. {
  5634. cl_int error;
  5635. CommandQueue queue = CommandQueue::getDefault(&error);
  5636. if (error != CL_SUCCESS) {
  5637. return error;
  5638. }
  5639. return queue.enqueueCopyBufferRect(
  5640. src,
  5641. dst,
  5642. src_origin,
  5643. dst_origin,
  5644. region,
  5645. src_row_pitch,
  5646. src_slice_pitch,
  5647. dst_row_pitch,
  5648. dst_slice_pitch,
  5649. events,
  5650. event);
  5651. }
  5652. #endif
  5653. inline cl_int enqueueReadImage(
  5654. const Image& image,
  5655. cl_bool blocking,
  5656. const size_t<3>& origin,
  5657. const size_t<3>& region,
  5658. ::size_t row_pitch,
  5659. ::size_t slice_pitch,
  5660. void* ptr,
  5661. const VECTOR_CLASS<Event>* events = NULL,
  5662. Event* event = NULL)
  5663. {
  5664. cl_int error;
  5665. CommandQueue queue = CommandQueue::getDefault(&error);
  5666. if (error != CL_SUCCESS) {
  5667. return error;
  5668. }
  5669. return queue.enqueueReadImage(
  5670. image,
  5671. blocking,
  5672. origin,
  5673. region,
  5674. row_pitch,
  5675. slice_pitch,
  5676. ptr,
  5677. events,
  5678. event);
  5679. }
  5680. inline cl_int enqueueWriteImage(
  5681. const Image& image,
  5682. cl_bool blocking,
  5683. const size_t<3>& origin,
  5684. const size_t<3>& region,
  5685. ::size_t row_pitch,
  5686. ::size_t slice_pitch,
  5687. void* ptr,
  5688. const VECTOR_CLASS<Event>* events = NULL,
  5689. Event* event = NULL)
  5690. {
  5691. cl_int error;
  5692. CommandQueue queue = CommandQueue::getDefault(&error);
  5693. if (error != CL_SUCCESS) {
  5694. return error;
  5695. }
  5696. return queue.enqueueWriteImage(
  5697. image,
  5698. blocking,
  5699. origin,
  5700. region,
  5701. row_pitch,
  5702. slice_pitch,
  5703. ptr,
  5704. events,
  5705. event);
  5706. }
  5707. inline cl_int enqueueCopyImage(
  5708. const Image& src,
  5709. const Image& dst,
  5710. const size_t<3>& src_origin,
  5711. const size_t<3>& dst_origin,
  5712. const size_t<3>& region,
  5713. const VECTOR_CLASS<Event>* events = NULL,
  5714. Event* event = NULL)
  5715. {
  5716. cl_int error;
  5717. CommandQueue queue = CommandQueue::getDefault(&error);
  5718. if (error != CL_SUCCESS) {
  5719. return error;
  5720. }
  5721. return queue.enqueueCopyImage(
  5722. src,
  5723. dst,
  5724. src_origin,
  5725. dst_origin,
  5726. region,
  5727. events,
  5728. event);
  5729. }
  5730. inline cl_int enqueueCopyImageToBuffer(
  5731. const Image& src,
  5732. const Buffer& dst,
  5733. const size_t<3>& src_origin,
  5734. const size_t<3>& region,
  5735. ::size_t dst_offset,
  5736. const VECTOR_CLASS<Event>* events = NULL,
  5737. Event* event = NULL)
  5738. {
  5739. cl_int error;
  5740. CommandQueue queue = CommandQueue::getDefault(&error);
  5741. if (error != CL_SUCCESS) {
  5742. return error;
  5743. }
  5744. return queue.enqueueCopyImageToBuffer(
  5745. src,
  5746. dst,
  5747. src_origin,
  5748. region,
  5749. dst_offset,
  5750. events,
  5751. event);
  5752. }
  5753. inline cl_int enqueueCopyBufferToImage(
  5754. const Buffer& src,
  5755. const Image& dst,
  5756. ::size_t src_offset,
  5757. const size_t<3>& dst_origin,
  5758. const size_t<3>& region,
  5759. const VECTOR_CLASS<Event>* events = NULL,
  5760. Event* event = NULL)
  5761. {
  5762. cl_int error;
  5763. CommandQueue queue = CommandQueue::getDefault(&error);
  5764. if (error != CL_SUCCESS) {
  5765. return error;
  5766. }
  5767. return queue.enqueueCopyBufferToImage(
  5768. src,
  5769. dst,
  5770. src_offset,
  5771. dst_origin,
  5772. region,
  5773. events,
  5774. event);
  5775. }
  5776. inline cl_int flush(void)
  5777. {
  5778. cl_int error;
  5779. CommandQueue queue = CommandQueue::getDefault(&error);
  5780. if (error != CL_SUCCESS) {
  5781. return error;
  5782. }
  5783. return queue.flush();
  5784. }
  5785. inline cl_int finish(void)
  5786. {
  5787. cl_int error;
  5788. CommandQueue queue = CommandQueue::getDefault(&error);
  5789. if (error != CL_SUCCESS) {
  5790. return error;
  5791. }
  5792. return queue.finish();
  5793. }
  5794. // Kernel Functor support
  5795. // New interface as of September 2011
  5796. // Requires the C++11 std::tr1::function (note do not support TR1)
  5797. // Visual Studio 2010 and GCC 4.2
  5798. struct EnqueueArgs
  5799. {
  5800. CommandQueue queue_;
  5801. const NDRange offset_;
  5802. const NDRange global_;
  5803. const NDRange local_;
  5804. VECTOR_CLASS<Event> events_;
  5805. EnqueueArgs(NDRange global) :
  5806. queue_(CommandQueue::getDefault()),
  5807. offset_(NullRange),
  5808. global_(global),
  5809. local_(NullRange)
  5810. {
  5811. }
  5812. EnqueueArgs(NDRange global, NDRange local) :
  5813. queue_(CommandQueue::getDefault()),
  5814. offset_(NullRange),
  5815. global_(global),
  5816. local_(local)
  5817. {
  5818. }
  5819. EnqueueArgs(NDRange offset, NDRange global, NDRange local) :
  5820. queue_(CommandQueue::getDefault()),
  5821. offset_(offset),
  5822. global_(global),
  5823. local_(local)
  5824. {
  5825. }
  5826. EnqueueArgs(Event e, NDRange global) :
  5827. queue_(CommandQueue::getDefault()),
  5828. offset_(NullRange),
  5829. global_(global),
  5830. local_(NullRange)
  5831. {
  5832. events_.push_back(e);
  5833. }
  5834. EnqueueArgs(Event e, NDRange global, NDRange local) :
  5835. queue_(CommandQueue::getDefault()),
  5836. offset_(NullRange),
  5837. global_(global),
  5838. local_(local)
  5839. {
  5840. events_.push_back(e);
  5841. }
  5842. EnqueueArgs(Event e, NDRange offset, NDRange global, NDRange local) :
  5843. queue_(CommandQueue::getDefault()),
  5844. offset_(offset),
  5845. global_(global),
  5846. local_(local)
  5847. {
  5848. events_.push_back(e);
  5849. }
  5850. EnqueueArgs(const VECTOR_CLASS<Event> &events, NDRange global) :
  5851. queue_(CommandQueue::getDefault()),
  5852. offset_(NullRange),
  5853. global_(global),
  5854. local_(NullRange),
  5855. events_(events)
  5856. {
  5857. }
  5858. EnqueueArgs(const VECTOR_CLASS<Event> &events, NDRange global, NDRange local) :
  5859. queue_(CommandQueue::getDefault()),
  5860. offset_(NullRange),
  5861. global_(global),
  5862. local_(local),
  5863. events_(events)
  5864. {
  5865. }
  5866. EnqueueArgs(const VECTOR_CLASS<Event> &events, NDRange offset, NDRange global, NDRange local) :
  5867. queue_(CommandQueue::getDefault()),
  5868. offset_(offset),
  5869. global_(global),
  5870. local_(local),
  5871. events_(events)
  5872. {
  5873. }
  5874. EnqueueArgs(CommandQueue &queue, NDRange global) :
  5875. queue_(queue),
  5876. offset_(NullRange),
  5877. global_(global),
  5878. local_(NullRange)
  5879. {
  5880. }
  5881. EnqueueArgs(CommandQueue &queue, NDRange global, NDRange local) :
  5882. queue_(queue),
  5883. offset_(NullRange),
  5884. global_(global),
  5885. local_(local)
  5886. {
  5887. }
  5888. EnqueueArgs(CommandQueue &queue, NDRange offset, NDRange global, NDRange local) :
  5889. queue_(queue),
  5890. offset_(offset),
  5891. global_(global),
  5892. local_(local)
  5893. {
  5894. }
  5895. EnqueueArgs(CommandQueue &queue, Event e, NDRange global) :
  5896. queue_(queue),
  5897. offset_(NullRange),
  5898. global_(global),
  5899. local_(NullRange)
  5900. {
  5901. events_.push_back(e);
  5902. }
  5903. EnqueueArgs(CommandQueue &queue, Event e, NDRange global, NDRange local) :
  5904. queue_(queue),
  5905. offset_(NullRange),
  5906. global_(global),
  5907. local_(local)
  5908. {
  5909. events_.push_back(e);
  5910. }
  5911. EnqueueArgs(CommandQueue &queue, Event e, NDRange offset, NDRange global, NDRange local) :
  5912. queue_(queue),
  5913. offset_(offset),
  5914. global_(global),
  5915. local_(local)
  5916. {
  5917. events_.push_back(e);
  5918. }
  5919. EnqueueArgs(CommandQueue &queue, const VECTOR_CLASS<Event> &events, NDRange global) :
  5920. queue_(queue),
  5921. offset_(NullRange),
  5922. global_(global),
  5923. local_(NullRange),
  5924. events_(events)
  5925. {
  5926. }
  5927. EnqueueArgs(CommandQueue &queue, const VECTOR_CLASS<Event> &events, NDRange global, NDRange local) :
  5928. queue_(queue),
  5929. offset_(NullRange),
  5930. global_(global),
  5931. local_(local),
  5932. events_(events)
  5933. {
  5934. }
  5935. EnqueueArgs(CommandQueue &queue, const VECTOR_CLASS<Event> &events, NDRange offset, NDRange global, NDRange local) :
  5936. queue_(queue),
  5937. offset_(offset),
  5938. global_(global),
  5939. local_(local),
  5940. events_(events)
  5941. {
  5942. }
  5943. };
  5944. namespace detail {
  5945. class NullType {};
  5946. template<int index, typename T0>
  5947. struct SetArg
  5948. {
  5949. static void set (Kernel kernel, T0 arg)
  5950. {
  5951. kernel.setArg(index, arg);
  5952. }
  5953. };
  5954. template<int index>
  5955. struct SetArg<index, NullType>
  5956. {
  5957. static void set (Kernel, NullType)
  5958. {
  5959. }
  5960. };
  5961. template <
  5962. typename T0, typename T1, typename T2, typename T3,
  5963. typename T4, typename T5, typename T6, typename T7,
  5964. typename T8, typename T9, typename T10, typename T11,
  5965. typename T12, typename T13, typename T14, typename T15,
  5966. typename T16, typename T17, typename T18, typename T19,
  5967. typename T20, typename T21, typename T22, typename T23,
  5968. typename T24, typename T25, typename T26, typename T27,
  5969. typename T28, typename T29, typename T30, typename T31
  5970. >
  5971. class KernelFunctorGlobal
  5972. {
  5973. private:
  5974. Kernel kernel_;
  5975. public:
  5976. KernelFunctorGlobal(
  5977. Kernel kernel) :
  5978. kernel_(kernel)
  5979. {}
  5980. KernelFunctorGlobal(
  5981. const Program& program,
  5982. const STRING_CLASS name,
  5983. cl_int * err = NULL) :
  5984. kernel_(program, name.c_str(), err)
  5985. {}
  5986. Event operator() (
  5987. const EnqueueArgs& args,
  5988. T0 t0,
  5989. T1 t1 = NullType(),
  5990. T2 t2 = NullType(),
  5991. T3 t3 = NullType(),
  5992. T4 t4 = NullType(),
  5993. T5 t5 = NullType(),
  5994. T6 t6 = NullType(),
  5995. T7 t7 = NullType(),
  5996. T8 t8 = NullType(),
  5997. T9 t9 = NullType(),
  5998. T10 t10 = NullType(),
  5999. T11 t11 = NullType(),
  6000. T12 t12 = NullType(),
  6001. T13 t13 = NullType(),
  6002. T14 t14 = NullType(),
  6003. T15 t15 = NullType(),
  6004. T16 t16 = NullType(),
  6005. T17 t17 = NullType(),
  6006. T18 t18 = NullType(),
  6007. T19 t19 = NullType(),
  6008. T20 t20 = NullType(),
  6009. T21 t21 = NullType(),
  6010. T22 t22 = NullType(),
  6011. T23 t23 = NullType(),
  6012. T24 t24 = NullType(),
  6013. T25 t25 = NullType(),
  6014. T26 t26 = NullType(),
  6015. T27 t27 = NullType(),
  6016. T28 t28 = NullType(),
  6017. T29 t29 = NullType(),
  6018. T30 t30 = NullType(),
  6019. T31 t31 = NullType()
  6020. )
  6021. {
  6022. Event event;
  6023. SetArg<0, T0>::set(kernel_, t0);
  6024. SetArg<1, T1>::set(kernel_, t1);
  6025. SetArg<2, T2>::set(kernel_, t2);
  6026. SetArg<3, T3>::set(kernel_, t3);
  6027. SetArg<4, T4>::set(kernel_, t4);
  6028. SetArg<5, T5>::set(kernel_, t5);
  6029. SetArg<6, T6>::set(kernel_, t6);
  6030. SetArg<7, T7>::set(kernel_, t7);
  6031. SetArg<8, T8>::set(kernel_, t8);
  6032. SetArg<9, T9>::set(kernel_, t9);
  6033. SetArg<10, T10>::set(kernel_, t10);
  6034. SetArg<11, T11>::set(kernel_, t11);
  6035. SetArg<12, T12>::set(kernel_, t12);
  6036. SetArg<13, T13>::set(kernel_, t13);
  6037. SetArg<14, T14>::set(kernel_, t14);
  6038. SetArg<15, T15>::set(kernel_, t15);
  6039. SetArg<16, T16>::set(kernel_, t16);
  6040. SetArg<17, T17>::set(kernel_, t17);
  6041. SetArg<18, T18>::set(kernel_, t18);
  6042. SetArg<19, T19>::set(kernel_, t19);
  6043. SetArg<20, T20>::set(kernel_, t20);
  6044. SetArg<21, T21>::set(kernel_, t21);
  6045. SetArg<22, T22>::set(kernel_, t22);
  6046. SetArg<23, T23>::set(kernel_, t23);
  6047. SetArg<24, T24>::set(kernel_, t24);
  6048. SetArg<25, T25>::set(kernel_, t25);
  6049. SetArg<26, T26>::set(kernel_, t26);
  6050. SetArg<27, T27>::set(kernel_, t27);
  6051. SetArg<28, T28>::set(kernel_, t28);
  6052. SetArg<29, T29>::set(kernel_, t29);
  6053. SetArg<30, T30>::set(kernel_, t30);
  6054. SetArg<31, T31>::set(kernel_, t31);
  6055. args.queue_.enqueueNDRangeKernel(
  6056. kernel_,
  6057. args.offset_,
  6058. args.global_,
  6059. args.local_,
  6060. &args.events_,
  6061. &event);
  6062. return event;
  6063. }
  6064. };
  6065. //------------------------------------------------------------------------------------------------------
  6066. template<
  6067. typename T0,
  6068. typename T1,
  6069. typename T2,
  6070. typename T3,
  6071. typename T4,
  6072. typename T5,
  6073. typename T6,
  6074. typename T7,
  6075. typename T8,
  6076. typename T9,
  6077. typename T10,
  6078. typename T11,
  6079. typename T12,
  6080. typename T13,
  6081. typename T14,
  6082. typename T15,
  6083. typename T16,
  6084. typename T17,
  6085. typename T18,
  6086. typename T19,
  6087. typename T20,
  6088. typename T21,
  6089. typename T22,
  6090. typename T23,
  6091. typename T24,
  6092. typename T25,
  6093. typename T26,
  6094. typename T27,
  6095. typename T28,
  6096. typename T29,
  6097. typename T30,
  6098. typename T31>
  6099. struct functionImplementation_
  6100. {
  6101. typedef detail::KernelFunctorGlobal<
  6102. T0,
  6103. T1,
  6104. T2,
  6105. T3,
  6106. T4,
  6107. T5,
  6108. T6,
  6109. T7,
  6110. T8,
  6111. T9,
  6112. T10,
  6113. T11,
  6114. T12,
  6115. T13,
  6116. T14,
  6117. T15,
  6118. T16,
  6119. T17,
  6120. T18,
  6121. T19,
  6122. T20,
  6123. T21,
  6124. T22,
  6125. T23,
  6126. T24,
  6127. T25,
  6128. T26,
  6129. T27,
  6130. T28,
  6131. T29,
  6132. T30,
  6133. T31> FunctorType;
  6134. FunctorType functor_;
  6135. functionImplementation_(const FunctorType &functor) :
  6136. functor_(functor)
  6137. {
  6138. #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 32))
  6139. // Fail variadic expansion for dev11
  6140. static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
  6141. #endif
  6142. }
  6143. //! \brief Return type of the functor
  6144. typedef Event result_type;
  6145. //! \brief Function signature of kernel functor with no event dependency.
  6146. typedef Event type_(
  6147. const EnqueueArgs&,
  6148. T0,
  6149. T1,
  6150. T2,
  6151. T3,
  6152. T4,
  6153. T5,
  6154. T6,
  6155. T7,
  6156. T8,
  6157. T9,
  6158. T10,
  6159. T11,
  6160. T12,
  6161. T13,
  6162. T14,
  6163. T15,
  6164. T16,
  6165. T17,
  6166. T18,
  6167. T19,
  6168. T20,
  6169. T21,
  6170. T22,
  6171. T23,
  6172. T24,
  6173. T25,
  6174. T26,
  6175. T27,
  6176. T28,
  6177. T29,
  6178. T30,
  6179. T31);
  6180. Event operator()(
  6181. const EnqueueArgs& enqueueArgs,
  6182. T0 arg0,
  6183. T1 arg1,
  6184. T2 arg2,
  6185. T3 arg3,
  6186. T4 arg4,
  6187. T5 arg5,
  6188. T6 arg6,
  6189. T7 arg7,
  6190. T8 arg8,
  6191. T9 arg9,
  6192. T10 arg10,
  6193. T11 arg11,
  6194. T12 arg12,
  6195. T13 arg13,
  6196. T14 arg14,
  6197. T15 arg15,
  6198. T16 arg16,
  6199. T17 arg17,
  6200. T18 arg18,
  6201. T19 arg19,
  6202. T20 arg20,
  6203. T21 arg21,
  6204. T22 arg22,
  6205. T23 arg23,
  6206. T24 arg24,
  6207. T25 arg25,
  6208. T26 arg26,
  6209. T27 arg27,
  6210. T28 arg28,
  6211. T29 arg29,
  6212. T30 arg30,
  6213. T31 arg31)
  6214. {
  6215. return functor_(
  6216. enqueueArgs,
  6217. arg0,
  6218. arg1,
  6219. arg2,
  6220. arg3,
  6221. arg4,
  6222. arg5,
  6223. arg6,
  6224. arg7,
  6225. arg8,
  6226. arg9,
  6227. arg10,
  6228. arg11,
  6229. arg12,
  6230. arg13,
  6231. arg14,
  6232. arg15,
  6233. arg16,
  6234. arg17,
  6235. arg18,
  6236. arg19,
  6237. arg20,
  6238. arg21,
  6239. arg22,
  6240. arg23,
  6241. arg24,
  6242. arg25,
  6243. arg26,
  6244. arg27,
  6245. arg28,
  6246. arg29,
  6247. arg30,
  6248. arg31);
  6249. }
  6250. };
  6251. template<
  6252. typename T0,
  6253. typename T1,
  6254. typename T2,
  6255. typename T3,
  6256. typename T4,
  6257. typename T5,
  6258. typename T6,
  6259. typename T7,
  6260. typename T8,
  6261. typename T9,
  6262. typename T10,
  6263. typename T11,
  6264. typename T12,
  6265. typename T13,
  6266. typename T14,
  6267. typename T15,
  6268. typename T16,
  6269. typename T17,
  6270. typename T18,
  6271. typename T19,
  6272. typename T20,
  6273. typename T21,
  6274. typename T22,
  6275. typename T23,
  6276. typename T24,
  6277. typename T25,
  6278. typename T26,
  6279. typename T27,
  6280. typename T28,
  6281. typename T29,
  6282. typename T30>
  6283. struct functionImplementation_
  6284. < T0,
  6285. T1,
  6286. T2,
  6287. T3,
  6288. T4,
  6289. T5,
  6290. T6,
  6291. T7,
  6292. T8,
  6293. T9,
  6294. T10,
  6295. T11,
  6296. T12,
  6297. T13,
  6298. T14,
  6299. T15,
  6300. T16,
  6301. T17,
  6302. T18,
  6303. T19,
  6304. T20,
  6305. T21,
  6306. T22,
  6307. T23,
  6308. T24,
  6309. T25,
  6310. T26,
  6311. T27,
  6312. T28,
  6313. T29,
  6314. T30,
  6315. NullType>
  6316. {
  6317. typedef detail::KernelFunctorGlobal<
  6318. T0,
  6319. T1,
  6320. T2,
  6321. T3,
  6322. T4,
  6323. T5,
  6324. T6,
  6325. T7,
  6326. T8,
  6327. T9,
  6328. T10,
  6329. T11,
  6330. T12,
  6331. T13,
  6332. T14,
  6333. T15,
  6334. T16,
  6335. T17,
  6336. T18,
  6337. T19,
  6338. T20,
  6339. T21,
  6340. T22,
  6341. T23,
  6342. T24,
  6343. T25,
  6344. T26,
  6345. T27,
  6346. T28,
  6347. T29,
  6348. T30,
  6349. NullType> FunctorType;
  6350. FunctorType functor_;
  6351. functionImplementation_(const FunctorType &functor) :
  6352. functor_(functor)
  6353. {
  6354. #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 31))
  6355. // Fail variadic expansion for dev11
  6356. static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
  6357. #endif
  6358. }
  6359. //! \brief Return type of the functor
  6360. typedef Event result_type;
  6361. //! \brief Function signature of kernel functor with no event dependency.
  6362. typedef Event type_(
  6363. const EnqueueArgs&,
  6364. T0,
  6365. T1,
  6366. T2,
  6367. T3,
  6368. T4,
  6369. T5,
  6370. T6,
  6371. T7,
  6372. T8,
  6373. T9,
  6374. T10,
  6375. T11,
  6376. T12,
  6377. T13,
  6378. T14,
  6379. T15,
  6380. T16,
  6381. T17,
  6382. T18,
  6383. T19,
  6384. T20,
  6385. T21,
  6386. T22,
  6387. T23,
  6388. T24,
  6389. T25,
  6390. T26,
  6391. T27,
  6392. T28,
  6393. T29,
  6394. T30);
  6395. Event operator()(
  6396. const EnqueueArgs& enqueueArgs,
  6397. T0 arg0,
  6398. T1 arg1,
  6399. T2 arg2,
  6400. T3 arg3,
  6401. T4 arg4,
  6402. T5 arg5,
  6403. T6 arg6,
  6404. T7 arg7,
  6405. T8 arg8,
  6406. T9 arg9,
  6407. T10 arg10,
  6408. T11 arg11,
  6409. T12 arg12,
  6410. T13 arg13,
  6411. T14 arg14,
  6412. T15 arg15,
  6413. T16 arg16,
  6414. T17 arg17,
  6415. T18 arg18,
  6416. T19 arg19,
  6417. T20 arg20,
  6418. T21 arg21,
  6419. T22 arg22,
  6420. T23 arg23,
  6421. T24 arg24,
  6422. T25 arg25,
  6423. T26 arg26,
  6424. T27 arg27,
  6425. T28 arg28,
  6426. T29 arg29,
  6427. T30 arg30)
  6428. {
  6429. return functor_(
  6430. enqueueArgs,
  6431. arg0,
  6432. arg1,
  6433. arg2,
  6434. arg3,
  6435. arg4,
  6436. arg5,
  6437. arg6,
  6438. arg7,
  6439. arg8,
  6440. arg9,
  6441. arg10,
  6442. arg11,
  6443. arg12,
  6444. arg13,
  6445. arg14,
  6446. arg15,
  6447. arg16,
  6448. arg17,
  6449. arg18,
  6450. arg19,
  6451. arg20,
  6452. arg21,
  6453. arg22,
  6454. arg23,
  6455. arg24,
  6456. arg25,
  6457. arg26,
  6458. arg27,
  6459. arg28,
  6460. arg29,
  6461. arg30);
  6462. }
  6463. };
  6464. template<
  6465. typename T0,
  6466. typename T1,
  6467. typename T2,
  6468. typename T3,
  6469. typename T4,
  6470. typename T5,
  6471. typename T6,
  6472. typename T7,
  6473. typename T8,
  6474. typename T9,
  6475. typename T10,
  6476. typename T11,
  6477. typename T12,
  6478. typename T13,
  6479. typename T14,
  6480. typename T15,
  6481. typename T16,
  6482. typename T17,
  6483. typename T18,
  6484. typename T19,
  6485. typename T20,
  6486. typename T21,
  6487. typename T22,
  6488. typename T23,
  6489. typename T24,
  6490. typename T25,
  6491. typename T26,
  6492. typename T27,
  6493. typename T28,
  6494. typename T29>
  6495. struct functionImplementation_
  6496. < T0,
  6497. T1,
  6498. T2,
  6499. T3,
  6500. T4,
  6501. T5,
  6502. T6,
  6503. T7,
  6504. T8,
  6505. T9,
  6506. T10,
  6507. T11,
  6508. T12,
  6509. T13,
  6510. T14,
  6511. T15,
  6512. T16,
  6513. T17,
  6514. T18,
  6515. T19,
  6516. T20,
  6517. T21,
  6518. T22,
  6519. T23,
  6520. T24,
  6521. T25,
  6522. T26,
  6523. T27,
  6524. T28,
  6525. T29,
  6526. NullType,
  6527. NullType>
  6528. {
  6529. typedef detail::KernelFunctorGlobal<
  6530. T0,
  6531. T1,
  6532. T2,
  6533. T3,
  6534. T4,
  6535. T5,
  6536. T6,
  6537. T7,
  6538. T8,
  6539. T9,
  6540. T10,
  6541. T11,
  6542. T12,
  6543. T13,
  6544. T14,
  6545. T15,
  6546. T16,
  6547. T17,
  6548. T18,
  6549. T19,
  6550. T20,
  6551. T21,
  6552. T22,
  6553. T23,
  6554. T24,
  6555. T25,
  6556. T26,
  6557. T27,
  6558. T28,
  6559. T29,
  6560. NullType,
  6561. NullType> FunctorType;
  6562. FunctorType functor_;
  6563. functionImplementation_(const FunctorType &functor) :
  6564. functor_(functor)
  6565. {
  6566. #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 30))
  6567. // Fail variadic expansion for dev11
  6568. static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
  6569. #endif
  6570. }
  6571. //! \brief Return type of the functor
  6572. typedef Event result_type;
  6573. //! \brief Function signature of kernel functor with no event dependency.
  6574. typedef Event type_(
  6575. const EnqueueArgs&,
  6576. T0,
  6577. T1,
  6578. T2,
  6579. T3,
  6580. T4,
  6581. T5,
  6582. T6,
  6583. T7,
  6584. T8,
  6585. T9,
  6586. T10,
  6587. T11,
  6588. T12,
  6589. T13,
  6590. T14,
  6591. T15,
  6592. T16,
  6593. T17,
  6594. T18,
  6595. T19,
  6596. T20,
  6597. T21,
  6598. T22,
  6599. T23,
  6600. T24,
  6601. T25,
  6602. T26,
  6603. T27,
  6604. T28,
  6605. T29);
  6606. Event operator()(
  6607. const EnqueueArgs& enqueueArgs,
  6608. T0 arg0,
  6609. T1 arg1,
  6610. T2 arg2,
  6611. T3 arg3,
  6612. T4 arg4,
  6613. T5 arg5,
  6614. T6 arg6,
  6615. T7 arg7,
  6616. T8 arg8,
  6617. T9 arg9,
  6618. T10 arg10,
  6619. T11 arg11,
  6620. T12 arg12,
  6621. T13 arg13,
  6622. T14 arg14,
  6623. T15 arg15,
  6624. T16 arg16,
  6625. T17 arg17,
  6626. T18 arg18,
  6627. T19 arg19,
  6628. T20 arg20,
  6629. T21 arg21,
  6630. T22 arg22,
  6631. T23 arg23,
  6632. T24 arg24,
  6633. T25 arg25,
  6634. T26 arg26,
  6635. T27 arg27,
  6636. T28 arg28,
  6637. T29 arg29)
  6638. {
  6639. return functor_(
  6640. enqueueArgs,
  6641. arg0,
  6642. arg1,
  6643. arg2,
  6644. arg3,
  6645. arg4,
  6646. arg5,
  6647. arg6,
  6648. arg7,
  6649. arg8,
  6650. arg9,
  6651. arg10,
  6652. arg11,
  6653. arg12,
  6654. arg13,
  6655. arg14,
  6656. arg15,
  6657. arg16,
  6658. arg17,
  6659. arg18,
  6660. arg19,
  6661. arg20,
  6662. arg21,
  6663. arg22,
  6664. arg23,
  6665. arg24,
  6666. arg25,
  6667. arg26,
  6668. arg27,
  6669. arg28,
  6670. arg29);
  6671. }
  6672. };
  6673. template<
  6674. typename T0,
  6675. typename T1,
  6676. typename T2,
  6677. typename T3,
  6678. typename T4,
  6679. typename T5,
  6680. typename T6,
  6681. typename T7,
  6682. typename T8,
  6683. typename T9,
  6684. typename T10,
  6685. typename T11,
  6686. typename T12,
  6687. typename T13,
  6688. typename T14,
  6689. typename T15,
  6690. typename T16,
  6691. typename T17,
  6692. typename T18,
  6693. typename T19,
  6694. typename T20,
  6695. typename T21,
  6696. typename T22,
  6697. typename T23,
  6698. typename T24,
  6699. typename T25,
  6700. typename T26,
  6701. typename T27,
  6702. typename T28>
  6703. struct functionImplementation_
  6704. < T0,
  6705. T1,
  6706. T2,
  6707. T3,
  6708. T4,
  6709. T5,
  6710. T6,
  6711. T7,
  6712. T8,
  6713. T9,
  6714. T10,
  6715. T11,
  6716. T12,
  6717. T13,
  6718. T14,
  6719. T15,
  6720. T16,
  6721. T17,
  6722. T18,
  6723. T19,
  6724. T20,
  6725. T21,
  6726. T22,
  6727. T23,
  6728. T24,
  6729. T25,
  6730. T26,
  6731. T27,
  6732. T28,
  6733. NullType,
  6734. NullType,
  6735. NullType>
  6736. {
  6737. typedef detail::KernelFunctorGlobal<
  6738. T0,
  6739. T1,
  6740. T2,
  6741. T3,
  6742. T4,
  6743. T5,
  6744. T6,
  6745. T7,
  6746. T8,
  6747. T9,
  6748. T10,
  6749. T11,
  6750. T12,
  6751. T13,
  6752. T14,
  6753. T15,
  6754. T16,
  6755. T17,
  6756. T18,
  6757. T19,
  6758. T20,
  6759. T21,
  6760. T22,
  6761. T23,
  6762. T24,
  6763. T25,
  6764. T26,
  6765. T27,
  6766. T28,
  6767. NullType,
  6768. NullType,
  6769. NullType> FunctorType;
  6770. FunctorType functor_;
  6771. functionImplementation_(const FunctorType &functor) :
  6772. functor_(functor)
  6773. {
  6774. #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 29))
  6775. // Fail variadic expansion for dev11
  6776. static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
  6777. #endif
  6778. }
  6779. //! \brief Return type of the functor
  6780. typedef Event result_type;
  6781. //! \brief Function signature of kernel functor with no event dependency.
  6782. typedef Event type_(
  6783. const EnqueueArgs&,
  6784. T0,
  6785. T1,
  6786. T2,
  6787. T3,
  6788. T4,
  6789. T5,
  6790. T6,
  6791. T7,
  6792. T8,
  6793. T9,
  6794. T10,
  6795. T11,
  6796. T12,
  6797. T13,
  6798. T14,
  6799. T15,
  6800. T16,
  6801. T17,
  6802. T18,
  6803. T19,
  6804. T20,
  6805. T21,
  6806. T22,
  6807. T23,
  6808. T24,
  6809. T25,
  6810. T26,
  6811. T27,
  6812. T28);
  6813. Event operator()(
  6814. const EnqueueArgs& enqueueArgs,
  6815. T0 arg0,
  6816. T1 arg1,
  6817. T2 arg2,
  6818. T3 arg3,
  6819. T4 arg4,
  6820. T5 arg5,
  6821. T6 arg6,
  6822. T7 arg7,
  6823. T8 arg8,
  6824. T9 arg9,
  6825. T10 arg10,
  6826. T11 arg11,
  6827. T12 arg12,
  6828. T13 arg13,
  6829. T14 arg14,
  6830. T15 arg15,
  6831. T16 arg16,
  6832. T17 arg17,
  6833. T18 arg18,
  6834. T19 arg19,
  6835. T20 arg20,
  6836. T21 arg21,
  6837. T22 arg22,
  6838. T23 arg23,
  6839. T24 arg24,
  6840. T25 arg25,
  6841. T26 arg26,
  6842. T27 arg27,
  6843. T28 arg28)
  6844. {
  6845. return functor_(
  6846. enqueueArgs,
  6847. arg0,
  6848. arg1,
  6849. arg2,
  6850. arg3,
  6851. arg4,
  6852. arg5,
  6853. arg6,
  6854. arg7,
  6855. arg8,
  6856. arg9,
  6857. arg10,
  6858. arg11,
  6859. arg12,
  6860. arg13,
  6861. arg14,
  6862. arg15,
  6863. arg16,
  6864. arg17,
  6865. arg18,
  6866. arg19,
  6867. arg20,
  6868. arg21,
  6869. arg22,
  6870. arg23,
  6871. arg24,
  6872. arg25,
  6873. arg26,
  6874. arg27,
  6875. arg28);
  6876. }
  6877. };
  6878. template<
  6879. typename T0,
  6880. typename T1,
  6881. typename T2,
  6882. typename T3,
  6883. typename T4,
  6884. typename T5,
  6885. typename T6,
  6886. typename T7,
  6887. typename T8,
  6888. typename T9,
  6889. typename T10,
  6890. typename T11,
  6891. typename T12,
  6892. typename T13,
  6893. typename T14,
  6894. typename T15,
  6895. typename T16,
  6896. typename T17,
  6897. typename T18,
  6898. typename T19,
  6899. typename T20,
  6900. typename T21,
  6901. typename T22,
  6902. typename T23,
  6903. typename T24,
  6904. typename T25,
  6905. typename T26,
  6906. typename T27>
  6907. struct functionImplementation_
  6908. < T0,
  6909. T1,
  6910. T2,
  6911. T3,
  6912. T4,
  6913. T5,
  6914. T6,
  6915. T7,
  6916. T8,
  6917. T9,
  6918. T10,
  6919. T11,
  6920. T12,
  6921. T13,
  6922. T14,
  6923. T15,
  6924. T16,
  6925. T17,
  6926. T18,
  6927. T19,
  6928. T20,
  6929. T21,
  6930. T22,
  6931. T23,
  6932. T24,
  6933. T25,
  6934. T26,
  6935. T27,
  6936. NullType,
  6937. NullType,
  6938. NullType,
  6939. NullType>
  6940. {
  6941. typedef detail::KernelFunctorGlobal<
  6942. T0,
  6943. T1,
  6944. T2,
  6945. T3,
  6946. T4,
  6947. T5,
  6948. T6,
  6949. T7,
  6950. T8,
  6951. T9,
  6952. T10,
  6953. T11,
  6954. T12,
  6955. T13,
  6956. T14,
  6957. T15,
  6958. T16,
  6959. T17,
  6960. T18,
  6961. T19,
  6962. T20,
  6963. T21,
  6964. T22,
  6965. T23,
  6966. T24,
  6967. T25,
  6968. T26,
  6969. T27,
  6970. NullType,
  6971. NullType,
  6972. NullType,
  6973. NullType> FunctorType;
  6974. FunctorType functor_;
  6975. functionImplementation_(const FunctorType &functor) :
  6976. functor_(functor)
  6977. {
  6978. #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 28))
  6979. // Fail variadic expansion for dev11
  6980. static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
  6981. #endif
  6982. }
  6983. //! \brief Return type of the functor
  6984. typedef Event result_type;
  6985. //! \brief Function signature of kernel functor with no event dependency.
  6986. typedef Event type_(
  6987. const EnqueueArgs&,
  6988. T0,
  6989. T1,
  6990. T2,
  6991. T3,
  6992. T4,
  6993. T5,
  6994. T6,
  6995. T7,
  6996. T8,
  6997. T9,
  6998. T10,
  6999. T11,
  7000. T12,
  7001. T13,
  7002. T14,
  7003. T15,
  7004. T16,
  7005. T17,
  7006. T18,
  7007. T19,
  7008. T20,
  7009. T21,
  7010. T22,
  7011. T23,
  7012. T24,
  7013. T25,
  7014. T26,
  7015. T27);
  7016. Event operator()(
  7017. const EnqueueArgs& enqueueArgs,
  7018. T0 arg0,
  7019. T1 arg1,
  7020. T2 arg2,
  7021. T3 arg3,
  7022. T4 arg4,
  7023. T5 arg5,
  7024. T6 arg6,
  7025. T7 arg7,
  7026. T8 arg8,
  7027. T9 arg9,
  7028. T10 arg10,
  7029. T11 arg11,
  7030. T12 arg12,
  7031. T13 arg13,
  7032. T14 arg14,
  7033. T15 arg15,
  7034. T16 arg16,
  7035. T17 arg17,
  7036. T18 arg18,
  7037. T19 arg19,
  7038. T20 arg20,
  7039. T21 arg21,
  7040. T22 arg22,
  7041. T23 arg23,
  7042. T24 arg24,
  7043. T25 arg25,
  7044. T26 arg26,
  7045. T27 arg27)
  7046. {
  7047. return functor_(
  7048. enqueueArgs,
  7049. arg0,
  7050. arg1,
  7051. arg2,
  7052. arg3,
  7053. arg4,
  7054. arg5,
  7055. arg6,
  7056. arg7,
  7057. arg8,
  7058. arg9,
  7059. arg10,
  7060. arg11,
  7061. arg12,
  7062. arg13,
  7063. arg14,
  7064. arg15,
  7065. arg16,
  7066. arg17,
  7067. arg18,
  7068. arg19,
  7069. arg20,
  7070. arg21,
  7071. arg22,
  7072. arg23,
  7073. arg24,
  7074. arg25,
  7075. arg26,
  7076. arg27);
  7077. }
  7078. };
  7079. template<
  7080. typename T0,
  7081. typename T1,
  7082. typename T2,
  7083. typename T3,
  7084. typename T4,
  7085. typename T5,
  7086. typename T6,
  7087. typename T7,
  7088. typename T8,
  7089. typename T9,
  7090. typename T10,
  7091. typename T11,
  7092. typename T12,
  7093. typename T13,
  7094. typename T14,
  7095. typename T15,
  7096. typename T16,
  7097. typename T17,
  7098. typename T18,
  7099. typename T19,
  7100. typename T20,
  7101. typename T21,
  7102. typename T22,
  7103. typename T23,
  7104. typename T24,
  7105. typename T25,
  7106. typename T26>
  7107. struct functionImplementation_
  7108. < T0,
  7109. T1,
  7110. T2,
  7111. T3,
  7112. T4,
  7113. T5,
  7114. T6,
  7115. T7,
  7116. T8,
  7117. T9,
  7118. T10,
  7119. T11,
  7120. T12,
  7121. T13,
  7122. T14,
  7123. T15,
  7124. T16,
  7125. T17,
  7126. T18,
  7127. T19,
  7128. T20,
  7129. T21,
  7130. T22,
  7131. T23,
  7132. T24,
  7133. T25,
  7134. T26,
  7135. NullType,
  7136. NullType,
  7137. NullType,
  7138. NullType,
  7139. NullType>
  7140. {
  7141. typedef detail::KernelFunctorGlobal<
  7142. T0,
  7143. T1,
  7144. T2,
  7145. T3,
  7146. T4,
  7147. T5,
  7148. T6,
  7149. T7,
  7150. T8,
  7151. T9,
  7152. T10,
  7153. T11,
  7154. T12,
  7155. T13,
  7156. T14,
  7157. T15,
  7158. T16,
  7159. T17,
  7160. T18,
  7161. T19,
  7162. T20,
  7163. T21,
  7164. T22,
  7165. T23,
  7166. T24,
  7167. T25,
  7168. T26,
  7169. NullType,
  7170. NullType,
  7171. NullType,
  7172. NullType,
  7173. NullType> FunctorType;
  7174. FunctorType functor_;
  7175. functionImplementation_(const FunctorType &functor) :
  7176. functor_(functor)
  7177. {
  7178. #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 27))
  7179. // Fail variadic expansion for dev11
  7180. static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
  7181. #endif
  7182. }
  7183. //! \brief Return type of the functor
  7184. typedef Event result_type;
  7185. //! \brief Function signature of kernel functor with no event dependency.
  7186. typedef Event type_(
  7187. const EnqueueArgs&,
  7188. T0,
  7189. T1,
  7190. T2,
  7191. T3,
  7192. T4,
  7193. T5,
  7194. T6,
  7195. T7,
  7196. T8,
  7197. T9,
  7198. T10,
  7199. T11,
  7200. T12,
  7201. T13,
  7202. T14,
  7203. T15,
  7204. T16,
  7205. T17,
  7206. T18,
  7207. T19,
  7208. T20,
  7209. T21,
  7210. T22,
  7211. T23,
  7212. T24,
  7213. T25,
  7214. T26);
  7215. Event operator()(
  7216. const EnqueueArgs& enqueueArgs,
  7217. T0 arg0,
  7218. T1 arg1,
  7219. T2 arg2,
  7220. T3 arg3,
  7221. T4 arg4,
  7222. T5 arg5,
  7223. T6 arg6,
  7224. T7 arg7,
  7225. T8 arg8,
  7226. T9 arg9,
  7227. T10 arg10,
  7228. T11 arg11,
  7229. T12 arg12,
  7230. T13 arg13,
  7231. T14 arg14,
  7232. T15 arg15,
  7233. T16 arg16,
  7234. T17 arg17,
  7235. T18 arg18,
  7236. T19 arg19,
  7237. T20 arg20,
  7238. T21 arg21,
  7239. T22 arg22,
  7240. T23 arg23,
  7241. T24 arg24,
  7242. T25 arg25,
  7243. T26 arg26)
  7244. {
  7245. return functor_(
  7246. enqueueArgs,
  7247. arg0,
  7248. arg1,
  7249. arg2,
  7250. arg3,
  7251. arg4,
  7252. arg5,
  7253. arg6,
  7254. arg7,
  7255. arg8,
  7256. arg9,
  7257. arg10,
  7258. arg11,
  7259. arg12,
  7260. arg13,
  7261. arg14,
  7262. arg15,
  7263. arg16,
  7264. arg17,
  7265. arg18,
  7266. arg19,
  7267. arg20,
  7268. arg21,
  7269. arg22,
  7270. arg23,
  7271. arg24,
  7272. arg25,
  7273. arg26);
  7274. }
  7275. };
  7276. template<
  7277. typename T0,
  7278. typename T1,
  7279. typename T2,
  7280. typename T3,
  7281. typename T4,
  7282. typename T5,
  7283. typename T6,
  7284. typename T7,
  7285. typename T8,
  7286. typename T9,
  7287. typename T10,
  7288. typename T11,
  7289. typename T12,
  7290. typename T13,
  7291. typename T14,
  7292. typename T15,
  7293. typename T16,
  7294. typename T17,
  7295. typename T18,
  7296. typename T19,
  7297. typename T20,
  7298. typename T21,
  7299. typename T22,
  7300. typename T23,
  7301. typename T24,
  7302. typename T25>
  7303. struct functionImplementation_
  7304. < T0,
  7305. T1,
  7306. T2,
  7307. T3,
  7308. T4,
  7309. T5,
  7310. T6,
  7311. T7,
  7312. T8,
  7313. T9,
  7314. T10,
  7315. T11,
  7316. T12,
  7317. T13,
  7318. T14,
  7319. T15,
  7320. T16,
  7321. T17,
  7322. T18,
  7323. T19,
  7324. T20,
  7325. T21,
  7326. T22,
  7327. T23,
  7328. T24,
  7329. T25,
  7330. NullType,
  7331. NullType,
  7332. NullType,
  7333. NullType,
  7334. NullType,
  7335. NullType>
  7336. {
  7337. typedef detail::KernelFunctorGlobal<
  7338. T0,
  7339. T1,
  7340. T2,
  7341. T3,
  7342. T4,
  7343. T5,
  7344. T6,
  7345. T7,
  7346. T8,
  7347. T9,
  7348. T10,
  7349. T11,
  7350. T12,
  7351. T13,
  7352. T14,
  7353. T15,
  7354. T16,
  7355. T17,
  7356. T18,
  7357. T19,
  7358. T20,
  7359. T21,
  7360. T22,
  7361. T23,
  7362. T24,
  7363. T25,
  7364. NullType,
  7365. NullType,
  7366. NullType,
  7367. NullType,
  7368. NullType,
  7369. NullType> FunctorType;
  7370. FunctorType functor_;
  7371. functionImplementation_(const FunctorType &functor) :
  7372. functor_(functor)
  7373. {
  7374. #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 26))
  7375. // Fail variadic expansion for dev11
  7376. static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
  7377. #endif
  7378. }
  7379. //! \brief Return type of the functor
  7380. typedef Event result_type;
  7381. //! \brief Function signature of kernel functor with no event dependency.
  7382. typedef Event type_(
  7383. const EnqueueArgs&,
  7384. T0,
  7385. T1,
  7386. T2,
  7387. T3,
  7388. T4,
  7389. T5,
  7390. T6,
  7391. T7,
  7392. T8,
  7393. T9,
  7394. T10,
  7395. T11,
  7396. T12,
  7397. T13,
  7398. T14,
  7399. T15,
  7400. T16,
  7401. T17,
  7402. T18,
  7403. T19,
  7404. T20,
  7405. T21,
  7406. T22,
  7407. T23,
  7408. T24,
  7409. T25);
  7410. Event operator()(
  7411. const EnqueueArgs& enqueueArgs,
  7412. T0 arg0,
  7413. T1 arg1,
  7414. T2 arg2,
  7415. T3 arg3,
  7416. T4 arg4,
  7417. T5 arg5,
  7418. T6 arg6,
  7419. T7 arg7,
  7420. T8 arg8,
  7421. T9 arg9,
  7422. T10 arg10,
  7423. T11 arg11,
  7424. T12 arg12,
  7425. T13 arg13,
  7426. T14 arg14,
  7427. T15 arg15,
  7428. T16 arg16,
  7429. T17 arg17,
  7430. T18 arg18,
  7431. T19 arg19,
  7432. T20 arg20,
  7433. T21 arg21,
  7434. T22 arg22,
  7435. T23 arg23,
  7436. T24 arg24,
  7437. T25 arg25)
  7438. {
  7439. return functor_(
  7440. enqueueArgs,
  7441. arg0,
  7442. arg1,
  7443. arg2,
  7444. arg3,
  7445. arg4,
  7446. arg5,
  7447. arg6,
  7448. arg7,
  7449. arg8,
  7450. arg9,
  7451. arg10,
  7452. arg11,
  7453. arg12,
  7454. arg13,
  7455. arg14,
  7456. arg15,
  7457. arg16,
  7458. arg17,
  7459. arg18,
  7460. arg19,
  7461. arg20,
  7462. arg21,
  7463. arg22,
  7464. arg23,
  7465. arg24,
  7466. arg25);
  7467. }
  7468. };
  7469. template<
  7470. typename T0,
  7471. typename T1,
  7472. typename T2,
  7473. typename T3,
  7474. typename T4,
  7475. typename T5,
  7476. typename T6,
  7477. typename T7,
  7478. typename T8,
  7479. typename T9,
  7480. typename T10,
  7481. typename T11,
  7482. typename T12,
  7483. typename T13,
  7484. typename T14,
  7485. typename T15,
  7486. typename T16,
  7487. typename T17,
  7488. typename T18,
  7489. typename T19,
  7490. typename T20,
  7491. typename T21,
  7492. typename T22,
  7493. typename T23,
  7494. typename T24>
  7495. struct functionImplementation_
  7496. < T0,
  7497. T1,
  7498. T2,
  7499. T3,
  7500. T4,
  7501. T5,
  7502. T6,
  7503. T7,
  7504. T8,
  7505. T9,
  7506. T10,
  7507. T11,
  7508. T12,
  7509. T13,
  7510. T14,
  7511. T15,
  7512. T16,
  7513. T17,
  7514. T18,
  7515. T19,
  7516. T20,
  7517. T21,
  7518. T22,
  7519. T23,
  7520. T24,
  7521. NullType,
  7522. NullType,
  7523. NullType,
  7524. NullType,
  7525. NullType,
  7526. NullType,
  7527. NullType>
  7528. {
  7529. typedef detail::KernelFunctorGlobal<
  7530. T0,
  7531. T1,
  7532. T2,
  7533. T3,
  7534. T4,
  7535. T5,
  7536. T6,
  7537. T7,
  7538. T8,
  7539. T9,
  7540. T10,
  7541. T11,
  7542. T12,
  7543. T13,
  7544. T14,
  7545. T15,
  7546. T16,
  7547. T17,
  7548. T18,
  7549. T19,
  7550. T20,
  7551. T21,
  7552. T22,
  7553. T23,
  7554. T24,
  7555. NullType,
  7556. NullType,
  7557. NullType,
  7558. NullType,
  7559. NullType,
  7560. NullType,
  7561. NullType> FunctorType;
  7562. FunctorType functor_;
  7563. functionImplementation_(const FunctorType &functor) :
  7564. functor_(functor)
  7565. {
  7566. #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 25))
  7567. // Fail variadic expansion for dev11
  7568. static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
  7569. #endif
  7570. }
  7571. //! \brief Return type of the functor
  7572. typedef Event result_type;
  7573. //! \brief Function signature of kernel functor with no event dependency.
  7574. typedef Event type_(
  7575. const EnqueueArgs&,
  7576. T0,
  7577. T1,
  7578. T2,
  7579. T3,
  7580. T4,
  7581. T5,
  7582. T6,
  7583. T7,
  7584. T8,
  7585. T9,
  7586. T10,
  7587. T11,
  7588. T12,
  7589. T13,
  7590. T14,
  7591. T15,
  7592. T16,
  7593. T17,
  7594. T18,
  7595. T19,
  7596. T20,
  7597. T21,
  7598. T22,
  7599. T23,
  7600. T24);
  7601. Event operator()(
  7602. const EnqueueArgs& enqueueArgs,
  7603. T0 arg0,
  7604. T1 arg1,
  7605. T2 arg2,
  7606. T3 arg3,
  7607. T4 arg4,
  7608. T5 arg5,
  7609. T6 arg6,
  7610. T7 arg7,
  7611. T8 arg8,
  7612. T9 arg9,
  7613. T10 arg10,
  7614. T11 arg11,
  7615. T12 arg12,
  7616. T13 arg13,
  7617. T14 arg14,
  7618. T15 arg15,
  7619. T16 arg16,
  7620. T17 arg17,
  7621. T18 arg18,
  7622. T19 arg19,
  7623. T20 arg20,
  7624. T21 arg21,
  7625. T22 arg22,
  7626. T23 arg23,
  7627. T24 arg24)
  7628. {
  7629. return functor_(
  7630. enqueueArgs,
  7631. arg0,
  7632. arg1,
  7633. arg2,
  7634. arg3,
  7635. arg4,
  7636. arg5,
  7637. arg6,
  7638. arg7,
  7639. arg8,
  7640. arg9,
  7641. arg10,
  7642. arg11,
  7643. arg12,
  7644. arg13,
  7645. arg14,
  7646. arg15,
  7647. arg16,
  7648. arg17,
  7649. arg18,
  7650. arg19,
  7651. arg20,
  7652. arg21,
  7653. arg22,
  7654. arg23,
  7655. arg24);
  7656. }
  7657. };
  7658. template<
  7659. typename T0,
  7660. typename T1,
  7661. typename T2,
  7662. typename T3,
  7663. typename T4,
  7664. typename T5,
  7665. typename T6,
  7666. typename T7,
  7667. typename T8,
  7668. typename T9,
  7669. typename T10,
  7670. typename T11,
  7671. typename T12,
  7672. typename T13,
  7673. typename T14,
  7674. typename T15,
  7675. typename T16,
  7676. typename T17,
  7677. typename T18,
  7678. typename T19,
  7679. typename T20,
  7680. typename T21,
  7681. typename T22,
  7682. typename T23>
  7683. struct functionImplementation_
  7684. < T0,
  7685. T1,
  7686. T2,
  7687. T3,
  7688. T4,
  7689. T5,
  7690. T6,
  7691. T7,
  7692. T8,
  7693. T9,
  7694. T10,
  7695. T11,
  7696. T12,
  7697. T13,
  7698. T14,
  7699. T15,
  7700. T16,
  7701. T17,
  7702. T18,
  7703. T19,
  7704. T20,
  7705. T21,
  7706. T22,
  7707. T23,
  7708. NullType,
  7709. NullType,
  7710. NullType,
  7711. NullType,
  7712. NullType,
  7713. NullType,
  7714. NullType,
  7715. NullType>
  7716. {
  7717. typedef detail::KernelFunctorGlobal<
  7718. T0,
  7719. T1,
  7720. T2,
  7721. T3,
  7722. T4,
  7723. T5,
  7724. T6,
  7725. T7,
  7726. T8,
  7727. T9,
  7728. T10,
  7729. T11,
  7730. T12,
  7731. T13,
  7732. T14,
  7733. T15,
  7734. T16,
  7735. T17,
  7736. T18,
  7737. T19,
  7738. T20,
  7739. T21,
  7740. T22,
  7741. T23,
  7742. NullType,
  7743. NullType,
  7744. NullType,
  7745. NullType,
  7746. NullType,
  7747. NullType,
  7748. NullType,
  7749. NullType> FunctorType;
  7750. FunctorType functor_;
  7751. functionImplementation_(const FunctorType &functor) :
  7752. functor_(functor)
  7753. {
  7754. #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 24))
  7755. // Fail variadic expansion for dev11
  7756. static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
  7757. #endif
  7758. }
  7759. //! \brief Return type of the functor
  7760. typedef Event result_type;
  7761. //! \brief Function signature of kernel functor with no event dependency.
  7762. typedef Event type_(
  7763. const EnqueueArgs&,
  7764. T0,
  7765. T1,
  7766. T2,
  7767. T3,
  7768. T4,
  7769. T5,
  7770. T6,
  7771. T7,
  7772. T8,
  7773. T9,
  7774. T10,
  7775. T11,
  7776. T12,
  7777. T13,
  7778. T14,
  7779. T15,
  7780. T16,
  7781. T17,
  7782. T18,
  7783. T19,
  7784. T20,
  7785. T21,
  7786. T22,
  7787. T23);
  7788. Event operator()(
  7789. const EnqueueArgs& enqueueArgs,
  7790. T0 arg0,
  7791. T1 arg1,
  7792. T2 arg2,
  7793. T3 arg3,
  7794. T4 arg4,
  7795. T5 arg5,
  7796. T6 arg6,
  7797. T7 arg7,
  7798. T8 arg8,
  7799. T9 arg9,
  7800. T10 arg10,
  7801. T11 arg11,
  7802. T12 arg12,
  7803. T13 arg13,
  7804. T14 arg14,
  7805. T15 arg15,
  7806. T16 arg16,
  7807. T17 arg17,
  7808. T18 arg18,
  7809. T19 arg19,
  7810. T20 arg20,
  7811. T21 arg21,
  7812. T22 arg22,
  7813. T23 arg23)
  7814. {
  7815. return functor_(
  7816. enqueueArgs,
  7817. arg0,
  7818. arg1,
  7819. arg2,
  7820. arg3,
  7821. arg4,
  7822. arg5,
  7823. arg6,
  7824. arg7,
  7825. arg8,
  7826. arg9,
  7827. arg10,
  7828. arg11,
  7829. arg12,
  7830. arg13,
  7831. arg14,
  7832. arg15,
  7833. arg16,
  7834. arg17,
  7835. arg18,
  7836. arg19,
  7837. arg20,
  7838. arg21,
  7839. arg22,
  7840. arg23);
  7841. }
  7842. };
  7843. template<
  7844. typename T0,
  7845. typename T1,
  7846. typename T2,
  7847. typename T3,
  7848. typename T4,
  7849. typename T5,
  7850. typename T6,
  7851. typename T7,
  7852. typename T8,
  7853. typename T9,
  7854. typename T10,
  7855. typename T11,
  7856. typename T12,
  7857. typename T13,
  7858. typename T14,
  7859. typename T15,
  7860. typename T16,
  7861. typename T17,
  7862. typename T18,
  7863. typename T19,
  7864. typename T20,
  7865. typename T21,
  7866. typename T22>
  7867. struct functionImplementation_
  7868. < T0,
  7869. T1,
  7870. T2,
  7871. T3,
  7872. T4,
  7873. T5,
  7874. T6,
  7875. T7,
  7876. T8,
  7877. T9,
  7878. T10,
  7879. T11,
  7880. T12,
  7881. T13,
  7882. T14,
  7883. T15,
  7884. T16,
  7885. T17,
  7886. T18,
  7887. T19,
  7888. T20,
  7889. T21,
  7890. T22,
  7891. NullType,
  7892. NullType,
  7893. NullType,
  7894. NullType,
  7895. NullType,
  7896. NullType,
  7897. NullType,
  7898. NullType,
  7899. NullType>
  7900. {
  7901. typedef detail::KernelFunctorGlobal<
  7902. T0,
  7903. T1,
  7904. T2,
  7905. T3,
  7906. T4,
  7907. T5,
  7908. T6,
  7909. T7,
  7910. T8,
  7911. T9,
  7912. T10,
  7913. T11,
  7914. T12,
  7915. T13,
  7916. T14,
  7917. T15,
  7918. T16,
  7919. T17,
  7920. T18,
  7921. T19,
  7922. T20,
  7923. T21,
  7924. T22,
  7925. NullType,
  7926. NullType,
  7927. NullType,
  7928. NullType,
  7929. NullType,
  7930. NullType,
  7931. NullType,
  7932. NullType,
  7933. NullType> FunctorType;
  7934. FunctorType functor_;
  7935. functionImplementation_(const FunctorType &functor) :
  7936. functor_(functor)
  7937. {
  7938. #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 23))
  7939. // Fail variadic expansion for dev11
  7940. static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
  7941. #endif
  7942. }
  7943. //! \brief Return type of the functor
  7944. typedef Event result_type;
  7945. //! \brief Function signature of kernel functor with no event dependency.
  7946. typedef Event type_(
  7947. const EnqueueArgs&,
  7948. T0,
  7949. T1,
  7950. T2,
  7951. T3,
  7952. T4,
  7953. T5,
  7954. T6,
  7955. T7,
  7956. T8,
  7957. T9,
  7958. T10,
  7959. T11,
  7960. T12,
  7961. T13,
  7962. T14,
  7963. T15,
  7964. T16,
  7965. T17,
  7966. T18,
  7967. T19,
  7968. T20,
  7969. T21,
  7970. T22);
  7971. Event operator()(
  7972. const EnqueueArgs& enqueueArgs,
  7973. T0 arg0,
  7974. T1 arg1,
  7975. T2 arg2,
  7976. T3 arg3,
  7977. T4 arg4,
  7978. T5 arg5,
  7979. T6 arg6,
  7980. T7 arg7,
  7981. T8 arg8,
  7982. T9 arg9,
  7983. T10 arg10,
  7984. T11 arg11,
  7985. T12 arg12,
  7986. T13 arg13,
  7987. T14 arg14,
  7988. T15 arg15,
  7989. T16 arg16,
  7990. T17 arg17,
  7991. T18 arg18,
  7992. T19 arg19,
  7993. T20 arg20,
  7994. T21 arg21,
  7995. T22 arg22)
  7996. {
  7997. return functor_(
  7998. enqueueArgs,
  7999. arg0,
  8000. arg1,
  8001. arg2,
  8002. arg3,
  8003. arg4,
  8004. arg5,
  8005. arg6,
  8006. arg7,
  8007. arg8,
  8008. arg9,
  8009. arg10,
  8010. arg11,
  8011. arg12,
  8012. arg13,
  8013. arg14,
  8014. arg15,
  8015. arg16,
  8016. arg17,
  8017. arg18,
  8018. arg19,
  8019. arg20,
  8020. arg21,
  8021. arg22);
  8022. }
  8023. };
  8024. template<
  8025. typename T0,
  8026. typename T1,
  8027. typename T2,
  8028. typename T3,
  8029. typename T4,
  8030. typename T5,
  8031. typename T6,
  8032. typename T7,
  8033. typename T8,
  8034. typename T9,
  8035. typename T10,
  8036. typename T11,
  8037. typename T12,
  8038. typename T13,
  8039. typename T14,
  8040. typename T15,
  8041. typename T16,
  8042. typename T17,
  8043. typename T18,
  8044. typename T19,
  8045. typename T20,
  8046. typename T21>
  8047. struct functionImplementation_
  8048. < T0,
  8049. T1,
  8050. T2,
  8051. T3,
  8052. T4,
  8053. T5,
  8054. T6,
  8055. T7,
  8056. T8,
  8057. T9,
  8058. T10,
  8059. T11,
  8060. T12,
  8061. T13,
  8062. T14,
  8063. T15,
  8064. T16,
  8065. T17,
  8066. T18,
  8067. T19,
  8068. T20,
  8069. T21,
  8070. NullType,
  8071. NullType,
  8072. NullType,
  8073. NullType,
  8074. NullType,
  8075. NullType,
  8076. NullType,
  8077. NullType,
  8078. NullType,
  8079. NullType>
  8080. {
  8081. typedef detail::KernelFunctorGlobal<
  8082. T0,
  8083. T1,
  8084. T2,
  8085. T3,
  8086. T4,
  8087. T5,
  8088. T6,
  8089. T7,
  8090. T8,
  8091. T9,
  8092. T10,
  8093. T11,
  8094. T12,
  8095. T13,
  8096. T14,
  8097. T15,
  8098. T16,
  8099. T17,
  8100. T18,
  8101. T19,
  8102. T20,
  8103. T21,
  8104. NullType,
  8105. NullType,
  8106. NullType,
  8107. NullType,
  8108. NullType,
  8109. NullType,
  8110. NullType,
  8111. NullType,
  8112. NullType,
  8113. NullType> FunctorType;
  8114. FunctorType functor_;
  8115. functionImplementation_(const FunctorType &functor) :
  8116. functor_(functor)
  8117. {
  8118. #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 22))
  8119. // Fail variadic expansion for dev11
  8120. static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
  8121. #endif
  8122. }
  8123. //! \brief Return type of the functor
  8124. typedef Event result_type;
  8125. //! \brief Function signature of kernel functor with no event dependency.
  8126. typedef Event type_(
  8127. const EnqueueArgs&,
  8128. T0,
  8129. T1,
  8130. T2,
  8131. T3,
  8132. T4,
  8133. T5,
  8134. T6,
  8135. T7,
  8136. T8,
  8137. T9,
  8138. T10,
  8139. T11,
  8140. T12,
  8141. T13,
  8142. T14,
  8143. T15,
  8144. T16,
  8145. T17,
  8146. T18,
  8147. T19,
  8148. T20,
  8149. T21);
  8150. Event operator()(
  8151. const EnqueueArgs& enqueueArgs,
  8152. T0 arg0,
  8153. T1 arg1,
  8154. T2 arg2,
  8155. T3 arg3,
  8156. T4 arg4,
  8157. T5 arg5,
  8158. T6 arg6,
  8159. T7 arg7,
  8160. T8 arg8,
  8161. T9 arg9,
  8162. T10 arg10,
  8163. T11 arg11,
  8164. T12 arg12,
  8165. T13 arg13,
  8166. T14 arg14,
  8167. T15 arg15,
  8168. T16 arg16,
  8169. T17 arg17,
  8170. T18 arg18,
  8171. T19 arg19,
  8172. T20 arg20,
  8173. T21 arg21)
  8174. {
  8175. return functor_(
  8176. enqueueArgs,
  8177. arg0,
  8178. arg1,
  8179. arg2,
  8180. arg3,
  8181. arg4,
  8182. arg5,
  8183. arg6,
  8184. arg7,
  8185. arg8,
  8186. arg9,
  8187. arg10,
  8188. arg11,
  8189. arg12,
  8190. arg13,
  8191. arg14,
  8192. arg15,
  8193. arg16,
  8194. arg17,
  8195. arg18,
  8196. arg19,
  8197. arg20,
  8198. arg21);
  8199. }
  8200. };
  8201. template<
  8202. typename T0,
  8203. typename T1,
  8204. typename T2,
  8205. typename T3,
  8206. typename T4,
  8207. typename T5,
  8208. typename T6,
  8209. typename T7,
  8210. typename T8,
  8211. typename T9,
  8212. typename T10,
  8213. typename T11,
  8214. typename T12,
  8215. typename T13,
  8216. typename T14,
  8217. typename T15,
  8218. typename T16,
  8219. typename T17,
  8220. typename T18,
  8221. typename T19,
  8222. typename T20>
  8223. struct functionImplementation_
  8224. < T0,
  8225. T1,
  8226. T2,
  8227. T3,
  8228. T4,
  8229. T5,
  8230. T6,
  8231. T7,
  8232. T8,
  8233. T9,
  8234. T10,
  8235. T11,
  8236. T12,
  8237. T13,
  8238. T14,
  8239. T15,
  8240. T16,
  8241. T17,
  8242. T18,
  8243. T19,
  8244. T20,
  8245. NullType,
  8246. NullType,
  8247. NullType,
  8248. NullType,
  8249. NullType,
  8250. NullType,
  8251. NullType,
  8252. NullType,
  8253. NullType,
  8254. NullType,
  8255. NullType>
  8256. {
  8257. typedef detail::KernelFunctorGlobal<
  8258. T0,
  8259. T1,
  8260. T2,
  8261. T3,
  8262. T4,
  8263. T5,
  8264. T6,
  8265. T7,
  8266. T8,
  8267. T9,
  8268. T10,
  8269. T11,
  8270. T12,
  8271. T13,
  8272. T14,
  8273. T15,
  8274. T16,
  8275. T17,
  8276. T18,
  8277. T19,
  8278. T20,
  8279. NullType,
  8280. NullType,
  8281. NullType,
  8282. NullType,
  8283. NullType,
  8284. NullType,
  8285. NullType,
  8286. NullType,
  8287. NullType,
  8288. NullType,
  8289. NullType> FunctorType;
  8290. FunctorType functor_;
  8291. functionImplementation_(const FunctorType &functor) :
  8292. functor_(functor)
  8293. {
  8294. #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 21))
  8295. // Fail variadic expansion for dev11
  8296. static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
  8297. #endif
  8298. }
  8299. //! \brief Return type of the functor
  8300. typedef Event result_type;
  8301. //! \brief Function signature of kernel functor with no event dependency.
  8302. typedef Event type_(
  8303. const EnqueueArgs&,
  8304. T0,
  8305. T1,
  8306. T2,
  8307. T3,
  8308. T4,
  8309. T5,
  8310. T6,
  8311. T7,
  8312. T8,
  8313. T9,
  8314. T10,
  8315. T11,
  8316. T12,
  8317. T13,
  8318. T14,
  8319. T15,
  8320. T16,
  8321. T17,
  8322. T18,
  8323. T19,
  8324. T20);
  8325. Event operator()(
  8326. const EnqueueArgs& enqueueArgs,
  8327. T0 arg0,
  8328. T1 arg1,
  8329. T2 arg2,
  8330. T3 arg3,
  8331. T4 arg4,
  8332. T5 arg5,
  8333. T6 arg6,
  8334. T7 arg7,
  8335. T8 arg8,
  8336. T9 arg9,
  8337. T10 arg10,
  8338. T11 arg11,
  8339. T12 arg12,
  8340. T13 arg13,
  8341. T14 arg14,
  8342. T15 arg15,
  8343. T16 arg16,
  8344. T17 arg17,
  8345. T18 arg18,
  8346. T19 arg19,
  8347. T20 arg20)
  8348. {
  8349. return functor_(
  8350. enqueueArgs,
  8351. arg0,
  8352. arg1,
  8353. arg2,
  8354. arg3,
  8355. arg4,
  8356. arg5,
  8357. arg6,
  8358. arg7,
  8359. arg8,
  8360. arg9,
  8361. arg10,
  8362. arg11,
  8363. arg12,
  8364. arg13,
  8365. arg14,
  8366. arg15,
  8367. arg16,
  8368. arg17,
  8369. arg18,
  8370. arg19,
  8371. arg20);
  8372. }
  8373. };
  8374. template<
  8375. typename T0,
  8376. typename T1,
  8377. typename T2,
  8378. typename T3,
  8379. typename T4,
  8380. typename T5,
  8381. typename T6,
  8382. typename T7,
  8383. typename T8,
  8384. typename T9,
  8385. typename T10,
  8386. typename T11,
  8387. typename T12,
  8388. typename T13,
  8389. typename T14,
  8390. typename T15,
  8391. typename T16,
  8392. typename T17,
  8393. typename T18,
  8394. typename T19>
  8395. struct functionImplementation_
  8396. < T0,
  8397. T1,
  8398. T2,
  8399. T3,
  8400. T4,
  8401. T5,
  8402. T6,
  8403. T7,
  8404. T8,
  8405. T9,
  8406. T10,
  8407. T11,
  8408. T12,
  8409. T13,
  8410. T14,
  8411. T15,
  8412. T16,
  8413. T17,
  8414. T18,
  8415. T19,
  8416. NullType,
  8417. NullType,
  8418. NullType,
  8419. NullType,
  8420. NullType,
  8421. NullType,
  8422. NullType,
  8423. NullType,
  8424. NullType,
  8425. NullType,
  8426. NullType,
  8427. NullType>
  8428. {
  8429. typedef detail::KernelFunctorGlobal<
  8430. T0,
  8431. T1,
  8432. T2,
  8433. T3,
  8434. T4,
  8435. T5,
  8436. T6,
  8437. T7,
  8438. T8,
  8439. T9,
  8440. T10,
  8441. T11,
  8442. T12,
  8443. T13,
  8444. T14,
  8445. T15,
  8446. T16,
  8447. T17,
  8448. T18,
  8449. T19,
  8450. NullType,
  8451. NullType,
  8452. NullType,
  8453. NullType,
  8454. NullType,
  8455. NullType,
  8456. NullType,
  8457. NullType,
  8458. NullType,
  8459. NullType,
  8460. NullType,
  8461. NullType> FunctorType;
  8462. FunctorType functor_;
  8463. functionImplementation_(const FunctorType &functor) :
  8464. functor_(functor)
  8465. {
  8466. #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 20))
  8467. // Fail variadic expansion for dev11
  8468. static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
  8469. #endif
  8470. }
  8471. //! \brief Return type of the functor
  8472. typedef Event result_type;
  8473. //! \brief Function signature of kernel functor with no event dependency.
  8474. typedef Event type_(
  8475. const EnqueueArgs&,
  8476. T0,
  8477. T1,
  8478. T2,
  8479. T3,
  8480. T4,
  8481. T5,
  8482. T6,
  8483. T7,
  8484. T8,
  8485. T9,
  8486. T10,
  8487. T11,
  8488. T12,
  8489. T13,
  8490. T14,
  8491. T15,
  8492. T16,
  8493. T17,
  8494. T18,
  8495. T19);
  8496. Event operator()(
  8497. const EnqueueArgs& enqueueArgs,
  8498. T0 arg0,
  8499. T1 arg1,
  8500. T2 arg2,
  8501. T3 arg3,
  8502. T4 arg4,
  8503. T5 arg5,
  8504. T6 arg6,
  8505. T7 arg7,
  8506. T8 arg8,
  8507. T9 arg9,
  8508. T10 arg10,
  8509. T11 arg11,
  8510. T12 arg12,
  8511. T13 arg13,
  8512. T14 arg14,
  8513. T15 arg15,
  8514. T16 arg16,
  8515. T17 arg17,
  8516. T18 arg18,
  8517. T19 arg19)
  8518. {
  8519. return functor_(
  8520. enqueueArgs,
  8521. arg0,
  8522. arg1,
  8523. arg2,
  8524. arg3,
  8525. arg4,
  8526. arg5,
  8527. arg6,
  8528. arg7,
  8529. arg8,
  8530. arg9,
  8531. arg10,
  8532. arg11,
  8533. arg12,
  8534. arg13,
  8535. arg14,
  8536. arg15,
  8537. arg16,
  8538. arg17,
  8539. arg18,
  8540. arg19);
  8541. }
  8542. };
  8543. template<
  8544. typename T0,
  8545. typename T1,
  8546. typename T2,
  8547. typename T3,
  8548. typename T4,
  8549. typename T5,
  8550. typename T6,
  8551. typename T7,
  8552. typename T8,
  8553. typename T9,
  8554. typename T10,
  8555. typename T11,
  8556. typename T12,
  8557. typename T13,
  8558. typename T14,
  8559. typename T15,
  8560. typename T16,
  8561. typename T17,
  8562. typename T18>
  8563. struct functionImplementation_
  8564. < T0,
  8565. T1,
  8566. T2,
  8567. T3,
  8568. T4,
  8569. T5,
  8570. T6,
  8571. T7,
  8572. T8,
  8573. T9,
  8574. T10,
  8575. T11,
  8576. T12,
  8577. T13,
  8578. T14,
  8579. T15,
  8580. T16,
  8581. T17,
  8582. T18,
  8583. NullType,
  8584. NullType,
  8585. NullType,
  8586. NullType,
  8587. NullType,
  8588. NullType,
  8589. NullType,
  8590. NullType,
  8591. NullType,
  8592. NullType,
  8593. NullType,
  8594. NullType,
  8595. NullType>
  8596. {
  8597. typedef detail::KernelFunctorGlobal<
  8598. T0,
  8599. T1,
  8600. T2,
  8601. T3,
  8602. T4,
  8603. T5,
  8604. T6,
  8605. T7,
  8606. T8,
  8607. T9,
  8608. T10,
  8609. T11,
  8610. T12,
  8611. T13,
  8612. T14,
  8613. T15,
  8614. T16,
  8615. T17,
  8616. T18,
  8617. NullType,
  8618. NullType,
  8619. NullType,
  8620. NullType,
  8621. NullType,
  8622. NullType,
  8623. NullType,
  8624. NullType,
  8625. NullType,
  8626. NullType,
  8627. NullType,
  8628. NullType,
  8629. NullType> FunctorType;
  8630. FunctorType functor_;
  8631. functionImplementation_(const FunctorType &functor) :
  8632. functor_(functor)
  8633. {
  8634. #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 19))
  8635. // Fail variadic expansion for dev11
  8636. static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
  8637. #endif
  8638. }
  8639. //! \brief Return type of the functor
  8640. typedef Event result_type;
  8641. //! \brief Function signature of kernel functor with no event dependency.
  8642. typedef Event type_(
  8643. const EnqueueArgs&,
  8644. T0,
  8645. T1,
  8646. T2,
  8647. T3,
  8648. T4,
  8649. T5,
  8650. T6,
  8651. T7,
  8652. T8,
  8653. T9,
  8654. T10,
  8655. T11,
  8656. T12,
  8657. T13,
  8658. T14,
  8659. T15,
  8660. T16,
  8661. T17,
  8662. T18);
  8663. Event operator()(
  8664. const EnqueueArgs& enqueueArgs,
  8665. T0 arg0,
  8666. T1 arg1,
  8667. T2 arg2,
  8668. T3 arg3,
  8669. T4 arg4,
  8670. T5 arg5,
  8671. T6 arg6,
  8672. T7 arg7,
  8673. T8 arg8,
  8674. T9 arg9,
  8675. T10 arg10,
  8676. T11 arg11,
  8677. T12 arg12,
  8678. T13 arg13,
  8679. T14 arg14,
  8680. T15 arg15,
  8681. T16 arg16,
  8682. T17 arg17,
  8683. T18 arg18)
  8684. {
  8685. return functor_(
  8686. enqueueArgs,
  8687. arg0,
  8688. arg1,
  8689. arg2,
  8690. arg3,
  8691. arg4,
  8692. arg5,
  8693. arg6,
  8694. arg7,
  8695. arg8,
  8696. arg9,
  8697. arg10,
  8698. arg11,
  8699. arg12,
  8700. arg13,
  8701. arg14,
  8702. arg15,
  8703. arg16,
  8704. arg17,
  8705. arg18);
  8706. }
  8707. };
  8708. template<
  8709. typename T0,
  8710. typename T1,
  8711. typename T2,
  8712. typename T3,
  8713. typename T4,
  8714. typename T5,
  8715. typename T6,
  8716. typename T7,
  8717. typename T8,
  8718. typename T9,
  8719. typename T10,
  8720. typename T11,
  8721. typename T12,
  8722. typename T13,
  8723. typename T14,
  8724. typename T15,
  8725. typename T16,
  8726. typename T17>
  8727. struct functionImplementation_
  8728. < T0,
  8729. T1,
  8730. T2,
  8731. T3,
  8732. T4,
  8733. T5,
  8734. T6,
  8735. T7,
  8736. T8,
  8737. T9,
  8738. T10,
  8739. T11,
  8740. T12,
  8741. T13,
  8742. T14,
  8743. T15,
  8744. T16,
  8745. T17,
  8746. NullType,
  8747. NullType,
  8748. NullType,
  8749. NullType,
  8750. NullType,
  8751. NullType,
  8752. NullType,
  8753. NullType,
  8754. NullType,
  8755. NullType,
  8756. NullType,
  8757. NullType,
  8758. NullType,
  8759. NullType>
  8760. {
  8761. typedef detail::KernelFunctorGlobal<
  8762. T0,
  8763. T1,
  8764. T2,
  8765. T3,
  8766. T4,
  8767. T5,
  8768. T6,
  8769. T7,
  8770. T8,
  8771. T9,
  8772. T10,
  8773. T11,
  8774. T12,
  8775. T13,
  8776. T14,
  8777. T15,
  8778. T16,
  8779. T17,
  8780. NullType,
  8781. NullType,
  8782. NullType,
  8783. NullType,
  8784. NullType,
  8785. NullType,
  8786. NullType,
  8787. NullType,
  8788. NullType,
  8789. NullType,
  8790. NullType,
  8791. NullType,
  8792. NullType,
  8793. NullType> FunctorType;
  8794. FunctorType functor_;
  8795. functionImplementation_(const FunctorType &functor) :
  8796. functor_(functor)
  8797. {
  8798. #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 18))
  8799. // Fail variadic expansion for dev11
  8800. static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
  8801. #endif
  8802. }
  8803. //! \brief Return type of the functor
  8804. typedef Event result_type;
  8805. //! \brief Function signature of kernel functor with no event dependency.
  8806. typedef Event type_(
  8807. const EnqueueArgs&,
  8808. T0,
  8809. T1,
  8810. T2,
  8811. T3,
  8812. T4,
  8813. T5,
  8814. T6,
  8815. T7,
  8816. T8,
  8817. T9,
  8818. T10,
  8819. T11,
  8820. T12,
  8821. T13,
  8822. T14,
  8823. T15,
  8824. T16,
  8825. T17);
  8826. Event operator()(
  8827. const EnqueueArgs& enqueueArgs,
  8828. T0 arg0,
  8829. T1 arg1,
  8830. T2 arg2,
  8831. T3 arg3,
  8832. T4 arg4,
  8833. T5 arg5,
  8834. T6 arg6,
  8835. T7 arg7,
  8836. T8 arg8,
  8837. T9 arg9,
  8838. T10 arg10,
  8839. T11 arg11,
  8840. T12 arg12,
  8841. T13 arg13,
  8842. T14 arg14,
  8843. T15 arg15,
  8844. T16 arg16,
  8845. T17 arg17)
  8846. {
  8847. return functor_(
  8848. enqueueArgs,
  8849. arg0,
  8850. arg1,
  8851. arg2,
  8852. arg3,
  8853. arg4,
  8854. arg5,
  8855. arg6,
  8856. arg7,
  8857. arg8,
  8858. arg9,
  8859. arg10,
  8860. arg11,
  8861. arg12,
  8862. arg13,
  8863. arg14,
  8864. arg15,
  8865. arg16,
  8866. arg17);
  8867. }
  8868. };
  8869. template<
  8870. typename T0,
  8871. typename T1,
  8872. typename T2,
  8873. typename T3,
  8874. typename T4,
  8875. typename T5,
  8876. typename T6,
  8877. typename T7,
  8878. typename T8,
  8879. typename T9,
  8880. typename T10,
  8881. typename T11,
  8882. typename T12,
  8883. typename T13,
  8884. typename T14,
  8885. typename T15,
  8886. typename T16>
  8887. struct functionImplementation_
  8888. < T0,
  8889. T1,
  8890. T2,
  8891. T3,
  8892. T4,
  8893. T5,
  8894. T6,
  8895. T7,
  8896. T8,
  8897. T9,
  8898. T10,
  8899. T11,
  8900. T12,
  8901. T13,
  8902. T14,
  8903. T15,
  8904. T16,
  8905. NullType,
  8906. NullType,
  8907. NullType,
  8908. NullType,
  8909. NullType,
  8910. NullType,
  8911. NullType,
  8912. NullType,
  8913. NullType,
  8914. NullType,
  8915. NullType,
  8916. NullType,
  8917. NullType,
  8918. NullType,
  8919. NullType>
  8920. {
  8921. typedef detail::KernelFunctorGlobal<
  8922. T0,
  8923. T1,
  8924. T2,
  8925. T3,
  8926. T4,
  8927. T5,
  8928. T6,
  8929. T7,
  8930. T8,
  8931. T9,
  8932. T10,
  8933. T11,
  8934. T12,
  8935. T13,
  8936. T14,
  8937. T15,
  8938. T16,
  8939. NullType,
  8940. NullType,
  8941. NullType,
  8942. NullType,
  8943. NullType,
  8944. NullType,
  8945. NullType,
  8946. NullType,
  8947. NullType,
  8948. NullType,
  8949. NullType,
  8950. NullType,
  8951. NullType,
  8952. NullType,
  8953. NullType> FunctorType;
  8954. FunctorType functor_;
  8955. functionImplementation_(const FunctorType &functor) :
  8956. functor_(functor)
  8957. {
  8958. #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 17))
  8959. // Fail variadic expansion for dev11
  8960. static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
  8961. #endif
  8962. }
  8963. //! \brief Return type of the functor
  8964. typedef Event result_type;
  8965. //! \brief Function signature of kernel functor with no event dependency.
  8966. typedef Event type_(
  8967. const EnqueueArgs&,
  8968. T0,
  8969. T1,
  8970. T2,
  8971. T3,
  8972. T4,
  8973. T5,
  8974. T6,
  8975. T7,
  8976. T8,
  8977. T9,
  8978. T10,
  8979. T11,
  8980. T12,
  8981. T13,
  8982. T14,
  8983. T15,
  8984. T16);
  8985. Event operator()(
  8986. const EnqueueArgs& enqueueArgs,
  8987. T0 arg0,
  8988. T1 arg1,
  8989. T2 arg2,
  8990. T3 arg3,
  8991. T4 arg4,
  8992. T5 arg5,
  8993. T6 arg6,
  8994. T7 arg7,
  8995. T8 arg8,
  8996. T9 arg9,
  8997. T10 arg10,
  8998. T11 arg11,
  8999. T12 arg12,
  9000. T13 arg13,
  9001. T14 arg14,
  9002. T15 arg15,
  9003. T16 arg16)
  9004. {
  9005. return functor_(
  9006. enqueueArgs,
  9007. arg0,
  9008. arg1,
  9009. arg2,
  9010. arg3,
  9011. arg4,
  9012. arg5,
  9013. arg6,
  9014. arg7,
  9015. arg8,
  9016. arg9,
  9017. arg10,
  9018. arg11,
  9019. arg12,
  9020. arg13,
  9021. arg14,
  9022. arg15,
  9023. arg16);
  9024. }
  9025. };
  9026. template<
  9027. typename T0,
  9028. typename T1,
  9029. typename T2,
  9030. typename T3,
  9031. typename T4,
  9032. typename T5,
  9033. typename T6,
  9034. typename T7,
  9035. typename T8,
  9036. typename T9,
  9037. typename T10,
  9038. typename T11,
  9039. typename T12,
  9040. typename T13,
  9041. typename T14,
  9042. typename T15>
  9043. struct functionImplementation_
  9044. < T0,
  9045. T1,
  9046. T2,
  9047. T3,
  9048. T4,
  9049. T5,
  9050. T6,
  9051. T7,
  9052. T8,
  9053. T9,
  9054. T10,
  9055. T11,
  9056. T12,
  9057. T13,
  9058. T14,
  9059. T15,
  9060. NullType,
  9061. NullType,
  9062. NullType,
  9063. NullType,
  9064. NullType,
  9065. NullType,
  9066. NullType,
  9067. NullType,
  9068. NullType,
  9069. NullType,
  9070. NullType,
  9071. NullType,
  9072. NullType,
  9073. NullType,
  9074. NullType,
  9075. NullType>
  9076. {
  9077. typedef detail::KernelFunctorGlobal<
  9078. T0,
  9079. T1,
  9080. T2,
  9081. T3,
  9082. T4,
  9083. T5,
  9084. T6,
  9085. T7,
  9086. T8,
  9087. T9,
  9088. T10,
  9089. T11,
  9090. T12,
  9091. T13,
  9092. T14,
  9093. T15,
  9094. NullType,
  9095. NullType,
  9096. NullType,
  9097. NullType,
  9098. NullType,
  9099. NullType,
  9100. NullType,
  9101. NullType,
  9102. NullType,
  9103. NullType,
  9104. NullType,
  9105. NullType,
  9106. NullType,
  9107. NullType,
  9108. NullType,
  9109. NullType> FunctorType;
  9110. FunctorType functor_;
  9111. functionImplementation_(const FunctorType &functor) :
  9112. functor_(functor)
  9113. {
  9114. #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 16))
  9115. // Fail variadic expansion for dev11
  9116. static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
  9117. #endif
  9118. }
  9119. //! \brief Return type of the functor
  9120. typedef Event result_type;
  9121. //! \brief Function signature of kernel functor with no event dependency.
  9122. typedef Event type_(
  9123. const EnqueueArgs&,
  9124. T0,
  9125. T1,
  9126. T2,
  9127. T3,
  9128. T4,
  9129. T5,
  9130. T6,
  9131. T7,
  9132. T8,
  9133. T9,
  9134. T10,
  9135. T11,
  9136. T12,
  9137. T13,
  9138. T14,
  9139. T15);
  9140. Event operator()(
  9141. const EnqueueArgs& enqueueArgs,
  9142. T0 arg0,
  9143. T1 arg1,
  9144. T2 arg2,
  9145. T3 arg3,
  9146. T4 arg4,
  9147. T5 arg5,
  9148. T6 arg6,
  9149. T7 arg7,
  9150. T8 arg8,
  9151. T9 arg9,
  9152. T10 arg10,
  9153. T11 arg11,
  9154. T12 arg12,
  9155. T13 arg13,
  9156. T14 arg14,
  9157. T15 arg15)
  9158. {
  9159. return functor_(
  9160. enqueueArgs,
  9161. arg0,
  9162. arg1,
  9163. arg2,
  9164. arg3,
  9165. arg4,
  9166. arg5,
  9167. arg6,
  9168. arg7,
  9169. arg8,
  9170. arg9,
  9171. arg10,
  9172. arg11,
  9173. arg12,
  9174. arg13,
  9175. arg14,
  9176. arg15);
  9177. }
  9178. };
  9179. template<
  9180. typename T0,
  9181. typename T1,
  9182. typename T2,
  9183. typename T3,
  9184. typename T4,
  9185. typename T5,
  9186. typename T6,
  9187. typename T7,
  9188. typename T8,
  9189. typename T9,
  9190. typename T10,
  9191. typename T11,
  9192. typename T12,
  9193. typename T13,
  9194. typename T14>
  9195. struct functionImplementation_
  9196. < T0,
  9197. T1,
  9198. T2,
  9199. T3,
  9200. T4,
  9201. T5,
  9202. T6,
  9203. T7,
  9204. T8,
  9205. T9,
  9206. T10,
  9207. T11,
  9208. T12,
  9209. T13,
  9210. T14,
  9211. NullType,
  9212. NullType,
  9213. NullType,
  9214. NullType,
  9215. NullType,
  9216. NullType,
  9217. NullType,
  9218. NullType,
  9219. NullType,
  9220. NullType,
  9221. NullType,
  9222. NullType,
  9223. NullType,
  9224. NullType,
  9225. NullType,
  9226. NullType,
  9227. NullType>
  9228. {
  9229. typedef detail::KernelFunctorGlobal<
  9230. T0,
  9231. T1,
  9232. T2,
  9233. T3,
  9234. T4,
  9235. T5,
  9236. T6,
  9237. T7,
  9238. T8,
  9239. T9,
  9240. T10,
  9241. T11,
  9242. T12,
  9243. T13,
  9244. T14,
  9245. NullType,
  9246. NullType,
  9247. NullType,
  9248. NullType,
  9249. NullType,
  9250. NullType,
  9251. NullType,
  9252. NullType,
  9253. NullType,
  9254. NullType,
  9255. NullType,
  9256. NullType,
  9257. NullType,
  9258. NullType,
  9259. NullType,
  9260. NullType,
  9261. NullType> FunctorType;
  9262. FunctorType functor_;
  9263. functionImplementation_(const FunctorType &functor) :
  9264. functor_(functor)
  9265. {
  9266. #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 15))
  9267. // Fail variadic expansion for dev11
  9268. static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
  9269. #endif
  9270. }
  9271. //! \brief Return type of the functor
  9272. typedef Event result_type;
  9273. //! \brief Function signature of kernel functor with no event dependency.
  9274. typedef Event type_(
  9275. const EnqueueArgs&,
  9276. T0,
  9277. T1,
  9278. T2,
  9279. T3,
  9280. T4,
  9281. T5,
  9282. T6,
  9283. T7,
  9284. T8,
  9285. T9,
  9286. T10,
  9287. T11,
  9288. T12,
  9289. T13,
  9290. T14);
  9291. Event operator()(
  9292. const EnqueueArgs& enqueueArgs,
  9293. T0 arg0,
  9294. T1 arg1,
  9295. T2 arg2,
  9296. T3 arg3,
  9297. T4 arg4,
  9298. T5 arg5,
  9299. T6 arg6,
  9300. T7 arg7,
  9301. T8 arg8,
  9302. T9 arg9,
  9303. T10 arg10,
  9304. T11 arg11,
  9305. T12 arg12,
  9306. T13 arg13,
  9307. T14 arg14)
  9308. {
  9309. return functor_(
  9310. enqueueArgs,
  9311. arg0,
  9312. arg1,
  9313. arg2,
  9314. arg3,
  9315. arg4,
  9316. arg5,
  9317. arg6,
  9318. arg7,
  9319. arg8,
  9320. arg9,
  9321. arg10,
  9322. arg11,
  9323. arg12,
  9324. arg13,
  9325. arg14);
  9326. }
  9327. };
  9328. template<
  9329. typename T0,
  9330. typename T1,
  9331. typename T2,
  9332. typename T3,
  9333. typename T4,
  9334. typename T5,
  9335. typename T6,
  9336. typename T7,
  9337. typename T8,
  9338. typename T9,
  9339. typename T10,
  9340. typename T11,
  9341. typename T12,
  9342. typename T13>
  9343. struct functionImplementation_
  9344. < T0,
  9345. T1,
  9346. T2,
  9347. T3,
  9348. T4,
  9349. T5,
  9350. T6,
  9351. T7,
  9352. T8,
  9353. T9,
  9354. T10,
  9355. T11,
  9356. T12,
  9357. T13,
  9358. NullType,
  9359. NullType,
  9360. NullType,
  9361. NullType,
  9362. NullType,
  9363. NullType,
  9364. NullType,
  9365. NullType,
  9366. NullType,
  9367. NullType,
  9368. NullType,
  9369. NullType,
  9370. NullType,
  9371. NullType,
  9372. NullType,
  9373. NullType,
  9374. NullType,
  9375. NullType>
  9376. {
  9377. typedef detail::KernelFunctorGlobal<
  9378. T0,
  9379. T1,
  9380. T2,
  9381. T3,
  9382. T4,
  9383. T5,
  9384. T6,
  9385. T7,
  9386. T8,
  9387. T9,
  9388. T10,
  9389. T11,
  9390. T12,
  9391. T13,
  9392. NullType,
  9393. NullType,
  9394. NullType,
  9395. NullType,
  9396. NullType,
  9397. NullType,
  9398. NullType,
  9399. NullType,
  9400. NullType,
  9401. NullType,
  9402. NullType,
  9403. NullType,
  9404. NullType,
  9405. NullType,
  9406. NullType,
  9407. NullType,
  9408. NullType,
  9409. NullType> FunctorType;
  9410. FunctorType functor_;
  9411. functionImplementation_(const FunctorType &functor) :
  9412. functor_(functor)
  9413. {
  9414. #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 14))
  9415. // Fail variadic expansion for dev11
  9416. static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
  9417. #endif
  9418. }
  9419. //! \brief Return type of the functor
  9420. typedef Event result_type;
  9421. //! \brief Function signature of kernel functor with no event dependency.
  9422. typedef Event type_(
  9423. const EnqueueArgs&,
  9424. T0,
  9425. T1,
  9426. T2,
  9427. T3,
  9428. T4,
  9429. T5,
  9430. T6,
  9431. T7,
  9432. T8,
  9433. T9,
  9434. T10,
  9435. T11,
  9436. T12,
  9437. T13);
  9438. Event operator()(
  9439. const EnqueueArgs& enqueueArgs,
  9440. T0 arg0,
  9441. T1 arg1,
  9442. T2 arg2,
  9443. T3 arg3,
  9444. T4 arg4,
  9445. T5 arg5,
  9446. T6 arg6,
  9447. T7 arg7,
  9448. T8 arg8,
  9449. T9 arg9,
  9450. T10 arg10,
  9451. T11 arg11,
  9452. T12 arg12,
  9453. T13 arg13)
  9454. {
  9455. return functor_(
  9456. enqueueArgs,
  9457. arg0,
  9458. arg1,
  9459. arg2,
  9460. arg3,
  9461. arg4,
  9462. arg5,
  9463. arg6,
  9464. arg7,
  9465. arg8,
  9466. arg9,
  9467. arg10,
  9468. arg11,
  9469. arg12,
  9470. arg13);
  9471. }
  9472. };
  9473. template<
  9474. typename T0,
  9475. typename T1,
  9476. typename T2,
  9477. typename T3,
  9478. typename T4,
  9479. typename T5,
  9480. typename T6,
  9481. typename T7,
  9482. typename T8,
  9483. typename T9,
  9484. typename T10,
  9485. typename T11,
  9486. typename T12>
  9487. struct functionImplementation_
  9488. < T0,
  9489. T1,
  9490. T2,
  9491. T3,
  9492. T4,
  9493. T5,
  9494. T6,
  9495. T7,
  9496. T8,
  9497. T9,
  9498. T10,
  9499. T11,
  9500. T12,
  9501. NullType,
  9502. NullType,
  9503. NullType,
  9504. NullType,
  9505. NullType,
  9506. NullType,
  9507. NullType,
  9508. NullType,
  9509. NullType,
  9510. NullType,
  9511. NullType,
  9512. NullType,
  9513. NullType,
  9514. NullType,
  9515. NullType,
  9516. NullType,
  9517. NullType,
  9518. NullType,
  9519. NullType>
  9520. {
  9521. typedef detail::KernelFunctorGlobal<
  9522. T0,
  9523. T1,
  9524. T2,
  9525. T3,
  9526. T4,
  9527. T5,
  9528. T6,
  9529. T7,
  9530. T8,
  9531. T9,
  9532. T10,
  9533. T11,
  9534. T12,
  9535. NullType,
  9536. NullType,
  9537. NullType,
  9538. NullType,
  9539. NullType,
  9540. NullType,
  9541. NullType,
  9542. NullType,
  9543. NullType,
  9544. NullType,
  9545. NullType,
  9546. NullType,
  9547. NullType,
  9548. NullType,
  9549. NullType,
  9550. NullType,
  9551. NullType,
  9552. NullType,
  9553. NullType> FunctorType;
  9554. FunctorType functor_;
  9555. functionImplementation_(const FunctorType &functor) :
  9556. functor_(functor)
  9557. {
  9558. #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 13))
  9559. // Fail variadic expansion for dev11
  9560. static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
  9561. #endif
  9562. }
  9563. //! \brief Return type of the functor
  9564. typedef Event result_type;
  9565. //! \brief Function signature of kernel functor with no event dependency.
  9566. typedef Event type_(
  9567. const EnqueueArgs&,
  9568. T0,
  9569. T1,
  9570. T2,
  9571. T3,
  9572. T4,
  9573. T5,
  9574. T6,
  9575. T7,
  9576. T8,
  9577. T9,
  9578. T10,
  9579. T11,
  9580. T12);
  9581. Event operator()(
  9582. const EnqueueArgs& enqueueArgs,
  9583. T0 arg0,
  9584. T1 arg1,
  9585. T2 arg2,
  9586. T3 arg3,
  9587. T4 arg4,
  9588. T5 arg5,
  9589. T6 arg6,
  9590. T7 arg7,
  9591. T8 arg8,
  9592. T9 arg9,
  9593. T10 arg10,
  9594. T11 arg11,
  9595. T12 arg12)
  9596. {
  9597. return functor_(
  9598. enqueueArgs,
  9599. arg0,
  9600. arg1,
  9601. arg2,
  9602. arg3,
  9603. arg4,
  9604. arg5,
  9605. arg6,
  9606. arg7,
  9607. arg8,
  9608. arg9,
  9609. arg10,
  9610. arg11,
  9611. arg12);
  9612. }
  9613. };
  9614. template<
  9615. typename T0,
  9616. typename T1,
  9617. typename T2,
  9618. typename T3,
  9619. typename T4,
  9620. typename T5,
  9621. typename T6,
  9622. typename T7,
  9623. typename T8,
  9624. typename T9,
  9625. typename T10,
  9626. typename T11>
  9627. struct functionImplementation_
  9628. < T0,
  9629. T1,
  9630. T2,
  9631. T3,
  9632. T4,
  9633. T5,
  9634. T6,
  9635. T7,
  9636. T8,
  9637. T9,
  9638. T10,
  9639. T11,
  9640. NullType,
  9641. NullType,
  9642. NullType,
  9643. NullType,
  9644. NullType,
  9645. NullType,
  9646. NullType,
  9647. NullType,
  9648. NullType,
  9649. NullType,
  9650. NullType,
  9651. NullType,
  9652. NullType,
  9653. NullType,
  9654. NullType,
  9655. NullType,
  9656. NullType,
  9657. NullType,
  9658. NullType,
  9659. NullType>
  9660. {
  9661. typedef detail::KernelFunctorGlobal<
  9662. T0,
  9663. T1,
  9664. T2,
  9665. T3,
  9666. T4,
  9667. T5,
  9668. T6,
  9669. T7,
  9670. T8,
  9671. T9,
  9672. T10,
  9673. T11,
  9674. NullType,
  9675. NullType,
  9676. NullType,
  9677. NullType,
  9678. NullType,
  9679. NullType,
  9680. NullType,
  9681. NullType,
  9682. NullType,
  9683. NullType,
  9684. NullType,
  9685. NullType,
  9686. NullType,
  9687. NullType,
  9688. NullType,
  9689. NullType,
  9690. NullType,
  9691. NullType,
  9692. NullType,
  9693. NullType> FunctorType;
  9694. FunctorType functor_;
  9695. functionImplementation_(const FunctorType &functor) :
  9696. functor_(functor)
  9697. {
  9698. #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 12))
  9699. // Fail variadic expansion for dev11
  9700. static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
  9701. #endif
  9702. }
  9703. //! \brief Return type of the functor
  9704. typedef Event result_type;
  9705. //! \brief Function signature of kernel functor with no event dependency.
  9706. typedef Event type_(
  9707. const EnqueueArgs&,
  9708. T0,
  9709. T1,
  9710. T2,
  9711. T3,
  9712. T4,
  9713. T5,
  9714. T6,
  9715. T7,
  9716. T8,
  9717. T9,
  9718. T10,
  9719. T11);
  9720. Event operator()(
  9721. const EnqueueArgs& enqueueArgs,
  9722. T0 arg0,
  9723. T1 arg1,
  9724. T2 arg2,
  9725. T3 arg3,
  9726. T4 arg4,
  9727. T5 arg5,
  9728. T6 arg6,
  9729. T7 arg7,
  9730. T8 arg8,
  9731. T9 arg9,
  9732. T10 arg10,
  9733. T11 arg11)
  9734. {
  9735. return functor_(
  9736. enqueueArgs,
  9737. arg0,
  9738. arg1,
  9739. arg2,
  9740. arg3,
  9741. arg4,
  9742. arg5,
  9743. arg6,
  9744. arg7,
  9745. arg8,
  9746. arg9,
  9747. arg10,
  9748. arg11);
  9749. }
  9750. };
  9751. template<
  9752. typename T0,
  9753. typename T1,
  9754. typename T2,
  9755. typename T3,
  9756. typename T4,
  9757. typename T5,
  9758. typename T6,
  9759. typename T7,
  9760. typename T8,
  9761. typename T9,
  9762. typename T10>
  9763. struct functionImplementation_
  9764. < T0,
  9765. T1,
  9766. T2,
  9767. T3,
  9768. T4,
  9769. T5,
  9770. T6,
  9771. T7,
  9772. T8,
  9773. T9,
  9774. T10,
  9775. NullType,
  9776. NullType,
  9777. NullType,
  9778. NullType,
  9779. NullType,
  9780. NullType,
  9781. NullType,
  9782. NullType,
  9783. NullType,
  9784. NullType,
  9785. NullType,
  9786. NullType,
  9787. NullType,
  9788. NullType,
  9789. NullType,
  9790. NullType,
  9791. NullType,
  9792. NullType,
  9793. NullType,
  9794. NullType,
  9795. NullType>
  9796. {
  9797. typedef detail::KernelFunctorGlobal<
  9798. T0,
  9799. T1,
  9800. T2,
  9801. T3,
  9802. T4,
  9803. T5,
  9804. T6,
  9805. T7,
  9806. T8,
  9807. T9,
  9808. T10,
  9809. NullType,
  9810. NullType,
  9811. NullType,
  9812. NullType,
  9813. NullType,
  9814. NullType,
  9815. NullType,
  9816. NullType,
  9817. NullType,
  9818. NullType,
  9819. NullType,
  9820. NullType,
  9821. NullType,
  9822. NullType,
  9823. NullType,
  9824. NullType,
  9825. NullType,
  9826. NullType,
  9827. NullType,
  9828. NullType,
  9829. NullType> FunctorType;
  9830. FunctorType functor_;
  9831. functionImplementation_(const FunctorType &functor) :
  9832. functor_(functor)
  9833. {
  9834. #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 11))
  9835. // Fail variadic expansion for dev11
  9836. static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
  9837. #endif
  9838. }
  9839. //! \brief Return type of the functor
  9840. typedef Event result_type;
  9841. //! \brief Function signature of kernel functor with no event dependency.
  9842. typedef Event type_(
  9843. const EnqueueArgs&,
  9844. T0,
  9845. T1,
  9846. T2,
  9847. T3,
  9848. T4,
  9849. T5,
  9850. T6,
  9851. T7,
  9852. T8,
  9853. T9,
  9854. T10);
  9855. Event operator()(
  9856. const EnqueueArgs& enqueueArgs,
  9857. T0 arg0,
  9858. T1 arg1,
  9859. T2 arg2,
  9860. T3 arg3,
  9861. T4 arg4,
  9862. T5 arg5,
  9863. T6 arg6,
  9864. T7 arg7,
  9865. T8 arg8,
  9866. T9 arg9,
  9867. T10 arg10)
  9868. {
  9869. return functor_(
  9870. enqueueArgs,
  9871. arg0,
  9872. arg1,
  9873. arg2,
  9874. arg3,
  9875. arg4,
  9876. arg5,
  9877. arg6,
  9878. arg7,
  9879. arg8,
  9880. arg9,
  9881. arg10);
  9882. }
  9883. };
  9884. template<
  9885. typename T0,
  9886. typename T1,
  9887. typename T2,
  9888. typename T3,
  9889. typename T4,
  9890. typename T5,
  9891. typename T6,
  9892. typename T7,
  9893. typename T8,
  9894. typename T9>
  9895. struct functionImplementation_
  9896. < T0,
  9897. T1,
  9898. T2,
  9899. T3,
  9900. T4,
  9901. T5,
  9902. T6,
  9903. T7,
  9904. T8,
  9905. T9,
  9906. NullType,
  9907. NullType,
  9908. NullType,
  9909. NullType,
  9910. NullType,
  9911. NullType,
  9912. NullType,
  9913. NullType,
  9914. NullType,
  9915. NullType,
  9916. NullType,
  9917. NullType,
  9918. NullType,
  9919. NullType,
  9920. NullType,
  9921. NullType,
  9922. NullType,
  9923. NullType,
  9924. NullType,
  9925. NullType,
  9926. NullType,
  9927. NullType>
  9928. {
  9929. typedef detail::KernelFunctorGlobal<
  9930. T0,
  9931. T1,
  9932. T2,
  9933. T3,
  9934. T4,
  9935. T5,
  9936. T6,
  9937. T7,
  9938. T8,
  9939. T9,
  9940. NullType,
  9941. NullType,
  9942. NullType,
  9943. NullType,
  9944. NullType,
  9945. NullType,
  9946. NullType,
  9947. NullType,
  9948. NullType,
  9949. NullType,
  9950. NullType,
  9951. NullType,
  9952. NullType,
  9953. NullType,
  9954. NullType,
  9955. NullType,
  9956. NullType,
  9957. NullType,
  9958. NullType,
  9959. NullType,
  9960. NullType,
  9961. NullType> FunctorType;
  9962. FunctorType functor_;
  9963. functionImplementation_(const FunctorType &functor) :
  9964. functor_(functor)
  9965. {
  9966. #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 10))
  9967. // Fail variadic expansion for dev11
  9968. static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
  9969. #endif
  9970. }
  9971. //! \brief Return type of the functor
  9972. typedef Event result_type;
  9973. //! \brief Function signature of kernel functor with no event dependency.
  9974. typedef Event type_(
  9975. const EnqueueArgs&,
  9976. T0,
  9977. T1,
  9978. T2,
  9979. T3,
  9980. T4,
  9981. T5,
  9982. T6,
  9983. T7,
  9984. T8,
  9985. T9);
  9986. Event operator()(
  9987. const EnqueueArgs& enqueueArgs,
  9988. T0 arg0,
  9989. T1 arg1,
  9990. T2 arg2,
  9991. T3 arg3,
  9992. T4 arg4,
  9993. T5 arg5,
  9994. T6 arg6,
  9995. T7 arg7,
  9996. T8 arg8,
  9997. T9 arg9)
  9998. {
  9999. return functor_(
  10000. enqueueArgs,
  10001. arg0,
  10002. arg1,
  10003. arg2,
  10004. arg3,
  10005. arg4,
  10006. arg5,
  10007. arg6,
  10008. arg7,
  10009. arg8,
  10010. arg9);
  10011. }
  10012. };
  10013. template<
  10014. typename T0,
  10015. typename T1,
  10016. typename T2,
  10017. typename T3,
  10018. typename T4,
  10019. typename T5,
  10020. typename T6,
  10021. typename T7,
  10022. typename T8>
  10023. struct functionImplementation_
  10024. < T0,
  10025. T1,
  10026. T2,
  10027. T3,
  10028. T4,
  10029. T5,
  10030. T6,
  10031. T7,
  10032. T8,
  10033. NullType,
  10034. NullType,
  10035. NullType,
  10036. NullType,
  10037. NullType,
  10038. NullType,
  10039. NullType,
  10040. NullType,
  10041. NullType,
  10042. NullType,
  10043. NullType,
  10044. NullType,
  10045. NullType,
  10046. NullType,
  10047. NullType,
  10048. NullType,
  10049. NullType,
  10050. NullType,
  10051. NullType,
  10052. NullType,
  10053. NullType,
  10054. NullType,
  10055. NullType>
  10056. {
  10057. typedef detail::KernelFunctorGlobal<
  10058. T0,
  10059. T1,
  10060. T2,
  10061. T3,
  10062. T4,
  10063. T5,
  10064. T6,
  10065. T7,
  10066. T8,
  10067. NullType,
  10068. NullType,
  10069. NullType,
  10070. NullType,
  10071. NullType,
  10072. NullType,
  10073. NullType,
  10074. NullType,
  10075. NullType,
  10076. NullType,
  10077. NullType,
  10078. NullType,
  10079. NullType,
  10080. NullType,
  10081. NullType,
  10082. NullType,
  10083. NullType,
  10084. NullType,
  10085. NullType,
  10086. NullType,
  10087. NullType,
  10088. NullType,
  10089. NullType> FunctorType;
  10090. FunctorType functor_;
  10091. functionImplementation_(const FunctorType &functor) :
  10092. functor_(functor)
  10093. {
  10094. #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 9))
  10095. // Fail variadic expansion for dev11
  10096. static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
  10097. #endif
  10098. }
  10099. //! \brief Return type of the functor
  10100. typedef Event result_type;
  10101. //! \brief Function signature of kernel functor with no event dependency.
  10102. typedef Event type_(
  10103. const EnqueueArgs&,
  10104. T0,
  10105. T1,
  10106. T2,
  10107. T3,
  10108. T4,
  10109. T5,
  10110. T6,
  10111. T7,
  10112. T8);
  10113. Event operator()(
  10114. const EnqueueArgs& enqueueArgs,
  10115. T0 arg0,
  10116. T1 arg1,
  10117. T2 arg2,
  10118. T3 arg3,
  10119. T4 arg4,
  10120. T5 arg5,
  10121. T6 arg6,
  10122. T7 arg7,
  10123. T8 arg8)
  10124. {
  10125. return functor_(
  10126. enqueueArgs,
  10127. arg0,
  10128. arg1,
  10129. arg2,
  10130. arg3,
  10131. arg4,
  10132. arg5,
  10133. arg6,
  10134. arg7,
  10135. arg8);
  10136. }
  10137. };
  10138. template<
  10139. typename T0,
  10140. typename T1,
  10141. typename T2,
  10142. typename T3,
  10143. typename T4,
  10144. typename T5,
  10145. typename T6,
  10146. typename T7>
  10147. struct functionImplementation_
  10148. < T0,
  10149. T1,
  10150. T2,
  10151. T3,
  10152. T4,
  10153. T5,
  10154. T6,
  10155. T7,
  10156. NullType,
  10157. NullType,
  10158. NullType,
  10159. NullType,
  10160. NullType,
  10161. NullType,
  10162. NullType,
  10163. NullType,
  10164. NullType,
  10165. NullType,
  10166. NullType,
  10167. NullType,
  10168. NullType,
  10169. NullType,
  10170. NullType,
  10171. NullType,
  10172. NullType,
  10173. NullType,
  10174. NullType,
  10175. NullType,
  10176. NullType,
  10177. NullType,
  10178. NullType,
  10179. NullType>
  10180. {
  10181. typedef detail::KernelFunctorGlobal<
  10182. T0,
  10183. T1,
  10184. T2,
  10185. T3,
  10186. T4,
  10187. T5,
  10188. T6,
  10189. T7,
  10190. NullType,
  10191. NullType,
  10192. NullType,
  10193. NullType,
  10194. NullType,
  10195. NullType,
  10196. NullType,
  10197. NullType,
  10198. NullType,
  10199. NullType,
  10200. NullType,
  10201. NullType,
  10202. NullType,
  10203. NullType,
  10204. NullType,
  10205. NullType,
  10206. NullType,
  10207. NullType,
  10208. NullType,
  10209. NullType,
  10210. NullType,
  10211. NullType,
  10212. NullType,
  10213. NullType> FunctorType;
  10214. FunctorType functor_;
  10215. functionImplementation_(const FunctorType &functor) :
  10216. functor_(functor)
  10217. {
  10218. #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 8))
  10219. // Fail variadic expansion for dev11
  10220. static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
  10221. #endif
  10222. }
  10223. //! \brief Return type of the functor
  10224. typedef Event result_type;
  10225. //! \brief Function signature of kernel functor with no event dependency.
  10226. typedef Event type_(
  10227. const EnqueueArgs&,
  10228. T0,
  10229. T1,
  10230. T2,
  10231. T3,
  10232. T4,
  10233. T5,
  10234. T6,
  10235. T7);
  10236. Event operator()(
  10237. const EnqueueArgs& enqueueArgs,
  10238. T0 arg0,
  10239. T1 arg1,
  10240. T2 arg2,
  10241. T3 arg3,
  10242. T4 arg4,
  10243. T5 arg5,
  10244. T6 arg6,
  10245. T7 arg7)
  10246. {
  10247. return functor_(
  10248. enqueueArgs,
  10249. arg0,
  10250. arg1,
  10251. arg2,
  10252. arg3,
  10253. arg4,
  10254. arg5,
  10255. arg6,
  10256. arg7);
  10257. }
  10258. };
  10259. template<
  10260. typename T0,
  10261. typename T1,
  10262. typename T2,
  10263. typename T3,
  10264. typename T4,
  10265. typename T5,
  10266. typename T6>
  10267. struct functionImplementation_
  10268. < T0,
  10269. T1,
  10270. T2,
  10271. T3,
  10272. T4,
  10273. T5,
  10274. T6,
  10275. NullType,
  10276. NullType,
  10277. NullType,
  10278. NullType,
  10279. NullType,
  10280. NullType,
  10281. NullType,
  10282. NullType,
  10283. NullType,
  10284. NullType,
  10285. NullType,
  10286. NullType,
  10287. NullType,
  10288. NullType,
  10289. NullType,
  10290. NullType,
  10291. NullType,
  10292. NullType,
  10293. NullType,
  10294. NullType,
  10295. NullType,
  10296. NullType,
  10297. NullType,
  10298. NullType,
  10299. NullType>
  10300. {
  10301. typedef detail::KernelFunctorGlobal<
  10302. T0,
  10303. T1,
  10304. T2,
  10305. T3,
  10306. T4,
  10307. T5,
  10308. T6,
  10309. NullType,
  10310. NullType,
  10311. NullType,
  10312. NullType,
  10313. NullType,
  10314. NullType,
  10315. NullType,
  10316. NullType,
  10317. NullType,
  10318. NullType,
  10319. NullType,
  10320. NullType,
  10321. NullType,
  10322. NullType,
  10323. NullType,
  10324. NullType,
  10325. NullType,
  10326. NullType,
  10327. NullType,
  10328. NullType,
  10329. NullType,
  10330. NullType,
  10331. NullType,
  10332. NullType,
  10333. NullType> FunctorType;
  10334. FunctorType functor_;
  10335. functionImplementation_(const FunctorType &functor) :
  10336. functor_(functor)
  10337. {
  10338. #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 7))
  10339. // Fail variadic expansion for dev11
  10340. static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
  10341. #endif
  10342. }
  10343. //! \brief Return type of the functor
  10344. typedef Event result_type;
  10345. //! \brief Function signature of kernel functor with no event dependency.
  10346. typedef Event type_(
  10347. const EnqueueArgs&,
  10348. T0,
  10349. T1,
  10350. T2,
  10351. T3,
  10352. T4,
  10353. T5,
  10354. T6);
  10355. Event operator()(
  10356. const EnqueueArgs& enqueueArgs,
  10357. T0 arg0,
  10358. T1 arg1,
  10359. T2 arg2,
  10360. T3 arg3,
  10361. T4 arg4,
  10362. T5 arg5,
  10363. T6 arg6)
  10364. {
  10365. return functor_(
  10366. enqueueArgs,
  10367. arg0,
  10368. arg1,
  10369. arg2,
  10370. arg3,
  10371. arg4,
  10372. arg5,
  10373. arg6);
  10374. }
  10375. };
  10376. template<
  10377. typename T0,
  10378. typename T1,
  10379. typename T2,
  10380. typename T3,
  10381. typename T4,
  10382. typename T5>
  10383. struct functionImplementation_
  10384. < T0,
  10385. T1,
  10386. T2,
  10387. T3,
  10388. T4,
  10389. T5,
  10390. NullType,
  10391. NullType,
  10392. NullType,
  10393. NullType,
  10394. NullType,
  10395. NullType,
  10396. NullType,
  10397. NullType,
  10398. NullType,
  10399. NullType,
  10400. NullType,
  10401. NullType,
  10402. NullType,
  10403. NullType,
  10404. NullType,
  10405. NullType,
  10406. NullType,
  10407. NullType,
  10408. NullType,
  10409. NullType,
  10410. NullType,
  10411. NullType,
  10412. NullType,
  10413. NullType,
  10414. NullType,
  10415. NullType>
  10416. {
  10417. typedef detail::KernelFunctorGlobal<
  10418. T0,
  10419. T1,
  10420. T2,
  10421. T3,
  10422. T4,
  10423. T5,
  10424. NullType,
  10425. NullType,
  10426. NullType,
  10427. NullType,
  10428. NullType,
  10429. NullType,
  10430. NullType,
  10431. NullType,
  10432. NullType,
  10433. NullType,
  10434. NullType,
  10435. NullType,
  10436. NullType,
  10437. NullType,
  10438. NullType,
  10439. NullType,
  10440. NullType,
  10441. NullType,
  10442. NullType,
  10443. NullType,
  10444. NullType,
  10445. NullType,
  10446. NullType,
  10447. NullType,
  10448. NullType,
  10449. NullType> FunctorType;
  10450. FunctorType functor_;
  10451. functionImplementation_(const FunctorType &functor) :
  10452. functor_(functor)
  10453. {
  10454. #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 6))
  10455. // Fail variadic expansion for dev11
  10456. static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
  10457. #endif
  10458. }
  10459. //! \brief Return type of the functor
  10460. typedef Event result_type;
  10461. //! \brief Function signature of kernel functor with no event dependency.
  10462. typedef Event type_(
  10463. const EnqueueArgs&,
  10464. T0,
  10465. T1,
  10466. T2,
  10467. T3,
  10468. T4,
  10469. T5);
  10470. Event operator()(
  10471. const EnqueueArgs& enqueueArgs,
  10472. T0 arg0,
  10473. T1 arg1,
  10474. T2 arg2,
  10475. T3 arg3,
  10476. T4 arg4,
  10477. T5 arg5)
  10478. {
  10479. return functor_(
  10480. enqueueArgs,
  10481. arg0,
  10482. arg1,
  10483. arg2,
  10484. arg3,
  10485. arg4,
  10486. arg5);
  10487. }
  10488. };
  10489. template<
  10490. typename T0,
  10491. typename T1,
  10492. typename T2,
  10493. typename T3,
  10494. typename T4>
  10495. struct functionImplementation_
  10496. < T0,
  10497. T1,
  10498. T2,
  10499. T3,
  10500. T4,
  10501. NullType,
  10502. NullType,
  10503. NullType,
  10504. NullType,
  10505. NullType,
  10506. NullType,
  10507. NullType,
  10508. NullType,
  10509. NullType,
  10510. NullType,
  10511. NullType,
  10512. NullType,
  10513. NullType,
  10514. NullType,
  10515. NullType,
  10516. NullType,
  10517. NullType,
  10518. NullType,
  10519. NullType,
  10520. NullType,
  10521. NullType,
  10522. NullType,
  10523. NullType,
  10524. NullType,
  10525. NullType,
  10526. NullType,
  10527. NullType>
  10528. {
  10529. typedef detail::KernelFunctorGlobal<
  10530. T0,
  10531. T1,
  10532. T2,
  10533. T3,
  10534. T4,
  10535. NullType,
  10536. NullType,
  10537. NullType,
  10538. NullType,
  10539. NullType,
  10540. NullType,
  10541. NullType,
  10542. NullType,
  10543. NullType,
  10544. NullType,
  10545. NullType,
  10546. NullType,
  10547. NullType,
  10548. NullType,
  10549. NullType,
  10550. NullType,
  10551. NullType,
  10552. NullType,
  10553. NullType,
  10554. NullType,
  10555. NullType,
  10556. NullType,
  10557. NullType,
  10558. NullType,
  10559. NullType,
  10560. NullType,
  10561. NullType> FunctorType;
  10562. FunctorType functor_;
  10563. functionImplementation_(const FunctorType &functor) :
  10564. functor_(functor)
  10565. {
  10566. #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 5))
  10567. // Fail variadic expansion for dev11
  10568. static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
  10569. #endif
  10570. }
  10571. //! \brief Return type of the functor
  10572. typedef Event result_type;
  10573. //! \brief Function signature of kernel functor with no event dependency.
  10574. typedef Event type_(
  10575. const EnqueueArgs&,
  10576. T0,
  10577. T1,
  10578. T2,
  10579. T3,
  10580. T4);
  10581. Event operator()(
  10582. const EnqueueArgs& enqueueArgs,
  10583. T0 arg0,
  10584. T1 arg1,
  10585. T2 arg2,
  10586. T3 arg3,
  10587. T4 arg4)
  10588. {
  10589. return functor_(
  10590. enqueueArgs,
  10591. arg0,
  10592. arg1,
  10593. arg2,
  10594. arg3,
  10595. arg4);
  10596. }
  10597. };
  10598. template<
  10599. typename T0,
  10600. typename T1,
  10601. typename T2,
  10602. typename T3>
  10603. struct functionImplementation_
  10604. < T0,
  10605. T1,
  10606. T2,
  10607. T3,
  10608. NullType,
  10609. NullType,
  10610. NullType,
  10611. NullType,
  10612. NullType,
  10613. NullType,
  10614. NullType,
  10615. NullType,
  10616. NullType,
  10617. NullType,
  10618. NullType,
  10619. NullType,
  10620. NullType,
  10621. NullType,
  10622. NullType,
  10623. NullType,
  10624. NullType,
  10625. NullType,
  10626. NullType,
  10627. NullType,
  10628. NullType,
  10629. NullType,
  10630. NullType,
  10631. NullType,
  10632. NullType,
  10633. NullType,
  10634. NullType,
  10635. NullType>
  10636. {
  10637. typedef detail::KernelFunctorGlobal<
  10638. T0,
  10639. T1,
  10640. T2,
  10641. T3,
  10642. NullType,
  10643. NullType,
  10644. NullType,
  10645. NullType,
  10646. NullType,
  10647. NullType,
  10648. NullType,
  10649. NullType,
  10650. NullType,
  10651. NullType,
  10652. NullType,
  10653. NullType,
  10654. NullType,
  10655. NullType,
  10656. NullType,
  10657. NullType,
  10658. NullType,
  10659. NullType,
  10660. NullType,
  10661. NullType,
  10662. NullType,
  10663. NullType,
  10664. NullType,
  10665. NullType,
  10666. NullType,
  10667. NullType,
  10668. NullType,
  10669. NullType> FunctorType;
  10670. FunctorType functor_;
  10671. functionImplementation_(const FunctorType &functor) :
  10672. functor_(functor)
  10673. {
  10674. #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 4))
  10675. // Fail variadic expansion for dev11
  10676. static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
  10677. #endif
  10678. }
  10679. //! \brief Return type of the functor
  10680. typedef Event result_type;
  10681. //! \brief Function signature of kernel functor with no event dependency.
  10682. typedef Event type_(
  10683. const EnqueueArgs&,
  10684. T0,
  10685. T1,
  10686. T2,
  10687. T3);
  10688. Event operator()(
  10689. const EnqueueArgs& enqueueArgs,
  10690. T0 arg0,
  10691. T1 arg1,
  10692. T2 arg2,
  10693. T3 arg3)
  10694. {
  10695. return functor_(
  10696. enqueueArgs,
  10697. arg0,
  10698. arg1,
  10699. arg2,
  10700. arg3);
  10701. }
  10702. };
  10703. template<
  10704. typename T0,
  10705. typename T1,
  10706. typename T2>
  10707. struct functionImplementation_
  10708. < T0,
  10709. T1,
  10710. T2,
  10711. NullType,
  10712. NullType,
  10713. NullType,
  10714. NullType,
  10715. NullType,
  10716. NullType,
  10717. NullType,
  10718. NullType,
  10719. NullType,
  10720. NullType,
  10721. NullType,
  10722. NullType,
  10723. NullType,
  10724. NullType,
  10725. NullType,
  10726. NullType,
  10727. NullType,
  10728. NullType,
  10729. NullType,
  10730. NullType,
  10731. NullType,
  10732. NullType,
  10733. NullType,
  10734. NullType,
  10735. NullType,
  10736. NullType,
  10737. NullType,
  10738. NullType,
  10739. NullType>
  10740. {
  10741. typedef detail::KernelFunctorGlobal<
  10742. T0,
  10743. T1,
  10744. T2,
  10745. NullType,
  10746. NullType,
  10747. NullType,
  10748. NullType,
  10749. NullType,
  10750. NullType,
  10751. NullType,
  10752. NullType,
  10753. NullType,
  10754. NullType,
  10755. NullType,
  10756. NullType,
  10757. NullType,
  10758. NullType,
  10759. NullType,
  10760. NullType,
  10761. NullType,
  10762. NullType,
  10763. NullType,
  10764. NullType,
  10765. NullType,
  10766. NullType,
  10767. NullType,
  10768. NullType,
  10769. NullType,
  10770. NullType,
  10771. NullType,
  10772. NullType,
  10773. NullType> FunctorType;
  10774. FunctorType functor_;
  10775. functionImplementation_(const FunctorType &functor) :
  10776. functor_(functor)
  10777. {
  10778. #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 3))
  10779. // Fail variadic expansion for dev11
  10780. static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
  10781. #endif
  10782. }
  10783. //! \brief Return type of the functor
  10784. typedef Event result_type;
  10785. //! \brief Function signature of kernel functor with no event dependency.
  10786. typedef Event type_(
  10787. const EnqueueArgs&,
  10788. T0,
  10789. T1,
  10790. T2);
  10791. Event operator()(
  10792. const EnqueueArgs& enqueueArgs,
  10793. T0 arg0,
  10794. T1 arg1,
  10795. T2 arg2)
  10796. {
  10797. return functor_(
  10798. enqueueArgs,
  10799. arg0,
  10800. arg1,
  10801. arg2);
  10802. }
  10803. };
  10804. template<
  10805. typename T0,
  10806. typename T1>
  10807. struct functionImplementation_
  10808. < T0,
  10809. T1,
  10810. NullType,
  10811. NullType,
  10812. NullType,
  10813. NullType,
  10814. NullType,
  10815. NullType,
  10816. NullType,
  10817. NullType,
  10818. NullType,
  10819. NullType,
  10820. NullType,
  10821. NullType,
  10822. NullType,
  10823. NullType,
  10824. NullType,
  10825. NullType,
  10826. NullType,
  10827. NullType,
  10828. NullType,
  10829. NullType,
  10830. NullType,
  10831. NullType,
  10832. NullType,
  10833. NullType,
  10834. NullType,
  10835. NullType,
  10836. NullType,
  10837. NullType,
  10838. NullType,
  10839. NullType>
  10840. {
  10841. typedef detail::KernelFunctorGlobal<
  10842. T0,
  10843. T1,
  10844. NullType,
  10845. NullType,
  10846. NullType,
  10847. NullType,
  10848. NullType,
  10849. NullType,
  10850. NullType,
  10851. NullType,
  10852. NullType,
  10853. NullType,
  10854. NullType,
  10855. NullType,
  10856. NullType,
  10857. NullType,
  10858. NullType,
  10859. NullType,
  10860. NullType,
  10861. NullType,
  10862. NullType,
  10863. NullType,
  10864. NullType,
  10865. NullType,
  10866. NullType,
  10867. NullType,
  10868. NullType,
  10869. NullType,
  10870. NullType,
  10871. NullType,
  10872. NullType,
  10873. NullType> FunctorType;
  10874. FunctorType functor_;
  10875. functionImplementation_(const FunctorType &functor) :
  10876. functor_(functor)
  10877. {
  10878. #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 2))
  10879. // Fail variadic expansion for dev11
  10880. static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
  10881. #endif
  10882. }
  10883. //! \brief Return type of the functor
  10884. typedef Event result_type;
  10885. //! \brief Function signature of kernel functor with no event dependency.
  10886. typedef Event type_(
  10887. const EnqueueArgs&,
  10888. T0,
  10889. T1);
  10890. Event operator()(
  10891. const EnqueueArgs& enqueueArgs,
  10892. T0 arg0,
  10893. T1 arg1)
  10894. {
  10895. return functor_(
  10896. enqueueArgs,
  10897. arg0,
  10898. arg1);
  10899. }
  10900. };
  10901. template<
  10902. typename T0>
  10903. struct functionImplementation_
  10904. < T0,
  10905. NullType,
  10906. NullType,
  10907. NullType,
  10908. NullType,
  10909. NullType,
  10910. NullType,
  10911. NullType,
  10912. NullType,
  10913. NullType,
  10914. NullType,
  10915. NullType,
  10916. NullType,
  10917. NullType,
  10918. NullType,
  10919. NullType,
  10920. NullType,
  10921. NullType,
  10922. NullType,
  10923. NullType,
  10924. NullType,
  10925. NullType,
  10926. NullType,
  10927. NullType,
  10928. NullType,
  10929. NullType,
  10930. NullType,
  10931. NullType,
  10932. NullType,
  10933. NullType,
  10934. NullType,
  10935. NullType>
  10936. {
  10937. typedef detail::KernelFunctorGlobal<
  10938. T0,
  10939. NullType,
  10940. NullType,
  10941. NullType,
  10942. NullType,
  10943. NullType,
  10944. NullType,
  10945. NullType,
  10946. NullType,
  10947. NullType,
  10948. NullType,
  10949. NullType,
  10950. NullType,
  10951. NullType,
  10952. NullType,
  10953. NullType,
  10954. NullType,
  10955. NullType,
  10956. NullType,
  10957. NullType,
  10958. NullType,
  10959. NullType,
  10960. NullType,
  10961. NullType,
  10962. NullType,
  10963. NullType,
  10964. NullType,
  10965. NullType,
  10966. NullType,
  10967. NullType,
  10968. NullType,
  10969. NullType> FunctorType;
  10970. FunctorType functor_;
  10971. functionImplementation_(const FunctorType &functor) :
  10972. functor_(functor)
  10973. {
  10974. #if (defined(_WIN32) && defined(_VARIADIC_MAX) && (_VARIADIC_MAX < 1))
  10975. // Fail variadic expansion for dev11
  10976. static_assert(0, "Visual Studio has a hard limit of argument count for a std::function expansion. Please define _VARIADIC_MAX to be 10. If you need more arguments than that VC12 and below cannot support it.");
  10977. #endif
  10978. }
  10979. //! \brief Return type of the functor
  10980. typedef Event result_type;
  10981. //! \brief Function signature of kernel functor with no event dependency.
  10982. typedef Event type_(
  10983. const EnqueueArgs&,
  10984. T0);
  10985. Event operator()(
  10986. const EnqueueArgs& enqueueArgs,
  10987. T0 arg0)
  10988. {
  10989. return functor_(
  10990. enqueueArgs,
  10991. arg0);
  10992. }
  10993. };
  10994. } // namespace detail
  10995. //----------------------------------------------------------------------------------------------
  10996. template <
  10997. typename T0, typename T1 = detail::NullType, typename T2 = detail::NullType,
  10998. typename T3 = detail::NullType, typename T4 = detail::NullType,
  10999. typename T5 = detail::NullType, typename T6 = detail::NullType,
  11000. typename T7 = detail::NullType, typename T8 = detail::NullType,
  11001. typename T9 = detail::NullType, typename T10 = detail::NullType,
  11002. typename T11 = detail::NullType, typename T12 = detail::NullType,
  11003. typename T13 = detail::NullType, typename T14 = detail::NullType,
  11004. typename T15 = detail::NullType, typename T16 = detail::NullType,
  11005. typename T17 = detail::NullType, typename T18 = detail::NullType,
  11006. typename T19 = detail::NullType, typename T20 = detail::NullType,
  11007. typename T21 = detail::NullType, typename T22 = detail::NullType,
  11008. typename T23 = detail::NullType, typename T24 = detail::NullType,
  11009. typename T25 = detail::NullType, typename T26 = detail::NullType,
  11010. typename T27 = detail::NullType, typename T28 = detail::NullType,
  11011. typename T29 = detail::NullType, typename T30 = detail::NullType,
  11012. typename T31 = detail::NullType
  11013. >
  11014. struct make_kernel :
  11015. public detail::functionImplementation_<
  11016. T0, T1, T2, T3,
  11017. T4, T5, T6, T7,
  11018. T8, T9, T10, T11,
  11019. T12, T13, T14, T15,
  11020. T16, T17, T18, T19,
  11021. T20, T21, T22, T23,
  11022. T24, T25, T26, T27,
  11023. T28, T29, T30, T31
  11024. >
  11025. {
  11026. public:
  11027. typedef detail::KernelFunctorGlobal<
  11028. T0, T1, T2, T3,
  11029. T4, T5, T6, T7,
  11030. T8, T9, T10, T11,
  11031. T12, T13, T14, T15,
  11032. T16, T17, T18, T19,
  11033. T20, T21, T22, T23,
  11034. T24, T25, T26, T27,
  11035. T28, T29, T30, T31
  11036. > FunctorType;
  11037. make_kernel(
  11038. const Program& program,
  11039. const STRING_CLASS name,
  11040. cl_int * err = NULL) :
  11041. detail::functionImplementation_<
  11042. T0, T1, T2, T3,
  11043. T4, T5, T6, T7,
  11044. T8, T9, T10, T11,
  11045. T12, T13, T14, T15,
  11046. T16, T17, T18, T19,
  11047. T20, T21, T22, T23,
  11048. T24, T25, T26, T27,
  11049. T28, T29, T30, T31
  11050. >(
  11051. FunctorType(program, name, err))
  11052. {}
  11053. make_kernel(
  11054. const Kernel kernel) :
  11055. detail::functionImplementation_<
  11056. T0, T1, T2, T3,
  11057. T4, T5, T6, T7,
  11058. T8, T9, T10, T11,
  11059. T12, T13, T14, T15,
  11060. T16, T17, T18, T19,
  11061. T20, T21, T22, T23,
  11062. T24, T25, T26, T27,
  11063. T28, T29, T30, T31
  11064. >(
  11065. FunctorType(kernel))
  11066. {}
  11067. };
  11068. //----------------------------------------------------------------------------------------------------------------------
  11069. #undef __ERR_STR
  11070. #if !defined(__CL_USER_OVERRIDE_ERROR_STRINGS)
  11071. #undef __GET_DEVICE_INFO_ERR
  11072. #undef __GET_PLATFORM_INFO_ERR
  11073. #undef __GET_DEVICE_IDS_ERR
  11074. #undef __GET_CONTEXT_INFO_ERR
  11075. #undef __GET_EVENT_INFO_ERR
  11076. #undef __GET_EVENT_PROFILE_INFO_ERR
  11077. #undef __GET_MEM_OBJECT_INFO_ERR
  11078. #undef __GET_IMAGE_INFO_ERR
  11079. #undef __GET_SAMPLER_INFO_ERR
  11080. #undef __GET_KERNEL_INFO_ERR
  11081. #undef __GET_KERNEL_ARG_INFO_ERR
  11082. #undef __GET_KERNEL_WORK_GROUP_INFO_ERR
  11083. #undef __GET_PROGRAM_INFO_ERR
  11084. #undef __GET_PROGRAM_BUILD_INFO_ERR
  11085. #undef __GET_COMMAND_QUEUE_INFO_ERR
  11086. #undef __CREATE_CONTEXT_ERR
  11087. #undef __CREATE_CONTEXT_FROM_TYPE_ERR
  11088. #undef __GET_SUPPORTED_IMAGE_FORMATS_ERR
  11089. #undef __CREATE_BUFFER_ERR
  11090. #undef __CREATE_SUBBUFFER_ERR
  11091. #undef __CREATE_IMAGE2D_ERR
  11092. #undef __CREATE_IMAGE3D_ERR
  11093. #undef __CREATE_SAMPLER_ERR
  11094. #undef __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR
  11095. #undef __CREATE_USER_EVENT_ERR
  11096. #undef __SET_USER_EVENT_STATUS_ERR
  11097. #undef __SET_EVENT_CALLBACK_ERR
  11098. #undef __SET_PRINTF_CALLBACK_ERR
  11099. #undef __WAIT_FOR_EVENTS_ERR
  11100. #undef __CREATE_KERNEL_ERR
  11101. #undef __SET_KERNEL_ARGS_ERR
  11102. #undef __CREATE_PROGRAM_WITH_SOURCE_ERR
  11103. #undef __CREATE_PROGRAM_WITH_BINARY_ERR
  11104. #undef __CREATE_PROGRAM_WITH_BUILT_IN_KERNELS_ERR
  11105. #undef __BUILD_PROGRAM_ERR
  11106. #undef __CREATE_KERNELS_IN_PROGRAM_ERR
  11107. #undef __CREATE_COMMAND_QUEUE_ERR
  11108. #undef __SET_COMMAND_QUEUE_PROPERTY_ERR
  11109. #undef __ENQUEUE_READ_BUFFER_ERR
  11110. #undef __ENQUEUE_WRITE_BUFFER_ERR
  11111. #undef __ENQUEUE_READ_BUFFER_RECT_ERR
  11112. #undef __ENQUEUE_WRITE_BUFFER_RECT_ERR
  11113. #undef __ENQEUE_COPY_BUFFER_ERR
  11114. #undef __ENQEUE_COPY_BUFFER_RECT_ERR
  11115. #undef __ENQUEUE_READ_IMAGE_ERR
  11116. #undef __ENQUEUE_WRITE_IMAGE_ERR
  11117. #undef __ENQUEUE_COPY_IMAGE_ERR
  11118. #undef __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR
  11119. #undef __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR
  11120. #undef __ENQUEUE_MAP_BUFFER_ERR
  11121. #undef __ENQUEUE_MAP_IMAGE_ERR
  11122. #undef __ENQUEUE_UNMAP_MEM_OBJECT_ERR
  11123. #undef __ENQUEUE_NDRANGE_KERNEL_ERR
  11124. #undef __ENQUEUE_TASK_ERR
  11125. #undef __ENQUEUE_NATIVE_KERNEL
  11126. #undef __CL_EXPLICIT_CONSTRUCTORS
  11127. #undef __UNLOAD_COMPILER_ERR
  11128. #endif //__CL_USER_OVERRIDE_ERROR_STRINGS
  11129. #undef __CL_FUNCTION_TYPE
  11130. // Extensions
  11131. /**
  11132. * Deprecated APIs for 1.2
  11133. */
  11134. #if defined(CL_VERSION_1_1)
  11135. #undef __INIT_CL_EXT_FCN_PTR
  11136. #endif // #if defined(CL_VERSION_1_1)
  11137. #undef __CREATE_SUB_DEVICES
  11138. #if defined(USE_CL_DEVICE_FISSION)
  11139. #undef __PARAM_NAME_DEVICE_FISSION
  11140. #endif // USE_CL_DEVICE_FISSION
  11141. #undef __DEFAULT_NOT_INITIALIZED
  11142. #undef __DEFAULT_BEING_INITIALIZED
  11143. #undef __DEFAULT_INITIALIZED
  11144. } // namespace cl
  11145. #ifdef _WIN32
  11146. #pragma pop_macro("max")
  11147. #endif // _WIN32
  11148. #endif // CL_HPP_