generates a coalesced transpose kernel
| 89 | |
| 90 | // generates a coalesced transpose kernel |
| 91 | compute::kernel make_coalesced_transpose_kernel(const compute::context& context) |
| 92 | { |
| 93 | // source for the coalesced_transpose kernel |
| 94 | const char source[] = BOOST_COMPUTE_STRINGIZE_SOURCE( |
| 95 | __kernel void coalesced_transpose(__global const float *src, __global float *dst) |
| 96 | { |
| 97 | __local float tile[TILE_DIM][TILE_DIM]; |
| 98 | |
| 99 | // compute indexes |
| 100 | uint x = get_group_id(0) * TILE_DIM + get_local_id(0); |
| 101 | uint y = get_group_id(1) * TILE_DIM + get_local_id(1); |
| 102 | |
| 103 | uint width = get_num_groups(0) * TILE_DIM; |
| 104 | |
| 105 | // load inside local memory |
| 106 | for(uint i = 0 ; i < TILE_DIM; i+= BLOCK_ROWS){ |
| 107 | tile[get_local_id(1)+i][get_local_id(0)] = src[(y+i)*width + x]; |
| 108 | } |
| 109 | |
| 110 | barrier(CLK_LOCAL_MEM_FENCE); |
| 111 | |
| 112 | // transpose indexes |
| 113 | x = get_group_id(1) * TILE_DIM + get_local_id(0); |
| 114 | y = get_group_id(0) * TILE_DIM + get_local_id(1); |
| 115 | |
| 116 | // write output from local memory |
| 117 | for(uint i = 0 ; i < TILE_DIM ; i+=BLOCK_ROWS){ |
| 118 | dst[(y+i)*width + x] = tile[get_local_id(0)][get_local_id(1)+i]; |
| 119 | } |
| 120 | } |
| 121 | ); |
| 122 | |
| 123 | // setup compilation flags for the coalesced_transpose program |
| 124 | std::stringstream options; |
| 125 | options << "-DTILE_DIM=" << TILE_DIM << " -DBLOCK_ROWS=" << BLOCK_ROWS; |
| 126 | |
| 127 | // create and build the coalesced_transpose program |
| 128 | compute::program program = |
| 129 | compute::program::build_with_source(source, context, options.str()); |
| 130 | |
| 131 | // create and return coalesced_transpose kernel |
| 132 | return program.create_kernel("coalesced_transpose"); |
| 133 | } |
| 134 | |
| 135 | // generate a coalesced withtout bank conflicts kernel |
| 136 | compute::kernel make_coalesced_no_bank_conflicts_kernel(const compute::context& context) |