cl.hpp 275 KB

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