123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235 |
- //========================================================================================================================================================================================================200
- // DEFINE / INCLUDE
- //========================================================================================================================================================================================================200
- //======================================================================================================================================================150
- // MAIN FUNCTION HEADER
- //======================================================================================================================================================150
- #include "./main.h"
- //======================================================================================================================================================150
- // End
- //======================================================================================================================================================150
- //========================================================================================================================================================================================================200
- // KERNEL
- //========================================================================================================================================================================================================200
- __kernel void
- kernel_gpu_opencl( // structures
- params_common d_common, // 0
- // common_change
- __global fp* d_frame, // 1 INPUT
- int d_frame_no, // 2 INPUT
- // common
- __global int* d_endoRow, // 3 INPUT
- __global int* d_endoCol, // 4 INPUT
- __global int* d_tEndoRowLoc, // 5 OUTPUT common.endoPoints * common.no_frames
- __global int* d_tEndoColLoc, // 6 OUTPUT common.endoPoints * common.no_frames
- __global int* d_epiRow, // 7 INPUT
- __global int* d_epiCol, // 8 INPUT
- __global int* d_tEpiRowLoc, // 9 OUTPUT common.epiPoints * common.no_frames
- __global int* d_tEpiColLoc, // 10 OUTPUT common.epiPoints * common.no_frames
- // common_unique
- __global fp* d_endoT, // 11 OUTPUT common.in_elem * common.endoPoints
- __global fp* d_epiT, // 12 OUTPUT common.in_elem * common.epiPoints
- __global fp* d_in2_all, // 13 OUTPUT common.in2_elem * common.allPoints
- __global fp* d_conv_all, // 14 OUTPUT common.conv_elem * common.allPoints
- __global fp* d_in2_pad_cumv_all, // 15 OUTPUT common.in2_pad_cumv_elem * common.allPoints
- __global fp* d_in2_pad_cumv_sel_all, // 16 OUTPUT common.in2_pad_cumv_sel_elem * common.allPoints
- __global fp* d_in2_sub_cumh_all, // 17 OUTPUT common.in2_sub_cumh_elem * common.allPoints
- __global fp* d_in2_sub_cumh_sel_all, // 18 OUTPUT common.in2_sub_cumh_sel_elem * common.allPoints
- __global fp* d_in2_sub2_all, // 19 OUTPUT common.in2_sub2_elem * common.allPoints
- __global fp* d_in2_sqr_all, // 20 OUTPUT common.in2_elem * common.allPoints
- __global fp* d_in2_sqr_sub2_all, // 21 OUTPUT common.in2_sub2_elem * common.allPoints
- __global fp* d_in_sqr_all, // 22 OUTPUT common.in_elem * common.allPoints
- __global fp* d_tMask_all, // 23 OUTPUT common.tMask_elem * common.allPoints
- __global fp* d_mask_conv_all, // 24 OUTPUT common.mask_conv_elem * common.allPoints
- // // local
- // __local fp* d_in_mod_temp, // 25 OUTPUT common.in_elem
- // __local fp* in_partial_sum, // 26 OUTPUT common.in_cols
- // __local fp* in_sqr_partial_sum, // 27 OUTPUT common.in_sqr_rows
- // __local fp* par_max_val, // 28 OUTPUT common.mask_conv_rows
- // __local int* par_max_coo) // 29 OUTPUT common.mask_conv_rows
- // local
- __global fp* d_in_mod_temp_all, // 25 OUTPUT common.in_elem * common.allPoints
- __global fp* in_partial_sum_all, // 26 OUTPUT common.in_cols * common.allPoints
- __global fp* in_sqr_partial_sum_all, // 27 OUTPUT common.in_sqr_rows * common.allPoints
- __global fp* par_max_val_all, // 28 OUTPUT common.mask_conv_rows * common.allPoints
- __global int* par_max_coo_all, // 29 OUTPUT common.mask_conv_rows * common.allPoints
- __global fp* in_final_sum_all, // 30 OUTPUT common.allPoints
- __global fp* in_sqr_final_sum_all, // 31 OUTPUT common.allPoints
- __global fp* denomT_all, // 32 OUTPUT common.allPoints
- __global fp* checksum) // 33 OUTPUT 100
- {
- //======================================================================================================================================================150
- // COMMON VARIABLES
- //======================================================================================================================================================150
- // __global fp* d_in;
- int rot_row;
- int rot_col;
- int in2_rowlow;
- int in2_collow;
- int ic;
- int jc;
- int jp1;
- int ja1, ja2;
- int ip1;
- int ia1, ia2;
- int ja, jb;
- int ia, ib;
- fp s;
- int i;
- int j;
- int row;
- int col;
- int ori_row;
- int ori_col;
- int position;
- fp sum;
- int pos_ori;
- fp temp;
- fp temp2;
- int location;
- int cent;
- int tMask_row;
- int tMask_col;
- fp largest_value_current = 0;
- fp largest_value = 0;
- int largest_coordinate_current = 0;
- int largest_coordinate = 0;
- fp fin_max_val = 0;
- int fin_max_coo = 0;
- int largest_row;
- int largest_col;
- int offset_row;
- int offset_col;
- fp mean;
- fp mean_sqr;
- fp variance;
- fp deviation;
- int pointer;
- int ori_pointer;
- int loc_pointer;
- // __local fp in_final_sum;
- // __local fp in_sqr_final_sum;
- // __local fp denomT;
- //======================================================================================================================================================150
- // BLOCK/THREAD IDs
- //======================================================================================================================================================150
- int bx = get_group_id(0); // get current horizontal block index (0-n)
- int tx = get_local_id(0); // get current horizontal thread index (0-n)
- int ei_new;
- //======================================================================================================================================================150
- // UNIQUE STRUCTURE RECONSTRUCTED HERE
- //======================================================================================================================================================150
- // common
- __global fp* d_common_change_d_frame = &d_frame[0];
- // offsets for either endo or epi points (separate arrays for endo and epi points)
- int d_unique_point_no;
- __global int* d_unique_d_Row;
- __global int* d_unique_d_Col;
- __global int* d_unique_d_tRowLoc;
- __global int* d_unique_d_tColLoc;
- __global fp* d_in;
- if(bx < d_common.endoPoints){
- d_unique_point_no = bx; // endo point number 0-???
- d_unique_d_Row = d_endoRow; // initial endo row coordinates
- d_unique_d_Col = d_endoCol; // initial endo col coordinates
- d_unique_d_tRowLoc = d_tEndoRowLoc; // all endo row coordinates
- d_unique_d_tColLoc = d_tEndoColLoc; // all endo col coordinates
- d_in = &d_endoT[d_unique_point_no * d_common.in_elem]; // endo templates
- }
- else{
- d_unique_point_no = bx-d_common.endoPoints; // epi point number 0-???
- d_unique_d_Row = d_epiRow; // initial epi row coordinates
- d_unique_d_Col = d_epiCol; // initial epi col coordinates
- d_unique_d_tRowLoc = d_tEpiRowLoc; // all epi row coordinates
- d_unique_d_tColLoc = d_tEpiColLoc; // all epi col coordinates
- d_in = &d_epiT[d_unique_point_no * d_common.in_elem]; // epi templates
- }
- // offsets for all points (one array for all points)
- __global fp* d_unique_d_in2 = &d_in2_all[bx*d_common.in2_elem];
- __global fp* d_unique_d_conv = &d_conv_all[bx*d_common.conv_elem];
- __global fp* d_unique_d_in2_pad_cumv = &d_in2_pad_cumv_all[bx*d_common.in2_pad_cumv_elem];
- __global fp* d_unique_d_in2_pad_cumv_sel = &d_in2_pad_cumv_sel_all[bx*d_common.in2_pad_cumv_sel_elem];
- __global fp* d_unique_d_in2_sub_cumh = &d_in2_sub_cumh_all[bx*d_common.in2_sub_cumh_elem];
- __global fp* d_unique_d_in2_sub_cumh_sel = &d_in2_sub_cumh_sel_all[bx*d_common.in2_sub_cumh_sel_elem];
- __global fp* d_unique_d_in2_sub2 = &d_in2_sub2_all[bx*d_common.in2_sub2_elem];
- __global fp* d_unique_d_in2_sqr = &d_in2_sqr_all[bx*d_common.in2_sqr_elem];
- __global fp* d_unique_d_in2_sqr_sub2 = &d_in2_sqr_sub2_all[bx*d_common.in2_sqr_sub2_elem];
- __global fp* d_unique_d_in_sqr = &d_in_sqr_all[bx*d_common.in_sqr_elem];
- __global fp* d_unique_d_tMask = &d_tMask_all[bx*d_common.tMask_elem];
- __global fp* d_unique_d_mask_conv = &d_mask_conv_all[bx*d_common.mask_conv_elem];
- // used to be local
- __global fp* d_in_mod_temp = &d_in_mod_temp_all[bx*d_common.in_elem];
- __global fp* in_partial_sum = &in_partial_sum_all[bx*d_common.in_cols];
- __global fp* in_sqr_partial_sum = &in_sqr_partial_sum_all[bx*d_common.in_sqr_rows];
- __global fp* par_max_val = &par_max_val_all[bx*d_common.mask_conv_rows];
- __global int* par_max_coo = &par_max_coo_all[bx*d_common.mask_conv_rows];
- __global fp* in_final_sum = &in_final_sum_all[bx];
- __global fp* in_sqr_final_sum = &in_sqr_final_sum_all[bx];
- __global fp* denomT = &denomT_all[bx];
- //======================================================================================================================================================150
- // END
- //======================================================================================================================================================150
- //======================================================================================================================================================150
- // Initialize checksum
- //======================================================================================================================================================150
- #ifdef TEST_CHECKSUM
- if(bx==0 && tx==0){
- for(i=0; i<CHECK; i++){
- checksum[i] = 0;
- }
- }
- #endif
- //======================================================================================================================================================150
- // INITIAL COORDINATE AND TEMPLATE UPDATE
- //======================================================================================================================================================150
- // generate templates based on the first frame only
- if(d_frame_no == 0){
- //====================================================================================================100
- // Initialize cross-frame variables
- //====================================================================================================100
- #ifdef INIT
- // only the first thread initializes
- if(tx==0){
- // this block and for all frames
- for(i=0; i<d_common.no_frames; i++){
- d_unique_d_tRowLoc[d_unique_point_no*d_common.no_frames+i] = 0;
- d_unique_d_tColLoc[d_unique_point_no*d_common.no_frames+i] = 0;
- }
- // this block
- for(i=0; i<d_common.in_elem; i++){
- d_in[i] = 0;
- }
- }
- #endif
- //====================================================================================================100
- // SYNCHRONIZE THREADS
- //====================================================================================================100
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //====================================================================================================100
- // UPDATE ROW LOC AND COL LOC
- //====================================================================================================100
- // uptade temporary endo/epi row/col coordinates (in each block corresponding to point, narrow work to one thread)
- ei_new = tx;
- if(ei_new == 0){
- // update temporary row/col coordinates
- pointer = d_unique_point_no*d_common.no_frames+d_frame_no;
- d_unique_d_tRowLoc[pointer] = d_unique_d_Row[d_unique_point_no];
- d_unique_d_tColLoc[pointer] = d_unique_d_Col[d_unique_point_no];
- }
- //====================================================================================================100
- // CREATE TEMPLATES
- //====================================================================================================100
- // work
- ei_new = tx;
- while(ei_new < d_common.in_elem){
- // figure out row/col location in new matrix
- row = (ei_new+1) % d_common.in_rows - 1; // (0-n) row
- col = (ei_new+1) / d_common.in_rows + 1 - 1; // (0-n) column
- if((ei_new+1) % d_common.in_rows == 0){
- row = d_common.in_rows - 1;
- col = col-1;
- }
- // figure out row/col location in corresponding new template area in image and give to every thread (get top left corner and progress down and right)
- ori_row = d_unique_d_Row[d_unique_point_no] - 25 + row - 1;
- ori_col = d_unique_d_Col[d_unique_point_no] - 25 + col - 1;
- ori_pointer = ori_col*d_common.frame_rows+ori_row;
- // update template
- d_in[col*d_common.in_rows+row] = d_common_change_d_frame[ori_pointer];
- // go for second round
- ei_new = ei_new + NUMBER_THREADS;
- }
- //====================================================================================================100
- // SYNCHRONIZE THREADS
- //====================================================================================================100
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //====================================================================================================100
- // CHECKSUM
- //====================================================================================================100
- #ifdef TEST_CHECKSUM
- if(bx==0 && tx==0){
- for(i=0; i<d_common.in_elem; i++){
- checksum[0] = checksum[0]+d_in[i];
- }
- }
- //====================================================================================================100
- // SYNCHRONIZE THREADS
- //====================================================================================================100
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- #endif
- //====================================================================================================100
- // End
- //====================================================================================================100
- }
- //======================================================================================================================================================150
- // PROCESS POINTS
- //======================================================================================================================================================150
- // process points in all frames except for the first one
- if(d_frame_no != 0){
- //====================================================================================================100
- // Initialize frame-specific variables
- //====================================================================================================100
- #ifdef INIT
- // only the first thread initializes
- if(tx==0){
- // this block
- for(i=0; i<d_common.in2_elem; i++){
- d_unique_d_in2[i] = 0;
- }
- for(i=0; i<d_common.conv_elem; i++){
- d_unique_d_conv[i] = 0;
- }
- for(i=0; i<d_common.in2_pad_cumv_elem; i++){
- d_unique_d_in2_pad_cumv[i] = 0;
- }
- for(i=0; i<d_common.in2_pad_cumv_sel_elem; i++){
- d_unique_d_in2_pad_cumv_sel[i] = 0;
- }
- for(i=0; i<d_common.in2_sub_cumh_elem; i++){
- d_unique_d_in2_sub_cumh[i] = 0;
- }
- for(i=0; i<d_common.in2_sub_cumh_sel_elem; i++){
- d_unique_d_in2_sub_cumh_sel[i] = 0;
- }
- for(i=0; i<d_common.in2_sub2_elem; i++){
- d_unique_d_in2_sub2[i] = 0;
- }
- for(i=0; i<d_common.in2_sqr_elem; i++){
- d_unique_d_in2_sqr[i] = 0;
- }
- for(i=0; i<d_common.in2_sqr_sub2_elem; i++){
- d_unique_d_in2_sqr_sub2[i] = 0;
- }
- for(i=0; i<d_common.in_sqr_elem; i++){
- d_unique_d_in_sqr[i] = 0;
- }
- for(i=0; i<d_common.tMask_elem; i++){
- d_unique_d_tMask[i] = 0;
- }
- for(i=0; i<d_common.mask_conv_elem; i++){
- d_unique_d_mask_conv[i] = 0;
- }
- for(i=0; i<d_common.in_elem; i++){
- d_in_mod_temp[i] = 0;
- }
- for(i=0; i<d_common.in_cols; i++){
- in_partial_sum[i] = 0;
- }
- for(i=0; i<d_common.in_sqr_rows; i++){
- in_sqr_partial_sum[i] = 0;
- }
- for(i=0; i<d_common.mask_conv_rows; i++){
- par_max_val[i] = 0;
- }
- for(i=0; i<d_common.mask_conv_rows; i++){
- par_max_coo[i] = 0;
- }
- in_final_sum[0] = 0;
- in_sqr_final_sum[0] = 0;
- denomT[0] = 0;
- }
- #endif
- //====================================================================================================100
- // SYNCHRONIZE THREADS
- //====================================================================================================100
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //====================================================================================================100
- // SELECTION
- //====================================================================================================100
- in2_rowlow = d_unique_d_Row[d_unique_point_no] - d_common.sSize; // (1 to n+1)
- in2_collow = d_unique_d_Col[d_unique_point_no] - d_common.sSize;
- // work
- ei_new = tx;
- while(ei_new < d_common.in2_elem){
- // figure out row/col location in new matrix
- row = (ei_new+1) % d_common.in2_rows - 1; // (0-n) row
- col = (ei_new+1) / d_common.in2_rows + 1 - 1; // (0-n) column
- if((ei_new+1) % d_common.in2_rows == 0){
- row = d_common.in2_rows - 1;
- col = col-1;
- }
- // figure out corresponding location in old matrix and copy values to new matrix
- ori_row = row + in2_rowlow - 1;
- ori_col = col + in2_collow - 1;
- d_unique_d_in2[ei_new] = d_common_change_d_frame[ori_col*d_common.frame_rows+ori_row];
- // go for second round
- ei_new = ei_new + NUMBER_THREADS;
- }
- //====================================================================================================100
- // SYNCHRONIZE THREADS
- //====================================================================================================100
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //====================================================================================================100
- // CHECKSUM
- //====================================================================================================100
- #ifdef TEST_CHECKSUM
- if(bx==0 && tx==0){
- for(i=0; i<d_common.in2_elem; i++){
- checksum[1] = checksum[1]+d_unique_d_in2[i];
- }
- }
- //====================================================================================================100
- // SYNCHRONIZE THREADS
- //====================================================================================================100
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- #endif
- //====================================================================================================100
- // CONVOLUTION
- //====================================================================================================100
- //==================================================50
- // ROTATION
- //==================================================50
- // work
- ei_new = tx;
- while(ei_new < d_common.in_elem){
- // while(ei_new < 1){
- // figure out row/col location in padded array
- row = (ei_new+1) % d_common.in_rows - 1; // (0-n) row
- col = (ei_new+1) / d_common.in_rows + 1 - 1; // (0-n) column
- if((ei_new+1) % d_common.in_rows == 0){
- row = d_common.in_rows - 1;
- col = col-1;
- }
- // execution
- rot_row = (d_common.in_rows-1) - row;
- rot_col = (d_common.in_rows-1) - col;
- d_in_mod_temp[ei_new] = d_in[rot_col*d_common.in_rows+rot_row];
- // d_in_mod_temp[ei_new] = d_in[0];
- // d_in_mod_temp[ei_new] = d_unique_d_T[d_unique_in_pointer];
- // d_in_mod_temp[ei_new] = d_unique_d_T[d_unique_point_no * d_common.in_elem];
- // d_in_mod_temp[ei_new] = d_unique_d_T[d_unique_point_no * 2601];
- // if((d_unique_point_no * d_common.in_elem) > (2601*51
- // printf("frame_no IS %d\n", d_common_change[0].frame_no);
- // d_in_mod_temp[ei_new] = d_unique_d_T[d_unique_point_no];
- // d_in_mod_temp[ei_new] = 1;
- // kot = d_in[rot_col*d_common.in_rows+rot_row];
- // d_in_mod_temp[ei_new] = kot;
- // d_in_mod_temp[ei_new] = d_unique_d_T[d_unique_in_pointer+rot_col*d_common.in_rows+rot_row];
- // d_in_mod_temp[ei_new] = d_unique_d_T[d_unique_point_no * d_common.in_elem+rot_col*d_common.in_rows+rot_row];
- //d_in_mod_temp[ei_new] = d_unique_d_T[d_unique_point_no];
- // d_unique_d_T[d_unique_in_pointer+rot_col*d_common.in_rows+rot_row] = 1;
- // d_unique_d_T[d_unique_in_pointer] = 1;
- // d_endoT[d_unique_in_pointer] = 1;
- // d_in_mod_temp[ei_new] = 1;
- // go for second round
- ei_new = ei_new + NUMBER_THREADS;
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //==================================================50
- // CHECKSUM
- //==================================================50
- #ifdef TEST_CHECKSUM
- if(bx==0 && tx==0){
- for(i=0; i<d_common.in_elem; i++){
- checksum[2] = checksum[2]+d_in_mod_temp[i];
- }
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- #endif
- //==================================================50
- // ACTUAL CONVOLUTION
- //==================================================50
- // work
- ei_new = tx;
- while(ei_new < d_common.conv_elem){
- // figure out row/col location in array
- ic = (ei_new+1) % d_common.conv_rows; // (1-n)
- jc = (ei_new+1) / d_common.conv_rows + 1; // (1-n)
- if((ei_new+1) % d_common.conv_rows == 0){
- ic = d_common.conv_rows;
- jc = jc-1;
- }
- //
- j = jc + d_common.joffset;
- jp1 = j + 1;
- if(d_common.in2_cols < jp1){
- ja1 = jp1 - d_common.in2_cols;
- }
- else{
- ja1 = 1;
- }
- if(d_common.in_cols < j){
- ja2 = d_common.in_cols;
- }
- else{
- ja2 = j;
- }
- i = ic + d_common.ioffset;
- ip1 = i + 1;
-
- if(d_common.in2_rows < ip1){
- ia1 = ip1 - d_common.in2_rows;
- }
- else{
- ia1 = 1;
- }
- if(d_common.in_rows < i){
- ia2 = d_common.in_rows;
- }
- else{
- ia2 = i;
- }
- s = 0;
- for(ja=ja1; ja<=ja2; ja++){
- jb = jp1 - ja;
- for(ia=ia1; ia<=ia2; ia++){
- ib = ip1 - ia;
- s = s + d_in_mod_temp[d_common.in_rows*(ja-1)+ia-1] * d_unique_d_in2[d_common.in2_rows*(jb-1)+ib-1];
- }
- }
- //d_unique_d_conv[d_common.conv_rows*(jc-1)+ic-1] = s;
- d_unique_d_conv[ei_new] = s;
- // go for second round
- ei_new = ei_new + NUMBER_THREADS;
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //==================================================50
- // CHECKSUM
- //==================================================50
- #ifdef TEST_CHECKSUM
- if(bx==0 && tx==0){
- for(i=0; i<d_common.conv_elem; i++){
- checksum[3] = checksum[3]+d_unique_d_conv[i];
- }
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- #endif
- //==================================================50
- // End
- //==================================================50
- //====================================================================================================100
- // CUMULATIVE SUM (LOCAL)
- //====================================================================================================100
- //==================================================50
- // PADD ARRAY
- //==================================================50
- // work
- ei_new = tx;
- while(ei_new < d_common.in2_pad_cumv_elem){
- // figure out row/col location in padded array
- row = (ei_new+1) % d_common.in2_pad_cumv_rows - 1; // (0-n) row
- col = (ei_new+1) / d_common.in2_pad_cumv_rows + 1 - 1; // (0-n) column
- if((ei_new+1) % d_common.in2_pad_cumv_rows == 0){
- row = d_common.in2_pad_cumv_rows - 1;
- col = col-1;
- }
- // execution
- if( row > (d_common.in2_pad_add_rows-1) && // do if has numbers in original array
- row < (d_common.in2_pad_add_rows+d_common.in2_rows) &&
- col > (d_common.in2_pad_add_cols-1) &&
- col < (d_common.in2_pad_add_cols+d_common.in2_cols)){
- ori_row = row - d_common.in2_pad_add_rows;
- ori_col = col - d_common.in2_pad_add_cols;
- d_unique_d_in2_pad_cumv[ei_new] = d_unique_d_in2[ori_col*d_common.in2_rows+ori_row];
- }
- else{ // do if otherwise
- d_unique_d_in2_pad_cumv[ei_new] = 0;
- }
- // go for second round
- ei_new = ei_new + NUMBER_THREADS;
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //==================================================50
- // CHECKSUM
- //==================================================50
- #ifdef TEST_CHECKSUM
- if(bx==0 && tx==0){
- for(i=0; i<d_common.in2_pad_cumv_elem; i++){
- checksum[4] = checksum[4]+d_unique_d_in2_pad_cumv[i];
- }
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- #endif
- //==================================================50
- // VERTICAL CUMULATIVE SUM
- //==================================================50
- //work
- ei_new = tx;
- while(ei_new < d_common.in2_pad_cumv_cols){
- // figure out column position
- pos_ori = ei_new*d_common.in2_pad_cumv_rows;
- // variables
- sum = 0;
-
- // loop through all rows
- for(position = pos_ori; position < pos_ori+d_common.in2_pad_cumv_rows; position = position + 1){
- d_unique_d_in2_pad_cumv[position] = d_unique_d_in2_pad_cumv[position] + sum;
- sum = d_unique_d_in2_pad_cumv[position];
- }
- // go for second round
- ei_new = ei_new + NUMBER_THREADS;
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //==================================================50
- // CHECKSUM
- //==================================================50
- #ifdef TEST_CHECKSUM
- if(bx==0 && tx==0){
- for(i=0; i<d_common.in2_pad_cumv_cols; i++){
- checksum[5] = checksum[5]+d_unique_d_in2_pad_cumv[i];
- }
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- #endif
- //==================================================50
- // SELECTION
- //==================================================50
- // work
- ei_new = tx;
- while(ei_new < d_common.in2_pad_cumv_sel_elem){
- // figure out row/col location in new matrix
- row = (ei_new+1) % d_common.in2_pad_cumv_sel_rows - 1; // (0-n) row
- col = (ei_new+1) / d_common.in2_pad_cumv_sel_rows + 1 - 1; // (0-n) column
- if((ei_new+1) % d_common.in2_pad_cumv_sel_rows == 0){
- row = d_common.in2_pad_cumv_sel_rows - 1;
- col = col-1;
- }
- // figure out corresponding location in old matrix and copy values to new matrix
- ori_row = row + d_common.in2_pad_cumv_sel_rowlow - 1;
- ori_col = col + d_common.in2_pad_cumv_sel_collow - 1;
- d_unique_d_in2_pad_cumv_sel[ei_new] = d_unique_d_in2_pad_cumv[ori_col*d_common.in2_pad_cumv_rows+ori_row];
- // go for second round
- ei_new = ei_new + NUMBER_THREADS;
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //==================================================50
- // CHECKSUM
- //==================================================50
- #ifdef TEST_CHECKSUM
- if(bx==0 && tx==0){
- for(i=0; i<d_common.in2_pad_cumv_sel_elem; i++){
- checksum[6] = checksum[6]+d_unique_d_in2_pad_cumv_sel[i];
- }
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- #endif
- //==================================================50
- // SELECTION 2
- //==================================================50
- // work
- ei_new = tx;
- while(ei_new < d_common.in2_sub_cumh_elem){
- // figure out row/col location in new matrix
- row = (ei_new+1) % d_common.in2_sub_cumh_rows - 1; // (0-n) row
- col = (ei_new+1) / d_common.in2_sub_cumh_rows + 1 - 1; // (0-n) column
- if((ei_new+1) % d_common.in2_sub_cumh_rows == 0){
- row = d_common.in2_sub_cumh_rows - 1;
- col = col-1;
- }
- // figure out corresponding location in old matrix and copy values to new matrix
- ori_row = row + d_common.in2_pad_cumv_sel2_rowlow - 1;
- ori_col = col + d_common.in2_pad_cumv_sel2_collow - 1;
- d_unique_d_in2_sub_cumh[ei_new] = d_unique_d_in2_pad_cumv[ori_col*d_common.in2_pad_cumv_rows+ori_row];
- // go for second round
- ei_new = ei_new + NUMBER_THREADS;
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //==================================================50
- // CHECKSUM
- //==================================================50
- #ifdef TEST_CHECKSUM
- if(bx==0 && tx==0){
- for(i=0; i<d_common.in2_sub_cumh_elem; i++){
- checksum[7] = checksum[7]+d_unique_d_in2_sub_cumh[i];
- }
- }
- #endif
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //==================================================50
- // SUBTRACTION
- //==================================================50
- // work
- ei_new = tx;
- while(ei_new < d_common.in2_sub_cumh_elem){
- // subtract
- d_unique_d_in2_sub_cumh[ei_new] = d_unique_d_in2_pad_cumv_sel[ei_new] - d_unique_d_in2_sub_cumh[ei_new];
- // go for second round
- ei_new = ei_new + NUMBER_THREADS;
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //==================================================50
- // CHECKSUM
- //==================================================50
- #ifdef TEST_CHECKSUM
- if(bx==0 && tx==0){
- for(i=0; i<d_common.in2_sub_cumh_elem; i++){
- checksum[8] = checksum[8]+d_unique_d_in2_sub_cumh[i];
- }
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- #endif
- //==================================================50
- // HORIZONTAL CUMULATIVE SUM
- //==================================================50
- // work
- ei_new = tx;
- while(ei_new < d_common.in2_sub_cumh_rows){
- // figure out row position
- pos_ori = ei_new;
- // variables
- sum = 0;
- // loop through all rows
- for(position = pos_ori; position < pos_ori+d_common.in2_sub_cumh_elem; position = position + d_common.in2_sub_cumh_rows){
- d_unique_d_in2_sub_cumh[position] = d_unique_d_in2_sub_cumh[position] + sum;
- sum = d_unique_d_in2_sub_cumh[position];
- }
- // go for second round
- ei_new = ei_new + NUMBER_THREADS;
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //==================================================50
- // CHECKSUM
- //==================================================50
- #ifdef TEST_CHECKSUM
- if(bx==0 && tx==0){
- for(i=0; i<d_common.in2_sub_cumh_elem; i++){
- checksum[9] = checksum[9]+d_unique_d_in2_sub_cumh[i];
- }
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- #endif
- //==================================================50
- // SELECTION
- //==================================================50
- // work
- ei_new = tx;
- while(ei_new < d_common.in2_sub_cumh_sel_elem){
- // figure out row/col location in new matrix
- row = (ei_new+1) % d_common.in2_sub_cumh_sel_rows - 1; // (0-n) row
- col = (ei_new+1) / d_common.in2_sub_cumh_sel_rows + 1 - 1; // (0-n) column
- if((ei_new+1) % d_common.in2_sub_cumh_sel_rows == 0){
- row = d_common.in2_sub_cumh_sel_rows - 1;
- col = col - 1;
- }
- // figure out corresponding location in old matrix and copy values to new matrix
- ori_row = row + d_common.in2_sub_cumh_sel_rowlow - 1;
- ori_col = col + d_common.in2_sub_cumh_sel_collow - 1;
- d_unique_d_in2_sub_cumh_sel[ei_new] = d_unique_d_in2_sub_cumh[ori_col*d_common.in2_sub_cumh_rows+ori_row];
- // go for second round
- ei_new = ei_new + NUMBER_THREADS;
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //==================================================50
- // CHECKSUM
- //==================================================50
- #ifdef TEST_CHECKSUM
- if(bx==0 && tx==0){
- for(i=0; i<d_common.in2_sub_cumh_sel_elem; i++){
- checksum[10] = checksum[10]+d_unique_d_in2_sub_cumh_sel[i];
- }
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- #endif
- //==================================================50
- // SELECTION 2
- //==================================================50
- // work
- ei_new = tx;
- while(ei_new < d_common.in2_sub2_elem){
- // figure out row/col location in new matrix
- row = (ei_new+1) % d_common.in2_sub2_rows - 1; // (0-n) row
- col = (ei_new+1) / d_common.in2_sub2_rows + 1 - 1; // (0-n) column
- if((ei_new+1) % d_common.in2_sub2_rows == 0){
- row = d_common.in2_sub2_rows - 1;
- col = col-1;
- }
- // figure out corresponding location in old matrix and copy values to new matrix
- ori_row = row + d_common.in2_sub_cumh_sel2_rowlow - 1;
- ori_col = col + d_common.in2_sub_cumh_sel2_collow - 1;
- d_unique_d_in2_sub2[ei_new] = d_unique_d_in2_sub_cumh[ori_col*d_common.in2_sub_cumh_rows+ori_row];
- // go for second round
- ei_new = ei_new + NUMBER_THREADS;
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //==================================================50
- // CHECKSUM
- //==================================================50
- #ifdef TEST_CHECKSUM
- if(bx==0 && tx==0){
- for(i=0; i<d_common.in2_sub2_elem; i++){
- checksum[11] = checksum[11]+d_unique_d_in2_sub2[i];
- }
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- #endif
- //==================================================50
- // SUBTRACTION
- //==================================================50
- // work
- ei_new = tx;
- while(ei_new < d_common.in2_sub2_elem){
- // subtract
- d_unique_d_in2_sub2[ei_new] = d_unique_d_in2_sub_cumh_sel[ei_new] - d_unique_d_in2_sub2[ei_new];
- // go for second round
- ei_new = ei_new + NUMBER_THREADS;
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //==================================================50
- // CHECKSUM
- //==================================================50
- #ifdef TEST_CHECKSUM
- if(bx==0 && tx==0){
- for(i=0; i<d_common.in2_sub2_elem; i++){
- checksum[12] = checksum[12]+d_unique_d_in2_sub2[i];
- }
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- #endif
- //==================================================50
- // End
- //==================================================50
- //====================================================================================================100
- // CUMULATIVE SUM 2
- //====================================================================================================100
- //==================================================50
- // MULTIPLICATION
- //==================================================50
- // work
- ei_new = tx;
- while(ei_new < d_common.in2_sqr_elem){
- temp = d_unique_d_in2[ei_new];
- d_unique_d_in2_sqr[ei_new] = temp * temp;
- // go for second round
- ei_new = ei_new + NUMBER_THREADS;
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //==================================================50
- // CHECKSUM
- //==================================================50
- #ifdef TEST_CHECKSUM
- if(bx==0 && tx==0){
- for(i=0; i<d_common.in2_sqr_elem; i++){
- checksum[13] = checksum[13]+d_unique_d_in2_sqr[i];
- }
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- #endif
- //==================================================50
- // PAD ARRAY, VERTICAL CUMULATIVE SUM
- //==================================================50
- //==================================================50
- // PAD ARRAY
- //==================================================50
- // work
- ei_new = tx;
- while(ei_new < d_common.in2_pad_cumv_elem){
- // figure out row/col location in padded array
- row = (ei_new+1) % d_common.in2_pad_cumv_rows - 1; // (0-n) row
- col = (ei_new+1) / d_common.in2_pad_cumv_rows + 1 - 1; // (0-n) column
- if((ei_new+1) % d_common.in2_pad_cumv_rows == 0){
- row = d_common.in2_pad_cumv_rows - 1;
- col = col-1;
- }
- // execution
- if( row > (d_common.in2_pad_add_rows-1) && // do if has numbers in original array
- row < (d_common.in2_pad_add_rows+d_common.in2_sqr_rows) &&
- col > (d_common.in2_pad_add_cols-1) &&
- col < (d_common.in2_pad_add_cols+d_common.in2_sqr_cols)){
- ori_row = row - d_common.in2_pad_add_rows;
- ori_col = col - d_common.in2_pad_add_cols;
- d_unique_d_in2_pad_cumv[ei_new] = d_unique_d_in2_sqr[ori_col*d_common.in2_sqr_rows+ori_row];
- }
- else{ // do if otherwise
- d_unique_d_in2_pad_cumv[ei_new] = 0;
- }
- // go for second round
- ei_new = ei_new + NUMBER_THREADS;
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //==================================================50
- // CHECKSUM
- //==================================================50
- #ifdef TEST_CHECKSUM
- if(bx==0 && tx==0){
- for(i=0; i<d_common.in2_pad_cumv_elem; i++){
- checksum[14] = checksum[14]+d_unique_d_in2_pad_cumv[i];
- }
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- #endif
- //==================================================50
- // VERTICAL CUMULATIVE SUM
- //==================================================50
- //work
- ei_new = tx;
- while(ei_new < d_common.in2_pad_cumv_cols){
- // figure out column position
- pos_ori = ei_new*d_common.in2_pad_cumv_rows;
- // variables
- sum = 0;
-
- // loop through all rows
- for(position = pos_ori; position < pos_ori+d_common.in2_pad_cumv_rows; position = position + 1){
- d_unique_d_in2_pad_cumv[position] = d_unique_d_in2_pad_cumv[position] + sum;
- sum = d_unique_d_in2_pad_cumv[position];
- }
- // go for second round
- ei_new = ei_new + NUMBER_THREADS;
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //==================================================50
- // CHECKSUM
- //==================================================50
- #ifdef TEST_CHECKSUM
- if(bx==0 && tx==0){
- for(i=0; i<d_common.in2_pad_cumv_elem; i++){
- checksum[15] = checksum[15]+d_unique_d_in2_pad_cumv[i];
- }
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- #endif
- //==================================================50
- // SELECTION
- //==================================================50
- // work
- ei_new = tx;
- while(ei_new < d_common.in2_pad_cumv_sel_elem){
- // figure out row/col location in new matrix
- row = (ei_new+1) % d_common.in2_pad_cumv_sel_rows - 1; // (0-n) row
- col = (ei_new+1) / d_common.in2_pad_cumv_sel_rows + 1 - 1; // (0-n) column
- if((ei_new+1) % d_common.in2_pad_cumv_sel_rows == 0){
- row = d_common.in2_pad_cumv_sel_rows - 1;
- col = col-1;
- }
- // figure out corresponding location in old matrix and copy values to new matrix
- ori_row = row + d_common.in2_pad_cumv_sel_rowlow - 1;
- ori_col = col + d_common.in2_pad_cumv_sel_collow - 1;
- d_unique_d_in2_pad_cumv_sel[ei_new] = d_unique_d_in2_pad_cumv[ori_col*d_common.in2_pad_cumv_rows+ori_row];
- // go for second round
- ei_new = ei_new + NUMBER_THREADS;
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //==================================================50
- // CHECKSUM
- //==================================================50
- #ifdef TEST_CHECKSUM
- if(bx==0 && tx==0){
- for(i=0; i<d_common.in2_pad_cumv_sel_elem; i++){
- checksum[16] = checksum[16]+d_unique_d_in2_pad_cumv_sel[i];
- }
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- #endif
- //==================================================50
- // SELECTION 2
- //==================================================50
- // work
- ei_new = tx;
- while(ei_new < d_common.in2_sub_cumh_elem){
- // figure out row/col location in new matrix
- row = (ei_new+1) % d_common.in2_sub_cumh_rows - 1; // (0-n) row
- col = (ei_new+1) / d_common.in2_sub_cumh_rows + 1 - 1; // (0-n) column
- if((ei_new+1) % d_common.in2_sub_cumh_rows == 0){
- row = d_common.in2_sub_cumh_rows - 1;
- col = col-1;
- }
- // figure out corresponding location in old matrix and copy values to new matrix
- ori_row = row + d_common.in2_pad_cumv_sel2_rowlow - 1;
- ori_col = col + d_common.in2_pad_cumv_sel2_collow - 1;
- d_unique_d_in2_sub_cumh[ei_new] = d_unique_d_in2_pad_cumv[ori_col*d_common.in2_pad_cumv_rows+ori_row];
- // go for second round
- ei_new = ei_new + NUMBER_THREADS;
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //==================================================50
- // CHECKSUM
- //==================================================50
- #ifdef TEST_CHECKSUM
- if(bx==0 && tx==0){
- for(i=0; i<d_common.in2_sub_cumh_elem; i++){
- checksum[17] = checksum[17]+d_unique_d_in2_sub_cumh[i];
- }
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- #endif
- //==================================================50
- // SUBTRACTION
- //==================================================50
- // work
- ei_new = tx;
- while(ei_new < d_common.in2_sub_cumh_elem){
- // subtract
- d_unique_d_in2_sub_cumh[ei_new] = d_unique_d_in2_pad_cumv_sel[ei_new] - d_unique_d_in2_sub_cumh[ei_new];
- // go for second round
- ei_new = ei_new + NUMBER_THREADS;
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //==================================================50
- // CHECKSUM
- //==================================================50
- #ifdef TEST_CHECKSUM
- if(bx==0 && tx==0){
- for(i=0; i<d_common.in2_sub_cumh_elem; i++){
- checksum[18] = checksum[18]+d_unique_d_in2_sub_cumh[i];
- }
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- #endif
- //==================================================50
- // HORIZONTAL CUMULATIVE SUM
- //==================================================50
- // work
- ei_new = tx;
- while(ei_new < d_common.in2_sub_cumh_rows){
- // figure out row position
- pos_ori = ei_new;
- // variables
- sum = 0;
- // loop through all rows
- for(position = pos_ori; position < pos_ori+d_common.in2_sub_cumh_elem; position = position + d_common.in2_sub_cumh_rows){
- d_unique_d_in2_sub_cumh[position] = d_unique_d_in2_sub_cumh[position] + sum;
- sum = d_unique_d_in2_sub_cumh[position];
- }
- // go for second round
- ei_new = ei_new + NUMBER_THREADS;
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //==================================================50
- // CHECKSUM
- //==================================================50
- #ifdef TEST_CHECKSUM
- if(bx==0 && tx==0){
- for(i=0; i<d_common.in2_sub_cumh_rows; i++){
- checksum[19] = checksum[19]+d_unique_d_in2_sub_cumh[i];
- }
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- #endif
- //==================================================50
- // SELECTION
- //==================================================50
- // work
- ei_new = tx;
- while(ei_new < d_common.in2_sub_cumh_sel_elem){
- // figure out row/col location in new matrix
- row = (ei_new+1) % d_common.in2_sub_cumh_sel_rows - 1; // (0-n) row
- col = (ei_new+1) / d_common.in2_sub_cumh_sel_rows + 1 - 1; // (0-n) column
- if((ei_new+1) % d_common.in2_sub_cumh_sel_rows == 0){
- row = d_common.in2_sub_cumh_sel_rows - 1;
- col = col - 1;
- }
- // figure out corresponding location in old matrix and copy values to new matrix
- ori_row = row + d_common.in2_sub_cumh_sel_rowlow - 1;
- ori_col = col + d_common.in2_sub_cumh_sel_collow - 1;
- d_unique_d_in2_sub_cumh_sel[ei_new] = d_unique_d_in2_sub_cumh[ori_col*d_common.in2_sub_cumh_rows+ori_row];
- // go for second round
- ei_new = ei_new + NUMBER_THREADS;
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //==================================================50
- // CHECKSUM
- //==================================================50
- #ifdef TEST_CHECKSUM
- if(bx==0 && tx==0){
- for(i=0; i<d_common.in2_sub_cumh_sel_elem; i++){
- checksum[20] = checksum[20]+d_unique_d_in2_sub_cumh_sel[i];
- }
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- #endif
- //==================================================50
- // SELECTION 2
- //==================================================50
- // work
- ei_new = tx;
- while(ei_new < d_common.in2_sub2_elem){
- // figure out row/col location in new matrix
- row = (ei_new+1) % d_common.in2_sub2_rows - 1; // (0-n) row
- col = (ei_new+1) / d_common.in2_sub2_rows + 1 - 1; // (0-n) column
- if((ei_new+1) % d_common.in2_sub2_rows == 0){
- row = d_common.in2_sub2_rows - 1;
- col = col-1;
- }
- // figure out corresponding location in old matrix and copy values to new matrix
- ori_row = row + d_common.in2_sub_cumh_sel2_rowlow - 1;
- ori_col = col + d_common.in2_sub_cumh_sel2_collow - 1;
- d_unique_d_in2_sqr_sub2[ei_new] = d_unique_d_in2_sub_cumh[ori_col*d_common.in2_sub_cumh_rows+ori_row];
- // go for second round
- ei_new = ei_new + NUMBER_THREADS;
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //==================================================50
- // CHECKSUM
- //==================================================50
- #ifdef TEST_CHECKSUM
- if(bx==0 && tx==0){
- for(i=0; i<d_common.in2_sub2_elem; i++){
- checksum[21] = checksum[21]+d_unique_d_in2_sqr_sub2[i];
- }
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- #endif
- //==================================================50
- // SUBTRACTION
- //==================================================50
- // work
- ei_new = tx;
- while(ei_new < d_common.in2_sub2_elem){
- // subtract
- d_unique_d_in2_sqr_sub2[ei_new] = d_unique_d_in2_sub_cumh_sel[ei_new] - d_unique_d_in2_sqr_sub2[ei_new];
- // go for second round
- ei_new = ei_new + NUMBER_THREADS;
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //==================================================50
- // CHECKSUM
- //==================================================50
- #ifdef TEST_CHECKSUM
- if(bx==0 && tx==0){
- for(i=0; i<d_common.in2_sub2_elem; i++){
- checksum[22] = checksum[22]+d_unique_d_in2_sqr_sub2[i];
- }
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- #endif
- //==================================================50
- // End
- //==================================================50
- //====================================================================================================100
- // FINAL
- //====================================================================================================100
- //==================================================50
- // DENOMINATOR A SAVE RESULT IN CUMULATIVE SUM A2
- //==================================================50
- // work
- ei_new = tx;
- while(ei_new < d_common.in2_sub2_elem){
- temp = d_unique_d_in2_sub2[ei_new];
- temp2 = d_unique_d_in2_sqr_sub2[ei_new] - (temp * temp / d_common.in_elem);
- if(temp2 < 0){
- temp2 = 0;
- }
- d_unique_d_in2_sqr_sub2[ei_new] = sqrt(temp2);
-
- // go for second round
- ei_new = ei_new + NUMBER_THREADS;
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //==================================================50
- // CHECKSUM
- //==================================================50
- #ifdef TEST_CHECKSUM
- if(bx==0 && tx==0){
- for(i=0; i<d_common.in2_sub2_elem; i++){
- checksum[23] = checksum[23]+d_unique_d_in2_sqr_sub2[i];
- }
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- #endif
- //==================================================50
- // MULTIPLICATION
- //==================================================50
- // work
- ei_new = tx;
- while(ei_new < d_common.in_sqr_elem){
- temp = d_in[ei_new];
- d_unique_d_in_sqr[ei_new] = temp * temp;
- // go for second round
- ei_new = ei_new + NUMBER_THREADS;
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //==================================================50
- // CHECKSUM
- //==================================================50
- #ifdef TEST_CHECKSUM
- if(bx==0 && tx==0){
- for(i=0; i<d_common.in_sqr_elem; i++){
- checksum[24] = checksum[24]+d_unique_d_in_sqr[i];
- }
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- #endif
- //==================================================50
- // IN SUM
- //==================================================50
- // work
- ei_new = tx;
- while(ei_new < d_common.in_cols){
- sum = 0;
- for(i = 0; i < d_common.in_rows; i++){
- sum = sum + d_in[ei_new*d_common.in_rows+i];
- }
- in_partial_sum[ei_new] = sum;
- // go for second round
- ei_new = ei_new + NUMBER_THREADS;
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //==================================================50
- // CHECKSUM
- //==================================================50
- #ifdef TEST_CHECKSUM
- if(bx==0 && tx==0){
- for(i=0; i<d_common.in_cols; i++){
- checksum[25] = checksum[25]+in_partial_sum[i];
- }
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- #endif
- //==================================================50
- // IN_SQR SUM
- //==================================================50
- ei_new = tx;
- while(ei_new < d_common.in_sqr_rows){
-
- sum = 0;
- for(i = 0; i < d_common.in_sqr_cols; i++){
- sum = sum + d_unique_d_in_sqr[ei_new+d_common.in_sqr_rows*i];
- }
- in_sqr_partial_sum[ei_new] = sum;
- // go for second round
- ei_new = ei_new + NUMBER_THREADS;
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //==================================================50
- // CHECKSUM
- //==================================================50
- #ifdef TEST_CHECKSUM
- if(bx==0 && tx==0){
- for(i=0; i<d_common.in_sqr_rows; i++){
- checksum[26] = checksum[26]+in_sqr_partial_sum[i];
- }
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- #endif
- //==================================================50
- // FINAL SUMMATION
- //==================================================50
- if(tx == 0){
- in_final_sum[0] = 0;
- for(i = 0; i<d_common.in_cols; i++){
- // in_final_sum = in_final_sum + in_partial_sum[i];
- in_final_sum[0] = in_final_sum[0] + in_partial_sum[i];
- }
- }else if(tx == 1){
- in_sqr_final_sum[0] = 0;
- for(i = 0; i<d_common.in_sqr_cols; i++){
- // in_sqr_final_sum = in_sqr_final_sum + in_sqr_partial_sum[i];
- in_sqr_final_sum[0] = in_sqr_final_sum[0] + in_sqr_partial_sum[i];
- }
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //==================================================50
- // CHECKSUM
- //==================================================50
- #ifdef TEST_CHECKSUM
- if(bx==0 && tx==0){
- checksum[27] = checksum[27]+in_final_sum[0]+in_sqr_final_sum[0];
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- #endif
- //==================================================50
- // DENOMINATOR T
- //==================================================50
- if(tx == 0){
- // mean = in_final_sum / d_common.in_elem; // gets mean (average) value of element in ROI
- mean = in_final_sum[0] / d_common.in_elem; // gets mean (average) value of element in ROI
- mean_sqr = mean * mean;
- // variance = (in_sqr_final_sum / d_common.in_elem) - mean_sqr; // gets variance of ROI
- variance = (in_sqr_final_sum[0] / d_common.in_elem) - mean_sqr; // gets variance of ROI
- deviation = sqrt(variance); // gets standard deviation of ROI
- // denomT = sqrt((float)(d_common.in_elem-1))*deviation;
- denomT[0] = sqrt((float)(d_common.in_elem-1))*deviation;
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //==================================================50
- // CHECKSUM
- //==================================================50
- #ifdef TEST_CHECKSUM
- if(bx==0 && tx==0){
- checksum[28] = checksum[28]+denomT[i];
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- #endif
- //==================================================50
- // DENOMINATOR SAVE RESULT IN CUMULATIVE SUM A2
- //==================================================50
- // work
- ei_new = tx;
- while(ei_new < d_common.in2_sub2_elem){
- // d_unique_d_in2_sqr_sub2[ei_new] = d_unique_d_in2_sqr_sub2[ei_new] * denomT;
- d_unique_d_in2_sqr_sub2[ei_new] = d_unique_d_in2_sqr_sub2[ei_new] * denomT[0];
- // go for second round
- ei_new = ei_new + NUMBER_THREADS;
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //==================================================50
- // CHECKSUM
- //==================================================50
- #ifdef TEST_CHECKSUM
- if(bx==0 && tx==0){
- for(i=0; i<d_common.in2_sub2_elem; i++){
- checksum[29] = checksum[29]+d_unique_d_in2_sqr_sub2[i];
- }
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- #endif
- //==================================================50
- // NUMERATOR SAVE RESULT IN CONVOLUTION
- //==================================================50
- // work
- ei_new = tx;
- while(ei_new < d_common.conv_elem){
- // d_unique_d_conv[ei_new] = d_unique_d_conv[ei_new] - d_unique_d_in2_sub2[ei_new] * in_final_sum / d_common.in_elem;
- d_unique_d_conv[ei_new] = d_unique_d_conv[ei_new] - d_unique_d_in2_sub2[ei_new] * in_final_sum[0] / d_common.in_elem;
- // go for second round
- ei_new = ei_new + NUMBER_THREADS;
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //==================================================50
- // CHECKSUM
- //==================================================50
- #ifdef TEST_CHECKSUM
- if(bx==0 && tx==0){
- for(i=0; i<d_common.conv_elem; i++){
- checksum[30] = checksum[30]+d_unique_d_conv[i];
- }
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- #endif
- //==================================================50
- // CORRELATION SAVE RESULT IN CUMULATIVE SUM A2
- //==================================================50
- // work
- ei_new = tx;
- while(ei_new < d_common.in2_sub2_elem){
- d_unique_d_in2_sqr_sub2[ei_new] = d_unique_d_conv[ei_new] / d_unique_d_in2_sqr_sub2[ei_new];
- // go for second round
- ei_new = ei_new + NUMBER_THREADS;
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //==================================================50
- // CHECKSUM
- //==================================================50
- #ifdef TEST_CHECKSUM
- if(bx==0 && tx==0){
- for(i=0; i<d_common.in2_sub2_elem; i++){
- checksum[31] = checksum[31]+d_unique_d_in2_sqr_sub2[i];
- }
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- #endif
- //==================================================50
- // End
- //==================================================50
- //====================================================================================================100
- // TEMPLATE MASK CREATE
- //====================================================================================================100
- cent = d_common.sSize + d_common.tSize + 1;
- if(d_frame_no == 0){
- tMask_row = cent + d_unique_d_Row[d_unique_point_no] - d_unique_d_Row[d_unique_point_no] - 1;
- tMask_col = cent + d_unique_d_Col[d_unique_point_no] - d_unique_d_Col[d_unique_point_no] - 1;
- }
- else{
- pointer = d_unique_point_no*d_common.no_frames+d_frame_no-1;
- tMask_row = cent + d_unique_d_tRowLoc[pointer] - d_unique_d_Row[d_unique_point_no] - 1;
- tMask_col = cent + d_unique_d_tColLoc[pointer] - d_unique_d_Col[d_unique_point_no] - 1;
- }
- //work
- ei_new = tx;
- while(ei_new < d_common.tMask_elem){
- location = tMask_col*d_common.tMask_rows + tMask_row;
- if(ei_new==location){
- d_unique_d_tMask[ei_new] = 1;
- }
- else{
- d_unique_d_tMask[ei_new] = 0;
- }
- //go for second round
- ei_new = ei_new + NUMBER_THREADS;
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //==================================================50
- // CHECKSUM
- //==================================================50
- #ifdef TEST_CHECKSUM
- if(bx==0 && tx==0){
- for(i=0; i<d_common.tMask_elem; i++){
- checksum[32] = checksum[32]+d_unique_d_tMask[i];
- }
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- #endif
- //==================================================50
- // End
- //==================================================50
- //====================================================================================================100
- // MASK CONVOLUTION
- //====================================================================================================100
- // work
- ei_new = tx;
- while(ei_new < d_common.mask_conv_elem){
- // figure out row/col location in array
- ic = (ei_new+1) % d_common.mask_conv_rows; // (1-n)
- jc = (ei_new+1) / d_common.mask_conv_rows + 1; // (1-n)
- if((ei_new+1) % d_common.mask_conv_rows == 0){
- ic = d_common.mask_conv_rows;
- jc = jc-1;
- }
- //
- j = jc + d_common.mask_conv_joffset;
- jp1 = j + 1;
- if(d_common.mask_cols < jp1){
- ja1 = jp1 - d_common.mask_cols;
- }
- else{
- ja1 = 1;
- }
- if(d_common.tMask_cols < j){
- ja2 = d_common.tMask_cols;
- }
- else{
- ja2 = j;
- }
- i = ic + d_common.mask_conv_ioffset;
- ip1 = i + 1;
-
- if(d_common.mask_rows < ip1){
- ia1 = ip1 - d_common.mask_rows;
- }
- else{
- ia1 = 1;
- }
- if(d_common.tMask_rows < i){
- ia2 = d_common.tMask_rows;
- }
- else{
- ia2 = i;
- }
- s = 0;
- for(ja=ja1; ja<=ja2; ja++){
- jb = jp1 - ja;
- for(ia=ia1; ia<=ia2; ia++){
- ib = ip1 - ia;
- s = s + d_unique_d_tMask[d_common.tMask_rows*(ja-1)+ia-1] * 1;
- }
- }
- // //d_unique_d_mask_conv[d_common.mask_conv_rows*(jc-1)+ic-1] = s;
- d_unique_d_mask_conv[ei_new] = d_unique_d_in2_sqr_sub2[ei_new] * s;
- // go for second round
- ei_new = ei_new + NUMBER_THREADS;
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //==================================================50
- // CHECKSUM
- //==================================================50
- #ifdef TEST_CHECKSUM
- if(bx==0 && tx==0){
- for(i=0; i<d_common.mask_conv_elem; i++){
- checksum[33] = checksum[33]+d_unique_d_mask_conv[i];
- }
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- #endif
- //==================================================50
- // End
- //==================================================50
- //====================================================================================================100
- // MAXIMUM VALUE
- //====================================================================================================100
- //==================================================50
- // INITIAL SEARCH
- //==================================================50
- ei_new = tx;
- while(ei_new < d_common.mask_conv_rows){
- for(i=0; i<d_common.mask_conv_cols; i++){
- largest_coordinate_current = ei_new*d_common.mask_conv_rows+i;
- largest_value_current = fabs(d_unique_d_mask_conv[largest_coordinate_current]);
- if(largest_value_current > largest_value){
- largest_coordinate = largest_coordinate_current;
- largest_value = largest_value_current;
- }
- }
- par_max_coo[ei_new] = largest_coordinate;
- par_max_val[ei_new] = largest_value;
- // go for second round
- ei_new = ei_new + NUMBER_THREADS;
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //==================================================50
- // CHECKSUM
- //==================================================50
- #ifdef TEST_CHECKSUM
- if(bx==0 && tx==0){
- for(i=0; i<d_common.mask_conv_rows; i++){
- checksum[34] = checksum[34]+par_max_coo[i]+par_max_val[i];
- }
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- #endif
- //==================================================50
- // FINAL SEARCH
- //==================================================50
- if(tx == 0){
- for(i = 0; i < d_common.mask_conv_rows; i++){
- if(par_max_val[i] > fin_max_val){
- fin_max_val = par_max_val[i];
- fin_max_coo = par_max_coo[i];
- }
- }
- // convert coordinate to row/col form
- largest_row = (fin_max_coo+1) % d_common.mask_conv_rows - 1; // (0-n) row
- largest_col = (fin_max_coo+1) / d_common.mask_conv_rows; // (0-n) column
- if((fin_max_coo+1) % d_common.mask_conv_rows == 0){
- largest_row = d_common.mask_conv_rows - 1;
- largest_col = largest_col - 1;
- }
- // calculate offset
- largest_row = largest_row + 1; // compensate to match MATLAB format (1-n)
- largest_col = largest_col + 1; // compensate to match MATLAB format (1-n)
- offset_row = largest_row - d_common.in_rows - (d_common.sSize - d_common.tSize);
- offset_col = largest_col - d_common.in_cols - (d_common.sSize - d_common.tSize);
- pointer = d_unique_point_no*d_common.no_frames+d_frame_no;
- d_unique_d_tRowLoc[pointer] = d_unique_d_Row[d_unique_point_no] + offset_row;
- d_unique_d_tColLoc[pointer] = d_unique_d_Col[d_unique_point_no] + offset_col;
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //==================================================50
- // CHECKSUM
- //==================================================50
- #ifdef TEST_CHECKSUM
- if(bx==0 && tx==0){
- checksum[35] = checksum[35]+d_unique_d_tRowLoc[pointer]+d_unique_d_tColLoc[pointer];
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- #endif
- //==================================================50
- // End
- //==================================================50
- //====================================================================================================100
- // End
- //====================================================================================================100
- }
- //======================================================================================================================================================150
- // PERIODIC COORDINATE AND TEMPLATE UPDATE
- //======================================================================================================================================================150
- if(d_frame_no != 0 && (d_frame_no)%10 == 0){
- //====================================================================================================100
- // initialize cross-frame variables
- //====================================================================================================100
- #ifdef INIT
- // only the first thread initializes
- if(tx==0){
- // this block
- for(i=0; i<d_common.in_elem; i++){
- d_in[i] = 0;
- }
- }
- #endif
- //====================================================================================================100
- // SYNCHRONIZE THREADS
- //====================================================================================================100
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //====================================================================================================100
- // if the last frame in the bath, update template
- //====================================================================================================100
- // update coordinate
- loc_pointer = d_unique_point_no*d_common.no_frames+d_frame_no;
- d_unique_d_Row[d_unique_point_no] = d_unique_d_tRowLoc[loc_pointer];
- d_unique_d_Col[d_unique_point_no] = d_unique_d_tColLoc[loc_pointer];
- // work
- ei_new = tx;
- while(ei_new < d_common.in_elem){
- // figure out row/col location in new matrix
- row = (ei_new+1) % d_common.in_rows - 1; // (0-n) row
- col = (ei_new+1) / d_common.in_rows + 1 - 1; // (0-n) column
- if((ei_new+1) % d_common.in_rows == 0){
- row = d_common.in_rows - 1;
- col = col-1;
- }
- // figure out row/col location in corresponding new template area in image and give to every thread (get top left corner and progress down and right)
- ori_row = d_unique_d_Row[d_unique_point_no] - 25 + row - 1;
- ori_col = d_unique_d_Col[d_unique_point_no] - 25 + col - 1;
- ori_pointer = ori_col*d_common.frame_rows+ori_row;
- // update template
- d_in[ei_new] = d_common.alpha*d_in[ei_new] + (1-d_common.alpha)*d_common_change_d_frame[ori_pointer];
- // go for second round
- ei_new = ei_new + NUMBER_THREADS;
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- //==================================================50
- // CHECKSUM
- //==================================================50
- #ifdef TEST_CHECKSUM
- if(bx==0 && tx==0){
- for(i=0; i<d_common.in_elem; i++){
- checksum[36] = checksum[36]+d_in[i];
- }
- }
- //==================================================50
- // SYNCHRONIZE THREADS
- //==================================================50
- barrier(CLK_LOCAL_MEM_FENCE | CLK_GLOBAL_MEM_FENCE);
- #endif
- //==================================================50
- // End
- //==================================================50
- //====================================================================================================100
- // End
- //====================================================================================================100
- }
- //======================================================================================================================================================150
- // End
- //======================================================================================================================================================150
- }
- //========================================================================================================================================================================================================200
- // END
- //========================================================================================================================================================================================================200
|