cl.hpp 273 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408
  1. /*******************************************************************************
  2. * Copyright (c) 2008-2010 The Khronos Group Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and/or associated documentation files (the
  6. * "Materials"), to deal in the Materials without restriction, including
  7. * without limitation the rights to use, copy, modify, merge, publish,
  8. * distribute, sublicense, and/or sell copies of the Materials, and to
  9. * permit persons to whom the Materials are furnished to do so, subject to
  10. * the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included
  13. * in all copies or substantial portions of the Materials.
  14. *
  15. * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  18. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  19. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  20. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  21. * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
  22. ******************************************************************************/
  23. /*! \file
  24. *
  25. * \brief C++ bindings for OpenCL 1.0 (rev 48) and OpenCL 1.1 (rev 17)
  26. * \author Benedict R. Gaster and Laurent Morichetti
  27. *
  28. * Additions and fixes from Brian Cole, March 3rd 2010.
  29. *
  30. * \version 1.0
  31. * \date $Date: 2010-04-23 10:16:50 -0500 (Fri, 23 Apr 2010) $
  32. *
  33. */
  34. /*! \mainpage
  35. * \section intro Introduction
  36. * For many large applications C++ is the language of choice and so it seems
  37. * reasonable to define C++ bindings for OpenCL.
  38. *
  39. * This document describes C++ binding interface for OpenCL 1.0 (rev 45).
  40. *
  41. * The interface is contained with a single C++ header file \em cl.hpp and all
  42. * definitions are contained within the namespace \em cl. There is no additional
  43. * requirement to include \em cl.h and to use either the C++ or original C
  44. * bindings it is enough to simply include \em cl.hpp.
  45. *
  46. * The bindings themselves are lightweight and correspond closely to the
  47. * underlying C API. Using the C++ bindings introduces no additional execution
  48. * overhead.
  49. *
  50. * \section example Example
  51. *
  52. * The following example shows a general use case for the C++
  53. * bindings, including support for the optional exception feature and
  54. * also the supplied vector and string classes, see following sections for
  55. * decriptions of these features.
  56. *
  57. * \code
  58. * #define __CL_ENABLE_EXCEPTIONS
  59. * #define __NO_STD_VECTOR
  60. * #define __NO_STD_STRING
  61. *
  62. * #if defined(__APPLE__) || defined(__MACOSX)
  63. * #include <OpenCL/cl.hpp>
  64. * #else
  65. * #include <CL/cl.hpp>
  66. * #endif
  67. * #include <cstdio>
  68. * #include <cstdlib>
  69. * #include <iostream>
  70. *
  71. * const char * helloStr = "__kernel void "
  72. * "hello(void) "
  73. * "{ "
  74. * " "
  75. * "} ";
  76. *
  77. * int
  78. * main(void)
  79. * {
  80. * cl_int err = CL_SUCCESS;
  81. * try {
  82. * cl::Context context(CL_DEVICE_TYPE_CPU, 0, NULL, NULL, &err);
  83. *
  84. * cl::vector<cl::Device> devices = context.getInfo<CL_CONTEXT_DEVICES>();
  85. *
  86. * cl::Program::Sources source(1,
  87. * std::make_pair(helloStr,strlen(helloStr)));
  88. * cl::Program program_ = cl::Program(context, source);
  89. * program_.build(devices);
  90. *
  91. * cl::Kernel kernel(program_, "hello", &err);
  92. *
  93. * cl::CommandQueue queue(context, devices[0], 0, &err);
  94. * cl::KernelFunctor func = kernel.bind(
  95. * queue,
  96. * cl::NDRange(4, 4),
  97. * cl::NDRange(2, 2));
  98. *
  99. * func().wait();
  100. * }
  101. * catch (cl::Error err) {
  102. * std::cerr
  103. * << "ERROR: "
  104. * << err.what()
  105. * << "("
  106. * << err.err()
  107. * << ")"
  108. * << std::endl;
  109. * }
  110. *
  111. * return EXIT_SUCCESS;
  112. * }
  113. *
  114. * \endcode
  115. *
  116. * \section exceptions Exceptions
  117. * The use of C++ exceptions can provide a structured approach to error
  118. * handling within large applications. The OpenCL C++ bindings exception feature
  119. * provides the capability of using C++ exceptions to track and handle errors
  120. * generated by the underlying OpenCL C API.
  121. *
  122. * It is understood that the use of C++ exceptions is not universal and their
  123. * use should to optional. Furthermore, if exceptions are not used, then the
  124. * resulting application must compile and work without exception support. By
  125. * default C++ exceptions are not enabled and the OpenCL error code is returned,
  126. * or set, as per the original OpenCL C API.
  127. *
  128. * Exception usage must be explicitly enabled by defining the preprocessor macro
  129. * \em __CL_ENABLE_EXCEPTIONS. Once enabled an error, i.e. a value other than
  130. * \em CL_SUCCESS, originally reported via a return value will be reported by
  131. * throwing the exception class \em Error. By default the \em what() method of
  132. * the class \em Error will return a const pointer to a string naming the
  133. * particular OpenCL C API called that reported the error, e.g.
  134. * "clgetDeviceInfo", "clGetPlatformInfo", and so on.
  135. *
  136. * It is possible to override the default behavior for what() by defining the
  137. * preprocessor macro \em __CL_USER_OVERRIDE_ERROR_STRINGS and providing
  138. * string constants for each of the following preprocessor macros:\n
  139. * \code
  140. * __GET_DEVICE_INFO_ERR
  141. * __GET_PLATFORM_INFO_ERR
  142. * __GET_DEVICE_IDS_ERR
  143. * __GET_CONTEXT_INFO_ERR
  144. * __GET_EVENT_INFO_ERR
  145. * __GET_EVENT_PROFILE_INFO_ERR
  146. * __GET_MEM_OBJECT_INFO_ERR
  147. * __GET_IMAGE_INFO_ERR
  148. * __GET_SAMPLER_INFO_ERR
  149. * __GET_KERNEL_INFO_ERR
  150. * __GET_KERNEL_WORK_GROUP_INFO_ERR
  151. * __GET_PROGRAM_INFO_ERR
  152. * __GET_PROGRAM_BUILD_INFO_ERR
  153. * __GET_COMMAND_QUEUE_INFO_ERR
  154. * __CREATE_CONTEXT_FROM_TYPE_ERR
  155. * __GET_SUPPORTED_IMAGE_FORMATS_ERR
  156. * __CREATE_BUFFER_ERR
  157. * __CREATE_SUBBUFFER_ERR
  158. * __CREATE_GL_BUFFER_ERR
  159. * __CREATE_IMAGE2D_ERR
  160. * __CREATE_IMAGE3D_ERR
  161. * __CREATE_SAMPLER_ERR
  162. * __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR
  163. * __CREATE_USER_EVENT_ERR
  164. * __SET_USER_EVENT_STATUS_ERR
  165. * __SET_EVENT_CALLBACK_ERR
  166. * __WAIT_FOR_EVENTS_ERR
  167. * __CREATE_KERNEL_ERR
  168. * __SET_KERNEL_ARGS_ERR
  169. * __CREATE_PROGRAM_WITH_SOURCE_ERR
  170. * __CREATE_PROGRAM_WITH_BINARY_ERR
  171. * __BUILD_PROGRAM_ERR
  172. * __CREATE_KERNELS_IN_PROGRAM_ERR
  173. * __CREATE_COMMAND_QUEUE_ERR
  174. * __SET_COMMAND_QUEUE_PROPERTY_ERR
  175. * __ENQUEUE_READ_BUFFER_ERR
  176. * __ENQUEUE_READ_BUFFER_RECT_ERR
  177. * __ENQUEUE_WRITE_BUFFER_ERR
  178. * __ENQUEUE_WRITE_BUFFER_RECT_ERR
  179. * __ENQEUE_COPY_BUFFER_ERR
  180. * __ENQEUE_COPY_BUFFER_RECT_ERR
  181. * __ENQUEUE_READ_IMAGE_ERR
  182. * __ENQUEUE_WRITE_IMAGE_ERR
  183. * __ENQUEUE_COPY_IMAGE_ERR
  184. * __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR
  185. * __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR
  186. * __ENQUEUE_MAP_BUFFER_ERR
  187. * __ENQUEUE_MAP_IMAGE_ERR
  188. * __ENQUEUE_UNMAP_MEM_OBJECT_ERR
  189. * __ENQUEUE_NDRANGE_KERNEL_ERR
  190. * __ENQUEUE_TASK_ERR
  191. * __ENQUEUE_NATIVE_KERNEL
  192. * __ENQUEUE_MARKER_ERR
  193. * __ENQUEUE_WAIT_FOR_EVENTS_ERR
  194. * __ENQUEUE_BARRIER_ERR
  195. * __UNLOAD_COMPILER_ERR
  196. * __FLUSH_ERR
  197. * __FINISH_ERR
  198. * \endcode
  199. *
  200. * \section vectorstring Replacing STL's vector and string classes
  201. *
  202. * While C++'s Standard Template library provides an excellent
  203. * resource for quick access to many useful algorithms and containers
  204. * it is ofen not used due to compatability issues across different
  205. * toolchains operating systems. In designing the original set of C++
  206. * bindings we found it useful to access std::vector and std::string
  207. * but at the same time realise that it maynot feasible for these to
  208. * be used within a production system. So like exceptions the
  209. * developer is given the abilty to not include anything from the STL
  210. * while using the C++ bindings, and replacements are provided for both
  211. * std::vector and std::string or the developer has the option to replace
  212. * their own implementations.
  213. *
  214. * By default, to avoid issues with backward compatibility, both std::vector
  215. * and std::string are used. Either can be over ridden by defining, for vectors:
  216. *
  217. * - If __NO_STD_VECTOR is defined and __USE_DEV_VECTOR is not defined, then
  218. * the vector type:
  219. *
  220. * template cl::vector<
  221. * typename T,
  222. * unsigned int N = __MAX_DEFAULT_VECTOR_SIZE>;
  223. *
  224. * is used instead of std::vector. The space requirments for
  225. * cl::vector are defined statically and default to 10 elements,
  226. * this default can be over ridden by defining:
  227. *
  228. * #define __MAX_DEFAULT_VECTOR_SIZE N
  229. *
  230. * before including cl.hpp.
  231. *
  232. * For strings:
  233. *
  234. * - If __NO_STD_STRING is defined and __USE_DEV_STRING is not
  235. * defined, then the string type:
  236. *
  237. * class cl::string;
  238. *
  239. * is used instead of std::string. Unlike cl::vector the size of a
  240. * given string is not defined statically but allocated at creation,
  241. * however, unlike std::string once created its size cannot change.
  242. *
  243. * In the cases where the developer would like to provide their own
  244. * replacement implementations for either std::vector or std::string,
  245. * then this can be achived by defining the following.
  246. *
  247. * For vectors the developer must define:
  248. *
  249. * #define __USE_DEV_VECTOR
  250. *
  251. * to tell cl.hpp that std::vector and cl::vector should not be
  252. * used. When __USE_DEV_VECTOR the user must also provide a mapping
  253. * from their vector template type which must be parametrized with at
  254. * least a single type argument and all additional arguments must
  255. * follow this and have defaults. The mapping is given by defining:
  256. *
  257. * #define VECTOR_CLASS typeName
  258. *
  259. * Note, that as C++ does not currently support typedef templates the
  260. * vector type is given solely by its name through a #define.
  261. *
  262. * For strings the developer must define:
  263. *
  264. * #define __USE_DEV_STRING
  265. *
  266. * to tell cl.hpp that std::string and cl::string should not be
  267. * used. When __USE_DEV_STRING the user must also provide a mapping
  268. * from their string class. The mapping is given by defining:
  269. *
  270. * typedef stringType STRING_CLASS;
  271. */
  272. #ifndef CL_HPP_
  273. #define CL_HPP_
  274. #ifdef _WIN32
  275. #include <windows.h>
  276. #include <CL/cl.h>
  277. #endif // _WIN32
  278. #if defined(__APPLE__) || defined(__MACOSX)
  279. #include <OpenCL/cl.h>
  280. #include <OpenGL/OpenGL.h>
  281. #include <OpenCL/cl_gl.h>
  282. #else
  283. #include <CL/cl.h>
  284. #include <GL/gl.h>
  285. #include <CL/cl_gl.h>
  286. #include <CL/cl_gl.h>
  287. #if defined(USE_DX_INTEROP)
  288. #include <CL/cl_d3d10.h>
  289. #endif
  290. #endif // !__APPLE__
  291. #if !defined(CL_CALLBACK)
  292. #define CL_CALLBACK
  293. #endif //CL_CALLBACK
  294. #include <utility>
  295. #if !defined(__NO_STD_VECTOR)
  296. #include <vector>
  297. #endif
  298. #if !defined(__NO_STD_STRING)
  299. #include <string>
  300. #endif
  301. #if defined(linux) || defined(__APPLE__) || defined(__MACOSX)
  302. # include <alloca.h>
  303. #else
  304. # include <malloc.h>
  305. #endif // linux
  306. #include <cstring>
  307. /*! \namespace cl
  308. *
  309. * \brief The OpenCL C++ bindings are defined within this namespace.
  310. *
  311. */
  312. namespace cl {
  313. #define __INIT_CL_EXT_FCN_PTR(name) \
  314. if(!pfn_##name) { \
  315. pfn_##name = (PFN_##name) \
  316. clGetExtensionFunctionAddress(#name); \
  317. if(!pfn_##name) { \
  318. } \
  319. }
  320. class Program;
  321. class Device;
  322. class Context;
  323. class CommandQueue;
  324. class Memory;
  325. #if defined(__CL_ENABLE_EXCEPTIONS)
  326. #include <exception>
  327. /*! \class Error
  328. * \brief Exception class
  329. */
  330. class Error : public std::exception
  331. {
  332. private:
  333. cl_int err_;
  334. const char * errStr_;
  335. public:
  336. /*! Create a new CL error exception for a given error code
  337. * and corresponding message.
  338. */
  339. Error(cl_int err, const char * errStr = NULL) : err_(err), errStr_(errStr)
  340. {}
  341. ~Error() throw() {}
  342. /*! \brief Get error string associated with exception
  343. *
  344. * \return A memory pointer to the error message string.
  345. */
  346. virtual const char * what() const throw ()
  347. {
  348. if (errStr_ == NULL) {
  349. return "empty";
  350. }
  351. else {
  352. return errStr_;
  353. }
  354. }
  355. /*! \brief Get error code associated with exception
  356. *
  357. * \return The error code.
  358. */
  359. cl_int err(void) const { return err_; }
  360. };
  361. #define __ERR_STR(x) #x
  362. #else
  363. #define __ERR_STR(x) NULL
  364. #endif // __CL_ENABLE_EXCEPTIONS
  365. //! \cond DOXYGEN_DETAIL
  366. #if !defined(__CL_USER_OVERRIDE_ERROR_STRINGS)
  367. #define __GET_DEVICE_INFO_ERR __ERR_STR(clgetDeviceInfo)
  368. #define __GET_PLATFORM_INFO_ERR __ERR_STR(clGetPlatformInfo)
  369. #define __GET_DEVICE_IDS_ERR __ERR_STR(clGetDeviceIDs)
  370. #define __GET_PLATFORM_IDS_ERR __ERR_STR(clGetPlatformIDs)
  371. #define __GET_CONTEXT_INFO_ERR __ERR_STR(clGetContextInfo)
  372. #define __GET_EVENT_INFO_ERR __ERR_STR(clGetEventInfo)
  373. #define __GET_EVENT_PROFILE_INFO_ERR __ERR_STR(clGetEventProfileInfo)
  374. #define __GET_MEM_OBJECT_INFO_ERR __ERR_STR(clGetMemObjectInfo)
  375. #define __GET_IMAGE_INFO_ERR __ERR_STR(clGetImageInfo)
  376. #define __GET_SAMPLER_INFO_ERR __ERR_STR(clGetSamplerInfo)
  377. #define __GET_KERNEL_INFO_ERR __ERR_STR(clGetKernelInfo)
  378. #define __GET_KERNEL_WORK_GROUP_INFO_ERR __ERR_STR(clGetKernelWorkGroupInfo)
  379. #define __GET_PROGRAM_INFO_ERR __ERR_STR(clGetProgramInfo)
  380. #define __GET_PROGRAM_BUILD_INFO_ERR __ERR_STR(clGetProgramBuildInfo)
  381. #define __GET_COMMAND_QUEUE_INFO_ERR __ERR_STR(clGetCommandQueueInfo)
  382. #define __CREATE_CONTEXT_FROM_TYPE_ERR __ERR_STR(clCreateContextFromType)
  383. #define __GET_SUPPORTED_IMAGE_FORMATS_ERR __ERR_STR(clGetSupportedImageFormats)
  384. #define __CREATE_BUFFER_ERR __ERR_STR(clCreateBuffer)
  385. #define __CREATE_SUBBUFFER_ERR __ERR_STR(clCreateSubBuffer)
  386. #define __CREATE_GL_BUFFER_ERR __ERR_STR(clCreateFromGLBuffer)
  387. #define __GET_GL_OBJECT_INFO_ERR __ERR_STR(clGetGLObjectInfo)
  388. #define __CREATE_IMAGE2D_ERR __ERR_STR(clCreateImage2D)
  389. #define __CREATE_IMAGE3D_ERR __ERR_STR(clCreateImage3D)
  390. #define __CREATE_SAMPLER_ERR __ERR_STR(clCreateSampler)
  391. #define __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR __ERR_STR(clSetMemObjectDestructorCallback)
  392. #define __CREATE_USER_EVENT_ERR __ERR_STR(clCreateUserEvent)
  393. #define __SET_USER_EVENT_STATUS_ERR __ERR_STR(clSetUserEventStatus)
  394. #define __SET_EVENT_CALLBACK_ERR __ERR_STR(clSetEventCallback)
  395. #define __WAIT_FOR_EVENTS_ERR __ERR_STR(clWaitForEvents)
  396. #define __CREATE_KERNEL_ERR __ERR_STR(clCreateKernel)
  397. #define __SET_KERNEL_ARGS_ERR __ERR_STR(clSetKernelArg)
  398. #define __CREATE_PROGRAM_WITH_SOURCE_ERR __ERR_STR(clCreateProgramWithSource)
  399. #define __CREATE_PROGRAM_WITH_BINARY_ERR __ERR_STR(clCreateProgramWithBinary)
  400. #define __BUILD_PROGRAM_ERR __ERR_STR(clBuildProgram)
  401. #define __CREATE_KERNELS_IN_PROGRAM_ERR __ERR_STR(clCreateKernelsInProgram)
  402. #define __CREATE_COMMAND_QUEUE_ERR __ERR_STR(clCreateCommandQueue)
  403. #define __SET_COMMAND_QUEUE_PROPERTY_ERR __ERR_STR(clSetCommandQueueProperty)
  404. #define __ENQUEUE_READ_BUFFER_ERR __ERR_STR(clEnqueueReadBuffer)
  405. #define __ENQUEUE_READ_BUFFER_RECT_ERR __ERR_STR(clEnqueueReadBufferRect)
  406. #define __ENQUEUE_WRITE_BUFFER_ERR __ERR_STR(clEnqueueWriteBuffer)
  407. #define __ENQUEUE_WRITE_BUFFER_RECT_ERR __ERR_STR(clEnqueueWriteBufferRect)
  408. #define __ENQEUE_COPY_BUFFER_ERR __ERR_STR(clEnqueueCopyBuffer)
  409. #define __ENQEUE_COPY_BUFFER_RECT_ERR __ERR_STR(clEnqueueCopyBufferRect)
  410. #define __ENQUEUE_READ_IMAGE_ERR __ERR_STR(clEnqueueReadImage)
  411. #define __ENQUEUE_WRITE_IMAGE_ERR __ERR_STR(clEnqueueWriteImage)
  412. #define __ENQUEUE_COPY_IMAGE_ERR __ERR_STR(clEnqueueCopyImage)
  413. #define __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR __ERR_STR(clEnqueueCopyImageToBuffer)
  414. #define __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR __ERR_STR(clEnqueueCopyBufferToImage)
  415. #define __ENQUEUE_MAP_BUFFER_ERR __ERR_STR(clEnqueueMapBuffer)
  416. #define __ENQUEUE_MAP_IMAGE_ERR __ERR_STR(clEnqueueMapImage)
  417. #define __ENQUEUE_UNMAP_MEM_OBJECT_ERR __ERR_STR(clEnqueueUnMapMemObject)
  418. #define __ENQUEUE_NDRANGE_KERNEL_ERR __ERR_STR(clEnqueueNDRangeKernel)
  419. #define __ENQUEUE_TASK_ERR __ERR_STR(clEnqueueTask)
  420. #define __ENQUEUE_NATIVE_KERNEL __ERR_STR(clEnqueueNativeKernel)
  421. #define __ENQUEUE_MARKER_ERR __ERR_STR(clEnqueueMarker)
  422. #define __ENQUEUE_WAIT_FOR_EVENTS_ERR __ERR_STR(clEnqueueWaitForEvents)
  423. #define __ENQUEUE_BARRIER_ERR __ERR_STR(clEnqueueBarrier)
  424. #define __ENQUEUE_ACQUIRE_GL_ERR __ERR_STR(clEnqueueAcquireGLObjects)
  425. #define __ENQUEUE_RELEASE_GL_ERR __ERR_STR(clEnqueueReleaseGLObjects)
  426. #define __UNLOAD_COMPILER_ERR __ERR_STR(clUnloadCompiler)
  427. #define __FLUSH_ERR __ERR_STR(clFlush)
  428. #define __FINISH_ERR __ERR_STR(clFinish)
  429. #endif // __CL_USER_OVERRIDE_ERROR_STRINGS
  430. //! \endcond
  431. /*! \class string
  432. * \brief Simple string class, that provides a limited subset of std::string
  433. * functionality but avoids many of the issues that come with that class.
  434. */
  435. class string
  436. {
  437. private:
  438. ::size_t size_;
  439. char * str_;
  440. public:
  441. string(void) : size_(0), str_(NULL)
  442. {
  443. }
  444. string(char * str, ::size_t size) :
  445. size_(size),
  446. str_(NULL)
  447. {
  448. str_ = new char[size_+1];
  449. if (str_ != NULL) {
  450. memcpy(str_, str, size_ * sizeof(char));
  451. str_[size_] = '\0';
  452. }
  453. else {
  454. size_ = 0;
  455. }
  456. }
  457. string(char * str) :
  458. str_(NULL)
  459. {
  460. size_= ::strlen(str);
  461. str_ = new char[size_ + 1];
  462. if (str_ != NULL) {
  463. memcpy(str_, str, (size_ + 1) * sizeof(char));
  464. }
  465. else {
  466. size_ = 0;
  467. }
  468. }
  469. string& operator=(const string& rhs)
  470. {
  471. if (this == &rhs) {
  472. return *this;
  473. }
  474. if (rhs.size_ == 0 || rhs.str_ == NULL) {
  475. size_ = 0;
  476. str_ = NULL;
  477. }
  478. else {
  479. size_ = rhs.size_;
  480. str_ = new char[size_ + 1];
  481. if (str_ != NULL) {
  482. memcpy(str_, rhs.str_, (size_ + 1) * sizeof(char));
  483. }
  484. else {
  485. size_ = 0;
  486. }
  487. }
  488. return *this;
  489. }
  490. string(const string& rhs)
  491. {
  492. *this = rhs;
  493. }
  494. ~string()
  495. {
  496. if (str_ != NULL) {
  497. delete[] str_;
  498. }
  499. }
  500. ::size_t size(void) const { return size_; }
  501. ::size_t length(void) const { return size(); }
  502. const char * c_str(void) const { return (str_) ? str_ : "";}
  503. };
  504. #if !defined(__USE_DEV_STRING) && !defined(__NO_STD_STRING)
  505. #include <string>
  506. typedef std::string STRING_CLASS;
  507. #elif !defined(__USE_DEV_STRING)
  508. typedef cl::string STRING_CLASS;
  509. #endif
  510. #if !defined(__USE_DEV_VECTOR) && !defined(__NO_STD_VECTOR)
  511. #include <vector>
  512. #define VECTOR_CLASS std::vector
  513. #elif !defined(__USE_DEV_VECTOR)
  514. #define VECTOR_CLASS cl::vector
  515. #endif
  516. #if !defined(__MAX_DEFAULT_VECTOR_SIZE)
  517. #define __MAX_DEFAULT_VECTOR_SIZE 10
  518. #endif
  519. /*! \class vector
  520. * \brief Fixed sized vector implementation that mirroring
  521. * std::vector functionality.
  522. */
  523. template <typename T, unsigned int N = __MAX_DEFAULT_VECTOR_SIZE>
  524. class vector
  525. {
  526. private:
  527. T data_[N];
  528. unsigned int size_;
  529. bool empty_;
  530. public:
  531. vector() :
  532. size_(-1),
  533. empty_(true)
  534. {}
  535. ~vector() {}
  536. unsigned int size(void) const
  537. {
  538. return size_ + 1;
  539. }
  540. void clear()
  541. {
  542. size_ = -1;
  543. empty_ = true;
  544. }
  545. void push_back (const T& x)
  546. {
  547. if (size() < N) {
  548. size_++;
  549. data_[size_] = x;
  550. empty_ = false;
  551. }
  552. }
  553. void pop_back(void)
  554. {
  555. if (!empty_) {
  556. data_[size_].~T();
  557. size_--;
  558. if (size_ == -1) {
  559. empty_ = true;
  560. }
  561. }
  562. }
  563. vector(const vector<T, N>& vec) :
  564. size_(vec.size_),
  565. empty_(vec.empty_)
  566. {
  567. if (!empty_) {
  568. memcpy(&data_[0], &vec.data_[0], size() * sizeof(T));
  569. }
  570. }
  571. vector(unsigned int size, const T& val = T()) :
  572. size_(-1),
  573. empty_(true)
  574. {
  575. for (unsigned int i = 0; i < size; i++) {
  576. push_back(val);
  577. }
  578. }
  579. vector<T, N>& operator=(const vector<T, N>& rhs)
  580. {
  581. if (this == &rhs) {
  582. return *this;
  583. }
  584. size_ = rhs.size_;
  585. empty_ = rhs.empty_;
  586. if (!empty_) {
  587. memcpy(&data_[0], &rhs.data_[0], size() * sizeof(T));
  588. }
  589. return *this;
  590. }
  591. bool operator==(vector<T,N> &vec)
  592. {
  593. if (empty_ && vec.empty_) {
  594. return true;
  595. }
  596. if (size() != vec.size()) {
  597. return false;
  598. }
  599. return memcmp(&data_[0], &vec.data_[0], size() * sizeof(T)) == 0 ? true : false;
  600. }
  601. operator T* () { return data_; }
  602. operator const T* () const { return data_; }
  603. bool empty (void) const
  604. {
  605. return empty_;
  606. }
  607. unsigned int max_size (void) const
  608. {
  609. return N;
  610. }
  611. unsigned int capacity () const
  612. {
  613. return sizeof(T) * N;
  614. }
  615. T& operator[](int index)
  616. {
  617. return data_[index];
  618. }
  619. T operator[](int index) const
  620. {
  621. return data_[index];
  622. }
  623. template<class I>
  624. void assign(I start, I end)
  625. {
  626. clear();
  627. while(start < end) {
  628. push_back(*start);
  629. start++;
  630. }
  631. }
  632. /*! \class iterator
  633. * \brief Iterator class for vectors
  634. */
  635. class iterator
  636. {
  637. private:
  638. vector<T,N> vec_;
  639. int index_;
  640. bool initialized_;
  641. public:
  642. iterator(void) :
  643. index_(-1),
  644. initialized_(false)
  645. {
  646. index_ = -1;
  647. initialized_ = false;
  648. }
  649. ~iterator(void) {}
  650. static iterator begin(vector<T,N> &vec)
  651. {
  652. iterator i;
  653. if (!vec.empty()) {
  654. i.index_ = 0;
  655. }
  656. i.vec_ = vec;
  657. i.initialized_ = true;
  658. return i;
  659. }
  660. static iterator end(vector<T,N> &vec)
  661. {
  662. iterator i;
  663. if (!vec.empty()) {
  664. i.index_ = vec.size();
  665. }
  666. i.vec_ = vec;
  667. i.initialized_ = true;
  668. return i;
  669. }
  670. bool operator==(iterator i)
  671. {
  672. return ((vec_ == i.vec_) &&
  673. (index_ == i.index_) &&
  674. (initialized_ == i.initialized_));
  675. }
  676. bool operator!=(iterator i)
  677. {
  678. return (!(*this==i));
  679. }
  680. void operator++()
  681. {
  682. index_++;
  683. }
  684. void operator++(int x)
  685. {
  686. index_ += x;
  687. }
  688. void operator--()
  689. {
  690. index_--;
  691. }
  692. void operator--(int x)
  693. {
  694. index_ -= x;
  695. }
  696. T operator *()
  697. {
  698. return vec_[index_];
  699. }
  700. };
  701. iterator begin(void)
  702. {
  703. return iterator::begin(*this);
  704. }
  705. iterator end(void)
  706. {
  707. return iterator::end(*this);
  708. }
  709. T& front(void)
  710. {
  711. return data_[0];
  712. }
  713. T& back(void)
  714. {
  715. return data_[size_];
  716. }
  717. const T& front(void) const
  718. {
  719. return data_[0];
  720. }
  721. const T& back(void) const
  722. {
  723. return data_[size_];
  724. }
  725. };
  726. /*!
  727. * \brief size_t class used to interface between C++ and
  728. * OpenCL C calls that require arrays of size_t values, who's
  729. * size is known statically.
  730. */
  731. template <int N>
  732. struct size_t : public cl::vector< ::size_t, N> { };
  733. namespace detail {
  734. // GetInfo help struct
  735. template <typename Functor, typename T>
  736. struct GetInfoHelper
  737. {
  738. static cl_int
  739. get(Functor f, cl_uint name, T* param)
  740. {
  741. return f(name, sizeof(T), param, NULL);
  742. }
  743. };
  744. // Specialized GetInfoHelper for VECTOR_CLASS params
  745. template <typename Func, typename T>
  746. struct GetInfoHelper<Func, VECTOR_CLASS<T> >
  747. {
  748. static cl_int get(Func f, cl_uint name, VECTOR_CLASS<T>* param)
  749. {
  750. ::size_t required;
  751. cl_int err = f(name, 0, NULL, &required);
  752. if (err != CL_SUCCESS) {
  753. return err;
  754. }
  755. T* value = (T*) alloca(required);
  756. err = f(name, required, value, NULL);
  757. if (err != CL_SUCCESS) {
  758. return err;
  759. }
  760. param->assign(&value[0], &value[required/sizeof(T)]);
  761. return CL_SUCCESS;
  762. }
  763. };
  764. // Specialized GetInfoHelper for STRING_CLASS params
  765. template <typename Func>
  766. struct GetInfoHelper<Func, STRING_CLASS>
  767. {
  768. static cl_int get(Func f, cl_uint name, STRING_CLASS* param)
  769. {
  770. ::size_t required;
  771. cl_int err = f(name, 0, NULL, &required);
  772. if (err != CL_SUCCESS) {
  773. return err;
  774. }
  775. char* value = (char*) alloca(required);
  776. err = f(name, required, value, NULL);
  777. if (err != CL_SUCCESS) {
  778. return err;
  779. }
  780. *param = value;
  781. return CL_SUCCESS;
  782. }
  783. };
  784. #define __PARAM_NAME_INFO_1_0(F) \
  785. F(cl_platform_info, CL_PLATFORM_PROFILE, STRING_CLASS) \
  786. F(cl_platform_info, CL_PLATFORM_VERSION, STRING_CLASS) \
  787. F(cl_platform_info, CL_PLATFORM_NAME, STRING_CLASS) \
  788. F(cl_platform_info, CL_PLATFORM_VENDOR, STRING_CLASS) \
  789. F(cl_platform_info, CL_PLATFORM_EXTENSIONS, STRING_CLASS) \
  790. \
  791. F(cl_device_info, CL_DEVICE_TYPE, cl_device_type) \
  792. F(cl_device_info, CL_DEVICE_VENDOR_ID, cl_uint) \
  793. F(cl_device_info, CL_DEVICE_MAX_COMPUTE_UNITS, cl_uint) \
  794. F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, cl_uint) \
  795. F(cl_device_info, CL_DEVICE_MAX_WORK_GROUP_SIZE, ::size_t) \
  796. F(cl_device_info, CL_DEVICE_MAX_WORK_ITEM_SIZES, VECTOR_CLASS< ::size_t>) \
  797. F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, cl_uint) \
  798. F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, cl_uint) \
  799. F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, cl_uint) \
  800. F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, cl_uint) \
  801. F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, cl_uint) \
  802. F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, cl_uint) \
  803. F(cl_device_info, CL_DEVICE_MAX_CLOCK_FREQUENCY, cl_uint) \
  804. F(cl_device_info, CL_DEVICE_ADDRESS_BITS, cl_bitfield) \
  805. F(cl_device_info, CL_DEVICE_MAX_READ_IMAGE_ARGS, cl_uint) \
  806. F(cl_device_info, CL_DEVICE_MAX_WRITE_IMAGE_ARGS, cl_uint) \
  807. F(cl_device_info, CL_DEVICE_MAX_MEM_ALLOC_SIZE, cl_ulong) \
  808. F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_WIDTH, ::size_t) \
  809. F(cl_device_info, CL_DEVICE_IMAGE2D_MAX_HEIGHT, ::size_t) \
  810. F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_WIDTH, ::size_t) \
  811. F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_HEIGHT, ::size_t) \
  812. F(cl_device_info, CL_DEVICE_IMAGE3D_MAX_DEPTH, ::size_t) \
  813. F(cl_device_info, CL_DEVICE_IMAGE_SUPPORT, cl_uint) \
  814. F(cl_device_info, CL_DEVICE_MAX_PARAMETER_SIZE, ::size_t) \
  815. F(cl_device_info, CL_DEVICE_MAX_SAMPLERS, cl_uint) \
  816. F(cl_device_info, CL_DEVICE_MEM_BASE_ADDR_ALIGN, cl_uint) \
  817. F(cl_device_info, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, cl_uint) \
  818. F(cl_device_info, CL_DEVICE_SINGLE_FP_CONFIG, cl_device_fp_config) \
  819. F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, cl_device_mem_cache_type) \
  820. F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, cl_uint)\
  821. F(cl_device_info, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, cl_ulong) \
  822. F(cl_device_info, CL_DEVICE_GLOBAL_MEM_SIZE, cl_ulong) \
  823. F(cl_device_info, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, cl_ulong) \
  824. F(cl_device_info, CL_DEVICE_MAX_CONSTANT_ARGS, cl_uint) \
  825. F(cl_device_info, CL_DEVICE_LOCAL_MEM_TYPE, cl_device_local_mem_type) \
  826. F(cl_device_info, CL_DEVICE_LOCAL_MEM_SIZE, cl_ulong) \
  827. F(cl_device_info, CL_DEVICE_ERROR_CORRECTION_SUPPORT, cl_bool) \
  828. F(cl_device_info, CL_DEVICE_PROFILING_TIMER_RESOLUTION, ::size_t) \
  829. F(cl_device_info, CL_DEVICE_ENDIAN_LITTLE, cl_bool) \
  830. F(cl_device_info, CL_DEVICE_AVAILABLE, cl_bool) \
  831. F(cl_device_info, CL_DEVICE_COMPILER_AVAILABLE, cl_bool) \
  832. F(cl_device_info, CL_DEVICE_EXECUTION_CAPABILITIES, cl_device_exec_capabilities) \
  833. F(cl_device_info, CL_DEVICE_QUEUE_PROPERTIES, cl_command_queue_properties) \
  834. F(cl_device_info, CL_DEVICE_PLATFORM, cl_platform_id) \
  835. F(cl_device_info, CL_DEVICE_NAME, STRING_CLASS) \
  836. F(cl_device_info, CL_DEVICE_VENDOR, STRING_CLASS) \
  837. F(cl_device_info, CL_DRIVER_VERSION, STRING_CLASS) \
  838. F(cl_device_info, CL_DEVICE_PROFILE, STRING_CLASS) \
  839. F(cl_device_info, CL_DEVICE_VERSION, STRING_CLASS) \
  840. F(cl_device_info, CL_DEVICE_EXTENSIONS, STRING_CLASS) \
  841. \
  842. F(cl_context_info, CL_CONTEXT_REFERENCE_COUNT, cl_uint) \
  843. F(cl_context_info, CL_CONTEXT_DEVICES, VECTOR_CLASS<Device>) \
  844. F(cl_context_info, CL_CONTEXT_PROPERTIES, VECTOR_CLASS<cl_context_properties>) \
  845. \
  846. F(cl_event_info, CL_EVENT_COMMAND_QUEUE, cl::CommandQueue) \
  847. F(cl_event_info, CL_EVENT_COMMAND_TYPE, cl_command_type) \
  848. F(cl_event_info, CL_EVENT_REFERENCE_COUNT, cl_uint) \
  849. F(cl_event_info, CL_EVENT_COMMAND_EXECUTION_STATUS, cl_uint) \
  850. \
  851. F(cl_profiling_info, CL_PROFILING_COMMAND_QUEUED, cl_ulong) \
  852. F(cl_profiling_info, CL_PROFILING_COMMAND_SUBMIT, cl_ulong) \
  853. F(cl_profiling_info, CL_PROFILING_COMMAND_START, cl_ulong) \
  854. F(cl_profiling_info, CL_PROFILING_COMMAND_END, cl_ulong) \
  855. \
  856. F(cl_mem_info, CL_MEM_TYPE, cl_mem_object_type) \
  857. F(cl_mem_info, CL_MEM_FLAGS, cl_mem_flags) \
  858. F(cl_mem_info, CL_MEM_SIZE, ::size_t) \
  859. F(cl_mem_info, CL_MEM_HOST_PTR, void*) \
  860. F(cl_mem_info, CL_MEM_MAP_COUNT, cl_uint) \
  861. F(cl_mem_info, CL_MEM_REFERENCE_COUNT, cl_uint) \
  862. F(cl_mem_info, CL_MEM_CONTEXT, cl::Context) \
  863. \
  864. F(cl_image_info, CL_IMAGE_FORMAT, cl_image_format) \
  865. F(cl_image_info, CL_IMAGE_ELEMENT_SIZE, ::size_t) \
  866. F(cl_image_info, CL_IMAGE_ROW_PITCH, ::size_t) \
  867. F(cl_image_info, CL_IMAGE_SLICE_PITCH, ::size_t) \
  868. F(cl_image_info, CL_IMAGE_WIDTH, ::size_t) \
  869. F(cl_image_info, CL_IMAGE_HEIGHT, ::size_t) \
  870. F(cl_image_info, CL_IMAGE_DEPTH, ::size_t) \
  871. \
  872. F(cl_sampler_info, CL_SAMPLER_REFERENCE_COUNT, cl_uint) \
  873. F(cl_sampler_info, CL_SAMPLER_CONTEXT, cl::Context) \
  874. F(cl_sampler_info, CL_SAMPLER_NORMALIZED_COORDS, cl_addressing_mode) \
  875. F(cl_sampler_info, CL_SAMPLER_ADDRESSING_MODE, cl_filter_mode) \
  876. F(cl_sampler_info, CL_SAMPLER_FILTER_MODE, cl_bool) \
  877. \
  878. F(cl_program_info, CL_PROGRAM_REFERENCE_COUNT, cl_uint) \
  879. F(cl_program_info, CL_PROGRAM_CONTEXT, cl::Context) \
  880. F(cl_program_info, CL_PROGRAM_NUM_DEVICES, cl_uint) \
  881. F(cl_program_info, CL_PROGRAM_DEVICES, VECTOR_CLASS<cl_device_id>) \
  882. F(cl_program_info, CL_PROGRAM_SOURCE, STRING_CLASS) \
  883. F(cl_program_info, CL_PROGRAM_BINARY_SIZES, VECTOR_CLASS< ::size_t>) \
  884. F(cl_program_info, CL_PROGRAM_BINARIES, VECTOR_CLASS<char *>) \
  885. \
  886. F(cl_program_build_info, CL_PROGRAM_BUILD_STATUS, cl_build_status) \
  887. F(cl_program_build_info, CL_PROGRAM_BUILD_OPTIONS, STRING_CLASS) \
  888. F(cl_program_build_info, CL_PROGRAM_BUILD_LOG, STRING_CLASS) \
  889. \
  890. F(cl_kernel_info, CL_KERNEL_FUNCTION_NAME, STRING_CLASS) \
  891. F(cl_kernel_info, CL_KERNEL_NUM_ARGS, cl_uint) \
  892. F(cl_kernel_info, CL_KERNEL_REFERENCE_COUNT, cl_uint) \
  893. F(cl_kernel_info, CL_KERNEL_CONTEXT, cl::Context) \
  894. F(cl_kernel_info, CL_KERNEL_PROGRAM, cl::Program) \
  895. \
  896. F(cl_kernel_work_group_info, CL_KERNEL_WORK_GROUP_SIZE, ::size_t) \
  897. F(cl_kernel_work_group_info, CL_KERNEL_COMPILE_WORK_GROUP_SIZE, cl::size_t<3>) \
  898. F(cl_kernel_work_group_info, CL_KERNEL_LOCAL_MEM_SIZE, cl_ulong) \
  899. \
  900. F(cl_command_queue_info, CL_QUEUE_CONTEXT, cl::Context) \
  901. F(cl_command_queue_info, CL_QUEUE_DEVICE, cl::Device) \
  902. F(cl_command_queue_info, CL_QUEUE_REFERENCE_COUNT, cl_uint) \
  903. F(cl_command_queue_info, CL_QUEUE_PROPERTIES, cl_command_queue_properties)
  904. #if defined(CL_VERSION_1_1)
  905. #define __PARAM_NAME_INFO_1_1(F) \
  906. F(cl_context_info, CL_CONTEXT_NUM_DEVICES, cl_uint)\
  907. F(cl_device_info, CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF, cl_uint) \
  908. F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR, cl_uint) \
  909. F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT, cl_uint) \
  910. F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, cl_uint) \
  911. F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, cl_uint) \
  912. F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, cl_uint) \
  913. F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, cl_uint) \
  914. F(cl_device_info, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, cl_uint) \
  915. F(cl_device_info, CL_DEVICE_DOUBLE_FP_CONFIG, cl_device_fp_config) \
  916. F(cl_device_info, CL_DEVICE_HALF_FP_CONFIG, cl_device_fp_config) \
  917. F(cl_device_info, CL_DEVICE_HOST_UNIFIED_MEMORY, cl_bool) \
  918. \
  919. F(cl_mem_info, CL_MEM_ASSOCIATED_MEMOBJECT, cl::Memory) \
  920. F(cl_mem_info, CL_MEM_OFFSET, ::size_t) \
  921. \
  922. F(cl_kernel_work_group_info, CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE, ::size_t) \
  923. F(cl_kernel_work_group_info, CL_KERNEL_PRIVATE_MEM_SIZE, cl_ulong) \
  924. \
  925. F(cl_event_info, CL_EVENT_CONTEXT, cl::Context)
  926. #endif // CL_VERSION_1_1
  927. template <typename enum_type, cl_int Name>
  928. struct param_traits {};
  929. #define __DECLARE_PARAM_TRAITS(token, param_name, T) \
  930. struct token; \
  931. template<> \
  932. struct param_traits<detail:: token,param_name> \
  933. { \
  934. enum { value = param_name }; \
  935. typedef T param_type; \
  936. };
  937. __PARAM_NAME_INFO_1_0(__DECLARE_PARAM_TRAITS);
  938. #if defined(CL_VERSION_1_1)
  939. __PARAM_NAME_INFO_1_1(__DECLARE_PARAM_TRAITS);
  940. #endif // CL_VERSION_1_1
  941. #undef __DECLARE_PARAM_TRAITS
  942. // Convenience functions
  943. template <typename Func, typename T>
  944. inline cl_int
  945. getInfo(Func f, cl_uint name, T* param)
  946. {
  947. return GetInfoHelper<Func, T>::get(f, name, param);
  948. }
  949. template <typename Func, typename Arg0>
  950. struct GetInfoFunctor0
  951. {
  952. Func f_; const Arg0& arg0_;
  953. cl_int operator ()(
  954. cl_uint param, ::size_t size, void* value, ::size_t* size_ret)
  955. { return f_(arg0_, param, size, value, size_ret); }
  956. };
  957. template <typename Func, typename Arg0, typename Arg1>
  958. struct GetInfoFunctor1
  959. {
  960. Func f_; const Arg0& arg0_; const Arg1& arg1_;
  961. cl_int operator ()(
  962. cl_uint param, ::size_t size, void* value, ::size_t* size_ret)
  963. { return f_(arg0_, arg1_, param, size, value, size_ret); }
  964. };
  965. template <typename Func, typename Arg0, typename T>
  966. inline cl_int
  967. getInfo(Func f, const Arg0& arg0, cl_uint name, T* param)
  968. {
  969. GetInfoFunctor0<Func, Arg0> f0 = { f, arg0 };
  970. return GetInfoHelper<GetInfoFunctor0<Func, Arg0>, T>
  971. ::get(f0, name, param);
  972. }
  973. template <typename Func, typename Arg0, typename Arg1, typename T>
  974. inline cl_int
  975. getInfo(Func f, const Arg0& arg0, const Arg1& arg1, cl_uint name, T* param)
  976. {
  977. GetInfoFunctor1<Func, Arg0, Arg1> f0 = { f, arg0, arg1 };
  978. return GetInfoHelper<GetInfoFunctor1<Func, Arg0, Arg1>, T>
  979. ::get(f0, name, param);
  980. }
  981. template<typename T>
  982. struct ReferenceHandler
  983. { };
  984. template <>
  985. struct ReferenceHandler<cl_device_id>
  986. {
  987. // cl_device_id does not have retain().
  988. static cl_int retain(cl_device_id)
  989. { return CL_INVALID_DEVICE; }
  990. // cl_device_id does not have release().
  991. static cl_int release(cl_device_id)
  992. { return CL_INVALID_DEVICE; }
  993. };
  994. template <>
  995. struct ReferenceHandler<cl_platform_id>
  996. {
  997. // cl_platform_id does not have retain().
  998. static cl_int retain(cl_platform_id)
  999. { return CL_INVALID_PLATFORM; }
  1000. // cl_platform_id does not have release().
  1001. static cl_int release(cl_platform_id)
  1002. { return CL_INVALID_PLATFORM; }
  1003. };
  1004. template <>
  1005. struct ReferenceHandler<cl_context>
  1006. {
  1007. static cl_int retain(cl_context context)
  1008. { return ::clRetainContext(context); }
  1009. static cl_int release(cl_context context)
  1010. { return ::clReleaseContext(context); }
  1011. };
  1012. template <>
  1013. struct ReferenceHandler<cl_command_queue>
  1014. {
  1015. static cl_int retain(cl_command_queue queue)
  1016. { return ::clRetainCommandQueue(queue); }
  1017. static cl_int release(cl_command_queue queue)
  1018. { return ::clReleaseCommandQueue(queue); }
  1019. };
  1020. template <>
  1021. struct ReferenceHandler<cl_mem>
  1022. {
  1023. static cl_int retain(cl_mem memory)
  1024. { return ::clRetainMemObject(memory); }
  1025. static cl_int release(cl_mem memory)
  1026. { return ::clReleaseMemObject(memory); }
  1027. };
  1028. template <>
  1029. struct ReferenceHandler<cl_sampler>
  1030. {
  1031. static cl_int retain(cl_sampler sampler)
  1032. { return ::clRetainSampler(sampler); }
  1033. static cl_int release(cl_sampler sampler)
  1034. { return ::clReleaseSampler(sampler); }
  1035. };
  1036. template <>
  1037. struct ReferenceHandler<cl_program>
  1038. {
  1039. static cl_int retain(cl_program program)
  1040. { return ::clRetainProgram(program); }
  1041. static cl_int release(cl_program program)
  1042. { return ::clReleaseProgram(program); }
  1043. };
  1044. template <>
  1045. struct ReferenceHandler<cl_kernel>
  1046. {
  1047. static cl_int retain(cl_kernel kernel)
  1048. { return ::clRetainKernel(kernel); }
  1049. static cl_int release(cl_kernel kernel)
  1050. { return ::clReleaseKernel(kernel); }
  1051. };
  1052. template <>
  1053. struct ReferenceHandler<cl_event>
  1054. {
  1055. static cl_int retain(cl_event event)
  1056. { return ::clRetainEvent(event); }
  1057. static cl_int release(cl_event event)
  1058. { return ::clReleaseEvent(event); }
  1059. };
  1060. template <typename T>
  1061. class Wrapper
  1062. {
  1063. protected:
  1064. typedef T cl_type;
  1065. cl_type object_;
  1066. public:
  1067. Wrapper() : object_(NULL) { }
  1068. ~Wrapper()
  1069. {
  1070. if (object_ != NULL) { release(); }
  1071. }
  1072. Wrapper(const Wrapper<cl_type>& rhs)
  1073. {
  1074. object_ = rhs.object_;
  1075. if (object_ != NULL) { retain(); }
  1076. }
  1077. Wrapper<cl_type>& operator = (const Wrapper<cl_type>& rhs)
  1078. {
  1079. if (object_ != NULL) { release(); }
  1080. object_ = rhs.object_;
  1081. if (object_ != NULL) { retain(); }
  1082. return *this;
  1083. }
  1084. cl_type operator ()() const { return object_; }
  1085. cl_type& operator ()() { return object_; }
  1086. protected:
  1087. cl_int retain() const
  1088. {
  1089. return ReferenceHandler<cl_type>::retain(object_);
  1090. }
  1091. cl_int release() const
  1092. {
  1093. return ReferenceHandler<cl_type>::release(object_);
  1094. }
  1095. };
  1096. #if defined(__CL_ENABLE_EXCEPTIONS)
  1097. static inline cl_int errHandler (
  1098. cl_int err,
  1099. const char * errStr = NULL) throw(Error)
  1100. {
  1101. if (err != CL_SUCCESS) {
  1102. throw Error(err, errStr);
  1103. }
  1104. return err;
  1105. }
  1106. #else
  1107. static inline cl_int errHandler (cl_int err, const char * errStr = NULL)
  1108. {
  1109. return err;
  1110. }
  1111. #endif // __CL_ENABLE_EXCEPTIONS
  1112. } // namespace detail
  1113. //! \endcond
  1114. /*! \stuct ImageFormat
  1115. * \brief ImageFormat interface fro cl_image_format.
  1116. */
  1117. struct ImageFormat : public cl_image_format
  1118. {
  1119. ImageFormat(){}
  1120. /*! \brief Create an image format.
  1121. *
  1122. * \param order
  1123. * \param type
  1124. *
  1125. */
  1126. ImageFormat(cl_channel_order order, cl_channel_type type)
  1127. {
  1128. image_channel_order = order;
  1129. image_channel_data_type = type;
  1130. }
  1131. /*!
  1132. * \brief Assignment operator
  1133. *
  1134. * \param rhs the imageformat object on rhs of the assignment.
  1135. */
  1136. ImageFormat& operator = (const ImageFormat& rhs)
  1137. {
  1138. if (this != &rhs) {
  1139. this->image_channel_data_type = rhs.image_channel_data_type;
  1140. this->image_channel_order = rhs.image_channel_order;
  1141. }
  1142. return *this;
  1143. }
  1144. };
  1145. /*! \class Device
  1146. * \brief Device interface for cl_device_id.
  1147. */
  1148. class Device : public detail::Wrapper<cl_device_id>
  1149. {
  1150. public:
  1151. //! Construct a new device from a device ID.
  1152. Device(cl_device_id device) { object_ = device; }
  1153. //! Default constructor; device is not valid at this point.
  1154. Device() : detail::Wrapper<cl_type>() { }
  1155. /*!
  1156. * \brief Construct a new device from a valid device.
  1157. *
  1158. * \param device The device object used for creation.
  1159. */
  1160. Device(const Device& device) : detail::Wrapper<cl_type>(device) { }
  1161. /*!
  1162. * \brief Assign a device to device.
  1163. *
  1164. * \param rhs the device object on rhs of the assignment.
  1165. */
  1166. Device& operator = (const Device& rhs)
  1167. {
  1168. if (this != &rhs) {
  1169. detail::Wrapper<cl_type>::operator=(rhs);
  1170. }
  1171. return *this;
  1172. }
  1173. /*!
  1174. * \brief Get specific information about an OpenCL device.
  1175. *
  1176. * \param name is an enum that identifies the device information being
  1177. * queried.
  1178. * \param param is a pointer to memory location where appropriate values
  1179. * for a given param_name will be returned. If value is NULL,
  1180. * it is ignored
  1181. *
  1182. * \retval CL_INVALID_DEVICE if device is not valid.
  1183. * \retval CL_INVALID_VALUE if name is not one of the supported values.
  1184. * \retval CL_SUCCESS if the function is executed successfully.
  1185. *
  1186. * \note In the case that exceptions are enabled and a return value
  1187. * other than CL_SUCCESS is generated, then cl::Error exception is
  1188. * generated.
  1189. *
  1190. */
  1191. template <typename T>
  1192. cl_int getInfo(cl_device_info name, T* param) const
  1193. {
  1194. return detail::errHandler(
  1195. detail::getInfo(&::clGetDeviceInfo, object_, name, param),
  1196. __GET_DEVICE_INFO_ERR);
  1197. }
  1198. /*!
  1199. * \brief Get specific information about an OpenCL device.
  1200. *
  1201. * \param name is is an enum that identifies the device information being
  1202. * queried. As this value is a template parameter if it is not a
  1203. * value member of cl_device_info, then a compile error will be
  1204. * generated.
  1205. *
  1206. * \param err pointer to memory location where error value will be returned.
  1207. * If not null, the default value, then one of the following values is
  1208. * returned:
  1209. * - CL_INVALID_DEVICE if device is not valid.
  1210. * - CL_INVALID_VALUE if name is not one of the supported values.
  1211. * - CL_SUCCESS if the function is executed successfully.
  1212. *
  1213. * \return the appropriate values for \em name will be returned.
  1214. *
  1215. * \note In the case that exceptions are enabled and error value
  1216. * other than CL_SUCCESS is generated, then cl::Error exception is
  1217. * generated.
  1218. *
  1219. */
  1220. template <cl_int name> typename
  1221. detail::param_traits<detail::cl_device_info, name>::param_type
  1222. getInfo(cl_int* err = NULL) const
  1223. {
  1224. typename detail::param_traits<
  1225. detail::cl_device_info, name>::param_type param;
  1226. cl_int result = getInfo(name, &param);
  1227. if (err != NULL) {
  1228. *err = result;
  1229. }
  1230. return param;
  1231. }
  1232. };
  1233. /*! \class Platform
  1234. * \brief Platform interface.
  1235. */
  1236. class Platform : public detail::Wrapper<cl_platform_id>
  1237. {
  1238. public:
  1239. static const Platform null();
  1240. //! Construct a new platform from a platform ID.
  1241. Platform(cl_platform_id platform) { object_ = platform; }
  1242. //! Default constructor; platform is not valid at this point.
  1243. Platform() : detail::Wrapper<cl_type>() { }
  1244. /*!
  1245. * \brief Construct a new platform from a valid platform.
  1246. *
  1247. * \param platform The platform object used for creation.
  1248. */
  1249. Platform(const Platform& platform) : detail::Wrapper<cl_type>(platform) { }
  1250. /*!
  1251. * \brief Assign a platform to platform.
  1252. *
  1253. * \param rhs the platform object on rhs of the assignment.
  1254. */
  1255. Platform& operator = (const Platform& rhs)
  1256. {
  1257. if (this != &rhs) {
  1258. detail::Wrapper<cl_type>::operator=(rhs);
  1259. }
  1260. return *this;
  1261. }
  1262. /*!
  1263. * \brief Get specific information about the OpenCL platform.
  1264. *
  1265. * \param name is an enum that identifies the platform information being
  1266. * queried.
  1267. * \param param is a pointer to memory location where appropriate values
  1268. * for a given name will be returned. If value is NULL,
  1269. * it is ignored
  1270. *
  1271. * \retval CL_INVALID_VALUE if param_name is not one of the supported
  1272. * values or if size in bytes specified by param_value_size
  1273. * is < size of return type and param_value is not a NULL value.
  1274. * \retval CL_SUCCESS if the function is executed successfully.
  1275. *
  1276. * \note In the case that exceptions are enabled and a return value
  1277. * other than CL_SUCCESS is generated, then cl::Error exception is
  1278. * generated.
  1279. */
  1280. cl_int getInfo(cl_platform_info name, STRING_CLASS* param) const
  1281. {
  1282. return detail::errHandler(
  1283. detail::getInfo(&::clGetPlatformInfo, object_, name, param),
  1284. __GET_PLATFORM_INFO_ERR);
  1285. }
  1286. /*!
  1287. * \brief Get specific information about the OpenCL Platform.
  1288. *
  1289. * \param name is is an enum that identifies the device information being
  1290. * queried. As this value is a template parameter if it is not a
  1291. * value member of cl_platform_info, then a compile error will be
  1292. * generated.
  1293. *
  1294. * \param err pointer to memory location where error value will be returned.
  1295. * If not null, the default value, then one of the following values is
  1296. * returned:
  1297. * - CL_INVALID_VALUE if name is not one of the supported values.
  1298. * - CL_SUCCESS if the function is executed successfully.
  1299. * *
  1300. * \return the appropriate values for \em name will be returned.
  1301. *
  1302. * \note In the case that exceptions are enabled and error value
  1303. * other than CL_SUCCESS is generated, then cl::Error exception is
  1304. * generated.
  1305. */
  1306. template <cl_int name> typename
  1307. detail::param_traits<detail::cl_platform_info, name>::param_type
  1308. getInfo(cl_int* err = NULL) const
  1309. {
  1310. typename detail::param_traits<
  1311. detail::cl_platform_info, name>::param_type param;
  1312. cl_int result = getInfo(name, &param);
  1313. if (err != NULL) {
  1314. *err = result;
  1315. }
  1316. return param;
  1317. }
  1318. /*! \brief Get the list of available devices.
  1319. *
  1320. * \param type is a bitfield that identifies the type of OpenCL device.
  1321. * The \a device_type can be used to query specific OpenCL devices or all
  1322. * OpenCL devices available.
  1323. *
  1324. * \param devices returns a vector of OpenCL devices found. The cl::Device
  1325. * values returned in devices can be used to identify a specific OpenCL
  1326. * device. If \a devices argument is NULL, this argument is ignored.
  1327. *
  1328. * \return One of the following values:
  1329. * - CL_INVALID_DEVICE_TYPE if \a type is not a valid value.
  1330. * - CL_DEVICE_ NOT_FOUND if no OpenCL devices that matched \a device_type
  1331. * were found.
  1332. * - CL_SUCCESS if the function is executed successfully.
  1333. *
  1334. * The application can query specific capabilities of the OpenCL device(s)
  1335. * returned by cl::getDevices. This can be used by the application to
  1336. * determine which device(s) to use.
  1337. *
  1338. * \note In the case that exceptions are enabled and a return value
  1339. * other than CL_SUCCESS is generated, then cl::Error exception is
  1340. * generated.
  1341. */
  1342. cl_int getDevices(
  1343. cl_device_type type,
  1344. VECTOR_CLASS<Device>* devices) const
  1345. {
  1346. cl_uint n = 0;
  1347. cl_int err = ::clGetDeviceIDs(object_, type, 0, NULL, &n);
  1348. if (err != CL_SUCCESS) {
  1349. return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
  1350. }
  1351. cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id));
  1352. err = ::clGetDeviceIDs(object_, type, n, ids, NULL);
  1353. if (err != CL_SUCCESS) {
  1354. return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
  1355. }
  1356. devices->assign(&ids[0], &ids[n]);
  1357. return CL_SUCCESS;
  1358. }
  1359. #if defined(USE_DX_INTEROP)
  1360. /*! \brief Get the list of available D3D10 devices.
  1361. *
  1362. * \param d3d_device_source.
  1363. *
  1364. * \param d3d_object.
  1365. *
  1366. * \param d3d_device_set.
  1367. *
  1368. * \param devices returns a vector of OpenCL D3D10 devices found. The cl::Device
  1369. * values returned in devices can be used to identify a specific OpenCL
  1370. * device. If \a devices argument is NULL, this argument is ignored.
  1371. *
  1372. * \return One of the following values:
  1373. * - CL_SUCCESS if the function is executed successfully.
  1374. *
  1375. * The application can query specific capabilities of the OpenCL device(s)
  1376. * returned by cl::getDevices. This can be used by the application to
  1377. * determine which device(s) to use.
  1378. *
  1379. * \note In the case that exceptions are enabled and a return value
  1380. * other than CL_SUCCESS is generated, then cl::Error exception is
  1381. * generated.
  1382. */
  1383. cl_int getDevices(
  1384. cl_d3d10_device_source_khr d3d_device_source,
  1385. void * d3d_object,
  1386. cl_d3d10_device_set_khr d3d_device_set,
  1387. VECTOR_CLASS<Device>* devices) const
  1388. {
  1389. typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clGetDeviceIDsFromD3D10KHR)(
  1390. cl_platform_id platform,
  1391. cl_d3d10_device_source_khr d3d_device_source,
  1392. void * d3d_object,
  1393. cl_d3d10_device_set_khr d3d_device_set,
  1394. cl_uint num_entries,
  1395. cl_device_id * devices,
  1396. cl_uint* num_devices);
  1397. static PFN_clGetDeviceIDsFromD3D10KHR pfn_clGetDeviceIDsFromD3D10KHR = NULL;
  1398. __INIT_CL_EXT_FCN_PTR(clGetDeviceIDsFromD3D10KHR);
  1399. cl_uint n = 0;
  1400. cl_int err = pfn_clGetDeviceIDsFromD3D10KHR(
  1401. object_,
  1402. d3d_device_source,
  1403. d3d_object,
  1404. d3d_device_set,
  1405. 0,
  1406. NULL,
  1407. &n);
  1408. if (err != CL_SUCCESS) {
  1409. return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
  1410. }
  1411. cl_device_id* ids = (cl_device_id*) alloca(n * sizeof(cl_device_id));
  1412. err = pfn_clGetDeviceIDsFromD3D10KHR(
  1413. object_,
  1414. d3d_device_source,
  1415. d3d_object,
  1416. d3d_device_set,
  1417. n,
  1418. ids,
  1419. NULL);
  1420. if (err != CL_SUCCESS) {
  1421. return detail::errHandler(err, __GET_DEVICE_IDS_ERR);
  1422. }
  1423. devices->assign(&ids[0], &ids[n]);
  1424. return CL_SUCCESS;
  1425. }
  1426. #endif
  1427. static cl_int get(
  1428. VECTOR_CLASS<Platform>* platforms)
  1429. {
  1430. cl_uint n = 0;
  1431. cl_int err = ::clGetPlatformIDs(0, NULL, &n);
  1432. if (err != CL_SUCCESS) {
  1433. return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
  1434. }
  1435. cl_platform_id* ids = (cl_platform_id*) alloca(
  1436. n * sizeof(cl_platform_id));
  1437. err = ::clGetPlatformIDs(n, ids, NULL);
  1438. if (err != CL_SUCCESS) {
  1439. return detail::errHandler(err, __GET_PLATFORM_IDS_ERR);
  1440. }
  1441. platforms->assign(&ids[0], &ids[n]);
  1442. return CL_SUCCESS;
  1443. }
  1444. };
  1445. /*! \brief Allow to runtime to release the resources allocated by the OpenCL
  1446. * compiler.
  1447. *
  1448. * This is a hint from the application and does not guarantee that the compiler
  1449. * will not be used in the future or that the compiler will actually be
  1450. * unloaded by the implementation.
  1451. *
  1452. * \return This call currently always returns CL_SUCCESS
  1453. *
  1454. */
  1455. static inline cl_int
  1456. UnloadCompiler()
  1457. {
  1458. return ::clUnloadCompiler();
  1459. }
  1460. /*! \class Context
  1461. * \brief Context interface for cl_context.
  1462. */
  1463. class Context : public detail::Wrapper<cl_context>
  1464. {
  1465. public:
  1466. /*! \brief Construct an OpenCL context.
  1467. *
  1468. * An OpenCL context is created with one or more devices. Contexts are used by
  1469. * the OpenCL runtime for managing objects such as command-queues, memory,
  1470. * program and kernel objects and for executing kernels on one or more devices
  1471. * specified in the context.
  1472. *
  1473. *
  1474. * \param devices is a pointer to a list of unique devices returned by
  1475. * clGetDevices. If more than one device is specified in devices,
  1476. * a selection criteria may be applied to determine if the list of devices
  1477. * specified can be used together to create a context.
  1478. *
  1479. * \param properties is reserved and must be zero, which is its default
  1480. * value.
  1481. *
  1482. * \param pfn_notify is a callback function that can be registered by the
  1483. * application. This callback function will be used by the runtime to
  1484. * report information on errors that occur in this context. This callback
  1485. * function may be called asynchronously by the runtime. If \a pfn_notify
  1486. * is NULL, its default value, no callback function is registered.
  1487. *
  1488. * \param user_data will be passed as the data argument when
  1489. * \a pfn_notify is called. \a data can be NULL, which is the default value.
  1490. *
  1491. * \param err will return an appropriate error code.
  1492. * If \a err is NULL, its default value, no error code is returned.
  1493. *
  1494. * \return A valid non-zero context and errcode_ret is set to CL_SUCCESS
  1495. * if the context is created successfully or NULL with the following
  1496. * error values stored in \a errcode_ret:
  1497. * - CL_INVALID_VALUE if \a properties is not zero.
  1498. * - CL_INVALID_DEVICE if \a devices contains an invalid device.
  1499. * - CL_INVALID_DEVICE_LIST if more than one device is specified in
  1500. * \a devices and the list of devices specified cannot be used together
  1501. * to create a context.
  1502. * - CL_DEVICE_NOT_AVAILABLE if a device in \a devices is currently not
  1503. * available even though the device was returned by clGetDevices.
  1504. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources
  1505. * required by the runtime.
  1506. *
  1507. * \note In the case that exceptsions are enabled and a return value
  1508. * other than CL_SUCCESS is generated, then cl::Error exception is
  1509. * generated.
  1510. */
  1511. Context(
  1512. const VECTOR_CLASS<Device>& devices,
  1513. cl_context_properties* properties = NULL,
  1514. void (CL_CALLBACK * notifyFptr)(
  1515. const char *,
  1516. const void *,
  1517. ::size_t,
  1518. void *) = NULL,
  1519. void* data = NULL,
  1520. cl_int* err = NULL)
  1521. {
  1522. cl_int error;
  1523. object_ = ::clCreateContext(
  1524. properties, (cl_uint) devices.size(),
  1525. (cl_device_id*) &devices.front(),
  1526. notifyFptr, data, &error);
  1527. detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
  1528. if (err != NULL) {
  1529. *err = error;
  1530. }
  1531. }
  1532. /*! \brief Create an OpenCL context from a device type that identifies the
  1533. * specific device(s) to use.
  1534. *
  1535. * \param type is a bit-field that identifies the type of device.
  1536. *
  1537. * \param properties is reserved and must be zero.
  1538. *
  1539. * \param pfn_notify described in previous definition of Context
  1540. * constructor.
  1541. *
  1542. * \param data described in previous definition of Context
  1543. * constructor.
  1544. *
  1545. * \param err will return an appropriate error code. If \a err
  1546. * is NULL, its default value, no error code is returned.
  1547. *
  1548. * \return A valid non-zero context and errcode_ret is set to CL_SUCCESS
  1549. * if the context is created successfully or NULL with the following error
  1550. * values stored in errcode_ret:
  1551. * - CL_INVALID_VALUE if \a properties is not zero.
  1552. * - CL_INVALID_DEVICE_TYPE if \a device_type is not a valid value.
  1553. * - CL_DEVICE_NOT_AVAILABLE if no devices that match \a device_type
  1554. * are currently available.
  1555. * - CL_DEVICE_NOT_FOUND if no devices that match \a device_type were found.
  1556. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources
  1557. * required by the runtime.
  1558. *
  1559. * \note In the case that exceptions are enabled and a return value
  1560. * other than CL_SUCCESS is generated, then cl::Error exception is
  1561. * generated.
  1562. */
  1563. Context(
  1564. cl_device_type type,
  1565. cl_context_properties* properties = NULL,
  1566. void (CL_CALLBACK * notifyFptr)(
  1567. const char *,
  1568. const void *,
  1569. ::size_t,
  1570. void *) = NULL,
  1571. void* data = NULL,
  1572. cl_int* err = NULL)
  1573. {
  1574. cl_int error;
  1575. object_ = ::clCreateContextFromType(
  1576. properties, type, notifyFptr, data, &error);
  1577. detail::errHandler(error, __CREATE_CONTEXT_FROM_TYPE_ERR);
  1578. if (err != NULL) {
  1579. *err = error;
  1580. }
  1581. }
  1582. //! Default constructor; context is not valid at this point.
  1583. Context() : detail::Wrapper<cl_type>() { }
  1584. /*!
  1585. * \brief Construct a new context from a valid context.
  1586. *
  1587. * \param context The context object used for creation.
  1588. */
  1589. Context(const Context& context) : detail::Wrapper<cl_type>(context) { }
  1590. /*!
  1591. * \brief Assign a context to context.
  1592. *
  1593. * \param rhs the context object on rhs of the assignment.
  1594. */
  1595. Context& operator = (const Context& rhs)
  1596. {
  1597. if (this != &rhs) {
  1598. detail::Wrapper<cl_type>::operator=(rhs);
  1599. }
  1600. return *this;
  1601. }
  1602. /*! \brief Query information about a context.
  1603. *
  1604. * \param context specifies the OpenCL context being queried.
  1605. *
  1606. * \param name is an enum that specifies the information to query.
  1607. *
  1608. * \param param is a pointer to memory where the appropriate result being
  1609. * queried is returned. If \a param_value is NULL, it is ignored.
  1610. *
  1611. * \return One of the following values:
  1612. * - CL_INVALID_CONTEXT if context is not a valid context.
  1613. * - CL_INVALID_VALUE if \a param_name is not one of the supported
  1614. * values.
  1615. * - CL_SUCCESS if the function is executed successfully.
  1616. *
  1617. * \note In the case that exceptions are enabled and a return value
  1618. * other than CL_SUCCESS is generated, then cl::Error exception is
  1619. * generated.
  1620. */
  1621. template <typename T>
  1622. cl_int getInfo(cl_context_info name, T* param) const
  1623. {
  1624. return detail::errHandler(
  1625. detail::getInfo(&::clGetContextInfo, object_, name, param),
  1626. __GET_CONTEXT_INFO_ERR);
  1627. }
  1628. /*! \brief Query information about a context.
  1629. *
  1630. * \param context specifies the OpenCL context being queried.
  1631. *
  1632. * \param name is an enum that specifies the information to query.
  1633. *
  1634. * * \param err pointer to memory location where error value will be
  1635. * returned. If not null, the default value, then one of the following
  1636. * values is returned:
  1637. * - CL_INVALID_CONTEXT if context is not a valid context.
  1638. * - CL_INVALID_VALUE if \a param_name is not one of the supported
  1639. * values.
  1640. * - CL_SUCCESS if the function is executed successfully.
  1641. *
  1642. * \return the appropriate values for \em name will be returned.
  1643. *
  1644. * \note In the case that exceptions are enabled and a return value
  1645. * other than CL_SUCCESS is generated, then cl::Error exception is
  1646. * generated.
  1647. */
  1648. template <cl_int name> typename
  1649. detail::param_traits<detail::cl_context_info, name>::param_type
  1650. getInfo(cl_int* err = NULL) const
  1651. {
  1652. typename detail::param_traits<
  1653. detail::cl_context_info, name>::param_type param;
  1654. cl_int result = getInfo(name, &param);
  1655. if (err != NULL) {
  1656. *err = result;
  1657. }
  1658. return param;
  1659. }
  1660. /*! \brief Query information supported image formats.
  1661. *
  1662. * \param flags is a bit-field that is used to specify allocation and usage
  1663. * information about the image memory object being created
  1664. * \param type describes the image type and must be either
  1665. * CL_MEM_OBJECT_IMAGE2D or CL_MEM_OBJECT_IMAGE3D.
  1666. * \param formats is a pointer to a memory location where the vector of
  1667. * supported image formats are returned. Each vector element describes a
  1668. * cl_image_format structure supported by the OpenCL implementation. If
  1669. * \a formats is NULL, it is ignored.
  1670. *
  1671. * \return One of the following values:
  1672. * - CL_INVALID_CONTEXT if context is not a valid context.
  1673. * - CL_INVALID_VALUE if \a flags or \type are not valid.
  1674. * - CL_SUCCESS if the function is executed successfully.
  1675. *
  1676. * \note In the case that exceptions are enabled and a return value
  1677. * other than CL_SUCCESS is generated, then cl::Error exception is
  1678. * generated.
  1679. */
  1680. cl_int getSupportedImageFormats(
  1681. cl_mem_flags flags,
  1682. cl_mem_object_type type,
  1683. VECTOR_CLASS<ImageFormat>* formats) const
  1684. {
  1685. cl_uint numEntries;
  1686. cl_int err = ::clGetSupportedImageFormats(
  1687. object_, flags,type, 0, NULL, &numEntries);
  1688. if (err != CL_SUCCESS) {
  1689. return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
  1690. }
  1691. ImageFormat* value = (ImageFormat*)
  1692. alloca(numEntries * sizeof(ImageFormat));
  1693. err = ::clGetSupportedImageFormats(
  1694. object_, flags, type, numEntries,
  1695. (cl_image_format*) value, NULL);
  1696. if (err != CL_SUCCESS) {
  1697. return detail::errHandler(err, __GET_SUPPORTED_IMAGE_FORMATS_ERR);
  1698. }
  1699. formats->assign(&value[0], &value[numEntries]);
  1700. return CL_SUCCESS;
  1701. }
  1702. };
  1703. /*! \class Event
  1704. * \brief Event interface for cl_event.
  1705. */
  1706. class Event : public detail::Wrapper<cl_event>
  1707. {
  1708. public:
  1709. //! Default constructor; event is not valid at this point.
  1710. Event() : detail::Wrapper<cl_type>() { }
  1711. /*!
  1712. * \brief Construct a new event from a valid event.
  1713. *
  1714. * \param event The event object used for creation.
  1715. */
  1716. Event(const Event& event) : detail::Wrapper<cl_type>(event) { }
  1717. /*!
  1718. * \brief Assign a event to event.
  1719. *
  1720. * \param rhs the event object on rhs of the assignment.
  1721. */
  1722. Event& operator = (const Event& rhs)
  1723. {
  1724. if (this != &rhs) {
  1725. detail::Wrapper<cl_type>::operator=(rhs);
  1726. }
  1727. return *this;
  1728. }
  1729. /*! \brief Return information about the event.
  1730. *
  1731. * \param name specifies the information to query.
  1732. *
  1733. * \param param is a pointer to memory where the appropriate result being
  1734. * queried is returned. If \a param_value is NULL, it is ignored.
  1735. *
  1736. * Using cl::Event::getEventInfo to determine if a command identified by
  1737. * event has finished execution (i.e. CL_EVENT_COMMAND_EXECUTION_STATUS
  1738. * returns CL_COMPLETE) is not a synchronization point i.e. there are
  1739. * no guarantees that the memory objects being modified by command
  1740. * associated with event will be visible to other enqueued commands.
  1741. *
  1742. * \return One of the following values:
  1743. * - CL_SUCCESS if the function is executed successfully
  1744. * - CL_INVALID_VALUE if \a name is not valid.
  1745. *
  1746. * \note In the case that exceptions are enabled and a return value
  1747. * other than CL_SUCCESS is generated, then cl::Error exception is
  1748. * generated.
  1749. */
  1750. template <typename T>
  1751. cl_int getInfo(cl_event_info name, T* param) const
  1752. {
  1753. return detail::errHandler(
  1754. detail::getInfo(&::clGetEventInfo, object_, name, param),
  1755. __GET_EVENT_INFO_ERR);
  1756. }
  1757. /*!
  1758. * \brief \brief Return information about the event.
  1759. *
  1760. * \param \param name specifies the information to query.
  1761. *
  1762. * \param err pointer to memory location where error value will be returned.
  1763. * If not null, the default value, then one of the following values is
  1764. * returned:
  1765. * - CL_SUCCESS if the function is executed successfully
  1766. * - CL_INVALID_VALUE if \a name is not valid.
  1767. *
  1768. * \return the appropriate values for \em name will be returned.
  1769. *
  1770. * \note In the case that exceptions are enabled and error value
  1771. * other than CL_SUCCESS is generated, then cl::Error exception is
  1772. * generated.
  1773. */
  1774. template <cl_int name> typename
  1775. detail::param_traits<detail::cl_event_info, name>::param_type
  1776. getInfo(cl_int* err = NULL) const
  1777. {
  1778. typename detail::param_traits<
  1779. detail::cl_event_info, name>::param_type param;
  1780. cl_int result = getInfo(name, &param);
  1781. if (err != NULL) {
  1782. *err = result;
  1783. }
  1784. return param;
  1785. }
  1786. /*! \brief Return profiling information for the command associated with
  1787. * event.
  1788. *
  1789. * \param name specifies the profiling data to query.
  1790. *
  1791. * \param param is a pointer to memory where the appropriate result being
  1792. * queried is returned. If \a param is NULL, it is ignored.
  1793. *
  1794. * The unsigned 64-bit values returned can be used to measure the time in
  1795. * nano-seconds consumed by OpenCL commands. OpenCL devices are required to
  1796. * correctly track time across changes in frequency and p-states. The
  1797. * CL_DEVICE_PROFILING_TIMER_RESOLUTION specifies the resolution of the timer
  1798. * i.e. the number of nanoseconds elapsed before the timer is incremented.
  1799. *
  1800. * \return One of the following values:
  1801. * - CL_SUCCESS if the function is executed successfully and the profiling
  1802. * information has been recorded
  1803. * - CL_PROFILING_INFO_NOT_AVAILABLE if the profiling information is currently
  1804. * not available (because the command identified by event has not completed)
  1805. * - CL_INVALID_VALUE if \a param_name is not valid.
  1806. *
  1807. * \note In the case that exceptions are enabled and error value
  1808. * other than CL_SUCCESS is generated, then cl::Error exception is
  1809. * generated.
  1810. */
  1811. template <typename T>
  1812. cl_int getProfilingInfo(cl_profiling_info name, T* param) const
  1813. {
  1814. return detail::errHandler(detail::getInfo(
  1815. &::clGetEventProfilingInfo, object_, name, param),
  1816. __GET_EVENT_PROFILE_INFO_ERR);
  1817. }
  1818. /*!
  1819. * \brief Return profiling information for the command associated with
  1820. * event.
  1821. *
  1822. * \param name specifies the profiling data to query.
  1823. *
  1824. * \param err pointer to memory location where error value will be returned.
  1825. * If not null, the default value, then one of the following values is
  1826. * returned:
  1827. * - CL_SUCCESS if the function is executed successfully and the profiling
  1828. * information has been recorded
  1829. * - CL_PROFILING_INFO_NOT_AVAILABLE if the profiling information is currently
  1830. * not available (because the command identified by event has not completed)
  1831. * - CL_INVALID_VALUE if \a param_name is not valid.
  1832. * \return the appropriate values for \em name will be returned.
  1833. *
  1834. * \note In the case that exceptions are enabled and error value
  1835. * other than CL_SUCCESS is generated, then cl::Error exception is
  1836. * generated.
  1837. */
  1838. template <cl_int name> typename
  1839. detail::param_traits<detail::cl_profiling_info, name>::param_type
  1840. getProfilingInfo(cl_int* err = NULL) const
  1841. {
  1842. typename detail::param_traits<
  1843. detail::cl_profiling_info, name>::param_type param;
  1844. cl_int result = getProfilingInfo(name, &param);
  1845. if (err != NULL) {
  1846. *err = result;
  1847. }
  1848. return param;
  1849. }
  1850. /*! \brief Wait on the host thread for command identified by event to
  1851. * complete.
  1852. *
  1853. * A command is considered complete if its execution status is CL_COMPLETE
  1854. * or a negative value. The events specified in event_list act as
  1855. * synchronization points.
  1856. *
  1857. * \return One of the following values:
  1858. * - CL_SUCCESS if the function was executed successfully.
  1859. */
  1860. cl_int wait() const
  1861. {
  1862. return detail::errHandler(
  1863. ::clWaitForEvents(1, &object_),
  1864. __WAIT_FOR_EVENTS_ERR);
  1865. }
  1866. #if defined(CL_VERSION_1_1)
  1867. /*!
  1868. * \brief Register a user callback function.
  1869. *
  1870. * \param type specifies the command execution status for which the callback
  1871. * is registered. The command execution callback mask values for which a
  1872. * callback can be registered are: CL_COMPLETE. There is no guarantee that
  1873. * the callback functions registered for various execution status values for
  1874. * an event will be called in the exact order that the execution status of a
  1875. * command changes.
  1876. *
  1877. * \param pfn_event_notify is the event callback function that can be
  1878. * registered by the application. This callback function may be called
  1879. * asynchronously by the OpenCL implementation. It is the application’s
  1880. * responsibility to ensure that the callback function is thread-safe.
  1881. * The parameters to this callback function are:
  1882. *
  1883. * - event is the event object for which the callback function is invoked.
  1884. * - event_command_exec_status represents the execution status of command
  1885. * for which this callback function is invoked. Refer to table 5.15 for
  1886. * the command execution status values. If the callback is called as the
  1887. * result of the command associated with event being abnormally terminated,
  1888. * an appropriate error code for the error that caused the termination
  1889. * will be passed to event_command_exec_status instead.
  1890. * - user_data is a pointer to user supplied data.
  1891. *
  1892. * \param user_data will be passed as the user_data argument when pfn_notify
  1893. * is called. user_data can be NULL.
  1894. *
  1895. * \return CL_SUCCESS if successfull otherwise one of the following
  1896. * error values:
  1897. *
  1898. * - CL_INVALID_EVENT if event is not a valid event object or is a user
  1899. * event object created using clCreateUserEvent.
  1900. * - CL_INVALID_VALUE if pfn_event_notify is NULL or if
  1901. * command_exec_callback_type is not a valid command execution status.
  1902. *
  1903. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources
  1904. * required by the OpenCL implementation on the host.
  1905. *
  1906. * \note In the case that exceptions are enabled and error value
  1907. * other than CL_SUCCESS is generated, then cl::Error exception is
  1908. * generated.
  1909. */
  1910. cl_int setCallback(
  1911. cl_int type,
  1912. void (CL_CALLBACK * pfn_notify)(cl_event, cl_int, void *),
  1913. void * user_data = NULL)
  1914. {
  1915. return detail::errHandler(
  1916. ::clSetEventCallback(
  1917. object_,
  1918. type,
  1919. pfn_notify,
  1920. user_data),
  1921. __SET_EVENT_CALLBACK_ERR);
  1922. }
  1923. #endif
  1924. /*! \brief Wait on the host thread for commands identified by event objects in
  1925. * event_list to complete.
  1926. *
  1927. * A command is considered complete if its execution status is CL_COMPLETE or
  1928. * a negative value. The events specified in event_list act as synchronization
  1929. * points.
  1930. *
  1931. * \param events is a vector of events.
  1932. *
  1933. * \return One of the following values:
  1934. * - CL_SUCCESS if the function was executed successfully.
  1935. * - CL_INVALID_VALUE if size of \a events is zero.
  1936. * - CL_INVALID_EVENT if an event in \a events is not valid.
  1937. *
  1938. * \note In the case that exceptions are enabled and error value
  1939. * other than CL_SUCCESS is generated, then cl::Error exception is
  1940. * generated.
  1941. */
  1942. static cl_int
  1943. waitForEvents(const VECTOR_CLASS<Event>& events)
  1944. {
  1945. return detail::errHandler(
  1946. ::clWaitForEvents(
  1947. (cl_uint) events.size(), (cl_event*)&events.front()),
  1948. __WAIT_FOR_EVENTS_ERR);
  1949. }
  1950. };
  1951. #if defined(CL_VERSION_1_1)
  1952. /*! \class UserEvent
  1953. * \brief User event interface for cl_event.
  1954. */
  1955. class UserEvent : public Event
  1956. {
  1957. public:
  1958. /*! \brief Create a user event object.
  1959. *
  1960. * \param context is a valid OpenCL context used to create the event object.
  1961. *
  1962. * \param err will return an appropriate error code.
  1963. * If \a err is NULL, no error code is returned.
  1964. *
  1965. * \return A valid non-zero buffer object and \a err is set to
  1966. * CL_SUCCESS if the buffer object is created successfully or a NULL value
  1967. * with one of the following error values returned in \a err:
  1968. * - CL_INVALID_CONTEXT if \a context is not a valid context.
  1969. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources
  1970. * required by the runtime.
  1971. *
  1972. * \note In the case that exceptions are enabled and error value
  1973. * other than CL_SUCCESS is generated, then cl::Error exception is
  1974. * generated.
  1975. */
  1976. UserEvent(
  1977. const Context& context,
  1978. cl_int * err = NULL)
  1979. {
  1980. cl_int error;
  1981. object_ = ::clCreateUserEvent(
  1982. context(),
  1983. &error);
  1984. detail::errHandler(error, __CREATE_USER_EVENT_ERR);
  1985. if (err != NULL) {
  1986. *err = error;
  1987. }
  1988. }
  1989. //! Default constructor; buffer is not valid at this point.
  1990. UserEvent() : Event() { }
  1991. /*!
  1992. * \brief Construct a new user event from a valid user event.
  1993. *
  1994. * \param event The event object used for creation.
  1995. */
  1996. UserEvent(const UserEvent& event) : Event(event) { }
  1997. /*!
  1998. * \brief Assign a user event.
  1999. *
  2000. * \param rhs the user event object on rhs of the assignment.
  2001. */
  2002. UserEvent& operator = (const UserEvent& rhs)
  2003. {
  2004. if (this != &rhs) {
  2005. Event::operator=(rhs);
  2006. }
  2007. return *this;
  2008. }
  2009. /*!
  2010. * \brief Set the execution status.
  2011. *
  2012. * \param status specifies the new execution status to be set
  2013. * and can be CL_COMPLETE or a negative integer value to indicate an error.
  2014. *
  2015. * \return CL_SUCCESS if the status is updated successfully or
  2016. * one of the following error values:
  2017. * - CL_INVALID_VALUE if the execution_status is not CL_COMPLETE or a
  2018. * negative integer value.
  2019. * - CL_INVALID_OPERATION if the execution_status for event has already
  2020. * been changed by a previous call to setStatus.
  2021. *
  2022. * \note In the case that exceptions are enabled and error value
  2023. * other than CL_SUCCESS is generated, then cl::Error exception is
  2024. * generated.
  2025. */
  2026. cl_int setStatus(cl_int status)
  2027. {
  2028. return detail::errHandler(
  2029. ::clSetUserEventStatus(object_,status),
  2030. __SET_USER_EVENT_STATUS_ERR);
  2031. }
  2032. };
  2033. #endif
  2034. /*! \brief Wait on the host thread for commands identified by event objects in
  2035. * event_list to complete.
  2036. *
  2037. * A command is considered complete if its execution status is CL_COMPLETE or
  2038. * a negative value. The events specified in event_list act as synchronization
  2039. * points.
  2040. *
  2041. * \param events is a vector of events.
  2042. *
  2043. * \return One of the following values:
  2044. * - CL_SUCCESS if the function was executed successfully.
  2045. * - CL_INVALID_VALUE if size of \a events is zero.
  2046. * - CL_INVALID_EVENT if an event in \a events is not valid.
  2047. *
  2048. * \note In the case that exceptions are enabled and error value
  2049. * other than CL_SUCCESS is generated, then cl::Error exception is
  2050. * generated.
  2051. */
  2052. inline static cl_int
  2053. WaitForEvents(const VECTOR_CLASS<Event>& events)
  2054. {
  2055. return detail::errHandler(
  2056. ::clWaitForEvents(
  2057. (cl_uint) events.size(), (cl_event*)&events.front()),
  2058. __WAIT_FOR_EVENTS_ERR);
  2059. }
  2060. /*! \class Memory
  2061. * \brief Memory interface for cl_mem.
  2062. */
  2063. class Memory : public detail::Wrapper<cl_mem>
  2064. {
  2065. public:
  2066. //! Default constructor; memory is not valid at this point.
  2067. Memory() : detail::Wrapper<cl_type>() { }
  2068. /*!
  2069. * \brief Construct a new memory from a valid memory.
  2070. *
  2071. * \param memory The memory object used for creation.
  2072. */
  2073. Memory(const Memory& memory) : detail::Wrapper<cl_type>(memory) { }
  2074. /*!
  2075. * \brief Assign a memory to memory.
  2076. *
  2077. * \param rhs the memory object on rhs of the assignment.
  2078. */
  2079. Memory& operator = (const Memory& rhs)
  2080. {
  2081. if (this != &rhs) {
  2082. detail::Wrapper<cl_type>::operator=(rhs);
  2083. }
  2084. return *this;
  2085. }
  2086. /*! \brief Get information that is common to all memory objects (buffer and
  2087. * image objects)
  2088. *
  2089. * \param name specifies the information to query.
  2090. *
  2091. * \param param is a pointer to memory where the appropriate result being
  2092. * queried is returned. If \a param_value is NULL, it is ignored.
  2093. *
  2094. * \return One of the following values:
  2095. * - CL_SUCCESS if the function is executed successfully.
  2096. * - CL_INVALID_VALUE if \a name is not valid.
  2097. *
  2098. * \note In the case that exceptions are enabled and error value
  2099. * other than CL_SUCCESS is generated, then cl::Error exception is
  2100. * generated.
  2101. */
  2102. template <typename T>
  2103. cl_int getInfo(cl_mem_info name, T* param) const
  2104. {
  2105. return detail::errHandler(
  2106. detail::getInfo(&::clGetMemObjectInfo, object_, name, param),
  2107. __GET_MEM_OBJECT_INFO_ERR);
  2108. }
  2109. /*!
  2110. * \brief Get information that is common to all memory objects (buffer and
  2111. * image objects).
  2112. *
  2113. * \param name specifies the information to query.
  2114. *
  2115. * \param err pointer to memory location where error value will be returned.
  2116. * If not null, the default value, then one of the following values is
  2117. * returned:
  2118. * - CL_SUCCESS if the function is executed successfully
  2119. * - CL_INVALID_VALUE if \a name is not valid.
  2120. *
  2121. * \return the appropriate values for \em name will be returned.
  2122. *
  2123. * \note In the case that exceptions are enabled and error value
  2124. * other than CL_SUCCESS is generated, then cl::Error exception is
  2125. * generated.
  2126. */
  2127. template <cl_int name> typename
  2128. detail::param_traits<detail::cl_mem_info, name>::param_type
  2129. getInfo(cl_int* err = NULL) const
  2130. {
  2131. typename detail::param_traits<
  2132. detail::cl_mem_info, name>::param_type param;
  2133. cl_int result = getInfo(name, &param);
  2134. if (err != NULL) {
  2135. *err = result;
  2136. }
  2137. return param;
  2138. }
  2139. #if defined(CL_VERSION_1_1)
  2140. /*!
  2141. * \brief Register a destructor callback function.
  2142. *
  2143. * \param pfn_event_notify is the event callback function that can be
  2144. * registered by the application. This callback function may be called
  2145. * asynchronously by the OpenCL implementation. It is the application’s
  2146. * responsibility to ensure that the callback function is thread-safe.
  2147. * The parameters to this callback function are:
  2148. *
  2149. * - memobj is the memory object being deleted.
  2150. * - user_data is a pointer to user supplied data.
  2151. *
  2152. * \param user_data will be passed as the user_data argument when pfn_notify
  2153. * is called. user_data can be NULL.
  2154. *
  2155. * \return CL_SUCCESS if successfull otherwise one of the following
  2156. * error values:
  2157. *
  2158. * - CL_INVALID_MEM_OBJECT if memobj is not a valid memory object.
  2159. *
  2160. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources
  2161. * required by the OpenCL implementation on the host.
  2162. *
  2163. * \note In the case that exceptions are enabled and error value
  2164. * other than CL_SUCCESS is generated, then cl::Error exception is
  2165. * generated.
  2166. */
  2167. cl_int setDestructorCallback(
  2168. void (CL_CALLBACK * pfn_notify)(cl_mem, void *),
  2169. void * user_data = NULL)
  2170. {
  2171. return detail::errHandler(
  2172. ::clSetMemObjectDestructorCallback(
  2173. object_,
  2174. pfn_notify,
  2175. user_data),
  2176. __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR);
  2177. }
  2178. #endif
  2179. };
  2180. /*! \class Buffer
  2181. * \brief Memory buffer interface.
  2182. */
  2183. class Buffer : public Memory
  2184. {
  2185. public:
  2186. /*! \brief Create a buffer object.
  2187. *
  2188. * \param context is a valid OpenCL context used to create the buffer object.
  2189. *
  2190. * \param flags is a bit-field that is used to specify allocation and usage
  2191. * information such as the memory arena that should be used to allocate the
  2192. * buffer object and how it will be used.
  2193. *
  2194. * \param size is the size in bytes of the buffer memory object to be
  2195. * allocated.
  2196. *
  2197. * \param host_ptr is a pointer to the buffer data that may already be
  2198. * allocated by the application. The size of the buffer that host_ptr points
  2199. * to must be >= \a size bytes. Passing in a pointer to an already allocated
  2200. * buffer on the host and using it as a buffer object allows applications to
  2201. * share data efficiently with kernels and the host.
  2202. *
  2203. * \param err will return an appropriate error code.
  2204. * If \a err is NULL, no error code is returned.
  2205. *
  2206. * \return A valid non-zero buffer object and \a err is set to
  2207. * CL_SUCCESS if the buffer object is created successfully or a NULL value
  2208. * with one of the following error values returned in \a err:
  2209. * - CL_INVALID_CONTEXT if \a context is not a valid context.
  2210. * - CL_INVALID_VALUE if values specified in \a flags are not valid.
  2211. * - CL_INVALID_BUFFER_SIZE if \a size is 0 or is greater than
  2212. * CL_DEVICE_MAX_MEM_ALLOC_SIZE value.
  2213. * - CL_INVALID_HOST_PTR if host_ptr is NULL and CL_MEM_USE_HOST_PTR or
  2214. * CL_MEM_COPY_HOST_PTR are set in \a flags or if \a host_ptr is not NULL
  2215. * but CL_MEM_COPY_HOST_PTR or CL_MEM_USE_HOST_PTR are not set in
  2216. * \a flags.
  2217. * - CL_MEM_OBJECT_ALLOCATION_FAILURE if there is a failure to allocate
  2218. * memory for buffer object.
  2219. * - CL_INVALID_OPERATION if the buffer object cannot be created for all
  2220. * devices in \a context.
  2221. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources
  2222. * required by the runtime.
  2223. *
  2224. * \note In the case that exceptions are enabled and error value
  2225. * other than CL_SUCCESS is generated, then cl::Error exception is
  2226. * generated.
  2227. */
  2228. Buffer(
  2229. const Context& context,
  2230. cl_mem_flags flags,
  2231. ::size_t size,
  2232. void* host_ptr = NULL,
  2233. cl_int* err = NULL)
  2234. {
  2235. cl_int error;
  2236. object_ = ::clCreateBuffer(context(), flags, size, host_ptr, &error);
  2237. detail::errHandler(error, __CREATE_BUFFER_ERR);
  2238. if (err != NULL) {
  2239. *err = error;
  2240. }
  2241. }
  2242. //! Default constructor; buffer is not valid at this point.
  2243. Buffer() : Memory() { }
  2244. /*!
  2245. * \brief Construct a new buffer from a valid buffer.
  2246. *
  2247. * \param buffer The buffer object used for creation.
  2248. */
  2249. Buffer(const Buffer& buffer) : Memory(buffer) { }
  2250. /*!
  2251. * \brief Assign a buffer to buffer.
  2252. *
  2253. * \param rhs the buffer object on rhs of the assignment.
  2254. */
  2255. Buffer& operator = (const Buffer& rhs)
  2256. {
  2257. if (this != &rhs) {
  2258. Memory::operator=(rhs);
  2259. }
  2260. return *this;
  2261. }
  2262. #if defined(CL_VERSION_1_1)
  2263. /*!
  2264. * \brief Create a new buffer object from current.
  2265. *
  2266. * \param flags is a bit-field that is used to specify allocation
  2267. * and usage information about the buffer memory object being created.
  2268. *
  2269. * \param buffer_create_type describes the type of buffer object to be
  2270. * created.
  2271. *
  2272. * \param buffer_create_info is the buffer descriptor.
  2273. *
  2274. * \param err is A valid non-zero buffer object and \a err is set to
  2275. * CL_SUCCESS if the buffer object is created successfully or a NULL value
  2276. * with one of the following error values returned in \a err:
  2277. * - CL_INVALID_VALUE if values specified in \a flags are not valid.
  2278. * - CL_INVALID_VALUE if value specified in \a buffer_create_type is not valid.
  2279. * - CL_INVALID_VALUE if value(s) specified in \a buffer_create_info
  2280. * (for a given \a buffer_create_type) is not a valid or if
  2281. * \a buffer_create_type is NULL.
  2282. *
  2283. * \return Buffer object, if the creation fails then the object is not valid.
  2284. *
  2285. * \note In the case that exceptions are enabled and error value
  2286. * other than CL_SUCCESS is generated, then cl::Error exception is
  2287. * generated.
  2288. */
  2289. Buffer createSubBuffer(
  2290. cl_mem_flags flags,
  2291. cl_buffer_create_type buffer_create_type,
  2292. const void * buffer_create_info,
  2293. cl_int * err = NULL)
  2294. {
  2295. Buffer result;
  2296. cl_int error;
  2297. result.object_ = ::clCreateSubBuffer(
  2298. object_,
  2299. flags,
  2300. buffer_create_type,
  2301. buffer_create_info,
  2302. &error);
  2303. detail::errHandler(error, __CREATE_SUBBUFFER_ERR);
  2304. if (err != NULL) {
  2305. *err = error;
  2306. }
  2307. }
  2308. #endif
  2309. };
  2310. #if defined (USE_DX_INTEROP)
  2311. class BufferD3D10 : public Buffer
  2312. {
  2313. public:
  2314. typedef CL_API_ENTRY cl_mem (CL_API_CALL *PFN_clCreateFromD3D10BufferKHR)(
  2315. cl_context context, cl_mem_flags flags, ID3D10Buffer* buffer,
  2316. cl_int* errcode_ret);
  2317. BufferD3D10(
  2318. const Context& context,
  2319. cl_mem_flags flags,
  2320. ID3D10Buffer* bufobj,
  2321. cl_int * err = NULL)
  2322. {
  2323. static PFN_clCreateFromD3D10BufferKHR pfn_clCreateFromD3D10BufferKHR = NULL;
  2324. __INIT_CL_EXT_FCN_PTR(clCreateFromD3D10BufferKHR);
  2325. cl_int error;
  2326. object_ = pfn_clCreateFromD3D10BufferKHR(
  2327. context(),
  2328. flags,
  2329. bufobj,
  2330. &error);
  2331. detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
  2332. if (err != NULL) {
  2333. *err = error;
  2334. }
  2335. }
  2336. //! Default constructor; buffer is not valid at this point.
  2337. BufferD3D10() : Buffer() { }
  2338. /*!
  2339. * \brief Construct a new D3D10 buffer from a valid D3D10 buffer.
  2340. *
  2341. * \param buffer The buffer object used for creation.
  2342. */
  2343. BufferD3D10(const BufferD3D10& buffer) : Buffer(buffer) { }
  2344. /*!
  2345. * \brief Assign a D3D10 buffer to D3D10 buffer.
  2346. *
  2347. * \param rhs the D3D10 buffer object on rhs of the assignment.
  2348. */
  2349. BufferD3D10& operator = (const BufferD3D10& rhs)
  2350. {
  2351. if (this != &rhs) {
  2352. Buffer::operator=(rhs);
  2353. }
  2354. return *this;
  2355. }
  2356. };
  2357. #endif
  2358. /*! \class BufferGL
  2359. * \brief Memory buffer interface for GL interop.
  2360. */
  2361. class BufferGL : public Buffer
  2362. {
  2363. public:
  2364. /*! \brief Create a buffer object.
  2365. *
  2366. * \param context is a valid OpenCL context used to create the buffer object.
  2367. *
  2368. * \param flags is a bit-field that is used to specify allocation and usage
  2369. * information such as the memory arena that should be used to allocate the
  2370. * buffer object and how it will be used.
  2371. *
  2372. * \param bufobj is the name fo a GL buffer object.
  2373. *
  2374. * \param err will return an appropriate error code.
  2375. * If \a err is NULL, no error code is returned.
  2376. *
  2377. * \return A valid non-zero buffer object and \a err is set to
  2378. * CL_SUCCESS if the buffer object is created successfully or a NULL value
  2379. * with one of the following error values returned in \a err:
  2380. * - CL_INVALID_CONTEXT if \a context is not a valid context.
  2381. * - CL_INVALID_VALUE if values specified in \a flags are not valid.
  2382. * - CL_INVALID_GL_OBJECT if bufobj is not a GL buffer object or is a GL
  2383. * buffer object but does not have an existing data store.
  2384. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources
  2385. * required by the runtime.
  2386. *
  2387. * \note In the case that exceptions are enabled and error value
  2388. * other than CL_SUCCESS is generated, then cl::Error exception is
  2389. * generated.
  2390. */
  2391. BufferGL(
  2392. const Context& context,
  2393. cl_mem_flags flags,
  2394. GLuint bufobj,
  2395. cl_int * err = NULL)
  2396. {
  2397. cl_int error;
  2398. object_ = ::clCreateFromGLBuffer(
  2399. context(),
  2400. flags,
  2401. bufobj,
  2402. &error);
  2403. detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
  2404. if (err != NULL) {
  2405. *err = error;
  2406. }
  2407. }
  2408. //! Default constructor; buffer is not valid at this point.
  2409. BufferGL() : Buffer() { }
  2410. /*!
  2411. * \brief Construct a new GL buffer from a valid GL buffer.
  2412. *
  2413. * \param buffer The buffer object used for creation.
  2414. */
  2415. BufferGL(const BufferGL& buffer) : Buffer(buffer) { }
  2416. /*!
  2417. * \brief Assign a GL buffer to GL buffer.
  2418. *
  2419. * \param rhs the GL buffer object on rhs of the assignment.
  2420. */
  2421. BufferGL& operator = (const BufferGL& rhs)
  2422. {
  2423. if (this != &rhs) {
  2424. Buffer::operator=(rhs);
  2425. }
  2426. return *this;
  2427. }
  2428. /*!
  2429. * \brief Report the type of GL buffer used to create the object.
  2430. *
  2431. * \param type type of GL buffer.
  2432. * \param gl_object_name
  2433. */
  2434. cl_int getObjectInfo(
  2435. cl_gl_object_type *type,
  2436. GLuint * gl_object_name)
  2437. {
  2438. return detail::errHandler(
  2439. ::clGetGLObjectInfo(object_,type,gl_object_name),
  2440. __GET_GL_OBJECT_INFO_ERR);
  2441. }
  2442. };
  2443. /*! \class BufferRenderGL
  2444. * \brief Memory buffer interface for GL interop with renderbuffer.
  2445. */
  2446. class BufferRenderGL : public Buffer
  2447. {
  2448. public:
  2449. /*! \brief Create a buffer object.
  2450. *
  2451. * \param context is a valid OpenCL context used to create the buffer object.
  2452. *
  2453. * \param flags is a bit-field that is used to specify allocation and usage
  2454. * information such as the memory arena that should be used to allocate the
  2455. * buffer object and how it will be used.
  2456. *
  2457. * \param bufobj is the name for a GL render buffer object.
  2458. *
  2459. * \param err will return an appropriate error code.
  2460. * If \a err is NULL, no error code is returned.
  2461. *
  2462. * \return A valid non-zero buffer object and \a err is set to
  2463. * CL_SUCCESS if the buffer object is created successfully or a NULL value
  2464. * with one of the following error values returned in \a err:
  2465. * - CL_INVALID_CONTEXT if \a context is not a valid context.
  2466. * - CL_INVALID_VALUE if values specified in \a flags are not valid.
  2467. * - CL_INVALID_GL_OBJECT if bufobj is not a GL render buffer object or is a GL
  2468. * render buffer object but does not have an existing data store.
  2469. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources
  2470. * required by the runtime.
  2471. *
  2472. * \note In the case that exceptions are enabled and error value
  2473. * other than CL_SUCCESS is generated, then cl::Error exception is
  2474. * generated.
  2475. */
  2476. BufferRenderGL(
  2477. const Context& context,
  2478. cl_mem_flags flags,
  2479. GLuint bufobj,
  2480. cl_int * err = NULL)
  2481. {
  2482. cl_int error;
  2483. object_ = ::clCreateFromGLRenderbuffer(
  2484. context(),
  2485. flags,
  2486. bufobj,
  2487. &error);
  2488. detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
  2489. if (err != NULL) {
  2490. *err = error;
  2491. }
  2492. }
  2493. //! Default constructor; buffer is not valid at this point.
  2494. BufferRenderGL() : Buffer() { }
  2495. /*!
  2496. * \brief Construct a new GL buffer from a valid GL buffer.
  2497. *
  2498. * \param buffer The buffer object used for creation.
  2499. */
  2500. BufferRenderGL(const BufferGL& buffer) : Buffer(buffer) { }
  2501. /*!
  2502. * \brief Assign a GL buffer to GL buffer.
  2503. *
  2504. * \param rhs the GL buffer object on rhs of the assignment.
  2505. */
  2506. BufferRenderGL& operator = (const BufferRenderGL& rhs)
  2507. {
  2508. if (this != &rhs) {
  2509. Buffer::operator=(rhs);
  2510. }
  2511. return *this;
  2512. }
  2513. /*!
  2514. * \brief Report the type of GL buffer used to create the object.
  2515. *
  2516. * \param type type of GL buffer.
  2517. * \param gl_object_name .
  2518. */
  2519. cl_int getObjectInfo(
  2520. cl_gl_object_type *type,
  2521. GLuint * gl_object_name)
  2522. {
  2523. return detail::errHandler(
  2524. ::clGetGLObjectInfo(object_,type,gl_object_name),
  2525. __GET_GL_OBJECT_INFO_ERR);
  2526. }
  2527. };
  2528. /*! \class Image
  2529. * \brief Base class interface for all images.
  2530. */
  2531. class Image : public Memory
  2532. {
  2533. protected:
  2534. //! Default constructor; image is not valid at this point.
  2535. Image() : Memory() { }
  2536. /*!
  2537. * \brief Construct a new image from a valid image.
  2538. *
  2539. * \param image The image object used for creation.
  2540. */
  2541. Image(const Image& image) : Memory(image) { }
  2542. /*!
  2543. * \brief Assign a image to image.
  2544. *
  2545. * \param rhs the image object on rhs of the assignment.
  2546. */
  2547. Image& operator = (const Image& rhs)
  2548. {
  2549. if (this != &rhs) {
  2550. Memory::operator=(rhs);
  2551. }
  2552. return *this;
  2553. }
  2554. public:
  2555. /*! \brief Get information specific to an image object.
  2556. *
  2557. * \param name specifies the information to query.
  2558. *
  2559. * \param param is a pointer to memory where the appropriate result being
  2560. * queried is returned. If \a param_value is NULL, it is ignored.
  2561. *
  2562. * \return One of the following values:
  2563. * - CL_SUCCESS if the function is executed successfully
  2564. * - CL_INVALID_VALUE if \a param_name is not valid.
  2565. *
  2566. * \note In the case that exceptions are enabled and error value
  2567. * other than CL_SUCCESS is generated, then cl::Error exception is
  2568. * generated.
  2569. */
  2570. template <typename T>
  2571. cl_int getImageInfo(cl_image_info name, T* param) const
  2572. {
  2573. return detail::errHandler(
  2574. detail::getInfo(&::clGetImageInfo, object_, name, param),
  2575. __GET_IMAGE_INFO_ERR);
  2576. }
  2577. /*!
  2578. * \brief Get information specific to an image object.
  2579. *
  2580. * \param name specifies the information to query.
  2581. *
  2582. * \param err pointer to memory location where error value will be returned.
  2583. * If not null, the default value, then one of the following values is
  2584. * returned:
  2585. * - CL_SUCCESS if the function is executed successfully
  2586. * - CL_INVALID_VALUE if \a name is not valid.
  2587. *
  2588. * \return the appropriate values for \em name will be returned.
  2589. *
  2590. * \note In the case that exceptions are enabled and error value
  2591. * other than CL_SUCCESS is generated, then cl::Error exception is
  2592. * generated.
  2593. */
  2594. template <cl_int name> typename
  2595. detail::param_traits<detail::cl_image_info, name>::param_type
  2596. getImageInfo(cl_int* err = NULL) const
  2597. {
  2598. typename detail::param_traits<
  2599. detail::cl_image_info, name>::param_type param;
  2600. cl_int result = getImageInfo(name, &param);
  2601. if (err != NULL) {
  2602. *err = result;
  2603. }
  2604. return param;
  2605. }
  2606. };
  2607. /*! \class Image2D
  2608. * \brief Image interface for 2D images.
  2609. */
  2610. class Image2D : public Image
  2611. {
  2612. public:
  2613. /*! \brief Create a (1D, or 2D) image object.
  2614. *
  2615. * \param context is a valid OpenCL context on which the image object is
  2616. * to be created.
  2617. *
  2618. * \param flags is a bit-field that is used to specify allocation and usage
  2619. * information about the image memory object being created.
  2620. *
  2621. * \param format is a pointer to a structure that describes format
  2622. * properties of the image to be allocated.
  2623. *
  2624. * \param width is the width of the image in pixels. Must be greater
  2625. * than or equal to 1.
  2626. *
  2627. * \param height is the height of the image in pixels. Must be greater
  2628. * than or equal to 1.
  2629. *
  2630. * \param row_pitch is the scan-line pitch in bytes. This must be 0 if
  2631. * \a host_ptr is NULL and can be either 0 or >= \a width * size of
  2632. * element in bytes if \a host_ptr is not NULL. If \a host_ptr is not NULL
  2633. * and \a row_pitch = 0, \a row_pitch is calculated as
  2634. * \a width * size of element in bytes.
  2635. *
  2636. * \param host_ptr is a pointer to the image data that may already be
  2637. * allocated by the application. The size of the buffer that \a host_ptr
  2638. * points to must be >= \a row_pitch * \a height. The size of each element
  2639. * in bytes must be a power of 2. Passing in a pointer to an already
  2640. * allocated buffer on the host and using it as a memory object allows
  2641. * applications to share data efficiently with kernels and the host.
  2642. *
  2643. * \param err will return an appropriate error code. If \a err
  2644. * is NULL, no error code is returned.
  2645. *
  2646. * \return A valid non-zero image object and errcode_ret is set to CL_SUCCESS
  2647. * if the image object is created successfully. It returns a NULL value with
  2648. * one of the following error values returned in \a err:
  2649. * - CL_INVALID_CONTEXT if \a context is not a valid context.
  2650. * - CL_INVALID_VALUE if values specified in \a flags are not valid.
  2651. * - CL_INVALID_IMAGE_FORMAT_DESCRIPTOR if values specified in \a format
  2652. * are not valid or if \a image_format is NULL.
  2653. * - CL_INVALID_IMAGE_SIZE if \a image_width or \a height are 0 or if
  2654. * they exceed values specified in CL_DEVICE_IMAGE2D_MAX_WIDTH or
  2655. * CL_DEVICE_IMAGE2D_MAX_HEIGHT respectively or if values specified by
  2656. * \a image_row_pitch do not follow rules described in the argument
  2657. * description above.
  2658. * - CL_INVALID_HOST_PTR if \a host_ptr is NULL and CL_MEM_USE_HOST_PTR or
  2659. * CL_MEM_COPY_HOST_PTR are set in \a flags or if \a host_ptr is not NULL
  2660. * but CL_MEM_COPY_HOST_PTR or CL_MEM_USE_HOST_PTR are not set in \a flags.
  2661. * - CL_IMAGE_FORMAT_NOT_SUPPORTED if the \a image_format is not supported.
  2662. * - CL_MEM_OBJECT_ALLOCATION_FAILURE if there is a failure to allocate memory
  2663. * for image object.
  2664. * - CL_INVALID_OPERATION if the image object as specified by the
  2665. * \a image_format, \a flags and dimensions cannot be created for all devices
  2666. * in context that support images or if there are no devices in context that
  2667. * support images.
  2668. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required
  2669. * by the runtime.
  2670. *
  2671. * \note In the case that exceptions are enabled and error value
  2672. * other than CL_SUCCESS is generated, then cl::Error exception is
  2673. * generated.
  2674. */
  2675. Image2D(
  2676. const Context& context,
  2677. cl_mem_flags flags,
  2678. ImageFormat format,
  2679. ::size_t width,
  2680. ::size_t height,
  2681. ::size_t row_pitch,
  2682. void* host_ptr = NULL,
  2683. cl_int* err = NULL)
  2684. {
  2685. cl_int error;
  2686. object_ = ::clCreateImage2D(
  2687. context(), flags,&format, width, height, row_pitch, host_ptr, &error);
  2688. detail::errHandler(error, __CREATE_IMAGE2D_ERR);
  2689. if (err != NULL) {
  2690. *err = error;
  2691. }
  2692. }
  2693. //! Default constructor; image is not valid at this point.
  2694. Image2D() { }
  2695. /*!
  2696. * \brief Construct a new image2D from a valid image2D.
  2697. *
  2698. * \param image2D The image2D object used for creation.
  2699. */
  2700. Image2D(const Image2D& image2D) : Image(image2D) { }
  2701. /*!
  2702. * \brief Assign a image2D to image2D.
  2703. *
  2704. * \param rhs the image2D object on rhs of the assignment.
  2705. */
  2706. Image2D& operator = (const Image2D& rhs)
  2707. {
  2708. if (this != &rhs) {
  2709. Image::operator=(rhs);
  2710. }
  2711. return *this;
  2712. }
  2713. };
  2714. /*! \class Image2DGL
  2715. * \brief 2D image interface for GL interop.
  2716. */
  2717. class Image2DGL : public Image2D
  2718. {
  2719. public:
  2720. /*! \brief Create a 2D image object.
  2721. *
  2722. * \param context is a valid OpenCL context used to create the buffer object.
  2723. *
  2724. * \param flags is a bit-field that is used to specify allocation and usage
  2725. * information such as the memory arena that should be used to allocate the
  2726. * buffer object and how it will be used.
  2727. *
  2728. * \param target.
  2729. *
  2730. * \param miplevel is the level for the incomming texture.
  2731. *
  2732. * \param texobj is the name fo a GL buffer object.
  2733. *
  2734. * \param err will return an appropriate error code.
  2735. * If \a err is NULL, no error code is returned.
  2736. *
  2737. * \return A valid non-zero buffer object and \a err is set to
  2738. * CL_SUCCESS if the buffer object is created successfully or a NULL value
  2739. * with one of the following error values returned in \a err:
  2740. * - CL_INVALID_CONTEXT if \a context is not a valid context.
  2741. * - CL_INVALID_VALUE if values specified in \a flags are not valid.
  2742. * - CL_INVALID_GL_OBJECT if bufobj is not a GL buffer object or is a GL
  2743. * buffer object but does not have an existing data store.
  2744. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources
  2745. * required by the runtime.
  2746. *
  2747. * \note In the case that exceptions are enabled and error value
  2748. * other than CL_SUCCESS is generated, then cl::Error exception is
  2749. * generated.
  2750. */
  2751. Image2DGL(
  2752. const Context& context,
  2753. cl_mem_flags flags,
  2754. GLenum target,
  2755. GLint miplevel,
  2756. GLuint texobj,
  2757. cl_int * err = NULL)
  2758. {
  2759. cl_int error;
  2760. object_ = ::clCreateFromGLTexture2D(
  2761. context(),
  2762. flags,
  2763. target,
  2764. miplevel,
  2765. texobj,
  2766. &error);
  2767. detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
  2768. if (err != NULL) {
  2769. *err = error;
  2770. }
  2771. }
  2772. //! Default constructor; image is not valid at this point.
  2773. Image2DGL() : Image2D() { }
  2774. /*!
  2775. * \brief Construct a new CL 2D image from a valid GL 2D texture.
  2776. *
  2777. * \param image The buffer object used for creation.
  2778. */
  2779. Image2DGL(const Image2DGL& image) : Image2D(image) { }
  2780. /*!
  2781. * \brief Assign a GL 2D image to GL 2D image buffer.
  2782. *
  2783. * \param rhs the GL buffer object on rhs of the assignment.
  2784. */
  2785. Image2DGL& operator = (const Image2DGL& rhs)
  2786. {
  2787. if (this != &rhs) {
  2788. Image2D::operator=(rhs);
  2789. }
  2790. return *this;
  2791. }
  2792. };
  2793. /*! \class Image3D
  2794. * \brief Image interface for 3D images.
  2795. */
  2796. class Image3D : public Image
  2797. {
  2798. public:
  2799. /*! \brief Create a 3D image object.
  2800. *
  2801. * \param context is a valid OpenCL context on which the image object is to be
  2802. * created.
  2803. *
  2804. * \param flags is a bit-field that is used to specify allocation and usage
  2805. * information about the image memory object being created.
  2806. *
  2807. * \param format is a pointer to a structure that describes format
  2808. * properties of the image to be allocated.
  2809. *
  2810. * \param width is the width of the image in pixels. Must be greater
  2811. * than or equal to 1.
  2812. *
  2813. * \param height is the height of the image in pixels. Must be greater
  2814. * than or equal to 1.
  2815. *
  2816. * \param depth is the depth of the image in pixels. This must be a
  2817. * value > 1.
  2818. *
  2819. * \param row_pitch is the scan-line pitch in bytes. This must be 0 if
  2820. * \a host_ptr is NULL and can be either 0 or >= \a width * size of
  2821. * element in bytes if \a host_ptr is not NULL. If \a host_ptr is not NULL and
  2822. * \a row_pitch = 0, \a row_pitch is calculated as
  2823. * \a width * size of element in bytes.
  2824. *
  2825. * \param slice_pitch is the size in bytes of each 2D slice in the 3D
  2826. * image. This must be 0 if \a host_ptr is NULL and can be either 0 or >=
  2827. * \a row_pitch * \a height if \a host_ptr is not NULL.
  2828. * If \a host_ptr is not NULL and \a image_slice_pitch = 0,
  2829. * \a slice_pitch is calculated as \a row_pitch * \a height.
  2830. *
  2831. * \param host_ptr is a pointer to the image data that may already be allocated
  2832. * by the application. The size of the buffer that \a host_ptr points to must
  2833. * be >= \a row_pitch * \a height * \a depth. The size of
  2834. * each element in bytes must be a power of 2. Passing in a pointer to an
  2835. * already allocated buffer on the host and using it as a memory object allows
  2836. * applications to share data efficiently with kernels and the host.
  2837. *
  2838. * \param err will return an appropriate error code. If \a err
  2839. * is NULL, no error code is returned.
  2840. *
  2841. * \return valid non-zero image object created and the \a err is set to
  2842. * CL_SUCCESS if the image object is created successfully. It returns a NULL
  2843. * value with one of the following error values returned in \a err:
  2844. * - CL_INVALID_CONTEXT if \a context is not a valid context.
  2845. * - CL_INVALID_VALUE if values specified in \a flags are not valid.
  2846. * - CL_INVALID_IMAGE_FORMAT_DESCRIPTOR if values specified in \a format
  2847. * are not valid or if \a format is NULL.
  2848. * - CL_INVALID_IMAGE_SIZE if \a width, \a height or \a depth
  2849. * are 0 or if they exceed values specified in CL_DEVICE_IMAGE3D_MAX_WIDTH,
  2850. * CL_DEVICE_IMAGE3D_MAX_HEIGHT or CL_DEVICE_IMAGE3D_MAX_DEPTH respectively
  2851. * or if values specified by \a row_pitch and \a slice_pitch do
  2852. * not follow rules described in the argument description above.
  2853. * - CL_INVALID_HOST_PTR if \a host_ptr is NULL and CL_MEM_USE_HOST_PTR or
  2854. * CL_MEM_COPY_HOST_PTR are set in \a flags or if \a host_ptr is not NULL but
  2855. * CL_MEM_COPY_HOST_PTR or CL_MEM_USE_HOST_PTR are not set in \a flags.
  2856. * - CL_IMAGE_FORMAT_NOT_SUPPORTED if the \a format is not supported.
  2857. * - CL_MEM_OBJECT_ALLOCATION_FAILURE if there is a failure to allocate memory
  2858. * for image object.
  2859. * - CL_INVALID_OPERATION if the image object as specified by the
  2860. * \a image_format, \a flags and dimensions cannot be created for all devices
  2861. * in context that support images, or if there are no devices in context that
  2862. * support images.
  2863. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required
  2864. * by the runtime.
  2865. *
  2866. * \note In the case that exceptions are enabled and error value
  2867. * other than CL_SUCCESS is generated, then cl::Error exception is
  2868. * generated.
  2869. */
  2870. Image3D(
  2871. const Context& context,
  2872. cl_mem_flags flags,
  2873. ImageFormat format,
  2874. ::size_t width,
  2875. ::size_t height,
  2876. ::size_t depth,
  2877. ::size_t row_pitch,
  2878. ::size_t slice_pitch,
  2879. void* host_ptr = NULL,
  2880. cl_int* err = NULL)
  2881. {
  2882. cl_int error;
  2883. object_ = ::clCreateImage3D(
  2884. context(), flags, &format, width, height, depth, row_pitch,
  2885. slice_pitch, host_ptr, &error);
  2886. detail::errHandler(error, __CREATE_IMAGE3D_ERR);
  2887. if (err != NULL) {
  2888. *err = error;
  2889. }
  2890. }
  2891. //! Default constructor; image is not valid at this point.
  2892. Image3D() { }
  2893. /*!
  2894. * \brief Construct a new image3D from a valid image3D.
  2895. *
  2896. * \param image3D The image3D object used for creation.
  2897. */
  2898. Image3D(const Image3D& image3D) : Image(image3D) { }
  2899. /*!
  2900. * \brief Assign a image3D to image3D.
  2901. *
  2902. * \param rhs the image3D object on rhs of the assignment.
  2903. */
  2904. Image3D& operator = (const Image3D& rhs)
  2905. {
  2906. if (this != &rhs) {
  2907. Image::operator=(rhs);
  2908. }
  2909. return *this;
  2910. }
  2911. };
  2912. /*! \class Image2DGL
  2913. * \brief 2D image interface for GL interop.
  2914. */
  2915. class Image3DGL : public Image3D
  2916. {
  2917. public:
  2918. /*! \brief Create a 3D image object.
  2919. *
  2920. * \param context is a valid OpenCL context used to create the buffer object.
  2921. *
  2922. * \param flags is a bit-field that is used to specify allocation and usage
  2923. * information such as the memory arena that should be used to allocate the
  2924. * buffer object and how it will be used.
  2925. *
  2926. * \param target.
  2927. *
  2928. * \param miplevel is the level for the incomming texture.
  2929. *
  2930. * \param texobj is the name fo a GL buffer object.
  2931. *
  2932. * \param err will return an appropriate error code.
  2933. * If \a err is NULL, no error code is returned.
  2934. *
  2935. * \return A valid non-zero buffer object and \a err is set to
  2936. * CL_SUCCESS if the buffer object is created successfully or a NULL value
  2937. * with one of the following error values returned in \a err:
  2938. * - CL_INVALID_CONTEXT if \a context is not a valid context.
  2939. * - CL_INVALID_VALUE if values specified in \a flags are not valid.
  2940. * - CL_INVALID_GL_OBJECT if bufobj is not a GL buffer object or is a GL
  2941. * buffer object but does not have an existing data store.
  2942. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources
  2943. * required by the runtime.
  2944. *
  2945. * \note In the case that exceptions are enabled and error value
  2946. * other than CL_SUCCESS is generated, then cl::Error exception is
  2947. * generated.
  2948. */
  2949. Image3DGL(
  2950. const Context& context,
  2951. cl_mem_flags flags,
  2952. GLenum target,
  2953. GLint miplevel,
  2954. GLuint texobj,
  2955. cl_int * err = NULL)
  2956. {
  2957. cl_int error;
  2958. object_ = ::clCreateFromGLTexture3D(
  2959. context(),
  2960. flags,
  2961. target,
  2962. miplevel,
  2963. texobj,
  2964. &error);
  2965. detail::errHandler(error, __CREATE_GL_BUFFER_ERR);
  2966. if (err != NULL) {
  2967. *err = error;
  2968. }
  2969. }
  2970. //! Default constructor; image is not valid at this point.
  2971. Image3DGL() : Image3D() { }
  2972. /*!
  2973. * \brief Construct a new CL 2D image from a valid GL 2D texture.
  2974. *
  2975. * \param image The buffer object used for creation.
  2976. */
  2977. Image3DGL(const Image3DGL& image) : Image3D(image) { }
  2978. /*!
  2979. * \brief Assign a GL 2D image to GL 2D image buffer.
  2980. *
  2981. * \param rhs the GL buffer object on rhs of the assignment.
  2982. */
  2983. Image3DGL& operator = (const Image3DGL& rhs)
  2984. {
  2985. if (this != &rhs) {
  2986. Image3D::operator=(rhs);
  2987. }
  2988. return *this;
  2989. }
  2990. };
  2991. /*! \class Sampler
  2992. * \brief Sampler interface for cl_sampler.
  2993. */
  2994. class Sampler : public detail::Wrapper<cl_sampler>
  2995. {
  2996. public:
  2997. //! Default constructor.
  2998. Sampler() { }
  2999. /*! \brief Create a sampler object.
  3000. *
  3001. */
  3002. Sampler(
  3003. const Context& context,
  3004. cl_bool normalized_coords,
  3005. cl_addressing_mode addressing_mode,
  3006. cl_filter_mode filter_mode,
  3007. cl_int* err = NULL)
  3008. {
  3009. cl_int error;
  3010. object_ = ::clCreateSampler(
  3011. context(),
  3012. normalized_coords,
  3013. addressing_mode,
  3014. filter_mode,
  3015. &error);
  3016. detail::errHandler(error, __CREATE_SAMPLER_ERR);
  3017. if (err != NULL) {
  3018. *err = error;
  3019. }
  3020. }
  3021. /*!
  3022. * \brief Construct a new sampler from a valid sampler.
  3023. *
  3024. * \param sampler The sampler object used for creation.
  3025. */
  3026. Sampler(const Sampler& sampler) : detail::Wrapper<cl_type>(sampler) { }
  3027. /*!
  3028. * \brief Assign a sampler to sampler.
  3029. *
  3030. * \param rhs the sampler object on rhs of the assignment.
  3031. */
  3032. Sampler& operator = (const Sampler& rhs)
  3033. {
  3034. if (this != &rhs) {
  3035. detail::Wrapper<cl_type>::operator=(rhs);
  3036. }
  3037. return *this;
  3038. }
  3039. /*! \brief Return information about the sampler object.
  3040. *
  3041. * \param name specifies the information to query.
  3042. *
  3043. * \param param is a pointer to memory where the appropriate result
  3044. * being queried is returned. If \a param_value is NULL, it is ignored.
  3045. *
  3046. * \return One of the following values:
  3047. * - CL_SUCCESS if the function is executed successfully.
  3048. * - CL_INVALID_VALUE if \a name is not valid.
  3049. *
  3050. * \note In the case that exceptions are enabled and error value
  3051. * other than CL_SUCCESS is generated, then cl::Error exception is
  3052. * generated.
  3053. */
  3054. template <typename T>
  3055. cl_int getInfo(cl_sampler_info name, T* param) const
  3056. {
  3057. return detail::errHandler(
  3058. detail::getInfo(&::clGetSamplerInfo, object_, name, param),
  3059. __GET_SAMPLER_INFO_ERR);
  3060. }
  3061. /*!
  3062. * \brief Return information about the sampler object.
  3063. *
  3064. * \param name specifies the information to query.
  3065. *
  3066. * \param err pointer to memory location where error value will be returned.
  3067. * If not null, the default value, then one of the following values is
  3068. * returned:
  3069. * - CL_SUCCESS if the function is executed successfully
  3070. * - CL_INVALID_VALUE if \a name is not valid.
  3071. *
  3072. * \return the appropriate values for \em name will be returned.
  3073. *
  3074. * \note In the case that exceptions are enabled and error value
  3075. * other than CL_SUCCESS is generated, then cl::Error exception is
  3076. * generated.
  3077. */
  3078. template <cl_int name> typename
  3079. detail::param_traits<detail::cl_sampler_info, name>::param_type
  3080. getInfo(cl_int* err = NULL) const
  3081. {
  3082. typename detail::param_traits<
  3083. detail::cl_sampler_info, name>::param_type param;
  3084. cl_int result = getInfo(name, &param);
  3085. if (err != NULL) {
  3086. *err = result;
  3087. }
  3088. return param;
  3089. }
  3090. };
  3091. class Program;
  3092. class CommandQueue;
  3093. class Kernel;
  3094. /*! \class NDRange
  3095. * \brief NDRange interface
  3096. */
  3097. class NDRange
  3098. {
  3099. private:
  3100. size_t<3> sizes_;
  3101. cl_uint dimensions_;
  3102. public:
  3103. NDRange()
  3104. : dimensions_(0)
  3105. { }
  3106. //! Create a 1D range
  3107. NDRange(::size_t size0)
  3108. : dimensions_(1)
  3109. {
  3110. sizes_.push_back(size0);
  3111. }
  3112. //! Create a 2D range
  3113. NDRange(::size_t size0, ::size_t size1)
  3114. : dimensions_(2)
  3115. {
  3116. sizes_.push_back(size0);
  3117. sizes_.push_back(size1);
  3118. }
  3119. //! Create a 3D range
  3120. NDRange(::size_t size0, ::size_t size1, ::size_t size2)
  3121. : dimensions_(3)
  3122. {
  3123. sizes_.push_back(size0);
  3124. sizes_.push_back(size1);
  3125. sizes_.push_back(size2);
  3126. }
  3127. operator const ::size_t*() const { return (const ::size_t*) sizes_; }
  3128. ::size_t dimensions() const { return dimensions_; }
  3129. };
  3130. //! Null range object
  3131. static const NDRange NullRange;
  3132. /*!
  3133. * \struct LocalSpaceArg
  3134. * \brief Local address raper for use with Kernel::setArg
  3135. */
  3136. struct LocalSpaceArg
  3137. {
  3138. ::size_t size_;
  3139. };
  3140. //! \cond DOXYGEN_DETAIL
  3141. namespace detail {
  3142. template <typename T>
  3143. struct KernelArgumentHandler
  3144. {
  3145. static ::size_t size(const T&) { return sizeof(T); }
  3146. static T* ptr(T& value) { return &value; }
  3147. };
  3148. template <>
  3149. struct KernelArgumentHandler<LocalSpaceArg>
  3150. {
  3151. static ::size_t size(const LocalSpaceArg& value) { return value.size_; }
  3152. static void* ptr(LocalSpaceArg&) { return NULL; }
  3153. };
  3154. } // namespace detail
  3155. //! \endcond
  3156. /*! \brief Create a local address space argument
  3157. *
  3158. * \param size is the size in bytes of the memory to be allocated in the
  3159. * __local memory space.
  3160. *
  3161. * \return A local address space argument, of \a size bytes, that can
  3162. * be used as an argument to Kernel::setArgs or to a KernelFunctor(...) call.
  3163. */
  3164. inline LocalSpaceArg
  3165. __local(::size_t size)
  3166. {
  3167. LocalSpaceArg ret = { size };
  3168. return ret;
  3169. }
  3170. class KernelFunctor;
  3171. /*! \class Kernel
  3172. * \brief Kernel interface that implements cl_kernel
  3173. */
  3174. class Kernel : public detail::Wrapper<cl_kernel>
  3175. {
  3176. public:
  3177. /*! \brief Create a kernel object.
  3178. *
  3179. * \param program is a program object with a successfully built executable.
  3180. *
  3181. * \param name is a function name in the program declared with the
  3182. * __kernel qualifer.
  3183. *
  3184. * \param err will return an appropriate error code. If \a err
  3185. * is NULL, no error code is returned.
  3186. *
  3187. * \return A valid non-zero kernel object and \a err is set to
  3188. * CL_SUCCESS if the kernel object is created successfully. It returns a
  3189. * NULL value with one of the following error values returned in \a err:
  3190. * - CL_INVALID_PROGRAM if \a program is not a valid program object
  3191. * - CL_INVALID_PROGRAM_EXECUTABLE if there is no successfully built
  3192. * executable for \a program.
  3193. * - CL_INVALID_KERNEL_NAME if \a name is not found in \a program.
  3194. * - CL_INVALID_KERNEL_DEFINITION if the function definition for __kernel
  3195. * function given by \a name such as the number of arguments, the
  3196. * argument types are not the same for all devices for which the program
  3197. * executable has been built.
  3198. * - CL_INVALID_VALUE if \a name is NULL.
  3199. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources
  3200. * required by the runtime.
  3201. *
  3202. * \note In the case that exceptions are enabled and error value
  3203. * other than CL_SUCCESS is generated, then cl::Error exception is
  3204. * generated.
  3205. */
  3206. inline Kernel(const Program& program, const char* name, cl_int* err = NULL);
  3207. //! Default constructor; kernel is not valid at this point.
  3208. Kernel() { }
  3209. /*!
  3210. * \brief Construct a new kernel from a valid kernel.
  3211. *
  3212. * \param kernel The kernel object used for creation.
  3213. */
  3214. Kernel(const Kernel& kernel) : detail::Wrapper<cl_type>(kernel) { }
  3215. /*!
  3216. * \brief Assign a kernel to kernel.
  3217. *
  3218. * \param rhs the kernel object on rhs of the assignment.
  3219. */
  3220. Kernel& operator = (const Kernel& rhs)
  3221. {
  3222. if (this != &rhs) {
  3223. detail::Wrapper<cl_type>::operator=(rhs);
  3224. }
  3225. return *this;
  3226. }
  3227. /*! \brief Return information about the kernel object.
  3228. *
  3229. * \param name specifies the information to query.
  3230. *
  3231. * \param param is a pointer to memory where the appropriate result
  3232. * being queried is returned. If \a param is NULL, it is ignored.
  3233. *
  3234. * \return One of the following values:
  3235. * - CL_SUCCESS if the function is executed successfully
  3236. * - CL_INVALID_VALUE if \a param is not valid.
  3237. * - CL_INVALID_KERNEL if \a kernel is a not a valid kernel object.
  3238. *
  3239. * \note In the case that exceptions are enabled and error value
  3240. * other than CL_SUCCESS is generated, then cl::Error exception is
  3241. * generated.
  3242. */
  3243. template <typename T>
  3244. cl_int getInfo(cl_kernel_info name, T* param) const
  3245. {
  3246. return detail::errHandler(
  3247. detail::getInfo(&::clGetKernelInfo, object_, name, param),
  3248. __GET_KERNEL_INFO_ERR);
  3249. }
  3250. /*!
  3251. * \brief Return information about the kernel object.
  3252. *
  3253. * \param name specifies the information to query.
  3254. *
  3255. * \param err pointer to memory location where error value will be returned.
  3256. * If not null, the default value, then one of the following values is
  3257. * returned:
  3258. * - CL_SUCCESS if the function is executed successfully
  3259. * - CL_INVALID_VALUE if \a name is not valid.
  3260. *
  3261. * \return the appropriate values for \em name will be returned.
  3262. *
  3263. * \note In the case that exceptions are enabled and error value
  3264. * other than CL_SUCCESS is generated, then cl::Error exception is
  3265. * generated.
  3266. */
  3267. template <cl_int name> typename
  3268. detail::param_traits<detail::cl_kernel_info, name>::param_type
  3269. getInfo(cl_int* err = NULL) const
  3270. {
  3271. typename detail::param_traits<
  3272. detail::cl_kernel_info, name>::param_type param;
  3273. cl_int result = getInfo(name, &param);
  3274. if (err != NULL) {
  3275. *err = result;
  3276. }
  3277. return param;
  3278. }
  3279. /*! \brief Return information about the kernel object that may be specific
  3280. * to a device.
  3281. *
  3282. * \param device identifies a specific device in the list of devices
  3283. * associated with \a kernel. The list of devices is the list of devices
  3284. * in the OpenCL context that is associated with \a kernel.
  3285. *
  3286. * \param name specifies the information to query
  3287. *
  3288. * \param param is a pointer to memory where the appropriate result being
  3289. * queried is returned. If \a param is NULL, it is ignored.
  3290. *
  3291. * \return One of the following values:
  3292. * - CL_SUCCESS if the function is executed successfully,
  3293. * - CL_INVALID_DEVICE if \a device is not in the list of devices
  3294. * associated with \a kernel.
  3295. * - CL_INVALID_VALUE if \a name is not valid.
  3296. * - CL_INVALID_KERNEL if \a kernel is a not a valid kernel object.
  3297. *
  3298. * \note In the case that exceptions are enabled and error value
  3299. * other than CL_SUCCESS is generated, then cl::Error exception is
  3300. * generated.
  3301. */
  3302. template <typename T>
  3303. cl_int getWorkGroupInfo(
  3304. const Device& device, cl_kernel_work_group_info name, T* param) const
  3305. {
  3306. return detail::errHandler(
  3307. detail::getInfo(
  3308. &::clGetKernelWorkGroupInfo, object_, device(), name, param),
  3309. __GET_KERNEL_WORK_GROUP_INFO_ERR);
  3310. }
  3311. /*!
  3312. * \brief Return information about the kernel object that may be specific
  3313. * to a device.
  3314. *
  3315. * \param name specifies the information to query.
  3316. *
  3317. * \param err pointer to memory location where error value will be returned.
  3318. * If not null, the default value, then one of the following values is
  3319. * returned:
  3320. * - CL_SUCCESS if the function is executed successfully
  3321. * - CL_INVALID_VALUE if \a name is not valid.
  3322. *
  3323. * \return the appropriate values for \em name will be returned.
  3324. *
  3325. * \note In the case that exceptions are enabled and error value
  3326. * other than CL_SUCCESS is generated, then cl::Error exception is
  3327. * generated.
  3328. */
  3329. template <cl_int name> typename
  3330. detail::param_traits<detail::cl_kernel_work_group_info, name>::param_type
  3331. getWorkGroupInfo(const Device& device, cl_int* err = NULL) const
  3332. {
  3333. typename detail::param_traits<
  3334. detail::cl_kernel_work_group_info, name>::param_type param;
  3335. cl_int result = getWorkGroupInfo(device, name, &param);
  3336. if (err != NULL) {
  3337. *err = result;
  3338. }
  3339. return param;
  3340. }
  3341. /*! \brief Set the argument value for a specific argument of a kernel.
  3342. *
  3343. * \param index is the argument index. Arguments to the kernel are referred
  3344. * by indices that go from 0 for the leftmost argument to n - 1,
  3345. * where n is the total number of arguments declared by a kernel.
  3346. *
  3347. * \param value is the data to be used as the argument
  3348. * value for argument specified by \a index. If the argument is
  3349. * a memory object (buffer or image), the \a value entry will be a pointer
  3350. * to the appropriate buffer or image object. The memory object must be
  3351. * created with the context associated with the kernel object. If the
  3352. * argument is declared with the __local qualifier, the \a value must
  3353. * be a of type detail::LocalSpaceArg (use __local helper function to build
  3354. * a value of this type). The memory object specified
  3355. * as argument value must be a buffer object if the argument is declared
  3356. * to be a pointer of a built-in or user defined type with the __global
  3357. * or __constant qualifier. If the argument is declared with the
  3358. * __constant qualifier, the size in bytes of the memory object cannot
  3359. * exceed CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE and the number of arguments
  3360. * declared with the __constant qualifier cannot exceed
  3361. * CL_DEVICE_MAX_CONSTANT_ARGS. The memory object specified as argument
  3362. * value must be a 2D image object if the argument is declared to be of
  3363. * type image2d_t. The memory object specified as argument value must be a
  3364. * 3D image object if argument is declared to be of type image3d_t. If the
  3365. * argument is of type sampler_t, the value entry
  3366. * must be a pointer to the sampler object.
  3367. *
  3368. * \return One of the following values:
  3369. * - CL_SUCCESS if the function was executed successfully
  3370. * - CL_INVALID_ARG_INDEX if \a arg_index is not a valid argument index.
  3371. * - CL_INVALID_ARG_VALUE if \a value specified is of type
  3372. * detail::LocalSpaceArg for an argument that is not declared with the
  3373. * __local qualifier or vice-versa.
  3374. * - CL_INVALID_MEM_OBJECT for an argument declared to be a memory object
  3375. * but the specified \a arg_value is not a valid memory object.
  3376. * - CL_INVALID_SAMPLER for an argument declared to be of type sampler_t but
  3377. * the specified \a arg_value is not a valid sampler object.
  3378. * - CL_INVALID_ARG_SIZE if \a argument size does not match the size of
  3379. * the data type for an argument that is not a memory object or if the
  3380. * argument is a memory object and \a arg_size != sizeof(cl_mem) or if
  3381. * the argument is a sampler and argument size != sizeof(cl_sampler).
  3382. *
  3383. * \note In the case that exceptions are enabled and error value
  3384. * other than CL_SUCCESS is generated, then cl::Error exception is
  3385. * generated.
  3386. */
  3387. template <typename T>
  3388. cl_int setArg(cl_uint index, T value)
  3389. {
  3390. return detail::errHandler(
  3391. ::clSetKernelArg(
  3392. object_,
  3393. index,
  3394. detail::KernelArgumentHandler<T>::size(value),
  3395. detail::KernelArgumentHandler<T>::ptr(value)),
  3396. __SET_KERNEL_ARGS_ERR);
  3397. }
  3398. /*! \brief Set the argument value for a specific argument of a kernel.
  3399. *
  3400. * \param index is the argument index. Arguments to the kernel are referred
  3401. * by indices that go from 0 for the leftmost argument to n - 1, where n is
  3402. * the total number of arguments declared by a kernel.
  3403. *
  3404. * \param value is a pointer to data that should be used as the argument
  3405. * value for argument specified by \a index. The argument data pointed to
  3406. * by \a value is copied and the \a value pointer can therefore be
  3407. * reused by the application after setArg returns. If the argument is
  3408. * a memory object (buffer or image), the \a value entry will be a pointer
  3409. * to the appropriate buffer or image object. The memory object must be
  3410. * created with the context associated with the kernel object. If the
  3411. * argument is declared with the __local qualifier, the \a value entry must
  3412. * be NULL. For all other kernel arguments, the \a value entry must be a
  3413. * pointer to the actual data to be used as argument value. The memory
  3414. * object specified as argument value must be a buffer object if the
  3415. * argument is declared to be a pointer of a built-in or user defined type
  3416. * with the __global or __constant qualifier. If the argument is declared
  3417. * with the __constant qualifier, the size in bytes of the memory object
  3418. * cannot exceed CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE and the number of
  3419. * arguments declared with the __constant qualifier cannot exceed
  3420. * CL_DEVICE_MAX_CONSTANT_ARGS. The memory object specified as argument
  3421. * value must be a 2D image object if the argument is declared to be of
  3422. * type image2d_t. The memory object specified as argument value must be a
  3423. * 3D image object if argument is declared to be of type image3d_t. If the
  3424. * argument is of type sampler_t, the value entry must be a pointer to the
  3425. * sampler object.
  3426. *
  3427. * \param size specifies the size of the argument value. If the argument is
  3428. * a memory object, the size is the size of the buffer or image object type.
  3429. * For arguments declared with the __local qualifier, the size specified
  3430. * will be the size in bytes of the buffer that must be allocated for the
  3431. * __local argument. If the argument is of type sampler_t, the \a size
  3432. * value must be equal to sizeof(cl_sampler). For all other arguments, the
  3433. * size will be the size of argument type.
  3434. *
  3435. * \return One of the following values:
  3436. * - CL_SUCCESS if the function was executed successfully
  3437. * - CL_INVALID_ARG_INDEX if \a index is not a valid argument index.
  3438. * - CL_INVALID_ARG_VALUE if \a value specified is NULL for an argument
  3439. * that is not declared with the __local qualifier or vice-versa.
  3440. * - CL_INVALID_MEM_OBJECT for an argument declared to be a memory object
  3441. * but the specified \a value is not a valid memory object.
  3442. * - CL_INVALID_SAMPLER for an argument declared to be of type sampler_t
  3443. * but the specified \a value is not a valid sampler object.
  3444. * - CL_INVALID_ARG_SIZE if \a size does not match the size of the data
  3445. * type for an argument that is not a memory object or if the argument is
  3446. * a memory object and \a size != sizeof(cl_mem) or if \a size is zero
  3447. * and the argument is declared with the __local qualifier or if the
  3448. * argument is a sampler and arg_size != sizeof(cl_sampler).
  3449. *
  3450. * \note In the case that exceptions are enabled and error value
  3451. * other than CL_SUCCESS is generated, then cl::Error exception is
  3452. * generated.
  3453. */
  3454. cl_int setArg(cl_uint index, ::size_t size, void* argPtr)
  3455. {
  3456. return detail::errHandler(
  3457. ::clSetKernelArg(object_, index, size, argPtr),
  3458. __SET_KERNEL_ARGS_ERR);
  3459. }
  3460. /*! \brief Bind a kernel to a command-queue and launch dimensions.
  3461. *
  3462. * \param queue is the command-queue to bind with.
  3463. *
  3464. * \param offset must currently be a NullRange value. In a future
  3465. * revision of OpenCL, \a global_work_offset can be used to specify an
  3466. * array of \a work_dim unsigned values that describe the offset used to
  3467. * calculate the global ID of a work-item instead of having the global IDs
  3468. * always start at offset (0, 0, 0).
  3469. *
  3470. * \param global describes the number of global work-items in will execute
  3471. * the kernel function. The total number of global
  3472. * work-items is computed as global_work_size[0] * ...
  3473. * * global_work_size[work_dim - 1].
  3474. *
  3475. * \param local describes the number of work-items that make up a
  3476. * work-group (also referred to as the size of the work-group) that
  3477. * will execute the kernel specified by kernel.
  3478. *
  3479. * \return A KernelFunctor object that when called with the appropriate
  3480. * number of arguments, as defined by kernel itself, will be launched
  3481. * with the corresponding queue, offset, global, and local values.
  3482. */
  3483. KernelFunctor bind(
  3484. const CommandQueue& queue,
  3485. const NDRange& offset,
  3486. const NDRange& global,
  3487. const NDRange& local);
  3488. /*! \brief Bind a kernel to a command-queue and launch dimensions.
  3489. *
  3490. * \param queue is the command-queue to bind with.
  3491. *
  3492. * \param global describes the number of global work-items in will execute
  3493. * the kernel function. The total number of global
  3494. * work-items is computed as global_work_size[0] * ...
  3495. * * global_work_size[work_dim - 1].
  3496. *
  3497. * \param local describes the number of work-items that make up a
  3498. * work-group (also referred to as the size of the work-group) that
  3499. * will execute the kernel specified by kernel.
  3500. *
  3501. * /return A KernelFunctor object that when called with the appropriate
  3502. * number of arguments, as defined by kernel itself, will be launched
  3503. * with the corresponding queue, offset=NullRange, global, and local values.
  3504. */
  3505. KernelFunctor bind(
  3506. const CommandQueue& queue,
  3507. const NDRange& global,
  3508. const NDRange& local);
  3509. };
  3510. /*! \class Program
  3511. * \brief Program interface that implements cl_program.
  3512. */
  3513. class Program : public detail::Wrapper<cl_program>
  3514. {
  3515. public:
  3516. typedef VECTOR_CLASS<std::pair<const void*, ::size_t> > Binaries;
  3517. typedef VECTOR_CLASS<std::pair<const char*, ::size_t> > Sources;
  3518. /*! \brief Create a program object for a context, and loads the source code
  3519. * specified by the text strings in the strings array into the program
  3520. * object.
  3521. *
  3522. * \param context must be a valid OpenCL context.
  3523. *
  3524. * \param sources is the source code.
  3525. *
  3526. * \param err will return an appropriate error code. If \a err
  3527. * is NULL, no error code is returned. The error code returned will be
  3528. * one of:
  3529. * - CL_SUCCESS if the program object is created successfully.
  3530. * - CL_INVALID_CONTEXT if \a context is not a valid context.
  3531. * - CL_COMPILER_NOT_AVAILABLE if a compiler is not available.
  3532. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources
  3533. * required by the runtime.
  3534. *
  3535. * \note In the case that exceptions are enabled and error value
  3536. * other than CL_SUCCESS is generated, then cl::Error exception is
  3537. * generated.
  3538. */
  3539. Program(
  3540. const Context& context,
  3541. const Sources& sources,
  3542. cl_int* err = NULL)
  3543. {
  3544. cl_int error;
  3545. const ::size_t n = (::size_t)sources.size();
  3546. ::size_t* lengths = (::size_t*) alloca(n * sizeof(::size_t));
  3547. const char** strings = (const char**) alloca(n * sizeof(const char*));
  3548. for (::size_t i = 0; i < n; ++i) {
  3549. strings[i] = sources[(int)i].first;
  3550. lengths[i] = sources[(int)i].second;
  3551. }
  3552. object_ = ::clCreateProgramWithSource(
  3553. context(), (cl_uint)n, strings, lengths, &error);
  3554. detail::errHandler(error, __CREATE_PROGRAM_WITH_SOURCE_ERR);
  3555. if (err != NULL) {
  3556. *err = error;
  3557. }
  3558. }
  3559. /*! \brief Create a program object for a context, and loads the binary
  3560. * images into the program object.
  3561. *
  3562. * \param context must be a valid OpenCL context.
  3563. *
  3564. * \param devices is a list of devices that are in context.
  3565. * The binaries are loaded for devices specified in this list.
  3566. *
  3567. * \param num_devices is the number of devices listed in \a device_list.
  3568. *
  3569. * \param device_list The devices associated with the program object. The
  3570. * list of devices specified by \a device_list must be devices associated
  3571. * with \a context.
  3572. *
  3573. * \param lengths is an array of the size in bytes of the program binaries
  3574. * to be loaded for devices specified by \a device_list.
  3575. *
  3576. * \param binaries is a program binarie to be loaded
  3577. * for devices specified by \a device_list. For each device given by
  3578. * \a device_list[i], the program binary for that device is
  3579. * given by \a binaries[i]. The program binaries specified by binaries
  3580. * contain the bits that describe the program executable that will be run
  3581. * on the device(s) associated with context. The program binary can consist
  3582. * of either or both:
  3583. * - Device-specific executable(s)
  3584. * - Implementation specific intermediate representation (IR) which will
  3585. * beconverted to the device-specific executable.
  3586. *
  3587. * \param binaryStatus returns whether the program binary for each device
  3588. * specified in \a device_list was loaded successfully or not. It is an
  3589. * array of \a num_devices entries and returns CL_SUCCESS in \a
  3590. * binaryStatus[i] if binary was successfully loaded for device specified
  3591. * by \a devices[i]; otherwise returns CL_INVALID_VALUE if \a lengths[i] is
  3592. * zero or if \a binaries[i] is a NULL value or CL_INVALID_BINARY in
  3593. * \a binaryStatus[i] if program binary is not a valid binary for the
  3594. * specified device. If \a binary_status is NULL, it is ignored.
  3595. *
  3596. * \param err will return an appropriate error code. If \a err
  3597. * is NULL, no error code is returned. The error code returned will be
  3598. * one of:
  3599. * - CL_SUCCESS if the program object is created successfully.
  3600. * - CL_INVALID_CONTEXT if \a context is not a valid context.
  3601. * - CL_INVALID_VALUE if \a devices has a size of zero.
  3602. * - CL_INVALID_DEVICE if OpenCL devices listed in \a devices are not in
  3603. * the list of devices associated with \a context,
  3604. * - CL_INVALID_BINARY if an invalid program binary was encountered for any
  3605. * device. \a binaryStatus will return specific status for each device.
  3606. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources
  3607. * required by the runtime.
  3608. *
  3609. * \note In the case that exceptions are enabled and error value
  3610. * other than CL_SUCCESS is generated, then cl::Error exception is
  3611. * generated.
  3612. */
  3613. Program(
  3614. const Context& context,
  3615. const VECTOR_CLASS<Device>& devices,
  3616. const Binaries& binaries,
  3617. VECTOR_CLASS<cl_int>* binaryStatus = NULL,
  3618. cl_int* err = NULL)
  3619. {
  3620. cl_int error;
  3621. const ::size_t n = binaries.size();
  3622. ::size_t* lengths = (::size_t*) alloca(n * sizeof(::size_t));
  3623. const unsigned char** images = (const unsigned char**) alloca(n * sizeof(const void*));
  3624. for (::size_t i = 0; i < n; ++i) {
  3625. images[i] = (const unsigned char*)binaries[(int)i].first;
  3626. lengths[i] = binaries[(int)i].second;
  3627. }
  3628. object_ = ::clCreateProgramWithBinary(
  3629. context(), (cl_uint) devices.size(),
  3630. (cl_device_id*)&devices.front(),
  3631. lengths, images, binaryStatus != NULL
  3632. ? (cl_int*) &binaryStatus->front()
  3633. : NULL, &error);
  3634. detail::errHandler(error, __CREATE_PROGRAM_WITH_BINARY_ERR);
  3635. if (err != NULL) {
  3636. *err = error;
  3637. }
  3638. }
  3639. //! Default constructor; program is not valid at this point.
  3640. Program() { }
  3641. /*!
  3642. * \brief Construct a new program from a valid program.
  3643. *
  3644. * \param program The program object used for creation.
  3645. */
  3646. Program(const Program& program) : detail::Wrapper<cl_type>(program) { }
  3647. /*!
  3648. * \brief Assign a program to program.
  3649. *
  3650. * \param rhs the program object on rhs of the assignment.
  3651. */
  3652. Program& operator = (const Program& rhs)
  3653. {
  3654. if (this != &rhs) {
  3655. detail::Wrapper<cl_type>::operator=(rhs);
  3656. }
  3657. return *this;
  3658. }
  3659. /*! \brief Build (compile & link) a program executable from the program
  3660. * source or binary for all the devices or a specific device(s) in the
  3661. * OpenCL context associated with program.
  3662. *
  3663. * OpenCL allows program executables to be built using the sources or
  3664. * binaries.
  3665. *
  3666. * \param program is the program object.
  3667. *
  3668. * \param devices is a list of devices associated with
  3669. * \a program. The program executable is built for devices specified in
  3670. * this list for which a source or binary has been loaded.
  3671. *
  3672. * \param options is a pointer to a string that describes the build options
  3673. * to be used for building the program executable. \options can be NULL and
  3674. * defaults to this value if not given.
  3675. *
  3676. * \param notifyFptr is a function pointer to a notification routine. The
  3677. * notification routine allows an application to register a callback
  3678. * function which will be called when the program executable has been built
  3679. * (successfully or unsuccessfully). If \a notifyFptr is not NULL,
  3680. * clBuildProgram does not need to wait for the build to complete and can
  3681. * return immediately. If \a notifyFptr is NULL, its default value,
  3682. * build does not return until the build has completed. This callback
  3683. * function may be called asynchronously by the OpenCL implementation. It
  3684. * is the application's responsibility to ensure that the callback function
  3685. * is thread-safe.
  3686. *
  3687. * \param data will be passed as the argument when \a notifyFptr is
  3688. * called. \a data can be NULL and is its default value.
  3689. *
  3690. * \return One of the following values:
  3691. * - CL_SUCCESS if the function is executed successfully.
  3692. * - CL_INVALID_DEVICE if OpenCL devices listed in \a devices are not in
  3693. * the list of devices associated with \a program.
  3694. * - CL_INVALID_BINARY if \a program is created with.
  3695. * createWithProgramBinary and devices listed in \a devices do not have a
  3696. * valid program binary loaded.
  3697. * - CL_INVALID_BUILD_OPTIONS if the build options specified by \a options
  3698. * are invalid.
  3699. * - CL_INVALID_OPERATION if the build of a program executable for any of
  3700. * the devices listed in \a devices by a previous call to build for
  3701. * \a program has not completed.
  3702. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources
  3703. * required by the runtime.
  3704. *
  3705. * \note In the case that exceptions are enabled and error value
  3706. * other than CL_SUCCESS is generated, then cl::Error exception is
  3707. * generated.
  3708. */
  3709. cl_int build(
  3710. const VECTOR_CLASS<Device>& devices,
  3711. const char* options = NULL,
  3712. void (CL_CALLBACK * notifyFptr)(cl_program, void *) = NULL,
  3713. void* data = NULL) const
  3714. {
  3715. return detail::errHandler(
  3716. ::clBuildProgram(
  3717. object_,
  3718. (cl_uint)
  3719. devices.size(),
  3720. (cl_device_id*)&devices.front(),
  3721. options,
  3722. notifyFptr,
  3723. data),
  3724. __BUILD_PROGRAM_ERR);
  3725. }
  3726. /*! \brief Return information about the program object.
  3727. *
  3728. * \param name specifies the information to query.
  3729. *
  3730. * \param param is a pointer to memory where the appropriate result
  3731. * being queried is returned. If \a param_value is NULL, it is ignored.
  3732. *
  3733. * \return One of the following values:
  3734. * - CL_SUCCESS if the function is executed successfully.
  3735. * - CL_INVALID_VALUE if \a name is not valid.
  3736. * - CL_INVALID_PROGRAM if \a program is a not a valid program object.
  3737. *
  3738. * \note In the case that exceptions are enabled and error value
  3739. * other than CL_SUCCESS is generated, then cl::Error exception is
  3740. * generated.
  3741. */
  3742. template <typename T>
  3743. cl_int getInfo(cl_program_info name, T* param) const
  3744. {
  3745. return detail::errHandler(
  3746. detail::getInfo(&::clGetProgramInfo, object_, name, param),
  3747. __GET_PROGRAM_INFO_ERR);
  3748. }
  3749. /*!
  3750. * \brief Return information about the program object.
  3751. *
  3752. * \param name specifies the information to query.
  3753. *
  3754. * \param err pointer to memory location where error value will be returned.
  3755. * If not null, the default value, then one of the following values is
  3756. * returned:
  3757. * - CL_SUCCESS if the function is executed successfully
  3758. * - CL_INVALID_VALUE if \a name is not valid.
  3759. *
  3760. * \return the appropriate values for \em name will be returned.
  3761. *
  3762. * \note In the case that exceptions are enabled and error value
  3763. * other than CL_SUCCESS is generated, then cl::Error exception is
  3764. * generated.
  3765. */
  3766. template <cl_int name> typename
  3767. detail::param_traits<detail::cl_program_info, name>::param_type
  3768. getInfo(cl_int* err = NULL) const
  3769. {
  3770. typename detail::param_traits<
  3771. detail::cl_program_info, name>::param_type param;
  3772. cl_int result = getInfo(name, &param);
  3773. if (err != NULL) {
  3774. *err = result;
  3775. }
  3776. return param;
  3777. }
  3778. /*! \brief Return build information for each device in the program object.
  3779. *
  3780. * \param device specifies the device for which build information is being
  3781. * queried. \a device must be a valid device associated with \a program.
  3782. *
  3783. * \param name specifies the information to query.
  3784. *
  3785. * \param param is a pointer to memory where the appropriate result being
  3786. * queried is returned. If \a param_value is NULL, it is ignored.
  3787. *
  3788. * \return One of the following values:
  3789. * - CL_SUCCESS if the function is executed successfully.
  3790. * - CL_INVALID_DEVICE if \a device is not in the list of devices
  3791. * associated with \a program.
  3792. * - CL_INVALID_VALUE if \a name is not valid.
  3793. * - CL_INVALID_PROGRAM if \a program is a not a valid program object.
  3794. *
  3795. * \note In the case that exceptions are enabled and error value
  3796. * other than CL_SUCCESS is generated, then cl::Error exception is
  3797. * generated.
  3798. */
  3799. template <typename T>
  3800. cl_int getBuildInfo(
  3801. const Device& device, cl_program_build_info name, T* param) const
  3802. {
  3803. return detail::errHandler(
  3804. detail::getInfo(
  3805. &::clGetProgramBuildInfo, object_, device(), name, param),
  3806. __GET_PROGRAM_BUILD_INFO_ERR);
  3807. }
  3808. /*!
  3809. * \brief Return build information for each device in the program object.
  3810. *
  3811. * \param name specifies the information to query.
  3812. *
  3813. * \param err pointer to memory location where error value will be returned.
  3814. * If not null, the default value, then one of the following values is
  3815. * returned:
  3816. * - CL_SUCCESS if the function is executed successfully
  3817. * - CL_INVALID_VALUE if \a name is not valid.
  3818. *
  3819. * \return the appropriate values for \em name will be returned.
  3820. *
  3821. * \note In the case that exceptions are enabled and error value
  3822. * other than CL_SUCCESS is generated, then cl::Error exception is
  3823. * generated.
  3824. */
  3825. template <cl_int name> typename
  3826. detail::param_traits<detail::cl_program_build_info, name>::param_type
  3827. getBuildInfo(const Device& device, cl_int* err = NULL) const
  3828. {
  3829. typename detail::param_traits<
  3830. detail::cl_program_build_info, name>::param_type param;
  3831. cl_int result = getBuildInfo(device, name, &param);
  3832. if (err != NULL) {
  3833. *err = result;
  3834. }
  3835. return param;
  3836. }
  3837. /*! \brief Create kernel objects for all kernel functions in program.
  3838. *
  3839. * Kernel objects may not be created for any __kernel functions in program
  3840. * that do not have the same function definition across all devices for
  3841. * which a program executable has been successfully built.
  3842. *
  3843. * \param kernels is the vector where the kernel objects for kernels in
  3844. * \a program will be returned. If \a kernels is NULL, it is ignored.
  3845. *
  3846. * \return One of the following values:
  3847. * - CL_SUCCESS if the kernel objects were successfully allocated.
  3848. * - CL_INVALID_PROGRAM_EXECUTABLE if there is no successfully built
  3849. executable for any device in \a program.
  3850. * - CL_INVALID_VALUE if \a kernels is not NULL and its size is less
  3851. * than the number of kernels in program.
  3852. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources
  3853. * required by the runtime.
  3854. *
  3855. * Kernel objects can only be created once you have a program object with a
  3856. * valid program source or binary loaded into the program object and the
  3857. * program executable has been successfully built for one or more devices
  3858. * associated with \a program. No changes to the program executable are
  3859. * allowed while there are kernel objects associated with a program object.
  3860. * This means that calls to \a build return CL_INVALID_OPERATION if there
  3861. * are kernel objects attached to a program object. The OpenCL context
  3862. * associated with program will be the context associated with kernel.
  3863. * Devices associated with a program object for which a valid program
  3864. * executable has been built can be used to execute kernels declared in the
  3865. * program object.
  3866. *
  3867. * \note In the case that exceptions are enabled and error value
  3868. * other than CL_SUCCESS is generated, then cl::Error exception is
  3869. * generated.
  3870. */
  3871. cl_int createKernels(VECTOR_CLASS<Kernel>* kernels)
  3872. {
  3873. cl_uint numKernels;
  3874. cl_int err = ::clCreateKernelsInProgram(object_, 0, NULL, &numKernels);
  3875. if (err != CL_SUCCESS) {
  3876. return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
  3877. }
  3878. Kernel* value = (Kernel*) alloca(numKernels * sizeof(Kernel));
  3879. err = ::clCreateKernelsInProgram(
  3880. object_, numKernels, (cl_kernel*) value, NULL);
  3881. if (err != CL_SUCCESS) {
  3882. return detail::errHandler(err, __CREATE_KERNELS_IN_PROGRAM_ERR);
  3883. }
  3884. kernels->assign(&value[0], &value[numKernels]);
  3885. return CL_SUCCESS;
  3886. }
  3887. };
  3888. inline Kernel::Kernel(const Program& program, const char* name, cl_int* err)
  3889. {
  3890. cl_int error;
  3891. object_ = ::clCreateKernel(program(), name, &error);
  3892. detail::errHandler(error, __CREATE_KERNEL_ERR);
  3893. if (err != NULL) {
  3894. *err = error;
  3895. }
  3896. }
  3897. /*! \class CommandQueue
  3898. * \brief CommandQueue interface for cl_command_queue.
  3899. */
  3900. class CommandQueue : public detail::Wrapper<cl_command_queue>
  3901. {
  3902. public:
  3903. /*! \brief Create a command-queue on a specific device.
  3904. *
  3905. * \param context must be a valid OpenCL context.
  3906. *
  3907. * \param device must be a device associated with context. It can either be
  3908. * in the list of devices specified when context is created using
  3909. * cl::Context or have the same device type as device type specified
  3910. * when context is created using cl::Context.
  3911. *
  3912. * \param properties specifies a list of properties for the command-queue.
  3913. *
  3914. * \param err will return an appropriate error code. If \a err
  3915. * is NULL, its default value, no error code is returned.
  3916. *
  3917. * \return A valid non-zero command-queue and \a err is set to
  3918. * CL_SUCCESS if the command-queue is created successfully or a NULL value
  3919. * with one of the following error values returned \a in err:
  3920. * - CL_INVALID_CONTEXT if context is not a valid.
  3921. * - CL_INVALID_DEVICE if device is not a valid device or is not
  3922. * associated with context
  3923. * - CL_INVALID_VALUE if values specified in properties are not valid.
  3924. * - CL_INVALID_QUEUE_PROPERTIES if values specified in properties are
  3925. * valid but are not supported by the device.
  3926. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources
  3927. * required by the runtime.
  3928. *
  3929. * \note In the case that exceptions are enabled and error value
  3930. * other than CL_SUCCESS is generated, then cl::Error exception is
  3931. * generated.
  3932. */
  3933. CommandQueue(
  3934. const Context& context,
  3935. const Device& device,
  3936. cl_command_queue_properties properties = 0,
  3937. cl_int* err = NULL)
  3938. {
  3939. cl_int error;
  3940. object_ = ::clCreateCommandQueue(
  3941. context(), device(), properties, &error);
  3942. detail::errHandler(error, __CREATE_COMMAND_QUEUE_ERR);
  3943. if (err != NULL) {
  3944. *err = error;
  3945. }
  3946. }
  3947. //! Default constructor; command queue is not valid at this point.
  3948. CommandQueue() { }
  3949. /*!
  3950. * \brief Construct a new commandQueue from a valid commandQueue.
  3951. *
  3952. * \param commandQueue The commandQueue object used for creation.
  3953. */
  3954. CommandQueue(const CommandQueue& commandQueue) : detail::Wrapper<cl_type>(commandQueue) { }
  3955. /*!
  3956. * \brief Assign a commandQueue to commandQueue.
  3957. *
  3958. * \param rhs the commandQueue object on rhs of the assignment.
  3959. */
  3960. CommandQueue& operator = (const CommandQueue& rhs)
  3961. {
  3962. if (this != &rhs) {
  3963. detail::Wrapper<cl_type>::operator=(rhs);
  3964. }
  3965. return *this;
  3966. }
  3967. /*! \brief Query information about a command-queue.
  3968. *
  3969. * \param name specifies the information to query.
  3970. *
  3971. * \param param is a pointer to memory where the appropriate result
  3972. * being queried is returned. If \a param_value is NULL, it is ignored.
  3973. *
  3974. * \return One of the following values:
  3975. * - CL_SUCCESS if the function is executed successfully.
  3976. * - CL_INVALID_VALUE if \a name is not one of the supported
  3977. * values.
  3978. *
  3979. * \note In the case that exceptions are enabled and error value
  3980. * other than CL_SUCCESS is generated, then cl::Error exception is
  3981. * generated.
  3982. */
  3983. template <typename T>
  3984. cl_int getInfo(cl_command_queue_info name, T* param) const
  3985. {
  3986. return detail::errHandler(
  3987. detail::getInfo(
  3988. &::clGetCommandQueueInfo, object_, name, param),
  3989. __GET_COMMAND_QUEUE_INFO_ERR);
  3990. }
  3991. /*!
  3992. * \brief Query information about a command-queue.
  3993. *
  3994. * \param name specifies the information to query.
  3995. *
  3996. * \param err pointer to memory location where error value will be returned.
  3997. * If not null, the default value, then one of the following values is
  3998. * returned:
  3999. * - CL_SUCCESS if the function is executed successfully
  4000. * - CL_INVALID_VALUE if \a name is not valid.
  4001. *
  4002. * \return the appropriate values for \em name will be returned.
  4003. *
  4004. * \note In the case that exceptions are enabled and error value
  4005. * other than CL_SUCCESS is generated, then cl::Error exception is
  4006. * generated.
  4007. */
  4008. template <cl_int name> typename
  4009. detail::param_traits<detail::cl_command_queue_info, name>::param_type
  4010. getInfo(cl_int* err = NULL) const
  4011. {
  4012. typename detail::param_traits<
  4013. detail::cl_command_queue_info, name>::param_type param;
  4014. cl_int result = getInfo(name, &param);
  4015. if (err != NULL) {
  4016. *err = result;
  4017. }
  4018. return param;
  4019. }
  4020. /*! \brief Enable or disable the properties of a command-queue.
  4021. *
  4022. * \param properties specifies the new command-queue properties to be
  4023. * applied to \a command_queue.
  4024. *
  4025. * \param enable determines whether the values specified by properties are
  4026. * enabled (if enable is CL_TRUE) or disabled (if enable is CL_FALSE) for
  4027. * the command-queue .
  4028. *
  4029. * \param old_properties returns the command-queue properties before they
  4030. * were changed by setProperty. If \a old_properties is NULL, its default,
  4031. * it is ignored.
  4032. *
  4033. * \return One of the following values:
  4034. * - CL_SUCCESS if the command-queue properties are successfully updated.
  4035. * - CL_INVALID_VALUE if the values specified in properties are not valid.
  4036. * - CL_INVALID_QUEUE_PROPERTIES if values specified in properties are
  4037. * not supported by the device.
  4038. *
  4039. * \note In the case that exceptions are enabled and error value
  4040. * other than CL_SUCCESS is generated, then cl::Error exception is
  4041. * generated.
  4042. */
  4043. cl_int setProperty(
  4044. cl_command_queue_properties properties,
  4045. cl_bool enable,
  4046. cl_command_queue_properties* old_properties = NULL) const
  4047. {
  4048. return detail::errHandler(
  4049. ::clSetCommandQueueProperty(
  4050. object_,
  4051. properties,
  4052. enable,
  4053. old_properties),
  4054. __SET_COMMAND_QUEUE_PROPERTY_ERR);
  4055. }
  4056. /*! \brief Enqueue a command to read from a buffer object to host memory.
  4057. *
  4058. * \param buffer refers to a valid buffer object.
  4059. *
  4060. * \param blocking indicates if the read operation is blocking or
  4061. * nonblocking. If \a blocking is CL_TRUE i.e. the read command is
  4062. * blocking, enqueueReadBuffer does not return until the buffer data has
  4063. * been read and copied into memory pointed to by ptr.
  4064. * If \a blocking is CL_FALSE i.e. the read command is non-blocking,
  4065. * enqueueReadBuffer queues a non-blocking read command and returns. The
  4066. * contents of the buffer that ptr points to cannot be used until the read
  4067. * command has completed. The \a event argument returns an event object
  4068. * which can be used to query the execution status of the read command.
  4069. * When the read command has completed, the contents of the buffer that ptr
  4070. * points to can be used by the application.
  4071. *
  4072. * \param offset is the offset in bytes in the buffer object to read from
  4073. * or write to.
  4074. *
  4075. * \param cb is the size in bytes of data being read or written.
  4076. *
  4077. * \param ptr is the pointer to buffer in host memory where data is to be
  4078. * read into or to be written from.
  4079. *
  4080. * \param events specifies events that need to complete before this
  4081. * particular command can be executed. If \a events is NULL,
  4082. * its default, then this particular command does not wait on any event to
  4083. * complete. The events specified in \a events act as
  4084. * synchronization points.
  4085. *
  4086. * \param event returns an event object that identifies this particular
  4087. * read command and can be used to query or queue a wait for this
  4088. * particular command to complete. \a event can be NULL, its default, in
  4089. * which case it will not be possible for the application to query the
  4090. * status of this command or queue a wait for this command to complete.
  4091. *
  4092. * \return CL_SUCCESS if the function is executed successfully. Otherwise
  4093. * it returns one of the following errors:
  4094. * - CL_INVALID_CONTEXT if the context associated with \a command_queue and
  4095. * \a buffer are not the same.
  4096. * - CL_INVALID_MEM_OBJECT if \a buffer is not a valid buffer object.
  4097. * - CL_INVALID_VALUE if the region being read or written specified by
  4098. * (offset, size) is out of bounds or if \a ptr is a NULL value.
  4099. * - CL_INVALID_EVENT_WAIT_LIST if event objects in \a events are not
  4100. * valid events.
  4101. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources
  4102. * required by the runtime.
  4103. *
  4104. * \note In the case that exceptions are enabled and error value
  4105. * other than CL_SUCCESS is generated, then cl::Error exception is
  4106. * generated.
  4107. */
  4108. cl_int enqueueReadBuffer(
  4109. const Buffer& buffer,
  4110. cl_bool blocking,
  4111. ::size_t offset,
  4112. ::size_t size,
  4113. void* ptr,
  4114. const VECTOR_CLASS<Event>* events = NULL,
  4115. Event* event = NULL) const
  4116. {
  4117. return detail::errHandler(
  4118. ::clEnqueueReadBuffer(
  4119. object_, buffer(), blocking, offset, size,
  4120. ptr,
  4121. (events != NULL) ? (cl_uint) events->size() : 0,
  4122. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  4123. (cl_event*) event),
  4124. __ENQUEUE_READ_BUFFER_ERR);
  4125. }
  4126. /*! \brief Enqueue a command to write to a buffer object from host memory.
  4127. *
  4128. * \param buffer refers to a valid buffer object.
  4129. *
  4130. * \param blocking indicates if the write operation is blocking or
  4131. * non-blocking. If \a blocking is CL_TRUE, the OpenCL implementation
  4132. * copies the data referred to by \a ptr and enqueues the write operation
  4133. * in the command-queue. The memory pointed to by \a ptr can be reused
  4134. * by the application after the enqueueWriteBuffer call returns. If
  4135. * \a blocking is CL_FALSE, the OpenCL implementation will use \a ptr to
  4136. * perform a nonblocking write. As the write is non-blocking the
  4137. * implementation can return immediately. The memory pointed to by \a ptr
  4138. * cannot be reused by the application after the call returns.
  4139. * The \a event argument returns an event object which can be used to
  4140. * query the execution status of the write command. When the write
  4141. * command has completed, the memory pointed to by \a ptr can then be
  4142. * reused by the application
  4143. *
  4144. * \param offset is the offset in bytes in the buffer object to write to.
  4145. *
  4146. * \param cb is the size in bytes of data being read or written.
  4147. *
  4148. * \param ptr is the pointer to buffer in host memory where data is to be
  4149. * read into or to be written from.
  4150. *
  4151. * \param events specifies events that need to complete before this
  4152. * particular command can be executed. If \a events is NULL, its default,
  4153. * then this particular command does not wait on any event to complete.
  4154. * The events specified in \a event_wait_list act as synchronization
  4155. * points.
  4156. *
  4157. * \param event returns an event object that identifies this particular
  4158. * write command and can be used to query or queue a wait for this
  4159. * particular command to complete. \a event can be NULL in which case it
  4160. * will not be possible for the application to query the status of this
  4161. * command or queue a wait for this command to complete.
  4162. *
  4163. * \return CL_SUCCESS if the function is executed successfully. Otherwise
  4164. * it returns one of the following errors:
  4165. * - CL_INVALID_MEM_OBJECT if \a buffer is not a valid buffer object.
  4166. * - CL_INVALID_VALUE if the region being read or written specified by
  4167. * (offset, size) is out of bounds or if \a ptr is a NULL value.
  4168. * - CL_INVALID_EVENT_WAIT_LIST if event objects in \a events are not
  4169. * valid events.
  4170. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources
  4171. * required
  4172. * by the runtime.
  4173. *
  4174. * \note In the case that exceptions are enabled and error value
  4175. * other than CL_SUCCESS is generated, then cl::Error exception is
  4176. * generated.
  4177. */
  4178. cl_int enqueueWriteBuffer(
  4179. const Buffer& buffer,
  4180. cl_bool blocking,
  4181. ::size_t offset,
  4182. ::size_t size,
  4183. const void* ptr,
  4184. const VECTOR_CLASS<Event>* events = NULL,
  4185. Event* event = NULL) const
  4186. {
  4187. return detail::errHandler(
  4188. ::clEnqueueWriteBuffer(
  4189. object_, buffer(), blocking, offset, size,
  4190. ptr,
  4191. (events != NULL) ? (cl_uint) events->size() : 0,
  4192. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  4193. (cl_event*) event),
  4194. __ENQUEUE_WRITE_BUFFER_ERR);
  4195. }
  4196. /*! \brief Enqueues a command to copy a buffer object to another
  4197. *
  4198. * \param src is the source buffer object.
  4199. *
  4200. * \param dst is the destination buffer object.
  4201. *
  4202. * \param src_offset refers to the offset where to begin reading data in
  4203. * \a src.
  4204. *
  4205. * \param dst_offset refers to the offset where to begin copying data in
  4206. * \a dst.
  4207. *
  4208. * \param size refers to the size in bytes to copy.
  4209. *
  4210. * \param events specifies events that need to complete before this
  4211. * particular command can be executed. If \a events is NULL,
  4212. * then this particular command does not wait on any event to complete.
  4213. * The events specified in \a event_wait_list act as synchronization
  4214. * points.
  4215. *
  4216. * \param event returns an event object that identifies this particular
  4217. * copy command and can be used to query or queue a wait for this
  4218. * particular command to complete. \a event can be NULL in which case it
  4219. * will not be possible for the application to query the status of this
  4220. * command or queue and wait for this command to complete. enqueueBarrier
  4221. * can be used instead.
  4222. *
  4223. * \return CL_SUCCESS if the function is executed successfully. Otherwise
  4224. * it returns one of the following errors:
  4225. * - CL_INVALID_CONTEXT if the context associated with \a command_queue,
  4226. * \a src and \a dst are not the same.
  4227. * - CL_INVALID_MEM_OBJECT if \a src_buffer and \a dst_buffer are not valid
  4228. * buffer objects.
  4229. * - CL_INVALID_VALUE if \a src_offset, \a dst_offset, \a cb,
  4230. * \a src_offset + \a size or \a dst_offset + \a size require accessing
  4231. * elements outside the buffer memory objects.
  4232. * - CL_INVALID_EVENT_WAIT_LIST if event objects in \a events are not
  4233. * valid events.
  4234. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources
  4235. * required by the runtime
  4236. *
  4237. * \note In the case that exceptions are enabled and error value
  4238. * other than CL_SUCCESS is generated, then cl::Error exception is
  4239. * generated.
  4240. */
  4241. cl_int enqueueCopyBuffer(
  4242. const Buffer& src,
  4243. const Buffer& dst,
  4244. ::size_t src_offset,
  4245. ::size_t dst_offset,
  4246. ::size_t size,
  4247. const VECTOR_CLASS<Event>* events = NULL,
  4248. Event* event = NULL) const
  4249. {
  4250. return detail::errHandler(
  4251. ::clEnqueueCopyBuffer(
  4252. object_, src(), dst(), src_offset, dst_offset, size,
  4253. (events != NULL) ? (cl_uint) events->size() : 0,
  4254. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  4255. (cl_event*) event),
  4256. __ENQEUE_COPY_BUFFER_ERR);
  4257. }
  4258. #if defined(CL_VERSION_1_1)
  4259. /*! \brief Enqueue a command to read a 2D or 3D rectangular region from
  4260. * a buffer object to host memory.
  4261. *
  4262. * \param buffer refers to a valid buffer object.
  4263. *
  4264. * \param blocking indicates if the write operation is blocking or
  4265. * non-blocking. If \a blocking is CL_TRUE, the OpenCL implementation
  4266. * copies the data referred to by \a ptr and enqueues the write operation
  4267. * in the command-queue. The memory pointed to by \a ptr can be reused
  4268. * by the application after the enqueueReadBufferRect call returns. If
  4269. * \a blocking is CL_FALSE, the OpenCL implementation will use \a ptr to
  4270. * perform a nonblocking write. As the write is non-blocking the
  4271. * implementation can return immediately. The memory pointed to by \a ptr
  4272. * cannot be reused by the application after the call returns.
  4273. * The \a event argument returns an event object which can be used to
  4274. * query the execution status of the write command. When the write
  4275. * command has completed, the memory pointed to by \a ptr can then be
  4276. * reused by the application
  4277. *
  4278. * \param buffer_origin defines the (x, y, z) offset in the memory region
  4279. * associated with buffer. For a 2D rectangle region, the z value given
  4280. * by buffer_origin[2] should be 0. The offset in bytes is computed as
  4281. * buffer_origin[2] * buffer_slice_pitch + buffer_origin[1] * buffer_row_pitch
  4282. * + buffer_origin[0].
  4283. *
  4284. * \param host_origin defines the (x, y, z) offset in the memory region
  4285. * pointed to by ptr. For a 2D rectangle region, the z value given by
  4286. * host_origin[2] should be 0. The offset in bytes is computed as
  4287. * host_origin[2] * host_slice_pitch + host_origin[1] * host_row_pitch +
  4288. * host_origin[0].
  4289. *
  4290. * \param region defines the (width, height, depth) in bytes of the 2D or
  4291. * 3D rectangle being read or written. For a 2D rectangle copy, the depth
  4292. * value given by region[2] should be 1.
  4293. *
  4294. * \param buffer_row_pitch is the length of each row in bytes to be used
  4295. * for the memory region associated with buffer. If buffer_row_pitch is 0,
  4296. * buffer_row_pitch is computed as region[0].
  4297. *
  4298. * \param buffer_slice_pitch is the length of each 2D slice in bytes to be
  4299. * used for the memory region associated with buffer. If buffer_slice_pitch
  4300. * is 0, buffer_slice_pitch is computed as region[1] * buffer_row_pitch.
  4301. *
  4302. * \param host_row_pitch is the length of each row in bytes to be used for
  4303. * the memory region pointed to by ptr. If host_row_pitch is 0, host_row_pitch
  4304. * is computed as region[0].
  4305. *
  4306. * \param host_slice_pitch is the length of each 2D slice in bytes to be
  4307. * used for the memory region pointed to by ptr. If host_slice_pitch is 0,
  4308. * host_slice_pitch is computed as region[1] * host_row_pitch.
  4309. *
  4310. * \param events specifies events that need to complete before this
  4311. * particular command can be executed. If \a events is NULL, its default,
  4312. * then this particular command does not wait on any event to complete.
  4313. * The events specified in \a event_wait_list act as synchronization
  4314. * points.
  4315. *
  4316. * \param event returns an event object that identifies this particular
  4317. * write command and can be used to query or queue a wait for this
  4318. * particular command to complete. \a event can be NULL in which case it
  4319. * will not be possible for the application to query the status of this
  4320. * command or queue a wait for this command to complete.
  4321. *
  4322. * \return CL_SUCCESS if the function is executed successfully. Otherwise
  4323. * it returns one of the following errors:
  4324. * - CL_INVALID_CONTEXT if the context associated with command_queue and
  4325. * buffer are not the same or if the context associated with command_queue
  4326. * and events in event_wait_list are not the same.
  4327. *
  4328. * - CL_INVALID_MEM_OBJECT if buffer is not a valid buffer object.
  4329. *
  4330. * - CL_INVALID_VALUE if the region being read or written specified by
  4331. * (buffer_offset,region) is out of bounds.
  4332. *
  4333. * - CL_INVALID_VALUE if ptr is a NULL value.
  4334. *
  4335. * - CL_MISALIGNED_SUB_BUFFER_OFFSET if buffer is a sub-buffer object and
  4336. * offset specified when the sub-buffer object is created is not aligned to
  4337. * CL_DEVICE_MEM_BASE_ADDR_ALIGN value for device associated with queue.
  4338. *
  4339. * - CL_MEM_OBJECT_ALLOCATION_FAILURE if there is a failure to allocate memory
  4340. * for data store associated with buffer.
  4341. *
  4342. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources
  4343. * required by the OpenCL implementation on the host.
  4344. *
  4345. * \note In the case that exceptions are enabled and error value
  4346. * other than CL_SUCCESS is generated, then cl::Error exception is
  4347. * generated.
  4348. */
  4349. cl_int enqueueReadBufferRect(
  4350. const Buffer& buffer,
  4351. cl_bool blocking,
  4352. const size_t<3>& buffer_offset,
  4353. const size_t<3>& host_offset,
  4354. const size_t<3>& region,
  4355. ::size_t buffer_row_pitch,
  4356. ::size_t buffer_slice_pitch,
  4357. ::size_t host_row_pitch,
  4358. ::size_t host_slice_pitch,
  4359. void *ptr,
  4360. const VECTOR_CLASS<Event>* events = NULL,
  4361. Event* event = NULL) const
  4362. {
  4363. return detail::errHandler(
  4364. ::clEnqueueReadBufferRect(
  4365. object_,
  4366. buffer(),
  4367. blocking,
  4368. (const ::size_t *)buffer_offset,
  4369. (const ::size_t *)host_offset,
  4370. (const ::size_t *)region,
  4371. buffer_row_pitch,
  4372. buffer_slice_pitch,
  4373. host_row_pitch,
  4374. host_slice_pitch,
  4375. ptr,
  4376. (events != NULL) ? (cl_uint) events->size() : 0,
  4377. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  4378. (cl_event*) event),
  4379. __ENQUEUE_READ_BUFFER_RECT_ERR);
  4380. }
  4381. /*! \brief Enqueue a command to write a 2D or 3D rectangular region from
  4382. * host memory to a buffer object.
  4383. *
  4384. * \param buffer refers to a valid buffer object.
  4385. *
  4386. * \param blocking indicates if the write operation is blocking or
  4387. * non-blocking. If \a blocking is CL_TRUE, the OpenCL implementation
  4388. * copies the data referred to by \a ptr and enqueues the write operation
  4389. * in the command-queue. The memory pointed to by \a ptr can be reused
  4390. * by the application after the enqueueWriteBufferRect call returns. If
  4391. * \a blocking is CL_FALSE, the OpenCL implementation will use \a ptr to
  4392. * perform a nonblocking write. As the write is non-blocking the
  4393. * implementation can return immediately. The memory pointed to by \a ptr
  4394. * cannot be reused by the application after the call returns.
  4395. * The \a event argument returns an event object which can be used to
  4396. * query the execution status of the write command. When the write
  4397. * command has completed, the memory pointed to by \a ptr can then be
  4398. * reused by the application
  4399. *
  4400. * \param buffer_origin defines the (x, y, z) offset in the memory region
  4401. * associated with buffer. For a 2D rectangle region, the z value given
  4402. * by buffer_origin[2] should be 0. The offset in bytes is computed as
  4403. * buffer_origin[2] * buffer_slice_pitch + buffer_origin[1] * buffer_row_pitch
  4404. * + buffer_origin[0].
  4405. *
  4406. * \param host_origin defines the (x, y, z) offset in the memory region
  4407. * pointed to by ptr. For a 2D rectangle region, the z value given by
  4408. * host_origin[2] should be 0. The offset in bytes is computed as
  4409. * host_origin[2] * host_slice_pitch + host_origin[1] * host_row_pitch +
  4410. * host_origin[0].
  4411. *
  4412. * \param region defines the (width, height, depth) in bytes of the 2D or
  4413. * 3D rectangle being read or written. For a 2D rectangle copy, the depth
  4414. * value given by region[2] should be 1.
  4415. *
  4416. * \param buffer_row_pitch is the length of each row in bytes to be used
  4417. * for the memory region associated with buffer. If buffer_row_pitch is 0,
  4418. * buffer_row_pitch is computed as region[0].
  4419. *
  4420. * \param buffer_slice_pitch is the length of each 2D slice in bytes to be
  4421. * used for the memory region associated with buffer. If buffer_slice_pitch
  4422. * is 0, buffer_slice_pitch is computed as region[1] * buffer_row_pitch.
  4423. *
  4424. * \param host_row_pitch is the length of each row in bytes to be used for
  4425. * the memory region pointed to by ptr. If host_row_pitch is 0, host_row_pitch
  4426. * is computed as region[0].
  4427. *
  4428. * \param host_slice_pitch is the length of each 2D slice in bytes to be
  4429. * used for the memory region pointed to by ptr. If host_slice_pitch is 0,
  4430. * host_slice_pitch is computed as region[1] * host_row_pitch.
  4431. *
  4432. * \param events specifies events that need to complete before this
  4433. * particular command can be executed. If \a events is NULL, its default,
  4434. * then this particular command does not wait on any event to complete.
  4435. * The events specified in \a event_wait_list act as synchronization
  4436. * points.
  4437. *
  4438. * \param event returns an event object that identifies this particular
  4439. * write command and can be used to query or queue a wait for this
  4440. * particular command to complete. \a event can be NULL in which case it
  4441. * will not be possible for the application to query the status of this
  4442. * command or queue a wait for this command to complete.
  4443. *
  4444. * \return CL_SUCCESS if the function is executed successfully. Otherwise
  4445. * it returns one of the following errors:
  4446. * - CL_INVALID_CONTEXT if the context associated with command_queue and
  4447. * buffer are not the same or if the context associated with command_queue
  4448. * and events in event_wait_list are not the same.
  4449. *
  4450. * - CL_INVALID_MEM_OBJECT if buffer is not a valid buffer object.
  4451. *
  4452. * - CL_INVALID_VALUE if the region being read or written specified by
  4453. * (buffer_offset,region) is out of bounds.
  4454. *
  4455. * - CL_INVALID_VALUE if ptr is a NULL value.
  4456. *
  4457. * - CL_MISALIGNED_SUB_BUFFER_OFFSET if buffer is a sub-buffer object and
  4458. * offset specified when the sub-buffer object is created is not aligned to
  4459. * CL_DEVICE_MEM_BASE_ADDR_ALIGN value for device associated with queue.
  4460. *
  4461. * - CL_MEM_OBJECT_ALLOCATION_FAILURE if there is a failure to allocate memory
  4462. * for data store associated with buffer.
  4463. *
  4464. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources
  4465. * required by the OpenCL implementation on the host.
  4466. *
  4467. * \note In the case that exceptions are enabled and error value
  4468. * other than CL_SUCCESS is generated, then cl::Error exception is
  4469. * generated.
  4470. */
  4471. cl_int enqueueWriteBufferRect(
  4472. const Buffer& buffer,
  4473. cl_bool blocking,
  4474. const size_t<3>& buffer_offset,
  4475. const size_t<3>& host_offset,
  4476. const size_t<3>& region,
  4477. ::size_t buffer_row_pitch,
  4478. ::size_t buffer_slice_pitch,
  4479. ::size_t host_row_pitch,
  4480. ::size_t host_slice_pitch,
  4481. const void *ptr,
  4482. const VECTOR_CLASS<Event>* events = NULL,
  4483. Event* event = NULL) const
  4484. {
  4485. return detail::errHandler(
  4486. ::clEnqueueWriteBufferRect(
  4487. object_,
  4488. buffer(),
  4489. blocking,
  4490. (const ::size_t *)buffer_offset,
  4491. (const ::size_t *)host_offset,
  4492. (const ::size_t *)region,
  4493. buffer_row_pitch,
  4494. buffer_slice_pitch,
  4495. host_row_pitch,
  4496. host_slice_pitch,
  4497. ptr,
  4498. (events != NULL) ? (cl_uint) events->size() : 0,
  4499. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  4500. (cl_event*) event),
  4501. __ENQUEUE_WRITE_BUFFER_RECT_ERR);
  4502. }
  4503. /*! \brief Enqueues a command to copy a 2D or 3D rectangular region from
  4504. * a buffer object to a 2D or 3D region of another.
  4505. *
  4506. * \param src is the source buffer object.
  4507. *
  4508. * \param dst is the destination buffer object.
  4509. *
  4510. * \param src_origin defines the (x, y, z) offset in the memory region
  4511. * associated with src_buffer. For a 2D rectangle region, the z value
  4512. * given by src_origin[2] should be 0. The offset in bytes is computed as
  4513. * src_origin[2] * src_slice_pitch + src_origin[1] *
  4514. * src_row_pitch + src_origin[0].
  4515. *
  4516. * \param dst_origin dst_origin defines the (x, y, z) offset in the memory
  4517. * region associated with dst_buffer. For a 2D rectangle region, the z
  4518. * value given by dst_origin[2] should be 0. The offset in bytes is
  4519. * computed as dst_origin[2] * dst_slice_pitch + dst_origin[1] *
  4520. * dst_row_pitch + dst_origin[0].
  4521. *
  4522. * \param region defines the (width, height, depth) in bytes of the 2D or
  4523. * 3D rectangle being copied. For a 2D rectangle, the depth value
  4524. * given by region[2] should be 1.
  4525. *
  4526. * \param src_row_pitch is the length of each row in bytes to be used for
  4527. * the memory region associated with src_buffer. If src_row_pitch is 0,
  4528. * src_row_pitch is computed as region[0].
  4529. *
  4530. * \param src_slice_pitch is the length of each 2D slice in bytes to be used
  4531. * for the memory region associated with src_buffer. If src_slice_pitch is 0,
  4532. * src_slice_pitch is computed as region[1] * src_row_pitch.
  4533. *
  4534. * \param dst_row_pitch is the length of each row in bytes to be used for the memory
  4535. * region associated with dst_buffer. If dst_row_pitch is 0, dst_row_pitch
  4536. * is computed as region[0].
  4537. *
  4538. * \param dst_slice_pitch is the length of each 2D slice in bytes to be used
  4539. * for the memory region associated with dst_buffer. If dst_slice_pitch is 0,
  4540. * dst_slice_pitch is computed as region[1] * dst_row_pitch.
  4541. *
  4542. * \param events specifies events that need to complete before this
  4543. * particular command can be executed. If \a events is NULL,
  4544. * then this particular command does not wait on any event to complete.
  4545. * The events specified in \a event_wait_list act as synchronization
  4546. * points.
  4547. *
  4548. * \param event returns an event object that identifies this particular
  4549. * copy command and can be used to query or queue a wait for this
  4550. * particular command to complete. \a event can be NULL in which case it
  4551. * will not be possible for the application to query the status of this
  4552. * command or queue and wait for this command to complete. enqueueBarrier
  4553. * can be used instead.
  4554. *
  4555. * \return CL_SUCCESS if the function is executed successfully. Otherwise
  4556. * it returns one of the following errors:
  4557. * - CL_INVALID_CONTEXT if the context associated with command_queue,
  4558. * src_buffer and dst_buffer are not the same or if the context
  4559. * associated with command_queue and events in \a events are not the same.
  4560. *
  4561. * - CL_INVALID_MEM_OBJECT if src_buffer and dst_buffer are not valid
  4562. * buffer objects.
  4563. *
  4564. * - CL_INVALID_VALUE if (src_offset, region) or (dst_offset, region)
  4565. * require accessing elements outside the src_buffer and dst_buffer
  4566. * buffer objects respectively.
  4567. *
  4568. * - CL_MEM_COPY_OVERLAP if src_buffer and dst_buffer are the same buffer
  4569. * object and the source and destination regions overlap.
  4570. *
  4571. * - CL_MISALIGNED_SUB_BUFFER_OFFSET if src_buffer is a sub-buffer object and
  4572. * offset specified when the sub-buffer object is created is not aligned to
  4573. *
  4574. * - CL_DEVICE_MEM_BASE_ADDR_ALIGN value for device associated with queue.
  4575. *
  4576. * - CL_MISALIGNED_SUB_BUFFER_OFFSET if dst_buffer is a sub-buffer object
  4577. * and offset specified when the sub-buffer object is created is not
  4578. * aligned to CL_DEVICE_MEM_BASE_ADDR_ALIGN value for device associated
  4579. * with queue.
  4580. *
  4581. * - CL_MEM_OBJECT_ALLOCATION_FAILURE if there is a failure to allocate
  4582. * memory for data store associated with src_buffer or dst_buffer.
  4583. *
  4584. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources
  4585. * required by the OpenCL implementation on the host.
  4586. *
  4587. * \note In the case that exceptions are enabled and error value
  4588. * other than CL_SUCCESS is generated, then cl::Error exception is
  4589. * generated.
  4590. */
  4591. cl_int enqueueCopyBufferRect(
  4592. const Buffer& src,
  4593. const Buffer& dst,
  4594. const size_t<3>& src_origin,
  4595. const size_t<3>& dst_origin,
  4596. const size_t<3>& region,
  4597. ::size_t src_row_pitch,
  4598. ::size_t src_slice_pitch,
  4599. ::size_t dst_row_pitch,
  4600. ::size_t dst_slice_pitch,
  4601. const VECTOR_CLASS<Event>* events = NULL,
  4602. Event* event = NULL) const
  4603. {
  4604. return detail::errHandler(
  4605. ::clEnqueueCopyBufferRect(
  4606. object_,
  4607. src(),
  4608. dst(),
  4609. (const ::size_t *)src_origin,
  4610. (const ::size_t *)dst_origin,
  4611. (const ::size_t *)region,
  4612. src_row_pitch,
  4613. src_slice_pitch,
  4614. dst_row_pitch,
  4615. dst_slice_pitch,
  4616. (events != NULL) ? (cl_uint) events->size() : 0,
  4617. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  4618. (cl_event*) event),
  4619. __ENQEUE_COPY_BUFFER_RECT_ERR);
  4620. }
  4621. #endif
  4622. /*! \brief Enqueue a command to read from a 2D or 3D image object to host
  4623. * memory
  4624. *
  4625. * \param image refers to a valid 2D or 3D image object.
  4626. *
  4627. * \param blocking indicates if the read is blocking or nonblocking. If
  4628. * \a blocking is CL_TRUE i.e. the read command is blocking,
  4629. * enqueueReadImage does not return until the buffer data has been read and
  4630. * copied into memory pointed to by \a ptr. If \a blocking is CL_FALSE
  4631. * i.e. the read command is non-blocking, enqueueReadImage queues a
  4632. * non-blocking read command and returns. The contents of the buffer that
  4633. * \a ptr points to cannot be used until the read command has completed.
  4634. * The \a event argument returns an event object which can be used to query
  4635. * the execution status of the read command. When the read command has
  4636. * completed, the contents of the buffer that ptr points to can be used by
  4637. * the application
  4638. *
  4639. * \param origin defines the (x, y, z) offset in the image from where to
  4640. * read or write. If image is a 2D image object, the z value given by
  4641. * origin[2] must be 0.
  4642. *
  4643. * \param region defines the (width, height, depth) of the 2D or 3D
  4644. * rectangle being read or written. If image is a 2D image object, the
  4645. * depth value given by region[2] must be 1.
  4646. *
  4647. * \param row_pitch in enqueueReadImage is the length of each row in bytes.
  4648. * This value must be greater than or equal to the element size in bytes
  4649. * width. If \a row_pitch is set to 0, the appropriate row pitch is
  4650. * calculated based on the size of each element in bytes multiplied by
  4651. * width.
  4652. *
  4653. * \param slice_pitch in enqueueReadImage is the size in bytes of the 2D
  4654. * slice of the 3D region of a 3D image being read or written respectively.
  4655. * This must be 0 if image is a 2D image. This value must be greater than
  4656. * or equal to row_pitch * height. If \a slice_pitch is set to 0, the
  4657. * appropriate slice pitch is calculated based on the \a row_pitch *
  4658. * \a height.
  4659. *
  4660. * \param ptr is the pointer to a buffer in host memory where image data is
  4661. * to be read from.
  4662. *
  4663. * \param events specifies events that need to complete before
  4664. * this particular command can be executed. If \a events is NULL, it
  4665. * default then this particular command does not wait on any event to
  4666. * complete.The events specified in \a events act as synchronization
  4667. * points.
  4668. *
  4669. * \param event returns an event object that identifies this particular
  4670. * read command and can be used to query or queue a wait for this
  4671. * particular command to complete. \a event can be NULL in which case it
  4672. * will not be possible for the application to query the status of this
  4673. * command or queue a wait for this command to complete.
  4674. *
  4675. * \return CL_SUCCESS if the function is executed successfully. Otherwise
  4676. * it returns one of the following errors:
  4677. * - CL_INVALID_CONTEXT if the context associated with \a command_queue and
  4678. * \a image are not the same.
  4679. * - CL_INVALID_MEM_OBJECT if \a image is not a valid image object.
  4680. * - CL_INVALID_VALUE if the region being read specified by \a origin and
  4681. * \a region is out of bounds or if \a ptr is a NULL value.
  4682. * - CL_INVALID_VALUE if \a image is a 2D image object and \a origin[2]
  4683. * is not equal to 0 or \a region[2] is not equal to 1 or \a slice_pitch
  4684. * is not equal to 0.
  4685. * - CL_INVALID_EVENT_WAIT_LIST if event objects in \a events are not valid
  4686. * events.
  4687. * - CL_INVALID_VALUE if blocking is CL_FALSE and \a event is NULL.
  4688. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources
  4689. * required by the runtime.
  4690. *
  4691. * \note In the case that exceptions are enabled and error value
  4692. * other than CL_SUCCESS is generated, then cl::Error exception is
  4693. * generated.
  4694. */
  4695. cl_int enqueueReadImage(
  4696. const Image& image,
  4697. cl_bool blocking,
  4698. const size_t<3>& origin,
  4699. const size_t<3>& region,
  4700. ::size_t row_pitch,
  4701. ::size_t slice_pitch,
  4702. void* ptr,
  4703. const VECTOR_CLASS<Event>* events = NULL,
  4704. Event* event = NULL) const
  4705. {
  4706. return detail::errHandler(
  4707. ::clEnqueueReadImage(
  4708. object_, image(), blocking, (const ::size_t *) origin,
  4709. (const ::size_t *) region, row_pitch, slice_pitch, ptr,
  4710. (events != NULL) ? (cl_uint) events->size() : 0,
  4711. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  4712. (cl_event*) event),
  4713. __ENQUEUE_READ_IMAGE_ERR);
  4714. }
  4715. /*! \brief Enqueue a command to write to a 2D or 3D image object from host
  4716. * memory
  4717. *
  4718. * \param image refers to a valid 2D or 3D image object.
  4719. *
  4720. * \param blocking indicates if the write operation is blocking or
  4721. * nonblocking. If blocking is CL_TRUE, the OpenCL implementation copies
  4722. * the data referred to by \a ptr and enqueues the write command in the
  4723. * command-queue. The memory pointed to by ptr can be reused by the
  4724. * application after the enqueueWriteImage call returns. If blocking is
  4725. * CL_FALSE, the OpenCL implementation will use ptr to perform a
  4726. * nonblocking write. As the write is non-blocking the implementation can
  4727. * return immediately. The memory pointed to by ptr cannot be reused by the
  4728. * application after the call returns. The event argument returns an event
  4729. * object which can be used to query the execution status of the write
  4730. * command. When the write command has completed, the memory pointed to by
  4731. * ptr can then be reused by the application.
  4732. *
  4733. * \param origin defines the (x, y, z) offset in the image from where to
  4734. * read or write. If image is a 2D image object, the z value given by
  4735. * origin[2] must be 0.
  4736. *
  4737. * \param region defines the (width, height, depth) of the 2D or 3D
  4738. * rectangle being read or written. If image is a 2D image object, the
  4739. * depth value given by region[2] must be 1.
  4740. *
  4741. * \param input_row_pitch in is the length of each row in bytes.
  4742. * This value must be greater than or equal to the element size in bytes
  4743. * width. If \a input_row_pitch is set to 0, the appropriate row pitch is
  4744. * calculated based on the size of each element in bytes multiplied by
  4745. * width.
  4746. *
  4747. * \param input_slice_pitch is the size
  4748. * in bytes of the 2D slice of the 3D region of a 3D image being read or
  4749. * written respectively. This must be 0 if image is a 2D image. This value
  4750. * must be greater than or equal to input_row_pitch * height. If
  4751. * \a input_slice_pitch is set to 0, the appropriate slice pitch is
  4752. * calculated based on the \a input_row_pitch * \a height.
  4753. *
  4754. * \param ptr is the pointer to a buffer in host memory where image data is
  4755. * to be written to.
  4756. *
  4757. * \param events specifies events that need to complete before
  4758. * this particular command can be executed. If \a events is NULL, it
  4759. * default then this particular command does not wait on any event to
  4760. * complete.The events specified in \a events act as synchronization
  4761. * points.
  4762. *
  4763. * \param event returns an event object that identifies this particular
  4764. * read command and can be used to query or queue a wait for this
  4765. * particular command to complete. \a event can be NULL in which case it
  4766. * will not be possible for the application to query the status of this
  4767. * command or queue a wait for this command to complete.
  4768. *
  4769. * \return CL_SUCCESS if the function is executed successfully. Otherwise
  4770. * it returns one of the following errors:
  4771. * - CL_INVALID_CONTEXT if the context associated with \a command_queue and
  4772. * \a image are not the same.
  4773. * - CL_INVALID_MEM_OBJECT if \a image is not a valid image object.
  4774. * - CL_INVALID_VALUE if the region being written specified by \a origin
  4775. * and \a region is out of bounds or if \a ptr is a NULL value.
  4776. * - CL_INVALID_VALUE if \a image is a 2D image object and \a origin[2]
  4777. * is not equal to 0 or \a region[2] is not equal to 1 or \a slice_pitch
  4778. * is not equal to 0.
  4779. * - CL_INVALID_EVENT_WAIT_LIST if event objects in \a events are not valid
  4780. * events.
  4781. * - CL_INVALID_VALUE if blocking is CL_FALSE and \a event is NULL.
  4782. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources
  4783. * required by the runtime.
  4784. *
  4785. * \note In the case that exceptions are enabled and error value
  4786. * other than CL_SUCCESS is generated, then cl::Error exception is
  4787. * generated.
  4788. */
  4789. cl_int enqueueWriteImage(
  4790. const Image& image,
  4791. cl_bool blocking,
  4792. const size_t<3>& origin,
  4793. const size_t<3>& region,
  4794. ::size_t row_pitch,
  4795. ::size_t slice_pitch,
  4796. void* ptr,
  4797. const VECTOR_CLASS<Event>* events = NULL,
  4798. Event* event = NULL) const
  4799. {
  4800. return detail::errHandler(
  4801. ::clEnqueueWriteImage(
  4802. object_, image(), blocking, (const ::size_t *) origin,
  4803. (const ::size_t *) region, row_pitch, slice_pitch, ptr,
  4804. (events != NULL) ? (cl_uint) events->size() : 0,
  4805. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  4806. (cl_event*) event),
  4807. __ENQUEUE_WRITE_IMAGE_ERR);
  4808. }
  4809. /*! \brief Enqueue a command to copy image objects.
  4810. *
  4811. * \param src is the source image object.
  4812. *
  4813. * \param dst is the destination image object.
  4814. *
  4815. * \param src_origin defines the starting (x, y, z) location in
  4816. * \a src from where to start the data copy. If \a src is a
  4817. * 2D image object, the z value given by \a src_origin[2] must be 0.
  4818. *
  4819. * \param dst_origin defines the starting (x, y, z) location in \a
  4820. * dst from where to start the data copy. If \a dst is a
  4821. * 2D image object, the z value given by \a dst_origin[2] must be 0.
  4822. *
  4823. * \param region defines the (width, height, depth) of the 2D or 3D
  4824. * rectangle to copy. If \a src or \a dst is a 2D image object,
  4825. * the depth value given by \a region[2] must be 1.
  4826. *
  4827. * \param events specifies events that need to complete before
  4828. * this particular command can be executed. If \a events is NULL, it
  4829. * default then this particular command does not wait on any event to
  4830. * complete.The events specified in \a events act as synchronization
  4831. * points.
  4832. *
  4833. * \param event returns an event object that identifies this particular
  4834. * copy command and can be used to query or queue a wait for this
  4835. * particular command to complete. \a event can be NULL, its default, in
  4836. * which case it will not be possible for the application to query the
  4837. * status of this command or queue a wait for this command to complete.
  4838. * enqueueBarrier can be used instead. It is currently a requirement that
  4839. * the \a src_image and \a dst_image image memory objects for
  4840. * enqueueCopyImage must have the exact image format (i.e. channel order
  4841. * and channel data type must match).
  4842. *
  4843. * \return CL_SUCCESS if the function is executed successfully. Otherwise
  4844. * it returns one of the following errors:
  4845. * - CL_INVALID_CONTEXT if the context associated with \a command-queue,
  4846. * \a src and \a dst are not the same.
  4847. * - CL_INVALID_MEM_OBJECT if \a src and \a dst are not valid
  4848. * image objects.
  4849. * - CL_IMAGE_FORMAT_MISMATCH if src and dst do not use the
  4850. * same image format.
  4851. * - CL_INVALID_VALUE if the 2D or 3D rectangular region specified by
  4852. * \a src_origin and \a src_origin + \a region refers to a region outside
  4853. * \a src, or if the 2D or 3D rectangular region specified by
  4854. * \a dst_origin and \a dst_origin + \a region refers to a region outside
  4855. * \a dst.
  4856. * - CL_INVALID_VALUE if \a src is a 2D image object and \a origin[2]
  4857. * is not equal to 0 or \a region[2] is not equal to 1.
  4858. * - CL_INVALID_VALUE if \a dst is a 2D image object and \a
  4859. * dst_origin[2] is not equal to 0 or \a region[2] is not equal to 1.
  4860. * - CL_INVALID_EVENT_WAIT_LIST if event objects in \a events are not valid
  4861. * events.
  4862. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources
  4863. * required by the runtime.
  4864. *
  4865. * \note In the case that exceptions are enabled and error value
  4866. * other than CL_SUCCESS is generated, then cl::Error exception is
  4867. * generated.
  4868. */
  4869. cl_int enqueueCopyImage(
  4870. const Image& src,
  4871. const Image& dst,
  4872. const size_t<3>& src_origin,
  4873. const size_t<3>& dst_origin,
  4874. const size_t<3>& region,
  4875. const VECTOR_CLASS<Event>* events = NULL,
  4876. Event* event = NULL) const
  4877. {
  4878. return detail::errHandler(
  4879. ::clEnqueueCopyImage(
  4880. object_, src(), dst(), (const ::size_t *) src_origin,
  4881. (const ::size_t *)dst_origin, (const ::size_t *) region,
  4882. (events != NULL) ? (cl_uint) events->size() : 0,
  4883. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  4884. (cl_event*) event),
  4885. __ENQUEUE_COPY_IMAGE_ERR);
  4886. }
  4887. /*! \brief Enqueue a command to copy an image object to a buffer object.
  4888. *
  4889. * \param src is a valid image object.
  4890. *
  4891. * \param dst is a valid buffer object.
  4892. *
  4893. * \param src_origin defines the (x, y, z) offset in the image from where
  4894. * to copy. If \a src is a 2D image object, the z value given by
  4895. * \a src_origin[2] must be 0.
  4896. *
  4897. * \param region defines the (width, height, depth) of the 2D or 3D
  4898. * rectangle to copy. If \a src_image is a 2D image object, the depth value
  4899. * given by \a region[2] must be 1.
  4900. *
  4901. * \param dst refers to the offset where to begin copying data in
  4902. * \a dst. The size in bytes of the region to be copied referred to
  4903. * as \a dst_cb is computed as width * height * depth * bytes/image element
  4904. * if \a src is a 3D image object and is computed as
  4905. * width * height * bytes/image element if \a src is a 2D image
  4906. * object.
  4907. *
  4908. * \param events specifies events that need to complete before
  4909. * this particular command can be executed. If \a events is NULL, it
  4910. * default then this particular command does not wait on any event to
  4911. * complete.The events specified in \a events act as synchronization
  4912. * points.
  4913. *
  4914. * \param event returns an event object that identifies this particular
  4915. * copy command and can be used to query or queue a wait for this
  4916. * particular command to complete. \a event can be NULL, its default value,
  4917. * in which case it will not be possible for the application to query the
  4918. * status of this command or queue a wait for this command to complete.
  4919. * enqueueBarrier can be used instead.
  4920. *
  4921. * \return CL_SUCCESS if the function is executed successfully. Otherwise
  4922. * it returns one of the following errors:
  4923. * - CL_INVALID_CONTEXT if the context associated with \a command-queue,
  4924. * \a src and \a dst_buffer are not the same.
  4925. * - CL_INVALID_MEM_OBJECT if \a src_image is not a valid image object or
  4926. * \a dst is not a valid buffer object.
  4927. * - CL_INVALID_VALUE if the 2D or 3D rectangular region specified by
  4928. * \a src_origin and \a src_origin + \a region refers to a region outside
  4929. * \a src, or if the region specified by \a dst_offset and
  4930. * \a dst_offset + \a dst_cb to a region outside \a dst.
  4931. * - CL_INVALID_VALUE if \a src is a 2D image object and \a
  4932. * src_origin[2] is not equal to 0 or \a region[2] is not equal to 1.
  4933. * - CL_INVALID_EVENT_WAIT_LIST if event objects in \a events are not
  4934. * valid events.
  4935. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources
  4936. * required by the runtime.
  4937. *
  4938. * \note In the case that exceptions are enabled and error value
  4939. * other than CL_SUCCESS is generated, then cl::Error exception is
  4940. * generated.
  4941. */
  4942. cl_int enqueueCopyImageToBuffer(
  4943. const Image& src,
  4944. const Buffer& dst,
  4945. const size_t<3>& src_origin,
  4946. const size_t<3>& region,
  4947. ::size_t dst_offset,
  4948. const VECTOR_CLASS<Event>* events = NULL,
  4949. Event* event = NULL) const
  4950. {
  4951. return detail::errHandler(
  4952. ::clEnqueueCopyImageToBuffer(
  4953. object_, src(), dst(), (const ::size_t *) src_origin,
  4954. (const ::size_t *) region, dst_offset,
  4955. (events != NULL) ? (cl_uint) events->size() : 0,
  4956. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  4957. (cl_event*) event),
  4958. __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR);
  4959. }
  4960. /*! \brief Enqueue a command to copy a buffer object to an image object.
  4961. *
  4962. * \param src is a valid buffer object.
  4963. *
  4964. * \param dst is a valid image object.
  4965. *
  4966. * \param src_offset refers to the offset where to begin copying data in
  4967. * \a src.
  4968. *
  4969. * \param dst_origin defines the (x, y, z) offset in the image from where
  4970. * to copy. If \a dst is a 2D image object, the z value given by
  4971. * \a dst_origin[2] must be 0.
  4972. *
  4973. * \param region defines the (width, height, depth) of the 2D or 3D
  4974. * rectangle to copy. If dst is a 2D image object, the depth value
  4975. * given by \a region[2] must be 1. The size in bytes of the region to be
  4976. * copied from \a src referred to as \a src_cb is computed as
  4977. * width * height * depth * bytes/image element if \a dst is a 3D image
  4978. * object and is computed as width * height * bytes/image element if
  4979. * \a dst is a 2D image object.
  4980. *
  4981. * \param events specifies events that need to complete before this
  4982. * particular command can be executed. If \a events is NULL, then
  4983. * this particular command does not wait on any event to complete.
  4984. * The events specified in \a events act as synchronization points.
  4985. *
  4986. * \param event returns an event object that identifies this particular
  4987. * copy command and can be used to query or queue a wait for this
  4988. * particular command to complete. \a event can be NULL, its default value,
  4989. * in which case it will not be possible for the application to query the
  4990. * status of this command or queue a wait for this command to complete.
  4991. * enqueueBarrier can be used instead.
  4992. *
  4993. * \return CL_SUCCESS if the function is executed successfully. Otherwise
  4994. * it returns one of the following errors:
  4995. * - CL_INVALID_CONTEXT if the context associated with \a command_queue,
  4996. * \a src and \a dst are not the same.
  4997. * - CL_INVALID_MEM_OBJECT if \a src_buffer is not a valid buffer object or
  4998. * \a dst is not a valid image object.
  4999. * - CL_INVALID_VALUE if the 2D or 3D rectangular region specified by
  5000. * \a dst_origin and \a dst_origin + \a region refers to a region outside
  5001. * \a dst, or if the region specified by \a src_offset and
  5002. * \a src_offset + \a src_cb to a region outside \a src.
  5003. * - CL_INVALID_VALUE if event objects in \a events are not valid events.
  5004. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources
  5005. * required by the runtime
  5006. *
  5007. * \note In the case that exceptions are enabled and error value
  5008. * other than CL_SUCCESS is generated, then cl::Error exception is
  5009. * generated.
  5010. */
  5011. cl_int enqueueCopyBufferToImage(
  5012. const Buffer& src,
  5013. const Image& dst,
  5014. ::size_t src_offset,
  5015. const size_t<3>& dst_origin,
  5016. const size_t<3>& region,
  5017. const VECTOR_CLASS<Event>* events = NULL,
  5018. Event* event = NULL) const
  5019. {
  5020. return detail::errHandler(
  5021. ::clEnqueueCopyBufferToImage(
  5022. object_, src(), dst(), src_offset,
  5023. (const ::size_t *) dst_origin, (const ::size_t *) region,
  5024. (events != NULL) ? (cl_uint) events->size() : 0,
  5025. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  5026. (cl_event*) event),
  5027. __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR);
  5028. }
  5029. /*! \brief Enqueue a command to map a region of a buffer object into the
  5030. * host address.
  5031. *
  5032. * \param blocking indicates if the map operation is blocking or
  5033. * non-blocking. If \a blocking is CL_TRUE, enqueueMapBuffer does not
  5034. * return until the specified region in \a buffer can be mapped. If
  5035. * \a blocking is CL_FALSE i.e. map operation is non-blocking, the pointer
  5036. * to the mapped region returned by enqueueMapBuffer cannot be used until
  5037. * the map command has completed. The event argument returns an event
  5038. * object which can be used to query the execution status of the map
  5039. * command. When the map command is completed, the application can access
  5040. * the contents of the mapped region using the pointer returned by
  5041. * enqueueMapBuffer.
  5042. *
  5043. * \param map_flags is a bit-field and can be set to CL_MAP_READ to
  5044. * indicate that the region specified by (\a offset, \a size) in the buffer
  5045. * object is being mapped for reading, and/or CL_MAP_WRITE to indicate that
  5046. * the region specified by (\a offset, \a size) in the buffer object is
  5047. * being mapped for writing.
  5048. *
  5049. * \param buffer is a valid buffer object. The OpenCL context associated
  5050. * with \a command-queue and \a buffer must be the same.
  5051. *
  5052. * \param offset is the offset in bytes of the region in the buffer object
  5053. * that is being mapped
  5054. *
  5055. * \param size is the size in bytes of the region in the buffer object that
  5056. * is being mapped.
  5057. *
  5058. * \param events specifies events that need to complete before this
  5059. * particular command can be executed. If \a events is NULL, its default
  5060. * value, then this particular command does not wait on any event to
  5061. * complete. The events specified in \a event_wait_list act as
  5062. * synchronization points.
  5063. *
  5064. * \param event returns an event object that identifies this particular
  5065. * command and can be used to query or queue a wait for this particular
  5066. * command to complete. \a event can be NULL in which case it will not be
  5067. * possible for the application to query the status of this command or
  5068. * queue a wait for this command to complete. enqueueBarrier can be used
  5069. * instead.
  5070. *
  5071. * \param err will return an appropriate error code. If \a err
  5072. * is NULL, its default value, no error code is returned.
  5073. *
  5074. * \return A pointer to the mapped region if buffer is a memory object
  5075. * created with clCreateBuffer and the region specified by (offset , cb)
  5076. * is a valid region in the buffer object and is successfully mapped into
  5077. * the host address space . The \a errcode_ret is set to CL_SUCCESS.
  5078. * A NULL pointer is returned otherwise with one of the following error
  5079. * values returned in \a errcode_ret:
  5080. * - CL_INVALID_CONTEXT if context associated with \a command-queue and
  5081. * \a buffer are not the same.
  5082. * - CL_INVALID_MEM_OBJECT if \a buffer is not a valid buffer object.
  5083. * - CL_INVALID_VALUE if region being mapped given by (\a offset, \a size)
  5084. * is out of bounds or if values specified in \a map_flags are not valid.
  5085. * - CL_INVALID_EVENT_WAIT_LIST if event objects in \a events are not
  5086. * valid events.
  5087. * - CL_MEM_O BJECT_MAP_FAILURE if there is a failure to map the
  5088. * specified region in the host address space.
  5089. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources
  5090. * required by the runtime.
  5091. *
  5092. * The pointer returned maps a region starting at \a offset and is at least
  5093. * \a size bytes in size. The result of a memory access outside this region
  5094. * is undefined.
  5095. *
  5096. * \note In the case that exceptions are enabled and error value
  5097. * other than CL_SUCCESS is generated, then cl::Error exception is
  5098. * generated.
  5099. */
  5100. void* enqueueMapBuffer(
  5101. const Buffer& buffer,
  5102. cl_bool blocking,
  5103. cl_map_flags flags,
  5104. ::size_t offset,
  5105. ::size_t size,
  5106. const VECTOR_CLASS<Event>* events = NULL,
  5107. Event* event = NULL,
  5108. cl_int* err = NULL) const
  5109. {
  5110. cl_int error;
  5111. void * result = ::clEnqueueMapBuffer(
  5112. object_, buffer(), blocking, flags, offset, size,
  5113. (events != NULL) ? (cl_uint) events->size() : 0,
  5114. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  5115. (cl_event*) event,
  5116. &error);
  5117. detail::errHandler(error, __ENQUEUE_MAP_BUFFER_ERR);
  5118. if (err != NULL) {
  5119. *err = error;
  5120. }
  5121. return result;
  5122. }
  5123. /*! \brief Enqueue a command to map a region in an image object given into
  5124. * the host address.
  5125. *
  5126. * \param image is a valid image object. The OpenCL context associated with
  5127. * the command-queue and \a image must be the same.
  5128. *
  5129. * \param blocking indicates if the map operation is blocking or
  5130. * non-blocking. If \a blocking is CL_TRUE, enqueueMapImage does not
  5131. * return until the specified region in image is mapped. If \a blocking is
  5132. * CL_FALSE i.e. map operation is non-blocking, the pointer to the mapped
  5133. * region returned by enqueueMapImage cannot be used until the map command
  5134. * has completed. The event argument returns an event object which can be
  5135. * used to query the execution status of the map command. When the map
  5136. * command is completed, the application can access the contents of the
  5137. * mapped region using the pointer returned by enqueueMapImage.
  5138. *
  5139. * \param flags is a bit-field and can be set to CL_MAP_READ to indicate
  5140. * that the region specified by (\a origin, \a region) in the image object
  5141. * is being mapped for reading, and/or CL_MAP_WRITE to indicate that the
  5142. * region specified by (\a origin, \a region) in the image object is being
  5143. * mapped for writing.
  5144. *
  5145. * \param origin define the (x, y, z) offset of the 2D or 3D rectangle
  5146. * region that is to be mapped. If image is a 2D image object, the z value
  5147. * given by \a origin[2] must be 0.
  5148. *
  5149. * \param region define the (width, height, depth) of the 2D or 3D
  5150. * rectangle region that is to be mapped. If image is a 2D image object,
  5151. * the depth value given by \a region[2] must be 1.
  5152. *
  5153. * \param row_pitch returns the scan-line pitch in bytes for the mapped
  5154. * region. This must be a non- NULL value.
  5155. *
  5156. * \param slice_pitch returns the size in bytes of each 2D slice for the
  5157. * mapped region. For a 2D image this argument is ignored. For a 3D image
  5158. * this must be a non-NULL value.
  5159. *
  5160. * \param events specifies events that need to complete before
  5161. * enqueueMapImage can be executed. If \a events is NULL, then
  5162. * enqueueMapImage does not wait on any event to complete. The events
  5163. * specified in \a events act as synchronization points.
  5164. *
  5165. * \param event returns an event object that identifies this particular
  5166. * command and can be used to query or queue a wait for this particular
  5167. * command to complete. \a event can be NULL, its default value, in which
  5168. * case it will not be possible for the application to query the status of
  5169. * this command or queue a wait for this command to complete.
  5170. * enqueueBarrier can be used instead.
  5171. *
  5172. * \param err will return an appropriate error code. If \a err
  5173. * is NULL, its default value, o error code is returned.
  5174. *
  5175. * \return A pointer to the mapped region if image is a memory object
  5176. * created with clCreateImage {2D|3D}, and the 2D or 3D rectangle
  5177. * specified by origin and region is a valid region in the image object
  5178. * and can be mapped into the host address space.
  5179. * The \a err is set to CL_SUCCESS. A NULL pointer is returned
  5180. * otherwise with one of the following error values returned in \a err:
  5181. * - CL_INVALID_CONTEXT if context associated with \a command_queue and
  5182. * \a image are not the same.
  5183. * - CL_INVALID_MEM_OBJECT if \a image is not a valid image object.
  5184. * - CL_INVALID_VALUE if region being mapped given by
  5185. * (\a origin, \a origin + \a region) is out of bounds or if values
  5186. * specified in \a map_flags are not valid.
  5187. * - CL_INVALID_VALUE if \a image is a 2D image object and \a origin[2]
  5188. * is not equal to 0 or \a region[2] is not equal to 1.
  5189. * - CL_INVALID_VALUE if \a row_pitch is NULL.
  5190. * - CL_INVALID_VALUE if \a image is a 3D image object and \a slice_pitch
  5191. * is NULL.
  5192. * - CL_INVALID_EVENT_WAIT_LIST if event objects in \a events are not
  5193. * valid events.
  5194. * - CL_MEM_OBJECT_MAP_FAILURE if there is a failure to map the specified
  5195. * region in the host address space.
  5196. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources
  5197. * required by the runtime.
  5198. *
  5199. * The pointer returned maps a 2D or 3D region starting at origin and is
  5200. * at least (\a row_pitch * \a region[1] + \a region[0]) pixels in size
  5201. * for a 2D image, and is at least (\a slice_pitch * \a region[2] +
  5202. * \a row_pitch * \a region[1] + \a region[0]) pixels in size for a 3D
  5203. * image. The result of a memory access outside this region is undefined.
  5204. *
  5205. * \note In the case that exceptions are enabled and error value
  5206. * other than CL_SUCCESS is generated, then cl::Error exception is
  5207. * generated.
  5208. */
  5209. void* enqueueMapImage(
  5210. const Image& buffer,
  5211. cl_bool blocking,
  5212. cl_map_flags flags,
  5213. const size_t<3>& origin,
  5214. const size_t<3>& region,
  5215. ::size_t * row_pitch,
  5216. ::size_t * slice_pitch,
  5217. const VECTOR_CLASS<Event>* events = NULL,
  5218. Event* event = NULL,
  5219. cl_int* err = NULL) const
  5220. {
  5221. cl_int error;
  5222. void * result = ::clEnqueueMapImage(
  5223. object_, buffer(), blocking, flags,
  5224. (const ::size_t *) origin, (const ::size_t *) region,
  5225. row_pitch, slice_pitch,
  5226. (events != NULL) ? (cl_uint) events->size() : 0,
  5227. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  5228. (cl_event*) event,
  5229. &error);
  5230. detail::errHandler(error, __ENQUEUE_MAP_IMAGE_ERR);
  5231. if (err != NULL) {
  5232. *err = error;
  5233. }
  5234. return result;
  5235. }
  5236. /*! \brief Enqueue a command to unmap a previously mapped region of a memory
  5237. * object.
  5238. *
  5239. * Reads or writes from the host using the pointer returned by
  5240. * enqueueMapBuffer or enqueueMapImage are considered to be complete.
  5241. *
  5242. * \param memobj is a valid memory object. The OpenCL context associated
  5243. * with the command-queue and \a memobj must be the same.
  5244. *
  5245. * \param mapped_ptr is the host address returned by a previous call to
  5246. * enqueueMapBuffer or enqueueMapImage for \a memobj.
  5247. *
  5248. *
  5249. * \param events specifies events that need to complete before
  5250. * enqueueUnmapMemObject can be executed. If \a events is NULL,
  5251. * then enqueueUnmapMemObject does not wait on any event to complete. The
  5252. * events specified in \a event_wait_list act as synchronization points.
  5253. *
  5254. * \param event returns an event object that identifies this particular
  5255. * command and can be used to query or queue a wait for this particular
  5256. * command to complete. \a event can be NULL, its default value, in which
  5257. * case it will not be possible for the application to query the status
  5258. * of this command or queue a wait for this command to complete.
  5259. * enqueueBarrier can be used instead.
  5260. *
  5261. * \return One of the following values:
  5262. * - CL_SUCCESS if the function is executed successfully.
  5263. * - CL_INVALID_MEM_OBJECT if \a memobj is not a valid memory object.
  5264. * - CL_INVALID_VALUE if \a mapped_ptr is not a valid pointer returned by
  5265. * enqueueMapBuffer or enqueueMapImage for \a memobj.
  5266. * - CL_INVALID_EVENT_WAIT_LIST if event objects in \a events are not
  5267. * valid events.
  5268. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources
  5269. * required by the runtime.
  5270. * - CL_INVALID_CONTEXT if context associated with the command-queue and
  5271. * \a memobj are not the same.
  5272. *
  5273. * enqueueMapBuffer and enqueueMapImage increments the mapped count of the
  5274. * memory object. Multiple calls to enqueueMapBuffer or enqueueMapImage on
  5275. * the same memory object will increment this mapped count by appropriate
  5276. * number of calls. enqueueUnmapMemObject decrements the mapped count of the
  5277. * memory object. enqueueMapBuffer and enqueueMapImage act as
  5278. * synchronization points for a region of the memory object being mapped.
  5279. *
  5280. * \note In the case that exceptions are enabled and error value
  5281. * other than CL_SUCCESS is generated, then cl::Error exception is
  5282. * generated.
  5283. */
  5284. cl_int enqueueUnmapMemObject(
  5285. const Memory& memory,
  5286. void* mapped_ptr,
  5287. const VECTOR_CLASS<Event>* events = NULL,
  5288. Event* event = NULL) const
  5289. {
  5290. return detail::errHandler(
  5291. ::clEnqueueUnmapMemObject(
  5292. object_, memory(), mapped_ptr,
  5293. (events != NULL) ? (cl_uint) events->size() : 0,
  5294. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  5295. (cl_event*) event),
  5296. __ENQUEUE_UNMAP_MEM_OBJECT_ERR);
  5297. }
  5298. /*! \brief Enqueue a command to execute a kernel on a device.
  5299. *
  5300. * \param kernel is a valid kernel object. The OpenCL context associated
  5301. * with \a kernel and \a command-queue must be the same.
  5302. *
  5303. * \param offset must currently be a NullRange value. In a future
  5304. * revision of OpenCL, \a global_work_offset can be used to specify an
  5305. * array of \a work_dim unsigned values that describe the offset used to
  5306. * calculate the global ID of a work-item instead of having the global IDs
  5307. * always start at offset (0, 0, 0).
  5308. *
  5309. * \param global describes the number of global work-items in will execute
  5310. * the kernel function. The total number of global
  5311. * work-items is computed as global_work_size[0] * ...
  5312. * * global_work_size[work_dim - 1].
  5313. *
  5314. * \param local describes the number of work-items that make up a
  5315. * work-group (also referred to as the size of the work-group) that
  5316. * will execute the kernel specified by kernel.
  5317. *
  5318. * \param events specifies events that need to complete before this
  5319. * particular command can be executed. If \a events is NULL, its
  5320. * default, or size zero then this particular command does not wait on
  5321. * any event to complete. The events specified in \a event_wait_list act as
  5322. * synchronization points.
  5323. *
  5324. * \param event returns an event object that identifies this particular
  5325. * kernel execution instance. Event objects are unique and can be used to
  5326. * identify a particular kernel execution instance later on. If \a event
  5327. * is NULL, its default value, no event will be created for this kernel
  5328. * execution instance and therefore it will not be possible for the
  5329. * application to query or queue a wait for this particular kernel
  5330. * execution instance.
  5331. *
  5332. * The total number of work-items in a work-group is computed as
  5333. * local_work_size[0] * ... * local_work_size[work_dim - 1].
  5334. * The total number of work-items in the work-group must be less than or
  5335. * equal to the CL_DEVICE_MAX_WORK_GROUP_SIZE. The explicitly specified
  5336. * \a local_work_size will be used to determine how to break the global
  5337. * work-items specified by global_work_size into appropriate work-group
  5338. * instances. If \a local_work_size is specified, the values specified in
  5339. * \a global_work_size[0], ..., global_work_size[work_dim - 1] must be
  5340. * evenly divisable by the corresponding values specified in
  5341. * \a local_work_size[0],..., local_work_size[work_dim - 1].
  5342. * \a local_work_size can also be a NULL value in which case the OpenCL
  5343. * implementation will determine how to be break the global work-items
  5344. * into appropriate work-groups.
  5345. *
  5346. * If \a local is NullRange and no work-group size is specified when the
  5347. * kernel is compiled, the OpenCL implementation will determine how to
  5348. * break the global work-items specified by \a global into appropriate
  5349. * work-group instances. The work-group size to be used for kernel can also
  5350. * be specified in the program source using the
  5351. * __attribute__((reqd_work_group_size(X, Y, Z))) qualifier. In this case
  5352. * the size of work group specified by \a local_work_size must match the
  5353. * value specified by the \a reqd_work_group_size attribute qualifier.
  5354. *
  5355. * These work-group instances are executed in parallel across multiple
  5356. * compute units or concurrently on the same compute unit. Each work-item
  5357. * is uniquely identified by a global identifier. The global ID, which
  5358. * can be read inside the kernel is computed using the value given by
  5359. * \a global_work_size and \a global_work_offset.
  5360. *
  5361. * \return One of the following values:
  5362. *
  5363. * - CL_SUCCESS if the kernel execution was successfully queued.
  5364. * - CL_INVALID_PROGRAM_EXECUTABLE if there is no successfully built
  5365. * program executable available for device associated with command-queue.
  5366. * - CL_INVALID_COMMAND_QUEUE if command-queue is not a valid
  5367. * command-queue.
  5368. * - CL_INVALID_KERNEL if \a kernel is not a valid kernel object.
  5369. * - CL_INVALID_KERNEL_ARGS if the kernel argument values have not been
  5370. * specified or are not valid for the device on which kernel will be
  5371. * executed.
  5372. * - CL_INVALID_WORK_DIMENSION if \a work_dim is not a valid value
  5373. * (i.e. a value between 1 and 3).
  5374. *
  5375. * - CL_INVALID_WORK_GROUP_SIZE if \a local is specified and number
  5376. * of workitems specified by \a global is not evenly divisable by
  5377. * size of work-given by \a local_work_size or does not match the
  5378. * work-group size specified for kernel using the
  5379. * __attribute__((reqd_work_group_size(X, Y, Z))) qualifier in program
  5380. * source.
  5381. *
  5382. * - CL_INVALID_GLOBAL_OFFSET if \a offset is not NullRange.
  5383. *
  5384. * - CL_OUT_OF_RESOURCES if there is a failure to queue the execution
  5385. * instance of \a kernel on the command-queue because of insufficient
  5386. * resources needed to execute the kernel. For example, the explicitly
  5387. * specified \a local_work_dim in range causes a failure to execute the
  5388. * kernel because of insufficient resources such as registers or local
  5389. * memory. Another example would be the number of read-only image args
  5390. * used in kernel exceed the CL_DEVICE_MAX_READ_IMAGE_ARGS value for
  5391. * device or the number of write-only image args used in kernel exceed
  5392. * the CL_DEVICE_MAX_WRITE_IMAGE_ARGS value for device or the number of
  5393. * samplers used in kernel exceed CL_DEVICE_MAX_SAMPLERS for device.
  5394. *
  5395. * - CL_MEM_OBJECT_ALLOCATION_FAILURE if there is a failure to allocate
  5396. * memory for image or buffer objects specified as arguments to kernel.
  5397. *
  5398. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources
  5399. * required by the runtime.
  5400. *
  5401. * \note In the case that exceptions are enabled and error value
  5402. * other than CL_SUCCESS is generated, then cl::Error exception is
  5403. * generated.
  5404. */
  5405. cl_int enqueueNDRangeKernel(
  5406. const Kernel& kernel,
  5407. const NDRange& offset,
  5408. const NDRange& global,
  5409. const NDRange& local,
  5410. const VECTOR_CLASS<Event>* events = NULL,
  5411. Event* event = NULL) const
  5412. {
  5413. return detail::errHandler(
  5414. ::clEnqueueNDRangeKernel(
  5415. object_, kernel(), (cl_uint) global.dimensions(),
  5416. offset.dimensions() != 0 ? (const ::size_t*) offset : NULL,
  5417. (const ::size_t*) global,
  5418. local.dimensions() != 0 ? (const ::size_t*) local : NULL,
  5419. (events != NULL) ? (cl_uint) events->size() : 0,
  5420. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  5421. (cl_event*) event),
  5422. __ENQUEUE_NDRANGE_KERNEL_ERR);
  5423. }
  5424. /*! \brief Enqueue a command to execute a kernel on a device.
  5425. * The kernel is executed using a single work-item.
  5426. *
  5427. * \param kernel is a valid kernel object. The OpenCL context associated
  5428. * with \a kernel and \a command-queue must be the same.
  5429. *
  5430. * \param events specifies the list of events that need to complete before
  5431. * this particular command can be executed. If \a events is NULL, its
  5432. * default value, then this particular command does not wait on any event
  5433. * to complete. The events specified in \a events act as
  5434. * synchronization points.
  5435. *
  5436. * \param event returns an event object that identifies this particular
  5437. * kernel execution instance. Event objects are unique and can be used to
  5438. * identify a particular kernel execution instance later on.
  5439. * If \a event is NULL, its default value, no event will be created for
  5440. * this kernel execution instance and therefore it will not be possible for
  5441. * the application to query or queue a wait for this particular kernel
  5442. * execution instance.
  5443. *
  5444. * \return One of the following values:
  5445. * - CL_SUCCESS if the kernel execution was successfully queued.
  5446. * - CL_INVALID_PROGRAM_EXECUTABLE if there is no successfully built
  5447. * program executable available for device associated with command-queue.
  5448. * - CL_INVALID_KERNEL if \a kernel is not a valid kernel object.
  5449. * - CL_INVALID_KERNEL_ARGS if the kernel argument values have not been
  5450. * specified or are not valid for the device on which kernel will be
  5451. * executed.
  5452. * - CL_INVALID_WORK_GROUP_SIZE if a work-group size is specified for
  5453. * kernel using the __attribute__((reqd_work_group_size(X, Y, Z)))
  5454. * qualifier in program source and is not (1, 1, 1).
  5455. * - CL_OUT_OF_RESOURCES if there is a failure to queue the execution
  5456. * instance of kernel on the command-queue because of insufficient
  5457. * resources needed to execute the kernel. For example, the explicitly
  5458. * specified \a local_work_dim in range causes a failure to execute the
  5459. * kernel because of insufficient resources such as registers or local
  5460. * memory. Another example would be the number of read-only image args
  5461. * used in kernel exceed the CL_DEVICE_MAX_READ_IMAGE_ARGS value for
  5462. * device or the number of write-only image args used in kernel exceed
  5463. * the CL_DEVICE_MAX_WRITE_IMAGE_ARGS value for device or the number of
  5464. * samplers used in kernel exceed CL_DEVICE_MAX_SAMPLERS for device.
  5465. * - CL_MEM_OBJECT_ALLOCATION_FAILURE if there is a failure to allocate
  5466. * memory for image or buffer objects specified as arguments to kernel.
  5467. * - CL_INVALID_EVENT_WAIT_LIST if event objects in \a events are not valid
  5468. * events.
  5469. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources
  5470. * required by the runtime.
  5471. *
  5472. * \note In the case that exceptions are enabled and error value
  5473. * other than CL_SUCCESS is generated, then cl::Error exception is
  5474. * generated.
  5475. */
  5476. cl_int enqueueTask(
  5477. const Kernel& kernel,
  5478. const VECTOR_CLASS<Event>* events = NULL,
  5479. Event* event = NULL) const
  5480. {
  5481. return detail::errHandler(
  5482. ::clEnqueueTask(
  5483. object_, kernel(),
  5484. (events != NULL) ? (cl_uint) events->size() : 0,
  5485. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  5486. (cl_event*) event),
  5487. __ENQUEUE_TASK_ERR);
  5488. }
  5489. /*! \brief Enqueue a command to execute a native C/C++ function not compiled
  5490. * using the OpenCL compiler.
  5491. *
  5492. * A native user function can only be executed on a command-queue
  5493. * created on a device that has CL_EXEC_NATIVE_KERNEL capability
  5494. * set in CL_DEVICE_EXECUTION_CAPABILITIES.
  5495. *
  5496. * \param userFptr is a pointer to a host-callable user function.
  5497. *
  5498. * \param args a pair containing a a pointer to the args list that
  5499. * \a user_func should be called with and the size in bytes of the args
  5500. * list that args points to. Size number of bytes of the data pointed to
  5501. * by args will be copied and a pointer to this copied region will be
  5502. * passed to \a userFptr. The copy needs to be done because the memory
  5503. * objects (cl_mem values) that args may contain need to be modified and
  5504. * replaced by appropriate pointers to global memory. When
  5505. * clEnqueueNativeKernel returns, the memory region pointed to by
  5506. * args can be reused by the application.
  5507. *
  5508. * \param mem_objects is a list of valid memory objects, whose size > 0
  5509. * implies that each element is a pointer to appropriate locations
  5510. * that args points to where memory object handles (cl_mem values) are
  5511. * stored. Before the user function is executed, the memory object handles
  5512. * are replaced by pointers to global memory.
  5513. *
  5514. * \param events as described in enqueueNDRangeKernel.
  5515. *
  5516. * \param event returns an event objects that identifies this particular
  5517. * kernel execution instance. Event objects are unique and can be used to
  5518. * identify a particular kernel execution instance later on. If \a event
  5519. * is NULL, its default, no event will be created for this kernel execution
  5520. * instance and therefore it will not be possible for the application to
  5521. * query or queue a wait for this particular kernel execution instance.
  5522. *
  5523. * \return One of the following values:
  5524. * - CL_SUCCESS if the user function execution instance was successfully
  5525. * queued
  5526. * - CL_INVALID_VALUE if \a user_func is NULL.
  5527. * - CL_INVALID_OPERATION if device cannot execute the native kernel.
  5528. * - CL_INVALID_MEM_OBJECT if one or more memory objects specified in
  5529. * \a mem_list are not valid or are not buffer objects.
  5530. * - CL_OUT_OF_RESOURCES if there is a failure to queue the execution
  5531. * instance of kernel on the command-queue because of insufficient
  5532. * resources needed to execute the kernel.
  5533. * - CL_MEM_OBJECT_ALLOCATION_FAILURE if there is a failure to allocate
  5534. * memory for buffer objects specified as arguments to \a kernel.
  5535. * - CL_INVALID_EVENT_WAIT_LIST if event objects in \a events are not valid
  5536. * events.
  5537. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources
  5538. * required by the runtime.
  5539. *
  5540. * \note In the case that exceptions are enabled and error value
  5541. * other than CL_SUCCESS is generated, then cl::Error exception is
  5542. * generated.
  5543. */
  5544. cl_int enqueueNativeKernel(
  5545. void (*userFptr)(void *),
  5546. std::pair<void*, ::size_t> args,
  5547. const VECTOR_CLASS<Memory>* mem_objects = NULL,
  5548. const VECTOR_CLASS<const void*>* mem_locs = NULL,
  5549. const VECTOR_CLASS<Event>* events = NULL,
  5550. Event* event = NULL) const
  5551. {
  5552. return detail::errHandler(
  5553. ::clEnqueueNativeKernel(
  5554. object_, userFptr, args.first, args.second,
  5555. (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
  5556. (mem_objects != NULL) ? (const cl_mem *) &mem_objects->front(): NULL,
  5557. (mem_locs != NULL) ? (const void **) &mem_locs->front() : NULL,
  5558. (events != NULL) ? (cl_uint) events->size() : 0,
  5559. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  5560. (cl_event*) event),
  5561. __ENQUEUE_NATIVE_KERNEL);
  5562. }
  5563. /*! \brief Enqueue a marker command.
  5564. *
  5565. * The marker command returns an event which can be used to queue a
  5566. * wait on this marker event i.e. wait for all commands queued before
  5567. * the marker command to complete.
  5568. *
  5569. * \return One of the following values:
  5570. * - CL_SUCCESS if the function is successfully executed
  5571. * - CL_INVALID_VALUE if \a event is a NULL value
  5572. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources
  5573. * required by the runtime.
  5574. *
  5575. * \note In the case that exceptions are enabled and error value
  5576. * other than CL_SUCCESS is generated, then cl::Error exception is
  5577. * generated.
  5578. */
  5579. cl_int enqueueMarker(Event* event = NULL) const
  5580. {
  5581. return detail::errHandler(
  5582. ::clEnqueueMarker(object_, (cl_event*) event),
  5583. __ENQUEUE_MARKER_ERR);
  5584. }
  5585. /*! \brief Enqueue a wait for a specific event or a list of events to
  5586. * complete before any future commands queued in the command-queue are
  5587. * executed.
  5588. *
  5589. *
  5590. * \param events is the list of events. Each event in \a events must
  5591. * be a valid event object returned by a previous call to:
  5592. * - enqueueNDRangeKernel
  5593. * - enqueueTask
  5594. * - enqueueNativeKernel
  5595. * - enqueue{Read|Write|Map}{Buffer|Image}
  5596. * - enqueueCopy{Buffer|Image}
  5597. * - enqueueCopyBufferToImage
  5598. * - enqueueCopyImageToBuffer
  5599. * - enqueueMarker.
  5600. * The events specified in \a event_list act as synchronization points.
  5601. *
  5602. * \return One of the following values:
  5603. * - CL_SUCCESS if the function was successfully executed.
  5604. * - CL_INVALID_VALUE if size of \a events is zero
  5605. * - CL_INVALID_EVENT if event objects specified in \a events are not valid
  5606. * events
  5607. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources
  5608. * required by the runtime.
  5609. *
  5610. * \note In the case that exceptions are enabled and error value
  5611. * other than CL_SUCCESS is generated, then cl::Error exception is
  5612. * generated.
  5613. */
  5614. cl_int enqueueWaitForEvents(const VECTOR_CLASS<Event>& events) const
  5615. {
  5616. return detail::errHandler(
  5617. ::clEnqueueWaitForEvents(
  5618. object_,
  5619. (cl_uint) events.size(),
  5620. (const cl_event*) &events.front()),
  5621. __ENQUEUE_WAIT_FOR_EVENTS_ERR);
  5622. }
  5623. cl_int enqueueAcquireGLObjects(
  5624. const VECTOR_CLASS<Memory>* mem_objects = NULL,
  5625. const VECTOR_CLASS<Event>* events = NULL,
  5626. Event* event = NULL) const
  5627. {
  5628. return detail::errHandler(
  5629. ::clEnqueueAcquireGLObjects(
  5630. object_,
  5631. (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
  5632. (mem_objects != NULL) ? (const cl_mem *) &mem_objects->front(): NULL,
  5633. (events != NULL) ? (cl_uint) events->size() : 0,
  5634. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  5635. (cl_event*) event),
  5636. __ENQUEUE_ACQUIRE_GL_ERR);
  5637. }
  5638. cl_int enqueueReleaseGLObjects(
  5639. const VECTOR_CLASS<Memory>* mem_objects = NULL,
  5640. const VECTOR_CLASS<Event>* events = NULL,
  5641. Event* event = NULL) const
  5642. {
  5643. return detail::errHandler(
  5644. ::clEnqueueReleaseGLObjects(
  5645. object_,
  5646. (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
  5647. (mem_objects != NULL) ? (const cl_mem *) &mem_objects->front(): NULL,
  5648. (events != NULL) ? (cl_uint) events->size() : 0,
  5649. (events != NULL && events->size() > 0) ? (cl_event*) &events->front() : NULL,
  5650. (cl_event*) event),
  5651. __ENQUEUE_RELEASE_GL_ERR);
  5652. }
  5653. #if defined (USE_DX_INTEROP)
  5654. typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueAcquireD3D10ObjectsKHR)(
  5655. cl_command_queue command_queue, cl_uint num_objects,
  5656. const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
  5657. const cl_event* event_wait_list, cl_event* event);
  5658. typedef CL_API_ENTRY cl_int (CL_API_CALL *PFN_clEnqueueReleaseD3D10ObjectsKHR)(
  5659. cl_command_queue command_queue, cl_uint num_objects,
  5660. const cl_mem* mem_objects, cl_uint num_events_in_wait_list,
  5661. const cl_event* event_wait_list, cl_event* event);
  5662. cl_int enqueueAcquireD3D10Objects(
  5663. const VECTOR_CLASS<Memory>* mem_objects = NULL,
  5664. const VECTOR_CLASS<Event>* events = NULL,
  5665. Event* event = NULL) const
  5666. {
  5667. static PFN_clEnqueueAcquireD3D10ObjectsKHR pfn_clEnqueueAcquireD3D10ObjectsKHR = NULL;
  5668. __INIT_CL_EXT_FCN_PTR(clEnqueueAcquireD3D10ObjectsKHR);
  5669. return detail::errHandler(
  5670. pfn_clEnqueueAcquireD3D10ObjectsKHR(
  5671. object_,
  5672. (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
  5673. (mem_objects != NULL) ? (const cl_mem *) &mem_objects->front(): NULL,
  5674. (events != NULL) ? (cl_uint) events->size() : 0,
  5675. (events != NULL) ? (cl_event*) &events->front() : NULL,
  5676. (cl_event*) event),
  5677. __ENQUEUE_ACQUIRE_GL_ERR);
  5678. }
  5679. cl_int enqueueReleaseD3D10Objects(
  5680. const VECTOR_CLASS<Memory>* mem_objects = NULL,
  5681. const VECTOR_CLASS<Event>* events = NULL,
  5682. Event* event = NULL) const
  5683. {
  5684. static PFN_clEnqueueReleaseD3D10ObjectsKHR pfn_clEnqueueReleaseD3D10ObjectsKHR = NULL;
  5685. __INIT_CL_EXT_FCN_PTR(clEnqueueReleaseD3D10ObjectsKHR);
  5686. return detail::errHandler(
  5687. pfn_clEnqueueReleaseD3D10ObjectsKHR(
  5688. object_,
  5689. (mem_objects != NULL) ? (cl_uint) mem_objects->size() : 0,
  5690. (mem_objects != NULL) ? (const cl_mem *) &mem_objects->front(): NULL,
  5691. (events != NULL) ? (cl_uint) events->size() : 0,
  5692. (events != NULL) ? (cl_event*) &events->front() : NULL,
  5693. (cl_event*) event),
  5694. __ENQUEUE_RELEASE_GL_ERR);
  5695. }
  5696. #endif
  5697. /*! \brief Enqueue a barrier operation.
  5698. *
  5699. * The enqueueBarrier command ensures that all queued commands in
  5700. * command-queue have finished execution before the next batch of commands
  5701. * can begin execution. enqueueBarrier is a synchronization point.
  5702. *
  5703. * \return One of the following values:
  5704. * - CL_SUCCESS if the function was executed successfully
  5705. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources
  5706. * required by the runtime.
  5707. *
  5708. * \note In the case that exceptions are enabled and error value
  5709. * other than CL_SUCCESS is generated, then cl::Error exception is
  5710. * generated.
  5711. *
  5712. * \note In the case that exceptions are enabled and error value
  5713. * other than CL_SUCCESS is generated, then cl::Error exception is
  5714. * generated.
  5715. */
  5716. cl_int enqueueBarrier() const
  5717. {
  5718. return detail::errHandler(
  5719. ::clEnqueueBarrier(object_),
  5720. __ENQUEUE_BARRIER_ERR);
  5721. }
  5722. /*! \brief Issue all previously queued OpenCL commands in command-queue to
  5723. * the device associated with command-queue.
  5724. *
  5725. * flush only guarantees that all queued commands get issued to the
  5726. * appropriate device. There is no guarantee that they will be
  5727. * complete after flush returns.
  5728. *
  5729. * \return One of the following values:
  5730. * - CL_SUCCESS if the function call was executed successfully
  5731. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources
  5732. * required by the runtime.
  5733. *
  5734. * Any blocking commands queued in a command-queue such as
  5735. * enqueueRead{Image|Buffer} with \a blocking_read set to CL_TRUE,
  5736. * enqueueWrite{Image|Buffer} with \a blocking_write set to CL_TRUE,
  5737. * enqueueMap{Buffer|Image} with \a blocking_map set to CL_TRUE or
  5738. * waitForEvents perform an implicit flush of the command-queue.
  5739. *
  5740. * \note In the case that exceptions are enabled and error value
  5741. * other than CL_SUCCESS is generated, then cl::Error exception is
  5742. * generated.
  5743. */
  5744. cl_int flush() const
  5745. {
  5746. return detail::errHandler(::clFlush(object_), __FLUSH_ERR);
  5747. }
  5748. /*! \brief Block until all previously queued OpenCL runtime commands in
  5749. * \a command_queue are issued to the associated device and have completed.
  5750. *
  5751. * finish does not return until all queued commands in \a command_queue
  5752. * have been processed and completed. finish is also a synchronization
  5753. * point.
  5754. *
  5755. * \return One of the following values:
  5756. * - CL_SUCCESS if the function call was executed successfully.
  5757. * - CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources
  5758. * required by the runtime.
  5759. *
  5760. * \note In the case that exceptions are enabled and error value
  5761. * other than CL_SUCCESS is generated, then cl::Error exception is
  5762. * generated.
  5763. */
  5764. cl_int finish() const
  5765. {
  5766. return detail::errHandler(::clFinish(object_), __FINISH_ERR);
  5767. }
  5768. };
  5769. /*! \class KernelFunctor
  5770. * \brief Kernel functor interface
  5771. *
  5772. * \note Currently only functors of zero to ten arguments are supported. It
  5773. * is straightforward to add more and a more general solution, similar to
  5774. * Boost.Lambda could be followed if required in the future.
  5775. */
  5776. class KernelFunctor
  5777. {
  5778. private:
  5779. Kernel kernel_;
  5780. CommandQueue queue_;
  5781. NDRange offset_;
  5782. NDRange global_;
  5783. NDRange local_;
  5784. cl_int err_;
  5785. public:
  5786. //! Default constructor; KernelFunctor is not valid at this point.
  5787. KernelFunctor() { }
  5788. /*! \brief Construct a KernelFunctor.
  5789. *
  5790. * A KernelFunctor object will launch the \a kernel with the
  5791. * corresponding \a queue, \a offset, \a global, and \a local
  5792. * values when called with the appropriate number of arguments,
  5793. * as defined by kernel itself,
  5794. *
  5795. * \param kernel is the kernel to launch when this functor is executed.
  5796. *
  5797. * \param queue is the command-queue to launch on.
  5798. *
  5799. * \param offset must currently be a NullRange value. In a future
  5800. * revision of OpenCL, \a global_work_offset can be used to specify an
  5801. * array of \a work_dim unsigned values that describe the offset used to
  5802. * calculate the global ID of a work-item instead of having the global IDs
  5803. * always start at offset (0, 0, 0).
  5804. *
  5805. * \param global describes the number of global work-items in will execute
  5806. * the kernel function. The total number of global
  5807. * work-items is computed as global_work_size[0] * ...
  5808. * * global_work_size[work_dim - 1].
  5809. *
  5810. * \param local describes the number of work-items that make up a
  5811. * work-group (also referred to as the size of the work-group) that
  5812. * will execute the kernel specified by kernel.
  5813. *
  5814. * \return A KernelFunctor object that when called with the appropriate
  5815. * number of arguments, as defined by kernel itself, will be launched
  5816. * with the corresponding queue, offset, global, and local values.
  5817. *
  5818. * \note This constructor is typically not used in favor of the Kernel::bind method.
  5819. */
  5820. KernelFunctor(
  5821. const Kernel& kernel,
  5822. const CommandQueue& queue,
  5823. const NDRange& offset,
  5824. const NDRange& global,
  5825. const NDRange& local) :
  5826. kernel_(kernel),
  5827. queue_(queue),
  5828. offset_(offset),
  5829. global_(global),
  5830. local_(local),
  5831. err_(CL_SUCCESS)
  5832. {}
  5833. /*! \brief Assignment operator.
  5834. *
  5835. * \param rhs KernelFunctor object for rhs of assignment.
  5836. *
  5837. * \return KernelFunctor object for lhs of assignment.
  5838. */
  5839. KernelFunctor& operator=(const KernelFunctor& rhs);
  5840. /*! \brief Copy constructor
  5841. *
  5842. * \param rhs is the KernelFunctor to be copied (cloned).
  5843. */
  5844. KernelFunctor(const KernelFunctor& rhs);
  5845. /*! \brief Get the error code returned by the last call to the
  5846. * functor.
  5847. *
  5848. * \return The last error; in the case that the functor object
  5849. * in question has not been called CL_SUCCESS is returned.
  5850. */
  5851. cl_int getError() { return err_; }
  5852. /*! \brief Enqueue a command to execute a kernel on a device.
  5853. *
  5854. * \param events specifies the list of events that need to complete before
  5855. * this particular command can be executed. If \a events is NULL, its
  5856. * default value, then this particular command does not wait on any event
  5857. * to complete. The events specified in \a events act as
  5858. * synchronization points.
  5859. *
  5860. * \return An event that identifies this particular kernel
  5861. * execution instance.
  5862. *
  5863. * \note In the case that exceptions are enabled and error value
  5864. * other than CL_SUCCESS is generated, then cl::Error exception is
  5865. * generated, otherwise the returned error is stored in the Kernel
  5866. * object and can get accessed using \a get_error.
  5867. */
  5868. inline Event operator()(const VECTOR_CLASS<Event>* events = NULL);
  5869. /*! \brief Enqueue a command to execute a kernel on a device.
  5870. *
  5871. * \param a1 is used argument 0 for the kernel call.
  5872. *
  5873. * \param events specifies the list of events that need to complete before
  5874. * this particular command can be executed. If \a events is NULL, its
  5875. * default value, then this particular command does not wait on any event
  5876. * to complete. The events specified in \a events act as
  5877. * synchronization points.
  5878. * \return An event that identifies this particular kernel
  5879. * execution instance.
  5880. *
  5881. * \note In the case that exceptions are enabled and error value
  5882. * other than CL_SUCCESS is generated, then cl::Error exception is
  5883. * generated, otherwise the returned error is stored in the Kernel
  5884. * object and can get accessed using \a get_error.
  5885. */
  5886. template<typename A1>
  5887. inline Event operator()(
  5888. const A1& a1,
  5889. const VECTOR_CLASS<Event>* events = NULL);
  5890. /*! \brief Enqueue a command to execute a kernel on a device.
  5891. *
  5892. * \param a1 is used argument 0 for the kernel call.
  5893. * \param a2 is used argument 1 for the kernel call.
  5894. *
  5895. * \param events specifies the list of events that need to complete before
  5896. * this particular command can be executed. If \a events is NULL, its
  5897. * default value, then this particular command does not wait on any event
  5898. * to complete. The events specified in \a events act as
  5899. * synchronization points.
  5900. *
  5901. * \return An event that identifies this particular kernel
  5902. * execution instance.
  5903. *
  5904. * \note In the case that exceptions are enabled and error value
  5905. * other than CL_SUCCESS is generated, then cl::Error exception is
  5906. * generated, otherwise the returned error is stored in the Kernel
  5907. * object and can get accessed using \a get_error.
  5908. */
  5909. template<class A1, class A2>
  5910. inline Event operator()(
  5911. const A1& a1,
  5912. const A2& a2,
  5913. const VECTOR_CLASS<Event>* events = NULL);
  5914. /*! \brief Enqueue a command to execute a kernel on a device.
  5915. *
  5916. * \param a1 is used argument 0 for the kernel call.
  5917. * \param a2 is used argument 1 for the kernel call.
  5918. * \param a3 is used argument 3 for the kernel call.
  5919. *
  5920. * \param events specifies the list of events that need to complete before
  5921. * this particular command can be executed. If \a events is NULL, its
  5922. * default value, then this particular command does not wait on any event
  5923. * to complete. The events specified in \a events act as
  5924. * synchronization points.
  5925. *
  5926. * \return An event that identifies this particular kernel
  5927. * execution instance.
  5928. *
  5929. * \note In the case that exceptions are enabled and error value
  5930. * other than CL_SUCCESS is generated, then cl::Error exception is
  5931. * generated, otherwise the returned error is stored in the Kernel
  5932. * object and can get accessed using \a get_error.
  5933. */
  5934. template<class A1, class A2, class A3>
  5935. inline Event operator()(
  5936. const A1& a1,
  5937. const A2& a2,
  5938. const A3& a3,
  5939. const VECTOR_CLASS<Event>* events = NULL);
  5940. /*! \brief Enqueue a command to execute a kernel on a device.
  5941. *
  5942. * \param a1 is used argument 0 for the kernel call.
  5943. * \param a2 is used argument 1 for the kernel call.
  5944. * \param a3 is used argument 2 for the kernel call.
  5945. * \param a4 is used argument 3 for the kernel call.
  5946. *
  5947. * \param events specifies the list of events that need to complete before
  5948. * this particular command can be executed. If \a events is NULL, its
  5949. * default value, then this particular command does not wait on any event
  5950. * to complete. The events specified in \a events act as
  5951. * synchronization points.
  5952. *
  5953. * \return An event that identifies this particular kernel
  5954. * execution instance.
  5955. *
  5956. * \note In the case that exceptions are enabled and error value
  5957. * other than CL_SUCCESS is generated, then cl::Error exception is
  5958. * generated, otherwise the returned error is stored in the Kernel
  5959. * object and can get accessed using \a get_error.
  5960. */
  5961. template<class A1, class A2, class A3, class A4>
  5962. inline Event operator()(
  5963. const A1& a1,
  5964. const A2& a2,
  5965. const A3& a3,
  5966. const A4& a4,
  5967. const VECTOR_CLASS<Event>* events = NULL);
  5968. /*! \brief Enqueue a command to execute a kernel on a device.
  5969. *
  5970. * \param a1 is used argument 0 for the kernel call.
  5971. * \param a2 is used argument 1 for the kernel call.
  5972. * \param a3 is used argument 2 for the kernel call.
  5973. * \param a4 is used argument 3 for the kernel call.
  5974. * \param a5 is used argument 4 for the kernel call.
  5975. *
  5976. * \param events specifies the list of events that need to complete before
  5977. * this particular command can be executed. If \a events is NULL, its
  5978. * default value, then this particular command does not wait on any event
  5979. * to complete. The events specified in \a events act as
  5980. * synchronization points.
  5981. *
  5982. * \return An event that identifies this particular kernel
  5983. * execution instance.
  5984. *
  5985. * \note In the case that exceptions are enabled and error value
  5986. * other than CL_SUCCESS is generated, then cl::Error exception is
  5987. * generated, otherwise the returned error is stored in the Kernel
  5988. * object and can get accessed using \a get_error.
  5989. */
  5990. template<class A1, class A2, class A3, class A4, class A5>
  5991. inline Event operator()(
  5992. const A1& a1,
  5993. const A2& a2,
  5994. const A3& a3,
  5995. const A4& a4,
  5996. const A5& a5,
  5997. const VECTOR_CLASS<Event>* events = NULL);
  5998. /*! \brief Enqueue a command to execute a kernel on a device.
  5999. *
  6000. * \param a1 is used argument 0 for the kernel call.
  6001. * \param a2 is used argument 1 for the kernel call.
  6002. * \param a3 is used argument 2 for the kernel call.
  6003. * \param a4 is used argument 3 for the kernel call.
  6004. * \param a5 is used argument 4 for the kernel call.
  6005. * \param a6 is used argument 5 for the kernel call.
  6006. *
  6007. * \param events specifies the list of events that need to complete before
  6008. * this particular command can be executed. If \a events is NULL, its
  6009. * default value, then this particular command does not wait on any event
  6010. * to complete. The events specified in \a events act as
  6011. * synchronization points.
  6012. *
  6013. * \return An event that identifies this particular kernel
  6014. * execution instance.
  6015. *
  6016. * \note In the case that exceptions are enabled and error value
  6017. * other than CL_SUCCESS is generated, then cl::Error exception is
  6018. * generated, otherwise the returned error is stored in the Kernel
  6019. * object and can get accessed using \a get_error.
  6020. */
  6021. template<class A1, class A2, class A3, class A4, class A5, class A6>
  6022. inline Event operator()(
  6023. const A1& a1,
  6024. const A2& a2,
  6025. const A3& a3,
  6026. const A4& a4,
  6027. const A5& a5,
  6028. const A6& a6,
  6029. const VECTOR_CLASS<Event>* events = NULL);
  6030. /*! \brief Enqueue a command to execute a kernel on a device.
  6031. *
  6032. * \param a1 is used argument 0 for the kernel call.
  6033. * \param a2 is used argument 1 for the kernel call.
  6034. * \param a3 is used argument 2 for the kernel call.
  6035. * \param a4 is used argument 3 for the kernel call.
  6036. * \param a5 is used argument 4 for the kernel call.
  6037. * \param a6 is used argument 5 for the kernel call.
  6038. * \param a7 is used argument 6 for the kernel call.
  6039. *
  6040. * \param events specifies the list of events that need to complete before
  6041. * this particular command can be executed. If \a events is NULL, its
  6042. * default value, then this particular command does not wait on any event
  6043. * to complete. The events specified in \a events act as
  6044. * synchronization points.
  6045. *
  6046. * \return An event that identifies this particular kernel
  6047. * execution instance.
  6048. *
  6049. * \note In the case that exceptions are enabled and error value
  6050. * other than CL_SUCCESS is generated, then cl::Error exception is
  6051. * generated, otherwise the returned error is stored in the Kernel
  6052. * object and can get accessed using \a get_error.
  6053. */
  6054. template<class A1, class A2, class A3, class A4,
  6055. class A5, class A6, class A7>
  6056. inline Event operator()(
  6057. const A1& a1,
  6058. const A2& a2,
  6059. const A3& a3,
  6060. const A4& a4,
  6061. const A5& a5,
  6062. const A6& a6,
  6063. const A7& a7,
  6064. const VECTOR_CLASS<Event>* events = NULL);
  6065. /*! \brief Enqueue a command to execute a kernel on a device.
  6066. *
  6067. * \param a1 is used argument 0 for the kernel call.
  6068. * \param a2 is used argument 1 for the kernel call.
  6069. * \param a3 is used argument 2 for the kernel call.
  6070. * \param a4 is used argument 3 for the kernel call.
  6071. * \param a5 is used argument 4 for the kernel call.
  6072. * \param a6 is used argument 5 for the kernel call.
  6073. * \param a7 is used argument 6 for the kernel call.
  6074. * \param a8 is used argument 7 for the kernel call.
  6075. *
  6076. * \param events specifies the list of events that need to complete before
  6077. * this particular command can be executed. If \a events is NULL, its
  6078. * default value, then this particular command does not wait on any event
  6079. * to complete. The events specified in \a events act as
  6080. * synchronization points.
  6081. *
  6082. * \return An event that identifies this particular kernel
  6083. * execution instance.
  6084. *
  6085. * \note In the case that exceptions are enabled and error value
  6086. * other than CL_SUCCESS is generated, then cl::Error exception is
  6087. * generated, otherwise the returned error is stored in the Kernel
  6088. * object and can get accessed using \a get_error.
  6089. */
  6090. template<class A1, class A2, class A3, class A4, class A5,
  6091. class A6, class A7, class A8>
  6092. inline Event operator()(
  6093. const A1& a1,
  6094. const A2& a2,
  6095. const A3& a3,
  6096. const A4& a4,
  6097. const A5& a5,
  6098. const A6& a6,
  6099. const A7& a7,
  6100. const A8& a8,
  6101. const VECTOR_CLASS<Event>* events = NULL);
  6102. /*! \brief Enqueue a command to execute a kernel on a device.
  6103. *
  6104. * \param a1 is used argument 0 for the kernel call.
  6105. * \param a2 is used argument 1 for the kernel call.
  6106. * \param a3 is used argument 2 for the kernel call.
  6107. * \param a4 is used argument 3 for the kernel call.
  6108. * \param a5 is used argument 4 for the kernel call.
  6109. * \param a6 is used argument 5 for the kernel call.
  6110. * \param a7 is used argument 6 for the kernel call.
  6111. * \param a8 is used argument 7 for the kernel call.
  6112. * \param a9 is used argument 8 for the kernel call.
  6113. *
  6114. * \param events specifies the list of events that need to complete before
  6115. * this particular command can be executed. If \a events is NULL, its
  6116. * default value, then this particular command does not wait on any event
  6117. * to complete. The events specified in \a events act as
  6118. * synchronization points.
  6119. *
  6120. * \return An event that identifies this particular kernel
  6121. * execution instance.
  6122. *
  6123. * \note In the case that exceptions are enabled and error value
  6124. * other than CL_SUCCESS is generated, then cl::Error exception is
  6125. * generated, otherwise the returned error is stored in the Kernel
  6126. * object and can get accessed using \a get_error.
  6127. */
  6128. template<class A1, class A2, class A3, class A4, class A5,
  6129. class A6, class A7, class A8, class A9>
  6130. inline Event operator()(
  6131. const A1& a1,
  6132. const A2& a2,
  6133. const A3& a3,
  6134. const A4& a4,
  6135. const A5& a5,
  6136. const A6& a6,
  6137. const A7& a7,
  6138. const A8& a8,
  6139. const A9& a9,
  6140. const VECTOR_CLASS<Event>* events = NULL);
  6141. /*! \brief Enqueue a command to execute a kernel on a device.
  6142. *
  6143. * \param a1 is used argument 0 for the kernel call.
  6144. * \param a2 is used argument 1 for the kernel call.
  6145. * \param a3 is used argument 2 for the kernel call.
  6146. * \param a4 is used argument 3 for the kernel call.
  6147. * \param a5 is used argument 4 for the kernel call.
  6148. * \param a6 is used argument 5 for the kernel call.
  6149. * \param a7 is used argument 6 for the kernel call.
  6150. * \param a8 is used argument 7 for the kernel call.
  6151. * \param a9 is used argument 8 for the kernel call.
  6152. * \param a10 is used argument 9 for the kernel call.
  6153. *
  6154. * \param events specifies the list of events that need to complete before
  6155. * this particular command can be executed. If \a events is NULL, its
  6156. * default value, then this particular command does not wait on any event
  6157. * to complete. The events specified in \a events act as
  6158. * synchronization points.
  6159. *
  6160. * \return An event that identifies this particular kernel
  6161. * execution instance.
  6162. *
  6163. * \note In the case that exceptions are enabled and error value
  6164. * other than CL_SUCCESS is generated, then cl::Error exception is
  6165. * generated, otherwise the returned error is stored in the Kernel
  6166. * object and can get accessed using \a get_error.
  6167. */
  6168. template<class A1, class A2, class A3, class A4, class A5,
  6169. class A6, class A7, class A8, class A9, class A10>
  6170. inline Event operator()(
  6171. const A1& a1,
  6172. const A2& a2,
  6173. const A3& a3,
  6174. const A4& a4,
  6175. const A5& a5,
  6176. const A6& a6,
  6177. const A7& a7,
  6178. const A8& a8,
  6179. const A9& a9,
  6180. const A10& a10,
  6181. const VECTOR_CLASS<Event>* events = NULL);
  6182. /*! \brief Enqueue a command to execute a kernel on a device.
  6183. *
  6184. * \param a1 is used argument 0 for the kernel call.
  6185. * \param a2 is used argument 1 for the kernel call.
  6186. * \param a3 is used argument 2 for the kernel call.
  6187. * \param a4 is used argument 3 for the kernel call.
  6188. * \param a5 is used argument 4 for the kernel call.
  6189. * \param a6 is used argument 5 for the kernel call.
  6190. * \param a7 is used argument 6 for the kernel call.
  6191. * \param a8 is used argument 7 for the kernel call.
  6192. * \param a9 is used argument 8 for the kernel call.
  6193. * \param a10 is used argument 9 for the kernel call.
  6194. * \param a11 is used argument 10 for the kernel call.
  6195. *
  6196. * \param events specifies the list of events that need to complete before
  6197. * this particular command can be executed. If \a events is NULL, its
  6198. * default value, then this particular command does not wait on any event
  6199. * to complete. The events specified in \a events act as
  6200. * synchronization points.
  6201. *
  6202. * \return An event that identifies this particular kernel
  6203. * execution instance.
  6204. *
  6205. * \note In the case that exceptions are enabled and error value
  6206. * other than CL_SUCCESS is generated, then cl::Error exception is
  6207. * generated, otherwise the returned error is stored in the Kernel
  6208. * object and can get accessed using \a get_error.
  6209. */
  6210. template<class A1, class A2, class A3, class A4, class A5,
  6211. class A6, class A7, class A8, class A9, class A10,
  6212. class A11>
  6213. inline Event operator()(
  6214. const A1& a1,
  6215. const A2& a2,
  6216. const A3& a3,
  6217. const A4& a4,
  6218. const A5& a5,
  6219. const A6& a6,
  6220. const A7& a7,
  6221. const A8& a8,
  6222. const A9& a9,
  6223. const A10& a10,
  6224. const A11& a11,
  6225. const VECTOR_CLASS<Event>* events = NULL);
  6226. /*! \brief Enqueue a command to execute a kernel on a device.
  6227. *
  6228. * \param a1 is used argument 0 for the kernel call.
  6229. * \param a2 is used argument 1 for the kernel call.
  6230. * \param a3 is used argument 2 for the kernel call.
  6231. * \param a4 is used argument 3 for the kernel call.
  6232. * \param a5 is used argument 4 for the kernel call.
  6233. * \param a6 is used argument 5 for the kernel call.
  6234. * \param a7 is used argument 6 for the kernel call.
  6235. * \param a8 is used argument 7 for the kernel call.
  6236. * \param a9 is used argument 8 for the kernel call.
  6237. * \param a10 is used argument 9 for the kernel call.
  6238. * \param a11 is used argument 10 for the kernel call.
  6239. * \param a12 is used argument 11 for the kernel call.
  6240. *
  6241. * \param events specifies the list of events that need to complete before
  6242. * this particular command can be executed. If \a events is NULL, its
  6243. * default value, then this particular command does not wait on any event
  6244. * to complete. The events specified in \a events act as
  6245. * synchronization points.
  6246. *
  6247. * \return An event that identifies this particular kernel
  6248. * execution instance.
  6249. *
  6250. * \note In the case that exceptions are enabled and error value
  6251. * other than CL_SUCCESS is generated, then cl::Error exception is
  6252. * generated, otherwise the returned error is stored in the Kernel
  6253. * object and can get accessed using \a get_error.
  6254. */
  6255. template<class A1, class A2, class A3, class A4, class A5,
  6256. class A6, class A7, class A8, class A9, class A10,
  6257. class A11, class A12>
  6258. inline Event operator()(
  6259. const A1& a1,
  6260. const A2& a2,
  6261. const A3& a3,
  6262. const A4& a4,
  6263. const A5& a5,
  6264. const A6& a6,
  6265. const A7& a7,
  6266. const A8& a8,
  6267. const A9& a9,
  6268. const A10& a10,
  6269. const A11& a11,
  6270. const A12& a12,
  6271. const VECTOR_CLASS<Event>* events = NULL);
  6272. /*! \brief Enqueue a command to execute a kernel on a device.
  6273. *
  6274. * \param a1 is used argument 0 for the kernel call.
  6275. * \param a2 is used argument 1 for the kernel call.
  6276. * \param a3 is used argument 2 for the kernel call.
  6277. * \param a4 is used argument 3 for the kernel call.
  6278. * \param a5 is used argument 4 for the kernel call.
  6279. * \param a6 is used argument 5 for the kernel call.
  6280. * \param a7 is used argument 6 for the kernel call.
  6281. * \param a8 is used argument 7 for the kernel call.
  6282. * \param a9 is used argument 8 for the kernel call.
  6283. * \param a10 is used argument 9 for the kernel call.
  6284. * \param a11 is used argument 10 for the kernel call.
  6285. * \param a12 is used argument 11 for the kernel call.
  6286. * \param a13 is used argument 12 for the kernel call.
  6287. *
  6288. * \param events specifies the list of events that need to complete before
  6289. * this particular command can be executed. If \a events is NULL, its
  6290. * default value, then this particular command does not wait on any event
  6291. * to complete. The events specified in \a events act as
  6292. * synchronization points.
  6293. *
  6294. * \return An event that identifies this particular kernel
  6295. * execution instance.
  6296. *
  6297. * \note In the case that exceptions are enabled and error value
  6298. * other than CL_SUCCESS is generated, then cl::Error exception is
  6299. * generated, otherwise the returned error is stored in the Kernel
  6300. * object and can get accessed using \a get_error.
  6301. */
  6302. template<class A1, class A2, class A3, class A4, class A5,
  6303. class A6, class A7, class A8, class A9, class A10,
  6304. class A11, class A12, class A13>
  6305. inline Event operator()(
  6306. const A1& a1,
  6307. const A2& a2,
  6308. const A3& a3,
  6309. const A4& a4,
  6310. const A5& a5,
  6311. const A6& a6,
  6312. const A7& a7,
  6313. const A8& a8,
  6314. const A9& a9,
  6315. const A10& a10,
  6316. const A11& a11,
  6317. const A12& a12,
  6318. const A13& a13,
  6319. const VECTOR_CLASS<Event>* events = NULL);
  6320. /*! \brief Enqueue a command to execute a kernel on a device.
  6321. *
  6322. * \param a1 is used argument 0 for the kernel call.
  6323. * \param a2 is used argument 1 for the kernel call.
  6324. * \param a3 is used argument 2 for the kernel call.
  6325. * \param a4 is used argument 3 for the kernel call.
  6326. * \param a5 is used argument 4 for the kernel call.
  6327. * \param a6 is used argument 5 for the kernel call.
  6328. * \param a7 is used argument 6 for the kernel call.
  6329. * \param a8 is used argument 7 for the kernel call.
  6330. * \param a9 is used argument 8 for the kernel call.
  6331. * \param a10 is used argument 9 for the kernel call.
  6332. * \param a11 is used argument 10 for the kernel call.
  6333. * \param a12 is used argument 11 for the kernel call.
  6334. * \param a13 is used argument 12 for the kernel call.
  6335. * \param a13 is used argument 13 for the kernel call.
  6336. *
  6337. * \param events specifies the list of events that need to complete before
  6338. * this particular command can be executed. If \a events is NULL, its
  6339. * default value, then this particular command does not wait on any event
  6340. * to complete. The events specified in \a events act as
  6341. * synchronization points.
  6342. *
  6343. * \return An event that identifies this particular kernel
  6344. * execution instance.
  6345. *
  6346. * \note In the case that exceptions are enabled and error value
  6347. * other than CL_SUCCESS is generated, then cl::Error exception is
  6348. * generated, otherwise the returned error is stored in the Kernel
  6349. * object and can get accessed using \a get_error.
  6350. */
  6351. template<class A1, class A2, class A3, class A4, class A5,
  6352. class A6, class A7, class A8, class A9, class A10,
  6353. class A11, class A12, class A13, class A14>
  6354. inline Event operator()(
  6355. const A1& a1,
  6356. const A2& a2,
  6357. const A3& a3,
  6358. const A4& a4,
  6359. const A5& a5,
  6360. const A6& a6,
  6361. const A7& a7,
  6362. const A8& a8,
  6363. const A9& a9,
  6364. const A10& a10,
  6365. const A11& a11,
  6366. const A12& a12,
  6367. const A13& a13,
  6368. const A14& a14,
  6369. const VECTOR_CLASS<Event>* events = NULL);
  6370. template<class A1, class A2, class A3, class A4, class A5,
  6371. class A6, class A7, class A8, class A9, class A10,
  6372. class A11, class A12, class A13, class A14, class A15>
  6373. inline Event operator()(
  6374. const A1& a1,
  6375. const A2& a2,
  6376. const A3& a3,
  6377. const A4& a4,
  6378. const A5& a5,
  6379. const A6& a6,
  6380. const A7& a7,
  6381. const A8& a8,
  6382. const A9& a9,
  6383. const A10& a10,
  6384. const A11& a11,
  6385. const A12& a12,
  6386. const A13& a13,
  6387. const A14& a14,
  6388. const A15& a15,
  6389. const VECTOR_CLASS<Event>* events = NULL);
  6390. };
  6391. inline KernelFunctor Kernel::bind(
  6392. const CommandQueue& queue,
  6393. const NDRange& offset,
  6394. const NDRange& global,
  6395. const NDRange& local)
  6396. {
  6397. return KernelFunctor(*this,queue,offset,global,local);
  6398. }
  6399. inline KernelFunctor Kernel::bind(
  6400. const CommandQueue& queue,
  6401. const NDRange& global,
  6402. const NDRange& local)
  6403. {
  6404. return KernelFunctor(*this,queue,NullRange,global,local);
  6405. }
  6406. inline KernelFunctor& KernelFunctor::operator=(const KernelFunctor& rhs)
  6407. {
  6408. if (this == &rhs) {
  6409. return *this;
  6410. }
  6411. kernel_ = rhs.kernel_;
  6412. queue_ = rhs.queue_;
  6413. offset_ = rhs.offset_;
  6414. global_ = rhs.global_;
  6415. local_ = rhs.local_;
  6416. return *this;
  6417. }
  6418. inline KernelFunctor::KernelFunctor(const KernelFunctor& rhs) :
  6419. kernel_(rhs.kernel_),
  6420. queue_(rhs.queue_),
  6421. offset_(rhs.offset_),
  6422. global_(rhs.global_),
  6423. local_(rhs.local_)
  6424. {
  6425. }
  6426. Event KernelFunctor::operator()(const VECTOR_CLASS<Event>* events __attribute__ ((unused)))
  6427. {
  6428. Event event;
  6429. err_ = queue_.enqueueNDRangeKernel(
  6430. kernel_,
  6431. offset_,
  6432. global_,
  6433. local_,
  6434. NULL, // bgaster_fixme - do we want to allow wait event lists?
  6435. &event);
  6436. return event;
  6437. }
  6438. template<typename A1>
  6439. Event KernelFunctor::operator()(
  6440. const A1& a1,
  6441. const VECTOR_CLASS<Event>* events)
  6442. {
  6443. Event event;
  6444. kernel_.setArg(0,a1);
  6445. err_ = queue_.enqueueNDRangeKernel(
  6446. kernel_,
  6447. offset_,
  6448. global_,
  6449. local_,
  6450. NULL, // bgaster_fixme - do we want to allow wait event lists?
  6451. &event);
  6452. return event;
  6453. }
  6454. template<typename A1, typename A2>
  6455. Event KernelFunctor::operator()(
  6456. const A1& a1,
  6457. const A2& a2,
  6458. const VECTOR_CLASS<Event>* events)
  6459. {
  6460. Event event;
  6461. kernel_.setArg(0,a1);
  6462. kernel_.setArg(1,a2);
  6463. err_ = queue_.enqueueNDRangeKernel(
  6464. kernel_,
  6465. offset_,
  6466. global_,
  6467. local_,
  6468. NULL, // bgaster_fixme - do we want to allow wait event lists?
  6469. &event);
  6470. return event;
  6471. }
  6472. template<typename A1, typename A2, typename A3>
  6473. Event KernelFunctor::operator()(
  6474. const A1& a1,
  6475. const A2& a2,
  6476. const A3& a3,
  6477. const VECTOR_CLASS<Event>* events)
  6478. {
  6479. Event event;
  6480. kernel_.setArg(0,a1);
  6481. kernel_.setArg(1,a2);
  6482. kernel_.setArg(2,a3);
  6483. err_ = queue_.enqueueNDRangeKernel(
  6484. kernel_,
  6485. offset_,
  6486. global_,
  6487. local_,
  6488. NULL, // bgaster_fixme - do we want to allow wait event lists?
  6489. &event);
  6490. return event;
  6491. }
  6492. template<typename A1, typename A2, typename A3, typename A4>
  6493. Event KernelFunctor::operator()(
  6494. const A1& a1,
  6495. const A2& a2,
  6496. const A3& a3,
  6497. const A4& a4,
  6498. const VECTOR_CLASS<Event>* events)
  6499. {
  6500. Event event;
  6501. kernel_.setArg(0,a1);
  6502. kernel_.setArg(1,a2);
  6503. kernel_.setArg(2,a3);
  6504. kernel_.setArg(3,a4);
  6505. err_ = queue_.enqueueNDRangeKernel(
  6506. kernel_,
  6507. offset_,
  6508. global_,
  6509. local_,
  6510. NULL, // bgaster_fixme - do we want to allow wait event lists?
  6511. &event);
  6512. return event;
  6513. }
  6514. template<typename A1, typename A2, typename A3, typename A4, typename A5>
  6515. Event KernelFunctor::operator()(
  6516. const A1& a1,
  6517. const A2& a2,
  6518. const A3& a3,
  6519. const A4& a4,
  6520. const A5& a5,
  6521. const VECTOR_CLASS<Event>* events)
  6522. {
  6523. Event event;
  6524. kernel_.setArg(0,a1);
  6525. kernel_.setArg(1,a2);
  6526. kernel_.setArg(2,a3);
  6527. kernel_.setArg(3,a4);
  6528. kernel_.setArg(4,a5);
  6529. err_ = queue_.enqueueNDRangeKernel(
  6530. kernel_,
  6531. offset_,
  6532. global_,
  6533. local_,
  6534. NULL, // bgaster_fixme - do we want to allow wait event lists?
  6535. &event);
  6536. return event;
  6537. }
  6538. template<typename A1, typename A2, typename A3, typename A4, typename A5,
  6539. typename A6>
  6540. Event KernelFunctor::operator()(
  6541. const A1& a1,
  6542. const A2& a2,
  6543. const A3& a3,
  6544. const A4& a4,
  6545. const A5& a5,
  6546. const A6& a6,
  6547. const VECTOR_CLASS<Event>* events)
  6548. {
  6549. Event event;
  6550. kernel_.setArg(0,a1);
  6551. kernel_.setArg(1,a2);
  6552. kernel_.setArg(2,a3);
  6553. kernel_.setArg(3,a4);
  6554. kernel_.setArg(4,a5);
  6555. kernel_.setArg(5,a6);
  6556. err_ = queue_.enqueueNDRangeKernel(
  6557. kernel_,
  6558. offset_,
  6559. global_,
  6560. local_,
  6561. NULL, // bgaster_fixme - do we want to allow wait event lists?
  6562. &event);
  6563. return event;
  6564. }
  6565. template<typename A1, typename A2, typename A3, typename A4,
  6566. typename A5, typename A6, typename A7>
  6567. Event KernelFunctor::operator()(
  6568. const A1& a1,
  6569. const A2& a2,
  6570. const A3& a3,
  6571. const A4& a4,
  6572. const A5& a5,
  6573. const A6& a6,
  6574. const A7& a7,
  6575. const VECTOR_CLASS<Event>* events)
  6576. {
  6577. Event event;
  6578. kernel_.setArg(0,a1);
  6579. kernel_.setArg(1,a2);
  6580. kernel_.setArg(2,a3);
  6581. kernel_.setArg(3,a4);
  6582. kernel_.setArg(4,a5);
  6583. kernel_.setArg(5,a6);
  6584. kernel_.setArg(6,a7);
  6585. err_ = queue_.enqueueNDRangeKernel(
  6586. kernel_,
  6587. offset_,
  6588. global_,
  6589. local_,
  6590. NULL, // bgaster_fixme - do we want to allow wait event lists?
  6591. &event);
  6592. return event;
  6593. }
  6594. template<typename A1, typename A2, typename A3, typename A4, typename A5,
  6595. typename A6, typename A7, typename A8>
  6596. Event KernelFunctor::operator()(
  6597. const A1& a1,
  6598. const A2& a2,
  6599. const A3& a3,
  6600. const A4& a4,
  6601. const A5& a5,
  6602. const A6& a6,
  6603. const A7& a7,
  6604. const A8& a8,
  6605. const VECTOR_CLASS<Event>* events)
  6606. {
  6607. Event event;
  6608. kernel_.setArg(0,a1);
  6609. kernel_.setArg(1,a2);
  6610. kernel_.setArg(2,a3);
  6611. kernel_.setArg(3,a4);
  6612. kernel_.setArg(4,a5);
  6613. kernel_.setArg(5,a6);
  6614. kernel_.setArg(6,a7);
  6615. kernel_.setArg(7,a8);
  6616. err_ = queue_.enqueueNDRangeKernel(
  6617. kernel_,
  6618. offset_,
  6619. global_,
  6620. local_,
  6621. NULL, // bgaster_fixme - do we want to allow wait event lists?
  6622. &event);
  6623. return event;
  6624. }
  6625. template<typename A1, typename A2, typename A3, typename A4, typename A5,
  6626. typename A6, typename A7, typename A8, typename A9>
  6627. Event KernelFunctor::operator()(
  6628. const A1& a1,
  6629. const A2& a2,
  6630. const A3& a3,
  6631. const A4& a4,
  6632. const A5& a5,
  6633. const A6& a6,
  6634. const A7& a7,
  6635. const A8& a8,
  6636. const A9& a9,
  6637. const VECTOR_CLASS<Event>* events)
  6638. {
  6639. Event event;
  6640. kernel_.setArg(0,a1);
  6641. kernel_.setArg(1,a2);
  6642. kernel_.setArg(2,a3);
  6643. kernel_.setArg(3,a4);
  6644. kernel_.setArg(4,a5);
  6645. kernel_.setArg(5,a6);
  6646. kernel_.setArg(6,a7);
  6647. kernel_.setArg(7,a8);
  6648. kernel_.setArg(8,a9);
  6649. err_ = queue_.enqueueNDRangeKernel(
  6650. kernel_,
  6651. offset_,
  6652. global_,
  6653. local_,
  6654. NULL, // bgaster_fixme - do we want to allow wait event lists?
  6655. &event);
  6656. return event;
  6657. }
  6658. template<typename A1, typename A2, typename A3, typename A4, typename A5,
  6659. typename A6, typename A7, typename A8, typename A9, typename A10>
  6660. Event KernelFunctor::operator()(
  6661. const A1& a1,
  6662. const A2& a2,
  6663. const A3& a3,
  6664. const A4& a4,
  6665. const A5& a5,
  6666. const A6& a6,
  6667. const A7& a7,
  6668. const A8& a8,
  6669. const A9& a9,
  6670. const A10& a10,
  6671. const VECTOR_CLASS<Event>* events)
  6672. {
  6673. Event event;
  6674. kernel_.setArg(0,a1);
  6675. kernel_.setArg(1,a2);
  6676. kernel_.setArg(2,a3);
  6677. kernel_.setArg(3,a4);
  6678. kernel_.setArg(4,a5);
  6679. kernel_.setArg(5,a6);
  6680. kernel_.setArg(6,a7);
  6681. kernel_.setArg(7,a8);
  6682. kernel_.setArg(8,a9);
  6683. kernel_.setArg(9,a10);
  6684. err_ = queue_.enqueueNDRangeKernel(
  6685. kernel_,
  6686. offset_,
  6687. global_,
  6688. local_,
  6689. NULL, // bgaster_fixme - do we want to allow wait event lists?
  6690. &event);
  6691. return event;
  6692. }
  6693. template<class A1, class A2, class A3, class A4, class A5,
  6694. class A6, class A7, class A8, class A9, class A10,
  6695. class A11>
  6696. Event KernelFunctor::operator()(
  6697. const A1& a1,
  6698. const A2& a2,
  6699. const A3& a3,
  6700. const A4& a4,
  6701. const A5& a5,
  6702. const A6& a6,
  6703. const A7& a7,
  6704. const A8& a8,
  6705. const A9& a9,
  6706. const A10& a10,
  6707. const A11& a11,
  6708. const VECTOR_CLASS<Event>* events)
  6709. {
  6710. Event event;
  6711. kernel_.setArg(0,a1);
  6712. kernel_.setArg(1,a2);
  6713. kernel_.setArg(2,a3);
  6714. kernel_.setArg(3,a4);
  6715. kernel_.setArg(4,a5);
  6716. kernel_.setArg(5,a6);
  6717. kernel_.setArg(6,a7);
  6718. kernel_.setArg(7,a8);
  6719. kernel_.setArg(8,a9);
  6720. kernel_.setArg(9,a10);
  6721. kernel_.setArg(10,a11);
  6722. err_ = queue_.enqueueNDRangeKernel(
  6723. kernel_,
  6724. offset_,
  6725. global_,
  6726. local_,
  6727. NULL, // bgaster_fixme - do we want to allow wait event lists?
  6728. &event);
  6729. return event;
  6730. }
  6731. template<class A1, class A2, class A3, class A4, class A5,
  6732. class A6, class A7, class A8, class A9, class A10,
  6733. class A11, class A12>
  6734. Event KernelFunctor::operator()(
  6735. const A1& a1,
  6736. const A2& a2,
  6737. const A3& a3,
  6738. const A4& a4,
  6739. const A5& a5,
  6740. const A6& a6,
  6741. const A7& a7,
  6742. const A8& a8,
  6743. const A9& a9,
  6744. const A10& a10,
  6745. const A11& a11,
  6746. const A12& a12,
  6747. const VECTOR_CLASS<Event>* events)
  6748. {
  6749. Event event;
  6750. kernel_.setArg(0,a1);
  6751. kernel_.setArg(1,a2);
  6752. kernel_.setArg(2,a3);
  6753. kernel_.setArg(3,a4);
  6754. kernel_.setArg(4,a5);
  6755. kernel_.setArg(5,a6);
  6756. kernel_.setArg(6,a7);
  6757. kernel_.setArg(7,a8);
  6758. kernel_.setArg(8,a9);
  6759. kernel_.setArg(9,a10);
  6760. kernel_.setArg(10,a11);
  6761. kernel_.setArg(11,a12);
  6762. err_ = queue_.enqueueNDRangeKernel(
  6763. kernel_,
  6764. offset_,
  6765. global_,
  6766. local_,
  6767. NULL, // bgaster_fixme - do we want to allow wait event lists?
  6768. &event);
  6769. return event;
  6770. }
  6771. template<class A1, class A2, class A3, class A4, class A5,
  6772. class A6, class A7, class A8, class A9, class A10,
  6773. class A11, class A12, class A13>
  6774. Event KernelFunctor::operator()(
  6775. const A1& a1,
  6776. const A2& a2,
  6777. const A3& a3,
  6778. const A4& a4,
  6779. const A5& a5,
  6780. const A6& a6,
  6781. const A7& a7,
  6782. const A8& a8,
  6783. const A9& a9,
  6784. const A10& a10,
  6785. const A11& a11,
  6786. const A12& a12,
  6787. const A13& a13,
  6788. const VECTOR_CLASS<Event>* events)
  6789. {
  6790. Event event;
  6791. kernel_.setArg(0,a1);
  6792. kernel_.setArg(1,a2);
  6793. kernel_.setArg(2,a3);
  6794. kernel_.setArg(3,a4);
  6795. kernel_.setArg(4,a5);
  6796. kernel_.setArg(5,a6);
  6797. kernel_.setArg(6,a7);
  6798. kernel_.setArg(7,a8);
  6799. kernel_.setArg(8,a9);
  6800. kernel_.setArg(9,a10);
  6801. kernel_.setArg(10,a11);
  6802. kernel_.setArg(11,a12);
  6803. kernel_.setArg(12,a13);
  6804. err_ = queue_.enqueueNDRangeKernel(
  6805. kernel_,
  6806. offset_,
  6807. global_,
  6808. local_,
  6809. NULL, // bgaster_fixme - do we want to allow wait event lists?
  6810. &event);
  6811. return event;
  6812. }
  6813. template<class A1, class A2, class A3, class A4, class A5,
  6814. class A6, class A7, class A8, class A9, class A10,
  6815. class A11, class A12, class A13, class A14>
  6816. Event KernelFunctor::operator()(
  6817. const A1& a1,
  6818. const A2& a2,
  6819. const A3& a3,
  6820. const A4& a4,
  6821. const A5& a5,
  6822. const A6& a6,
  6823. const A7& a7,
  6824. const A8& a8,
  6825. const A9& a9,
  6826. const A10& a10,
  6827. const A11& a11,
  6828. const A12& a12,
  6829. const A13& a13,
  6830. const A14& a14,
  6831. const VECTOR_CLASS<Event>* events)
  6832. {
  6833. Event event;
  6834. kernel_.setArg(0,a1);
  6835. kernel_.setArg(1,a2);
  6836. kernel_.setArg(2,a3);
  6837. kernel_.setArg(3,a4);
  6838. kernel_.setArg(4,a5);
  6839. kernel_.setArg(5,a6);
  6840. kernel_.setArg(6,a7);
  6841. kernel_.setArg(7,a8);
  6842. kernel_.setArg(8,a9);
  6843. kernel_.setArg(9,a10);
  6844. kernel_.setArg(10,a11);
  6845. kernel_.setArg(11,a12);
  6846. kernel_.setArg(12,a13);
  6847. kernel_.setArg(13,a14);
  6848. err_ = queue_.enqueueNDRangeKernel(
  6849. kernel_,
  6850. offset_,
  6851. global_,
  6852. local_,
  6853. NULL, // bgaster_fixme - do we want to allow wait event lists?
  6854. &event);
  6855. return event;
  6856. }
  6857. template<class A1, class A2, class A3, class A4, class A5,
  6858. class A6, class A7, class A8, class A9, class A10,
  6859. class A11, class A12, class A13, class A14, class A15>
  6860. Event KernelFunctor::operator()(
  6861. const A1& a1,
  6862. const A2& a2,
  6863. const A3& a3,
  6864. const A4& a4,
  6865. const A5& a5,
  6866. const A6& a6,
  6867. const A7& a7,
  6868. const A8& a8,
  6869. const A9& a9,
  6870. const A10& a10,
  6871. const A11& a11,
  6872. const A12& a12,
  6873. const A13& a13,
  6874. const A14& a14,
  6875. const A15& a15,
  6876. const VECTOR_CLASS<Event>* events)
  6877. {
  6878. Event event;
  6879. kernel_.setArg(0,a1);
  6880. kernel_.setArg(1,a2);
  6881. kernel_.setArg(2,a3);
  6882. kernel_.setArg(3,a4);
  6883. kernel_.setArg(4,a5);
  6884. kernel_.setArg(5,a6);
  6885. kernel_.setArg(6,a7);
  6886. kernel_.setArg(7,a8);
  6887. kernel_.setArg(8,a9);
  6888. kernel_.setArg(9,a10);
  6889. kernel_.setArg(10,a11);
  6890. kernel_.setArg(11,a12);
  6891. kernel_.setArg(12,a13);
  6892. kernel_.setArg(13,a14);
  6893. kernel_.setArg(14,a15);
  6894. err_ = queue_.enqueueNDRangeKernel(
  6895. kernel_,
  6896. offset_,
  6897. global_,
  6898. local_,
  6899. NULL, // bgaster_fixme - do we want to allow wait event lists?
  6900. &event);
  6901. return event;
  6902. }
  6903. #undef __ERR_STR
  6904. #if !defined(__CL_USER_OVERRIDE_ERROR_STRINGS)
  6905. #undef __GET_DEVICE_INFO_ERR
  6906. #undef __GET_PLATFORM_INFO_ERR
  6907. #undef __GET_DEVICE_IDS_ERR
  6908. #undef __GET_CONTEXT_INFO_ERR
  6909. #undef __GET_EVENT_INFO_ERR
  6910. #undef __GET_EVENT_PROFILE_INFO_ERR
  6911. #undef __GET_MEM_OBJECT_INFO_ERR
  6912. #undef __GET_IMAGE_INFO_ERR
  6913. #undef __GET_SAMPLER_INFO_ERR
  6914. #undef __GET_KERNEL_INFO_ERR
  6915. #undef __GET_KERNEL_WORK_GROUP_INFO_ERR
  6916. #undef __GET_PROGRAM_INFO_ERR
  6917. #undef __GET_PROGRAM_BUILD_INFO_ERR
  6918. #undef __GET_COMMAND_QUEUE_INFO_ERR
  6919. #undef __CREATE_CONTEXT_FROM_TYPE_ERR
  6920. #undef __GET_SUPPORTED_IMAGE_FORMATS_ERR
  6921. #undef __CREATE_BUFFER_ERR
  6922. #undef __CREATE_SUBBUFFER_ERR
  6923. #undef __CREATE_IMAGE2D_ERR
  6924. #undef __CREATE_IMAGE3D_ERR
  6925. #undef __CREATE_SAMPLER_ERR
  6926. #undef __SET_MEM_OBJECT_DESTRUCTOR_CALLBACK_ERR
  6927. #undef __CREATE_USER_EVENT_ERR
  6928. #undef __SET_USER_EVENT_STATUS_ERR
  6929. #undef __SET_EVENT_CALLBACK_ERR
  6930. #undef __WAIT_FOR_EVENTS_ERR
  6931. #undef __CREATE_KERNEL_ERR
  6932. #undef __SET_KERNEL_ARGS_ERR
  6933. #undef __CREATE_PROGRAM_WITH_SOURCE_ERR
  6934. #undef __CREATE_PROGRAM_WITH_BINARY_ERR
  6935. #undef __BUILD_PROGRAM_ERR
  6936. #undef __CREATE_KERNELS_IN_PROGRAM_ERR
  6937. #undef __CREATE_COMMAND_QUEUE_ERR
  6938. #undef __SET_COMMAND_QUEUE_PROPERTY_ERR
  6939. #undef __ENQUEUE_READ_BUFFER_ERR
  6940. #undef __ENQUEUE_WRITE_BUFFER_ERR
  6941. #undef __ENQUEUE_READ_BUFFER_RECT_ERR
  6942. #undef __ENQUEUE_WRITE_BUFFER_RECT_ERR
  6943. #undef __ENQEUE_COPY_BUFFER_ERR
  6944. #undef __ENQEUE_COPY_BUFFER_RECT_ERR
  6945. #undef __ENQUEUE_READ_IMAGE_ERR
  6946. #undef __ENQUEUE_WRITE_IMAGE_ERR
  6947. #undef __ENQUEUE_COPY_IMAGE_ERR
  6948. #undef __ENQUEUE_COPY_IMAGE_TO_BUFFER_ERR
  6949. #undef __ENQUEUE_COPY_BUFFER_TO_IMAGE_ERR
  6950. #undef __ENQUEUE_MAP_BUFFER_ERR
  6951. #undef __ENQUEUE_MAP_IMAGE_ERR
  6952. #undef __ENQUEUE_UNMAP_MEM_OBJECT_ERR
  6953. #undef __ENQUEUE_NDRANGE_KERNEL_ERR
  6954. #undef __ENQUEUE_TASK_ERR
  6955. #undef __ENQUEUE_NATIVE_KERNEL
  6956. #undef __UNLOAD_COMPILER_ERR
  6957. #endif //__CL_USER_OVERRIDE_ERROR_STRINGS
  6958. #undef __INIT_CL_EXT_FCN_PTR
  6959. } // namespace cl
  6960. #endif // CL_HPP_