/usr/include/bullet/Bullet3OpenCL/ParallelPrimitives/kernels/RadixSort32KernelsCL.h is in libbullet-dev 2.87+dfsg-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 | //this file is autogenerated using stringify.bat (premake --stringify) in the build folder of this project
static const char* radixSort32KernelsCL= \
"/*\n"
"Bullet Continuous Collision Detection and Physics Library\n"
"Copyright (c) 2011 Advanced Micro Devices, Inc. http://bulletphysics.org\n"
"This software is provided 'as-is', without any express or implied warranty.\n"
"In no event will the authors be held liable for any damages arising from the use of this software.\n"
"Permission is granted to anyone to use this software for any purpose, \n"
"including commercial applications, and to alter it and redistribute it freely, \n"
"subject to the following restrictions:\n"
"1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.\n"
"2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.\n"
"3. This notice may not be removed or altered from any source distribution.\n"
"*/\n"
"//Author Takahiro Harada\n"
"//#pragma OPENCL EXTENSION cl_amd_printf : enable\n"
"#pragma OPENCL EXTENSION cl_khr_local_int32_base_atomics : enable\n"
"#pragma OPENCL EXTENSION cl_khr_global_int32_base_atomics : enable\n"
"typedef unsigned int u32;\n"
"#define GET_GROUP_IDX get_group_id(0)\n"
"#define GET_LOCAL_IDX get_local_id(0)\n"
"#define GET_GLOBAL_IDX get_global_id(0)\n"
"#define GET_GROUP_SIZE get_local_size(0)\n"
"#define GROUP_LDS_BARRIER barrier(CLK_LOCAL_MEM_FENCE)\n"
"#define GROUP_MEM_FENCE mem_fence(CLK_LOCAL_MEM_FENCE)\n"
"#define AtomInc(x) atom_inc(&(x))\n"
"#define AtomInc1(x, out) out = atom_inc(&(x))\n"
"#define AtomAdd(x, value) atom_add(&(x), value)\n"
"#define SELECT_UINT4( b, a, condition ) select( b,a,condition )\n"
"#define make_uint4 (uint4)\n"
"#define make_uint2 (uint2)\n"
"#define make_int2 (int2)\n"
"#define WG_SIZE 64\n"
"#define ELEMENTS_PER_WORK_ITEM (256/WG_SIZE)\n"
"#define BITS_PER_PASS 4\n"
"#define NUM_BUCKET (1<<BITS_PER_PASS)\n"
"typedef uchar u8;\n"
"// this isn't optimization for VLIW. But just reducing writes. \n"
"#define USE_2LEVEL_REDUCE 1\n"
"//#define CHECK_BOUNDARY 1\n"
"//#define NV_GPU 1\n"
"// Cypress\n"
"#define nPerWI 16\n"
"// Cayman\n"
"//#define nPerWI 20\n"
"#define m_n x\n"
"#define m_nWGs y\n"
"#define m_startBit z\n"
"#define m_nBlocksPerWG w\n"
"/*\n"
"typedef struct\n"
"{\n"
" int m_n;\n"
" int m_nWGs;\n"
" int m_startBit;\n"
" int m_nBlocksPerWG;\n"
"} ConstBuffer;\n"
"*/\n"
"typedef struct\n"
"{\n"
" unsigned int m_key;\n"
" unsigned int m_value;\n"
"} SortDataCL;\n"
"uint prefixScanVectorEx( uint4* data )\n"
"{\n"
" u32 sum = 0;\n"
" u32 tmp = data[0].x;\n"
" data[0].x = sum;\n"
" sum += tmp;\n"
" tmp = data[0].y;\n"
" data[0].y = sum;\n"
" sum += tmp;\n"
" tmp = data[0].z;\n"
" data[0].z = sum;\n"
" sum += tmp;\n"
" tmp = data[0].w;\n"
" data[0].w = sum;\n"
" sum += tmp;\n"
" return sum;\n"
"}\n"
"u32 localPrefixSum( u32 pData, uint lIdx, uint* totalSum, __local u32* sorterSharedMemory, int wgSize /*64 or 128*/ )\n"
"{\n"
" { // Set data\n"
" sorterSharedMemory[lIdx] = 0;\n"
" sorterSharedMemory[lIdx+wgSize] = pData;\n"
" }\n"
" GROUP_LDS_BARRIER;\n"
" { // Prefix sum\n"
" int idx = 2*lIdx + (wgSize+1);\n"
"#if defined(USE_2LEVEL_REDUCE)\n"
" if( lIdx < 64 )\n"
" {\n"
" u32 u0, u1, u2;\n"
" u0 = sorterSharedMemory[idx-3];\n"
" u1 = sorterSharedMemory[idx-2];\n"
" u2 = sorterSharedMemory[idx-1];\n"
" AtomAdd( sorterSharedMemory[idx], u0+u1+u2 ); \n"
" GROUP_MEM_FENCE;\n"
" u0 = sorterSharedMemory[idx-12];\n"
" u1 = sorterSharedMemory[idx-8];\n"
" u2 = sorterSharedMemory[idx-4];\n"
" AtomAdd( sorterSharedMemory[idx], u0+u1+u2 ); \n"
" GROUP_MEM_FENCE;\n"
" u0 = sorterSharedMemory[idx-48];\n"
" u1 = sorterSharedMemory[idx-32];\n"
" u2 = sorterSharedMemory[idx-16];\n"
" AtomAdd( sorterSharedMemory[idx], u0+u1+u2 ); \n"
" GROUP_MEM_FENCE;\n"
" if( wgSize > 64 )\n"
" {\n"
" sorterSharedMemory[idx] += sorterSharedMemory[idx-64];\n"
" GROUP_MEM_FENCE;\n"
" }\n"
" sorterSharedMemory[idx-1] += sorterSharedMemory[idx-2];\n"
" GROUP_MEM_FENCE;\n"
" }\n"
"#else\n"
" if( lIdx < 64 )\n"
" {\n"
" sorterSharedMemory[idx] += sorterSharedMemory[idx-1];\n"
" GROUP_MEM_FENCE;\n"
" sorterSharedMemory[idx] += sorterSharedMemory[idx-2]; \n"
" GROUP_MEM_FENCE;\n"
" sorterSharedMemory[idx] += sorterSharedMemory[idx-4];\n"
" GROUP_MEM_FENCE;\n"
" sorterSharedMemory[idx] += sorterSharedMemory[idx-8];\n"
" GROUP_MEM_FENCE;\n"
" sorterSharedMemory[idx] += sorterSharedMemory[idx-16];\n"
" GROUP_MEM_FENCE;\n"
" sorterSharedMemory[idx] += sorterSharedMemory[idx-32];\n"
" GROUP_MEM_FENCE;\n"
" if( wgSize > 64 )\n"
" {\n"
" sorterSharedMemory[idx] += sorterSharedMemory[idx-64];\n"
" GROUP_MEM_FENCE;\n"
" }\n"
" sorterSharedMemory[idx-1] += sorterSharedMemory[idx-2];\n"
" GROUP_MEM_FENCE;\n"
" }\n"
"#endif\n"
" }\n"
" GROUP_LDS_BARRIER;\n"
" *totalSum = sorterSharedMemory[wgSize*2-1];\n"
" u32 addValue = sorterSharedMemory[lIdx+wgSize-1];\n"
" return addValue;\n"
"}\n"
"//__attribute__((reqd_work_group_size(128,1,1)))\n"
"uint4 localPrefixSum128V( uint4 pData, uint lIdx, uint* totalSum, __local u32* sorterSharedMemory )\n"
"{\n"
" u32 s4 = prefixScanVectorEx( &pData );\n"
" u32 rank = localPrefixSum( s4, lIdx, totalSum, sorterSharedMemory, 128 );\n"
" return pData + make_uint4( rank, rank, rank, rank );\n"
"}\n"
"//__attribute__((reqd_work_group_size(64,1,1)))\n"
"uint4 localPrefixSum64V( uint4 pData, uint lIdx, uint* totalSum, __local u32* sorterSharedMemory )\n"
"{\n"
" u32 s4 = prefixScanVectorEx( &pData );\n"
" u32 rank = localPrefixSum( s4, lIdx, totalSum, sorterSharedMemory, 64 );\n"
" return pData + make_uint4( rank, rank, rank, rank );\n"
"}\n"
"u32 unpack4Key( u32 key, int keyIdx ){ return (key>>(keyIdx*8)) & 0xff;}\n"
"u32 bit8Scan(u32 v)\n"
"{\n"
" return (v<<8) + (v<<16) + (v<<24);\n"
"}\n"
"//===\n"
"#define MY_HISTOGRAM(idx) localHistogramMat[(idx)*WG_SIZE+lIdx]\n"
"__kernel\n"
"__attribute__((reqd_work_group_size(WG_SIZE,1,1)))\n"
"void StreamCountKernel( __global u32* gSrc, __global u32* histogramOut, int4 cb )\n"
"{\n"
" __local u32 localHistogramMat[NUM_BUCKET*WG_SIZE];\n"
" u32 gIdx = GET_GLOBAL_IDX;\n"
" u32 lIdx = GET_LOCAL_IDX;\n"
" u32 wgIdx = GET_GROUP_IDX;\n"
" u32 wgSize = GET_GROUP_SIZE;\n"
" const int startBit = cb.m_startBit;\n"
" const int n = cb.m_n;\n"
" const int nWGs = cb.m_nWGs;\n"
" const int nBlocksPerWG = cb.m_nBlocksPerWG;\n"
" for(int i=0; i<NUM_BUCKET; i++)\n"
" {\n"
" MY_HISTOGRAM(i) = 0;\n"
" }\n"
" GROUP_LDS_BARRIER;\n"
" const int blockSize = ELEMENTS_PER_WORK_ITEM*WG_SIZE;\n"
" u32 localKey;\n"
" int nBlocks = (n)/blockSize - nBlocksPerWG*wgIdx;\n"
" int addr = blockSize*nBlocksPerWG*wgIdx + ELEMENTS_PER_WORK_ITEM*lIdx;\n"
" for(int iblock=0; iblock<min(nBlocksPerWG, nBlocks); iblock++, addr+=blockSize)\n"
" {\n"
" // MY_HISTOGRAM( localKeys.x ) ++ is much expensive than atomic add as it requires read and write while atomics can just add on AMD\n"
" // Using registers didn't perform well. It seems like use localKeys to address requires a lot of alu ops\n"
" // AMD: AtomInc performs better while NV prefers ++\n"
" for(int i=0; i<ELEMENTS_PER_WORK_ITEM; i++)\n"
" {\n"
"#if defined(CHECK_BOUNDARY)\n"
" if( addr+i < n )\n"
"#endif\n"
" {\n"
" localKey = (gSrc[addr+i]>>startBit) & 0xf;\n"
"#if defined(NV_GPU)\n"
" MY_HISTOGRAM( localKey )++;\n"
"#else\n"
" AtomInc( MY_HISTOGRAM( localKey ) );\n"
"#endif\n"
" }\n"
" }\n"
" }\n"
" GROUP_LDS_BARRIER;\n"
" \n"
" if( lIdx < NUM_BUCKET )\n"
" {\n"
" u32 sum = 0;\n"
" for(int i=0; i<GET_GROUP_SIZE; i++)\n"
" {\n"
" sum += localHistogramMat[lIdx*WG_SIZE+(i+lIdx)%GET_GROUP_SIZE];\n"
" }\n"
" histogramOut[lIdx*nWGs+wgIdx] = sum;\n"
" }\n"
"}\n"
"__kernel\n"
"__attribute__((reqd_work_group_size(WG_SIZE,1,1)))\n"
"void StreamCountSortDataKernel( __global SortDataCL* gSrc, __global u32* histogramOut, int4 cb )\n"
"{\n"
" __local u32 localHistogramMat[NUM_BUCKET*WG_SIZE];\n"
" u32 gIdx = GET_GLOBAL_IDX;\n"
" u32 lIdx = GET_LOCAL_IDX;\n"
" u32 wgIdx = GET_GROUP_IDX;\n"
" u32 wgSize = GET_GROUP_SIZE;\n"
" const int startBit = cb.m_startBit;\n"
" const int n = cb.m_n;\n"
" const int nWGs = cb.m_nWGs;\n"
" const int nBlocksPerWG = cb.m_nBlocksPerWG;\n"
" for(int i=0; i<NUM_BUCKET; i++)\n"
" {\n"
" MY_HISTOGRAM(i) = 0;\n"
" }\n"
" GROUP_LDS_BARRIER;\n"
" const int blockSize = ELEMENTS_PER_WORK_ITEM*WG_SIZE;\n"
" u32 localKey;\n"
" int nBlocks = (n)/blockSize - nBlocksPerWG*wgIdx;\n"
" int addr = blockSize*nBlocksPerWG*wgIdx + ELEMENTS_PER_WORK_ITEM*lIdx;\n"
" for(int iblock=0; iblock<min(nBlocksPerWG, nBlocks); iblock++, addr+=blockSize)\n"
" {\n"
" // MY_HISTOGRAM( localKeys.x ) ++ is much expensive than atomic add as it requires read and write while atomics can just add on AMD\n"
" // Using registers didn't perform well. It seems like use localKeys to address requires a lot of alu ops\n"
" // AMD: AtomInc performs better while NV prefers ++\n"
" for(int i=0; i<ELEMENTS_PER_WORK_ITEM; i++)\n"
" {\n"
"#if defined(CHECK_BOUNDARY)\n"
" if( addr+i < n )\n"
"#endif\n"
" {\n"
" localKey = (gSrc[addr+i].m_key>>startBit) & 0xf;\n"
"#if defined(NV_GPU)\n"
" MY_HISTOGRAM( localKey )++;\n"
"#else\n"
" AtomInc( MY_HISTOGRAM( localKey ) );\n"
"#endif\n"
" }\n"
" }\n"
" }\n"
" GROUP_LDS_BARRIER;\n"
" \n"
" if( lIdx < NUM_BUCKET )\n"
" {\n"
" u32 sum = 0;\n"
" for(int i=0; i<GET_GROUP_SIZE; i++)\n"
" {\n"
" sum += localHistogramMat[lIdx*WG_SIZE+(i+lIdx)%GET_GROUP_SIZE];\n"
" }\n"
" histogramOut[lIdx*nWGs+wgIdx] = sum;\n"
" }\n"
"}\n"
"#define nPerLane (nPerWI/4)\n"
"// NUM_BUCKET*nWGs < 128*nPerWI\n"
"__kernel\n"
"__attribute__((reqd_work_group_size(128,1,1)))\n"
"void PrefixScanKernel( __global u32* wHistogram1, int4 cb )\n"
"{\n"
" __local u32 ldsTopScanData[128*2];\n"
" u32 lIdx = GET_LOCAL_IDX;\n"
" u32 wgIdx = GET_GROUP_IDX;\n"
" const int nWGs = cb.m_nWGs;\n"
" u32 data[nPerWI];\n"
" for(int i=0; i<nPerWI; i++)\n"
" {\n"
" data[i] = 0;\n"
" if( (nPerWI*lIdx+i) < NUM_BUCKET*nWGs )\n"
" data[i] = wHistogram1[nPerWI*lIdx+i];\n"
" }\n"
" uint4 myData = make_uint4(0,0,0,0);\n"
" for(int i=0; i<nPerLane; i++)\n"
" {\n"
" myData.x += data[nPerLane*0+i];\n"
" myData.y += data[nPerLane*1+i];\n"
" myData.z += data[nPerLane*2+i];\n"
" myData.w += data[nPerLane*3+i];\n"
" }\n"
" uint totalSum;\n"
" uint4 scanned = localPrefixSum128V( myData, lIdx, &totalSum, ldsTopScanData );\n"
"// for(int j=0; j<4; j++) // somehow it introduces a lot of branches\n"
" { int j = 0;\n"
" u32 sum = 0;\n"
" for(int i=0; i<nPerLane; i++)\n"
" {\n"
" u32 tmp = data[nPerLane*j+i];\n"
" data[nPerLane*j+i] = sum;\n"
" sum += tmp;\n"
" }\n"
" }\n"
" { int j = 1;\n"
" u32 sum = 0;\n"
" for(int i=0; i<nPerLane; i++)\n"
" {\n"
" u32 tmp = data[nPerLane*j+i];\n"
" data[nPerLane*j+i] = sum;\n"
" sum += tmp;\n"
" }\n"
" }\n"
" { int j = 2;\n"
" u32 sum = 0;\n"
" for(int i=0; i<nPerLane; i++)\n"
" {\n"
" u32 tmp = data[nPerLane*j+i];\n"
" data[nPerLane*j+i] = sum;\n"
" sum += tmp;\n"
" }\n"
" }\n"
" { int j = 3;\n"
" u32 sum = 0;\n"
" for(int i=0; i<nPerLane; i++)\n"
" {\n"
" u32 tmp = data[nPerLane*j+i];\n"
" data[nPerLane*j+i] = sum;\n"
" sum += tmp;\n"
" }\n"
" }\n"
" for(int i=0; i<nPerLane; i++)\n"
" {\n"
" data[nPerLane*0+i] += scanned.x;\n"
" data[nPerLane*1+i] += scanned.y;\n"
" data[nPerLane*2+i] += scanned.z;\n"
" data[nPerLane*3+i] += scanned.w;\n"
" }\n"
" for(int i=0; i<nPerWI; i++)\n"
" {\n"
" int index = nPerWI*lIdx+i;\n"
" if (index < NUM_BUCKET*nWGs)\n"
" wHistogram1[nPerWI*lIdx+i] = data[i];\n"
" }\n"
"}\n"
"// 4 scan, 4 exchange\n"
"void sort4Bits(u32 sortData[4], int startBit, int lIdx, __local u32* ldsSortData)\n"
"{\n"
" for(int bitIdx=0; bitIdx<BITS_PER_PASS; bitIdx++)\n"
" {\n"
" u32 mask = (1<<bitIdx);\n"
" uint4 cmpResult = make_uint4( (sortData[0]>>startBit) & mask, (sortData[1]>>startBit) & mask, (sortData[2]>>startBit) & mask, (sortData[3]>>startBit) & mask );\n"
" uint4 prefixSum = SELECT_UINT4( make_uint4(1,1,1,1), make_uint4(0,0,0,0), cmpResult != make_uint4(0,0,0,0) );\n"
" u32 total;\n"
" prefixSum = localPrefixSum64V( prefixSum, lIdx, &total, ldsSortData );\n"
" {\n"
" uint4 localAddr = make_uint4(lIdx*4+0,lIdx*4+1,lIdx*4+2,lIdx*4+3);\n"
" uint4 dstAddr = localAddr - prefixSum + make_uint4( total, total, total, total );\n"
" dstAddr = SELECT_UINT4( prefixSum, dstAddr, cmpResult != make_uint4(0, 0, 0, 0) );\n"
" GROUP_LDS_BARRIER;\n"
" ldsSortData[dstAddr.x] = sortData[0];\n"
" ldsSortData[dstAddr.y] = sortData[1];\n"
" ldsSortData[dstAddr.z] = sortData[2];\n"
" ldsSortData[dstAddr.w] = sortData[3];\n"
" GROUP_LDS_BARRIER;\n"
" sortData[0] = ldsSortData[localAddr.x];\n"
" sortData[1] = ldsSortData[localAddr.y];\n"
" sortData[2] = ldsSortData[localAddr.z];\n"
" sortData[3] = ldsSortData[localAddr.w];\n"
" GROUP_LDS_BARRIER;\n"
" }\n"
" }\n"
"}\n"
"// 2 scan, 2 exchange\n"
"void sort4Bits1(u32 sortData[4], int startBit, int lIdx, __local u32* ldsSortData)\n"
"{\n"
" for(uint ibit=0; ibit<BITS_PER_PASS; ibit+=2)\n"
" {\n"
" uint4 b = make_uint4((sortData[0]>>(startBit+ibit)) & 0x3, \n"
" (sortData[1]>>(startBit+ibit)) & 0x3, \n"
" (sortData[2]>>(startBit+ibit)) & 0x3, \n"
" (sortData[3]>>(startBit+ibit)) & 0x3);\n"
" u32 key4;\n"
" u32 sKeyPacked[4] = { 0, 0, 0, 0 };\n"
" {\n"
" sKeyPacked[0] |= 1<<(8*b.x);\n"
" sKeyPacked[1] |= 1<<(8*b.y);\n"
" sKeyPacked[2] |= 1<<(8*b.z);\n"
" sKeyPacked[3] |= 1<<(8*b.w);\n"
" key4 = sKeyPacked[0] + sKeyPacked[1] + sKeyPacked[2] + sKeyPacked[3];\n"
" }\n"
" u32 rankPacked;\n"
" u32 sumPacked;\n"
" {\n"
" rankPacked = localPrefixSum( key4, lIdx, &sumPacked, ldsSortData, WG_SIZE );\n"
" }\n"
" GROUP_LDS_BARRIER;\n"
" u32 newOffset[4] = { 0,0,0,0 };\n"
" {\n"
" u32 sumScanned = bit8Scan( sumPacked );\n"
" u32 scannedKeys[4];\n"
" scannedKeys[0] = 1<<(8*b.x);\n"
" scannedKeys[1] = 1<<(8*b.y);\n"
" scannedKeys[2] = 1<<(8*b.z);\n"
" scannedKeys[3] = 1<<(8*b.w);\n"
" { // 4 scans at once\n"
" u32 sum4 = 0;\n"
" for(int ie=0; ie<4; ie++)\n"
" {\n"
" u32 tmp = scannedKeys[ie];\n"
" scannedKeys[ie] = sum4;\n"
" sum4 += tmp;\n"
" }\n"
" }\n"
" {\n"
" u32 sumPlusRank = sumScanned + rankPacked;\n"
" { u32 ie = b.x;\n"
" scannedKeys[0] += sumPlusRank;\n"
" newOffset[0] = unpack4Key( scannedKeys[0], ie );\n"
" }\n"
" { u32 ie = b.y;\n"
" scannedKeys[1] += sumPlusRank;\n"
" newOffset[1] = unpack4Key( scannedKeys[1], ie );\n"
" }\n"
" { u32 ie = b.z;\n"
" scannedKeys[2] += sumPlusRank;\n"
" newOffset[2] = unpack4Key( scannedKeys[2], ie );\n"
" }\n"
" { u32 ie = b.w;\n"
" scannedKeys[3] += sumPlusRank;\n"
" newOffset[3] = unpack4Key( scannedKeys[3], ie );\n"
" }\n"
" }\n"
" }\n"
" GROUP_LDS_BARRIER;\n"
" {\n"
" ldsSortData[newOffset[0]] = sortData[0];\n"
" ldsSortData[newOffset[1]] = sortData[1];\n"
" ldsSortData[newOffset[2]] = sortData[2];\n"
" ldsSortData[newOffset[3]] = sortData[3];\n"
" GROUP_LDS_BARRIER;\n"
" u32 dstAddr = 4*lIdx;\n"
" sortData[0] = ldsSortData[dstAddr+0];\n"
" sortData[1] = ldsSortData[dstAddr+1];\n"
" sortData[2] = ldsSortData[dstAddr+2];\n"
" sortData[3] = ldsSortData[dstAddr+3];\n"
" GROUP_LDS_BARRIER;\n"
" }\n"
" }\n"
"}\n"
"#define SET_HISTOGRAM(setIdx, key) ldsSortData[(setIdx)*NUM_BUCKET+key]\n"
"__kernel\n"
"__attribute__((reqd_work_group_size(WG_SIZE,1,1)))\n"
"void SortAndScatterKernel( __global const u32* restrict gSrc, __global const u32* rHistogram, __global u32* restrict gDst, int4 cb )\n"
"{\n"
" __local u32 ldsSortData[WG_SIZE*ELEMENTS_PER_WORK_ITEM+16];\n"
" __local u32 localHistogramToCarry[NUM_BUCKET];\n"
" __local u32 localHistogram[NUM_BUCKET*2];\n"
" u32 gIdx = GET_GLOBAL_IDX;\n"
" u32 lIdx = GET_LOCAL_IDX;\n"
" u32 wgIdx = GET_GROUP_IDX;\n"
" u32 wgSize = GET_GROUP_SIZE;\n"
" const int n = cb.m_n;\n"
" const int nWGs = cb.m_nWGs;\n"
" const int startBit = cb.m_startBit;\n"
" const int nBlocksPerWG = cb.m_nBlocksPerWG;\n"
" if( lIdx < (NUM_BUCKET) )\n"
" {\n"
" localHistogramToCarry[lIdx] = rHistogram[lIdx*nWGs + wgIdx];\n"
" }\n"
" GROUP_LDS_BARRIER;\n"
" const int blockSize = ELEMENTS_PER_WORK_ITEM*WG_SIZE;\n"
" int nBlocks = n/blockSize - nBlocksPerWG*wgIdx;\n"
" int addr = blockSize*nBlocksPerWG*wgIdx + ELEMENTS_PER_WORK_ITEM*lIdx;\n"
" for(int iblock=0; iblock<min(nBlocksPerWG, nBlocks); iblock++, addr+=blockSize)\n"
" {\n"
" u32 myHistogram = 0;\n"
" u32 sortData[ELEMENTS_PER_WORK_ITEM];\n"
" for(int i=0; i<ELEMENTS_PER_WORK_ITEM; i++)\n"
"#if defined(CHECK_BOUNDARY)\n"
" sortData[i] = ( addr+i < n )? gSrc[ addr+i ] : 0xffffffff;\n"
"#else\n"
" sortData[i] = gSrc[ addr+i ];\n"
"#endif\n"
" sort4Bits(sortData, startBit, lIdx, ldsSortData);\n"
" u32 keys[ELEMENTS_PER_WORK_ITEM];\n"
" for(int i=0; i<ELEMENTS_PER_WORK_ITEM; i++)\n"
" keys[i] = (sortData[i]>>startBit) & 0xf;\n"
" { // create histogram\n"
" u32 setIdx = lIdx/16;\n"
" if( lIdx < NUM_BUCKET )\n"
" {\n"
" localHistogram[lIdx] = 0;\n"
" }\n"
" ldsSortData[lIdx] = 0;\n"
" GROUP_LDS_BARRIER;\n"
" for(int i=0; i<ELEMENTS_PER_WORK_ITEM; i++)\n"
"#if defined(CHECK_BOUNDARY)\n"
" if( addr+i < n )\n"
"#endif\n"
"#if defined(NV_GPU)\n"
" SET_HISTOGRAM( setIdx, keys[i] )++;\n"
"#else\n"
" AtomInc( SET_HISTOGRAM( setIdx, keys[i] ) );\n"
"#endif\n"
" \n"
" GROUP_LDS_BARRIER;\n"
" \n"
" uint hIdx = NUM_BUCKET+lIdx;\n"
" if( lIdx < NUM_BUCKET )\n"
" {\n"
" u32 sum = 0;\n"
" for(int i=0; i<WG_SIZE/16; i++)\n"
" {\n"
" sum += SET_HISTOGRAM( i, lIdx );\n"
" }\n"
" myHistogram = sum;\n"
" localHistogram[hIdx] = sum;\n"
" }\n"
" GROUP_LDS_BARRIER;\n"
"#if defined(USE_2LEVEL_REDUCE)\n"
" if( lIdx < NUM_BUCKET )\n"
" {\n"
" localHistogram[hIdx] = localHistogram[hIdx-1];\n"
" GROUP_MEM_FENCE;\n"
" u32 u0, u1, u2;\n"
" u0 = localHistogram[hIdx-3];\n"
" u1 = localHistogram[hIdx-2];\n"
" u2 = localHistogram[hIdx-1];\n"
" AtomAdd( localHistogram[hIdx], u0 + u1 + u2 );\n"
" GROUP_MEM_FENCE;\n"
" u0 = localHistogram[hIdx-12];\n"
" u1 = localHistogram[hIdx-8];\n"
" u2 = localHistogram[hIdx-4];\n"
" AtomAdd( localHistogram[hIdx], u0 + u1 + u2 );\n"
" GROUP_MEM_FENCE;\n"
" }\n"
"#else\n"
" if( lIdx < NUM_BUCKET )\n"
" {\n"
" localHistogram[hIdx] = localHistogram[hIdx-1];\n"
" GROUP_MEM_FENCE;\n"
" localHistogram[hIdx] += localHistogram[hIdx-1];\n"
" GROUP_MEM_FENCE;\n"
" localHistogram[hIdx] += localHistogram[hIdx-2];\n"
" GROUP_MEM_FENCE;\n"
" localHistogram[hIdx] += localHistogram[hIdx-4];\n"
" GROUP_MEM_FENCE;\n"
" localHistogram[hIdx] += localHistogram[hIdx-8];\n"
" GROUP_MEM_FENCE;\n"
" }\n"
"#endif\n"
" GROUP_LDS_BARRIER;\n"
" }\n"
" {\n"
" for(int ie=0; ie<ELEMENTS_PER_WORK_ITEM; ie++)\n"
" {\n"
" int dataIdx = ELEMENTS_PER_WORK_ITEM*lIdx+ie;\n"
" int binIdx = keys[ie];\n"
" int groupOffset = localHistogramToCarry[binIdx];\n"
" int myIdx = dataIdx - localHistogram[NUM_BUCKET+binIdx];\n"
"#if defined(CHECK_BOUNDARY)\n"
" if( addr+ie < n )\n"
"#endif\n"
" gDst[ groupOffset + myIdx ] = sortData[ie];\n"
" }\n"
" }\n"
" GROUP_LDS_BARRIER;\n"
" if( lIdx < NUM_BUCKET )\n"
" {\n"
" localHistogramToCarry[lIdx] += myHistogram;\n"
" }\n"
" GROUP_LDS_BARRIER;\n"
" }\n"
"}\n"
"// 2 scan, 2 exchange\n"
"void sort4Bits1KeyValue(u32 sortData[4], int sortVal[4], int startBit, int lIdx, __local u32* ldsSortData, __local int *ldsSortVal)\n"
"{\n"
" for(uint ibit=0; ibit<BITS_PER_PASS; ibit+=2)\n"
" {\n"
" uint4 b = make_uint4((sortData[0]>>(startBit+ibit)) & 0x3, \n"
" (sortData[1]>>(startBit+ibit)) & 0x3, \n"
" (sortData[2]>>(startBit+ibit)) & 0x3, \n"
" (sortData[3]>>(startBit+ibit)) & 0x3);\n"
" u32 key4;\n"
" u32 sKeyPacked[4] = { 0, 0, 0, 0 };\n"
" {\n"
" sKeyPacked[0] |= 1<<(8*b.x);\n"
" sKeyPacked[1] |= 1<<(8*b.y);\n"
" sKeyPacked[2] |= 1<<(8*b.z);\n"
" sKeyPacked[3] |= 1<<(8*b.w);\n"
" key4 = sKeyPacked[0] + sKeyPacked[1] + sKeyPacked[2] + sKeyPacked[3];\n"
" }\n"
" u32 rankPacked;\n"
" u32 sumPacked;\n"
" {\n"
" rankPacked = localPrefixSum( key4, lIdx, &sumPacked, ldsSortData, WG_SIZE );\n"
" }\n"
" GROUP_LDS_BARRIER;\n"
" u32 newOffset[4] = { 0,0,0,0 };\n"
" {\n"
" u32 sumScanned = bit8Scan( sumPacked );\n"
" u32 scannedKeys[4];\n"
" scannedKeys[0] = 1<<(8*b.x);\n"
" scannedKeys[1] = 1<<(8*b.y);\n"
" scannedKeys[2] = 1<<(8*b.z);\n"
" scannedKeys[3] = 1<<(8*b.w);\n"
" { // 4 scans at once\n"
" u32 sum4 = 0;\n"
" for(int ie=0; ie<4; ie++)\n"
" {\n"
" u32 tmp = scannedKeys[ie];\n"
" scannedKeys[ie] = sum4;\n"
" sum4 += tmp;\n"
" }\n"
" }\n"
" {\n"
" u32 sumPlusRank = sumScanned + rankPacked;\n"
" { u32 ie = b.x;\n"
" scannedKeys[0] += sumPlusRank;\n"
" newOffset[0] = unpack4Key( scannedKeys[0], ie );\n"
" }\n"
" { u32 ie = b.y;\n"
" scannedKeys[1] += sumPlusRank;\n"
" newOffset[1] = unpack4Key( scannedKeys[1], ie );\n"
" }\n"
" { u32 ie = b.z;\n"
" scannedKeys[2] += sumPlusRank;\n"
" newOffset[2] = unpack4Key( scannedKeys[2], ie );\n"
" }\n"
" { u32 ie = b.w;\n"
" scannedKeys[3] += sumPlusRank;\n"
" newOffset[3] = unpack4Key( scannedKeys[3], ie );\n"
" }\n"
" }\n"
" }\n"
" GROUP_LDS_BARRIER;\n"
" {\n"
" ldsSortData[newOffset[0]] = sortData[0];\n"
" ldsSortData[newOffset[1]] = sortData[1];\n"
" ldsSortData[newOffset[2]] = sortData[2];\n"
" ldsSortData[newOffset[3]] = sortData[3];\n"
" ldsSortVal[newOffset[0]] = sortVal[0];\n"
" ldsSortVal[newOffset[1]] = sortVal[1];\n"
" ldsSortVal[newOffset[2]] = sortVal[2];\n"
" ldsSortVal[newOffset[3]] = sortVal[3];\n"
" GROUP_LDS_BARRIER;\n"
" u32 dstAddr = 4*lIdx;\n"
" sortData[0] = ldsSortData[dstAddr+0];\n"
" sortData[1] = ldsSortData[dstAddr+1];\n"
" sortData[2] = ldsSortData[dstAddr+2];\n"
" sortData[3] = ldsSortData[dstAddr+3];\n"
" sortVal[0] = ldsSortVal[dstAddr+0];\n"
" sortVal[1] = ldsSortVal[dstAddr+1];\n"
" sortVal[2] = ldsSortVal[dstAddr+2];\n"
" sortVal[3] = ldsSortVal[dstAddr+3];\n"
" GROUP_LDS_BARRIER;\n"
" }\n"
" }\n"
"}\n"
"__kernel\n"
"__attribute__((reqd_work_group_size(WG_SIZE,1,1)))\n"
"void SortAndScatterSortDataKernel( __global const SortDataCL* restrict gSrc, __global const u32* rHistogram, __global SortDataCL* restrict gDst, int4 cb)\n"
"{\n"
" __local int ldsSortData[WG_SIZE*ELEMENTS_PER_WORK_ITEM+16];\n"
" __local int ldsSortVal[WG_SIZE*ELEMENTS_PER_WORK_ITEM+16];\n"
" __local u32 localHistogramToCarry[NUM_BUCKET];\n"
" __local u32 localHistogram[NUM_BUCKET*2];\n"
" u32 gIdx = GET_GLOBAL_IDX;\n"
" u32 lIdx = GET_LOCAL_IDX;\n"
" u32 wgIdx = GET_GROUP_IDX;\n"
" u32 wgSize = GET_GROUP_SIZE;\n"
" const int n = cb.m_n;\n"
" const int nWGs = cb.m_nWGs;\n"
" const int startBit = cb.m_startBit;\n"
" const int nBlocksPerWG = cb.m_nBlocksPerWG;\n"
" if( lIdx < (NUM_BUCKET) )\n"
" {\n"
" localHistogramToCarry[lIdx] = rHistogram[lIdx*nWGs + wgIdx];\n"
" }\n"
" GROUP_LDS_BARRIER;\n"
" \n"
" const int blockSize = ELEMENTS_PER_WORK_ITEM*WG_SIZE;\n"
" int nBlocks = n/blockSize - nBlocksPerWG*wgIdx;\n"
" int addr = blockSize*nBlocksPerWG*wgIdx + ELEMENTS_PER_WORK_ITEM*lIdx;\n"
" for(int iblock=0; iblock<min(nBlocksPerWG, nBlocks); iblock++, addr+=blockSize)\n"
" {\n"
" u32 myHistogram = 0;\n"
" int sortData[ELEMENTS_PER_WORK_ITEM];\n"
" int sortVal[ELEMENTS_PER_WORK_ITEM];\n"
" for(int i=0; i<ELEMENTS_PER_WORK_ITEM; i++)\n"
"#if defined(CHECK_BOUNDARY)\n"
" {\n"
" sortData[i] = ( addr+i < n )? gSrc[ addr+i ].m_key : 0xffffffff;\n"
" sortVal[i] = ( addr+i < n )? gSrc[ addr+i ].m_value : 0xffffffff;\n"
" }\n"
"#else\n"
" {\n"
" sortData[i] = gSrc[ addr+i ].m_key;\n"
" sortVal[i] = gSrc[ addr+i ].m_value;\n"
" }\n"
"#endif\n"
" sort4Bits1KeyValue(sortData, sortVal, startBit, lIdx, ldsSortData, ldsSortVal);\n"
" u32 keys[ELEMENTS_PER_WORK_ITEM];\n"
" for(int i=0; i<ELEMENTS_PER_WORK_ITEM; i++)\n"
" keys[i] = (sortData[i]>>startBit) & 0xf;\n"
" { // create histogram\n"
" u32 setIdx = lIdx/16;\n"
" if( lIdx < NUM_BUCKET )\n"
" {\n"
" localHistogram[lIdx] = 0;\n"
" }\n"
" ldsSortData[lIdx] = 0;\n"
" GROUP_LDS_BARRIER;\n"
" for(int i=0; i<ELEMENTS_PER_WORK_ITEM; i++)\n"
"#if defined(CHECK_BOUNDARY)\n"
" if( addr+i < n )\n"
"#endif\n"
"#if defined(NV_GPU)\n"
" SET_HISTOGRAM( setIdx, keys[i] )++;\n"
"#else\n"
" AtomInc( SET_HISTOGRAM( setIdx, keys[i] ) );\n"
"#endif\n"
" \n"
" GROUP_LDS_BARRIER;\n"
" \n"
" uint hIdx = NUM_BUCKET+lIdx;\n"
" if( lIdx < NUM_BUCKET )\n"
" {\n"
" u32 sum = 0;\n"
" for(int i=0; i<WG_SIZE/16; i++)\n"
" {\n"
" sum += SET_HISTOGRAM( i, lIdx );\n"
" }\n"
" myHistogram = sum;\n"
" localHistogram[hIdx] = sum;\n"
" }\n"
" GROUP_LDS_BARRIER;\n"
"#if defined(USE_2LEVEL_REDUCE)\n"
" if( lIdx < NUM_BUCKET )\n"
" {\n"
" localHistogram[hIdx] = localHistogram[hIdx-1];\n"
" GROUP_MEM_FENCE;\n"
" u32 u0, u1, u2;\n"
" u0 = localHistogram[hIdx-3];\n"
" u1 = localHistogram[hIdx-2];\n"
" u2 = localHistogram[hIdx-1];\n"
" AtomAdd( localHistogram[hIdx], u0 + u1 + u2 );\n"
" GROUP_MEM_FENCE;\n"
" u0 = localHistogram[hIdx-12];\n"
" u1 = localHistogram[hIdx-8];\n"
" u2 = localHistogram[hIdx-4];\n"
" AtomAdd( localHistogram[hIdx], u0 + u1 + u2 );\n"
" GROUP_MEM_FENCE;\n"
" }\n"
"#else\n"
" if( lIdx < NUM_BUCKET )\n"
" {\n"
" localHistogram[hIdx] = localHistogram[hIdx-1];\n"
" GROUP_MEM_FENCE;\n"
" localHistogram[hIdx] += localHistogram[hIdx-1];\n"
" GROUP_MEM_FENCE;\n"
" localHistogram[hIdx] += localHistogram[hIdx-2];\n"
" GROUP_MEM_FENCE;\n"
" localHistogram[hIdx] += localHistogram[hIdx-4];\n"
" GROUP_MEM_FENCE;\n"
" localHistogram[hIdx] += localHistogram[hIdx-8];\n"
" GROUP_MEM_FENCE;\n"
" }\n"
"#endif\n"
" GROUP_LDS_BARRIER;\n"
" }\n"
" {\n"
" for(int ie=0; ie<ELEMENTS_PER_WORK_ITEM; ie++)\n"
" {\n"
" int dataIdx = ELEMENTS_PER_WORK_ITEM*lIdx+ie;\n"
" int binIdx = keys[ie];\n"
" int groupOffset = localHistogramToCarry[binIdx];\n"
" int myIdx = dataIdx - localHistogram[NUM_BUCKET+binIdx];\n"
"#if defined(CHECK_BOUNDARY)\n"
" if( addr+ie < n )\n"
" {\n"
" if ((groupOffset + myIdx)<n)\n"
" {\n"
" if (sortData[ie]==sortVal[ie])\n"
" {\n"
" \n"
" SortDataCL tmp;\n"
" tmp.m_key = sortData[ie];\n"
" tmp.m_value = sortVal[ie];\n"
" if (tmp.m_key == tmp.m_value)\n"
" gDst[groupOffset + myIdx ] = tmp;\n"
" }\n"
" \n"
" }\n"
" }\n"
"#else\n"
" if ((groupOffset + myIdx)<n)\n"
" {\n"
" gDst[ groupOffset + myIdx ].m_key = sortData[ie];\n"
" gDst[ groupOffset + myIdx ].m_value = sortVal[ie];\n"
" }\n"
"#endif\n"
" }\n"
" }\n"
" GROUP_LDS_BARRIER;\n"
" if( lIdx < NUM_BUCKET )\n"
" {\n"
" localHistogramToCarry[lIdx] += myHistogram;\n"
" }\n"
" GROUP_LDS_BARRIER;\n"
" }\n"
"}\n"
"__kernel\n"
"__attribute__((reqd_work_group_size(WG_SIZE,1,1)))\n"
"void SortAndScatterSortDataKernelSerial( __global const SortDataCL* restrict gSrc, __global const u32* rHistogram, __global SortDataCL* restrict gDst, int4 cb)\n"
"{\n"
" \n"
" u32 gIdx = GET_GLOBAL_IDX;\n"
" u32 realLocalIdx = GET_LOCAL_IDX;\n"
" u32 wgIdx = GET_GROUP_IDX;\n"
" u32 wgSize = GET_GROUP_SIZE;\n"
" const int startBit = cb.m_startBit;\n"
" const int n = cb.m_n;\n"
" const int nWGs = cb.m_nWGs;\n"
" const int nBlocksPerWG = cb.m_nBlocksPerWG;\n"
" int counter[NUM_BUCKET];\n"
" \n"
" if (realLocalIdx>0)\n"
" return;\n"
" \n"
" for (int c=0;c<NUM_BUCKET;c++)\n"
" counter[c]=0;\n"
" const int blockSize = ELEMENTS_PER_WORK_ITEM*WG_SIZE;\n"
" \n"
" int nBlocks = (n)/blockSize - nBlocksPerWG*wgIdx;\n"
" for(int iblock=0; iblock<min(nBlocksPerWG, nBlocks); iblock++)\n"
" {\n"
" for (int lIdx=0;lIdx<WG_SIZE;lIdx++)\n"
" {\n"
" int addr2 = iblock*blockSize + blockSize*nBlocksPerWG*wgIdx + ELEMENTS_PER_WORK_ITEM*lIdx;\n"
" \n"
" for(int j=0; j<ELEMENTS_PER_WORK_ITEM; j++)\n"
" {\n"
" int i = addr2+j;\n"
" if( i < n )\n"
" {\n"
" int tableIdx;\n"
" tableIdx = (gSrc[i].m_key>>startBit) & 0xf;//0xf = NUM_TABLES-1\n"
" gDst[rHistogram[tableIdx*nWGs+wgIdx] + counter[tableIdx]] = gSrc[i];\n"
" counter[tableIdx] ++;\n"
" }\n"
" }\n"
" }\n"
" }\n"
" \n"
"}\n"
"__kernel\n"
"__attribute__((reqd_work_group_size(WG_SIZE,1,1)))\n"
"void SortAndScatterKernelSerial( __global const u32* restrict gSrc, __global const u32* rHistogram, __global u32* restrict gDst, int4 cb )\n"
"{\n"
" \n"
" u32 gIdx = GET_GLOBAL_IDX;\n"
" u32 realLocalIdx = GET_LOCAL_IDX;\n"
" u32 wgIdx = GET_GROUP_IDX;\n"
" u32 wgSize = GET_GROUP_SIZE;\n"
" const int startBit = cb.m_startBit;\n"
" const int n = cb.m_n;\n"
" const int nWGs = cb.m_nWGs;\n"
" const int nBlocksPerWG = cb.m_nBlocksPerWG;\n"
" int counter[NUM_BUCKET];\n"
" \n"
" if (realLocalIdx>0)\n"
" return;\n"
" \n"
" for (int c=0;c<NUM_BUCKET;c++)\n"
" counter[c]=0;\n"
" const int blockSize = ELEMENTS_PER_WORK_ITEM*WG_SIZE;\n"
" \n"
" int nBlocks = (n)/blockSize - nBlocksPerWG*wgIdx;\n"
" for(int iblock=0; iblock<min(nBlocksPerWG, nBlocks); iblock++)\n"
" {\n"
" for (int lIdx=0;lIdx<WG_SIZE;lIdx++)\n"
" {\n"
" int addr2 = iblock*blockSize + blockSize*nBlocksPerWG*wgIdx + ELEMENTS_PER_WORK_ITEM*lIdx;\n"
" \n"
" for(int j=0; j<ELEMENTS_PER_WORK_ITEM; j++)\n"
" {\n"
" int i = addr2+j;\n"
" if( i < n )\n"
" {\n"
" int tableIdx;\n"
" tableIdx = (gSrc[i]>>startBit) & 0xf;//0xf = NUM_TABLES-1\n"
" gDst[rHistogram[tableIdx*nWGs+wgIdx] + counter[tableIdx]] = gSrc[i];\n"
" counter[tableIdx] ++;\n"
" }\n"
" }\n"
" }\n"
" }\n"
" \n"
"}\n"
;
|