cl.hpp 293 KB

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