david98031

eternity2 opencl kernel

Feb 17th, 2018
167
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. __constant short width=7, height=7, edgecount=10, fit_table1[] = {
  2. 3,2,2,2,8,2,15,2,18,2,26,2,28,2,36,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
  3. ,2,2,2,2,2,2,2,2,2,2,38,46,2,2,2,2,2,2,2,2,2,48,2,2,2,50,2,2,2,2
  4. ,2,2,52,2,2,2,54,2,2,2,57,2,2,2,59,2,2,2,2,2,62,69,2,2,2,2,2,72,2,2
  5. ,2,2,2,2,2,2,2,2,74,2,2,2,76,2,2,2,2,2,2,2,78,2,2,2,80,2,2,2,83,2
  6. ,86,94,2,2,2,2,2,2,2,2,2,96,2,2,2,2,2,2,98,2,2,2,101,2,2,2,103,2,2,2
  7. ,2,2,2,2,106,2,2,2,108,2,2,2,2,2,2,110,2,2,2,112,2,2,2,2,2,2,115,2,2,2
  8. ,119,2,2,2,123,2,2,2,126,2,2,2,129,2,2,2,134,2,2,2,2,2,2,2,2,138,2,2,2,2
  9. ,2,2,2,141,2,2,143,2,2,2,148,2,2,2,152,2,2,2,156,2,2,2,159,2,2,2,163,2,2,2
  10. ,2,2,2,2,2,166,2,2,2,2,2,2,2,169,2,2,172,2,2,2,176,2,2,2,2,2,2,2,179,2
  11. ,2,2,183,2,2,2,188,2,2,2,2,2,2,2,2,2,2,2,2,193,2,2,2,2,2,2,196,2,2,2
  12. ,201,2,2,2,206,2,2,2,211,2,2,2,2,2,2,2,216,2,2,2,2,2,2,2,2,2,2,2,2,219
  13. ,2,2,2,222,2,2,226,2,2,2,229,2,2,2,232,2,2,2,236,2,2,2,241,2,2,2,243,2,2,2
  14. ,2,2,2,2,2,247,2,2,2,2,2,2,2,250,2,2,252,2,2,2,254,2,2,2,258,2,2,2,263,2
  15. ,2,2,267,2,2,2,271,2,2,2}, fit_table2[] = {
  16. -1,-1,-1,3,7,11,15,-1,19,23,27,31,35,39,-1,2,6,-1,43,47,51,55,59,63,67,-1,10,-1,71,75
  17. ,79,83,87,91,95,-1,14,-1,16,20,60,68,76,80,92,-1,8,-1,1,-1,5,-1,18,-1,22,26,-1,30,-1,34
  18. ,38,-1,28,32,40,48,52,72,-1,0,12,-1,9,-1,42,-1,46,-1,50,-1,54,58,-1,62,66,-1,24,36,44,56
  19. ,64,84,88,-1,4,-1,13,-1,70,74,-1,78,-1,82,86,-1,90,-1,94,-1,69,-1,41,73,-1,99,103,107,-1,98
  20. ,111,115,-1,119,123,-1,102,106,-1,127,131,135,139,-1,143,147,151,-1,17,77,-1,45,-1,100,112,132,144,-1,110,155
  21. ,159,-1,163,167,171,-1,109,117,-1,97,114,154,-1,158,175,-1,21,81,-1,25,85,-1,120,136,148,-1,118,164,-1,122
  22. ,162,179,-1,141,166,183,187,-1,125,170,191,195,-1,29,49,-1,104,108,116,128,-1,101,152,156,160,-1,121,180,184,192
  23. ,-1,105,129,161,181,-1,173,178,-1,33,53,-1,37,57,89,-1,96,140,-1,113,145,-1,126,165,176,-1,130,153,182,185
  24. ,-1,186,-1,134,138,189,-1,61,93,-1,65,-1,124,-1,133,168,172,-1,137,142,149,188,-1,157,174,193,-1,146,177,190
  25. ,-1,150,169,194,-1}, pieces[][4] = {
  26. {0,0,1,2},{0,0,1,3},{0,0,2,1},{0,0,3,2},{0,1,5,1},{0,1,6,1},{0,1,6,3},{0,1,7,2},
  27. {0,1,8,2},{0,1,8,3},{0,2,4,2},{0,2,5,3},{0,2,7,2},{0,2,8,2},{0,2,8,3},{0,2,9,1},
  28. {0,2,9,3},{0,3,4,1},{0,3,4,2},{0,3,5,1},{0,3,6,1},{0,3,6,3},{0,3,8,3},{0,3,9,1},
  29. {4,4,5,8},{4,4,7,5},{4,4,7,7},{4,5,5,7},{4,5,8,5},{4,6,5,7},{4,6,7,6},{4,8,6,9},
  30. {4,8,7,7},{4,8,9,5},{4,8,9,6},{4,9,6,8},{4,9,8,5},{4,9,9,6},{5,5,8,7},{5,5,9,7},
  31. {5,6,7,7},{5,6,8,6},{5,6,9,9},{5,9,7,9},{6,7,9,8},{6,8,7,7},{6,8,8,7},{6,9,8,9},
  32. {6,9,9,7},};
  33. #define WIDTH 7
  34. #define HEIGHT 7
  35. #define MEMTYPE local
  36. #define GLOBMEM 0
  37.  
  38. long mysearch(MEMTYPE short *placed, int mindepth, int limit) {
  39.   int i,j,k,down,right,depth=-1;
  40.   long res=0;
  41.   short placed2[WIDTH*HEIGHT];
  42.  
  43.   for (i=0;i<width*height;i++) {
  44.     placed2[i] = 0;
  45.     if (placed[i] > 0) {
  46.       depth = i;
  47.     }
  48.   }
  49.   for (i=0;i<=depth;i++) {
  50.     if (placed[i] > 0) {
  51.       j = fit_table2[placed[i]];
  52.       if (j >= 0) {
  53.     placed2[j/4]++;
  54.       }
  55.     }
  56.   }
  57.  
  58.   while (depth >= mindepth) {
  59.     i = placed[depth];
  60.  
  61.     if (fit_table2[i] >= 0) {
  62.       placed2[fit_table2[i]/4]--;
  63.     }
  64.     i = ++placed[depth];
  65.     if (fit_table2[i] == -1) {
  66.       placed[depth] = 0;
  67.       depth--;
  68.       continue;
  69.     }
  70.  
  71.     if (++placed2[fit_table2[i]/4] > 1) {
  72.       continue;
  73.     }
  74.  
  75.     if (res++ >= limit) {
  76.       --placed[depth];
  77.       return --res;
  78.     }
  79.            
  80.     depth++;
  81.  
  82.     if(depth < width*height) {
  83.       k=fit_table2[placed[(depth-1)]];
  84.       i=pieces[k/4][(5-k%4)%4];
  85.       right=((depth+1)%width==0);
  86.  
  87.       k=fit_table2[placed[(depth-width)]];
  88.       j=pieces[k/4][(6-k%4)%4];
  89.       down=(depth >= WIDTH*(HEIGHT-1));
  90.  
  91.       placed[depth] = fit_table1[(i*edgecount+j)*4+down*2+right]-1;
  92.     } else {
  93.       return res;
  94.     }
  95.   }
  96.  
  97.   return res;
  98. }
  99.  
  100. __kernel void mykernel(__global short* in_out, int mindepth, int maxdepth, int limit, __local short *localbuf, __global int *results) {
  101.   int i,local_id, global_id;
  102.   MEMTYPE short *memptr;
  103.  
  104.   global_id = get_global_id(0);
  105. #if GLOBMEM == 0
  106.   local_id = get_local_id(0);
  107.   for(i=0;i<width*height;i++) {
  108.     localbuf[local_id*width*height+i] = in_out[global_id*width*height+i];
  109.   }
  110.   memptr = localbuf + local_id*width*height;
  111. #else
  112.   memptr = in_out+global_id*width*height;
  113. #endif
  114.   results[global_id] = mysearch(memptr, mindepth, limit);
  115. #if GLOBMEM == 0
  116.   for(i=0;i<width*height;i++) {
  117.     in_out[global_id*width*height+i] = localbuf[local_id*width*height+i];
  118.   }
  119. #endif
  120. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×