-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvaluebytile.cu
47 lines (38 loc) · 1.08 KB
/
valuebytile.cu
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
#include "tile_vfld.cuh"
/**
* @brief CUDA kernel for valuebytileSets x value in each tile to the tile id
*
* Must be called with one block per tile i.e. with grid equal to nxtiles
*
* @param data
* @param size
* @param int_nx
* @param ext_nx
*/
__global__
void valuebytile_kernel( float3 * data, int2 int_nx, int2 ext_nx ) {
int tile_id = blockIdx.y * gridDim.x + blockIdx.x;
size_t tile_off = tile_id * ext_nx.x * ext_nx.y;
for( int i = threadIdx.x; i < int_nx.x * int_nx.y; i+= blockDim.x ) {
int const ix = i % int_nx.x;
int const iy = i / int_nx.x;
size_t const idx = tile_off + iy * ext_nx.x + ix;
data[ idx ].x = tile_id;
}
}
/**
* @brief Sets x value in each tile to the tile id
*
* @param data VFLD object
*/
void valuebytile( VFLD &data ) {
int2 int_nx = data.nx;
int2 ext_nx = data.ext_nx();
int offset = data.offset();
dim3 grid( data.nxtiles.x, data.nxtiles.y );
dim3 block( 64 );
valuebytile_kernel <<< grid, block >>> (
data.d_buffer + offset,
int_nx, ext_nx
);
}