Refactoring readBlock

This commit is contained in:
André R. Brodtkorb
2018-08-24 14:11:29 +02:00
parent daa175ef32
commit 92fba5dc4f
8 changed files with 39 additions and 75 deletions

View File

@@ -120,10 +120,9 @@ __global__ void FORCEKernel(
//Read into shared memory //Read into shared memory
readBlock1(h0_ptr_, h0_pitch_, readBlock<BLOCK_WIDTH+2, BLOCK_HEIGHT+2>(h0_ptr_, h0_pitch_, Q[0], nx_+1, ny_+1);
hu0_ptr_, hu0_pitch_, readBlock<BLOCK_WIDTH+2, BLOCK_HEIGHT+2>(hu0_ptr_, hu0_pitch_, Q[1], nx_+1, ny_+1);
hv0_ptr_, hv0_pitch_, readBlock<BLOCK_WIDTH+2, BLOCK_HEIGHT+2>(hv0_ptr_, hv0_pitch_, Q[2], nx_+1, ny_+1);
Q, nx_, ny_);
__syncthreads(); __syncthreads();

View File

@@ -166,10 +166,9 @@ __global__ void HLL2Kernel(
//Read into shared memory //Read into shared memory
readBlock2(h0_ptr_, h0_pitch_, readBlock<BLOCK_WIDTH+4, BLOCK_HEIGHT+4>(h0_ptr_, h0_pitch_, Q[0], nx_+3, ny_+3);
hu0_ptr_, hu0_pitch_, readBlock<BLOCK_WIDTH+4, BLOCK_HEIGHT+4>(hu0_ptr_, hu0_pitch_, Q[1], nx_+3, ny_+3);
hv0_ptr_, hv0_pitch_, readBlock<BLOCK_WIDTH+4, BLOCK_HEIGHT+4>(hv0_ptr_, hv0_pitch_, Q[2], nx_+3, ny_+3);
Q, nx_, ny_);
__syncthreads(); __syncthreads();
//Set boundary conditions //Set boundary conditions

View File

@@ -131,10 +131,9 @@ __global__ void HLLKernel(
//Read into shared memory //Read into shared memory
readBlock1(h0_ptr_, h0_pitch_, readBlock<BLOCK_WIDTH+2, BLOCK_HEIGHT+2>(h0_ptr_, h0_pitch_, Q[0], nx_+1, ny_+1);
hu0_ptr_, hu0_pitch_, readBlock<BLOCK_WIDTH+2, BLOCK_HEIGHT+2>(hu0_ptr_, hu0_pitch_, Q[1], nx_+1, ny_+1);
hv0_ptr_, hv0_pitch_, readBlock<BLOCK_WIDTH+2, BLOCK_HEIGHT+2>(hv0_ptr_, hv0_pitch_, Q[2], nx_+1, ny_+1);
Q, nx_, ny_);
__syncthreads(); __syncthreads();
noFlowBoundary1(Q, nx_, ny_); noFlowBoundary1(Q, nx_, ny_);

View File

@@ -157,10 +157,9 @@ __global__ void KP07DimsplitKernel(
//Read into shared memory //Read into shared memory
readBlock2(h0_ptr_, h0_pitch_, readBlock<BLOCK_WIDTH+4, BLOCK_HEIGHT+4>(h0_ptr_, h0_pitch_, Q[0], nx_+3, ny_+3);
hu0_ptr_, hu0_pitch_, readBlock<BLOCK_WIDTH+4, BLOCK_HEIGHT+4>(hu0_ptr_, hu0_pitch_, Q[1], nx_+3, ny_+3);
hv0_ptr_, hv0_pitch_, readBlock<BLOCK_WIDTH+4, BLOCK_HEIGHT+4>(hv0_ptr_, hv0_pitch_, Q[2], nx_+3, ny_+3);
Q, nx_, ny_);
__syncthreads(); __syncthreads();

View File

@@ -141,10 +141,9 @@ __global__ void KP07Kernel(
//Read into shared memory //Read into shared memory
readBlock2(h0_ptr_, h0_pitch_, readBlock<BLOCK_WIDTH+4, BLOCK_HEIGHT+4>(h0_ptr_, h0_pitch_, Q[0], nx_+3, ny_+3);
hu0_ptr_, hu0_pitch_, readBlock<BLOCK_WIDTH+4, BLOCK_HEIGHT+4>(hu0_ptr_, hu0_pitch_, Q[1], nx_+3, ny_+3);
hv0_ptr_, hv0_pitch_, readBlock<BLOCK_WIDTH+4, BLOCK_HEIGHT+4>(hv0_ptr_, hv0_pitch_, Q[2], nx_+3, ny_+3);
Q, nx_, ny_);
__syncthreads(); __syncthreads();

View File

@@ -127,10 +127,9 @@ void LxFKernel(
__shared__ float G[3][block_height+1][block_width]; __shared__ float G[3][block_height+1][block_width];
//Read into shared memory //Read into shared memory
readBlock1(h0_ptr_, h0_pitch_, readBlock<BLOCK_WIDTH+2, BLOCK_HEIGHT+2>(h0_ptr_, h0_pitch_, Q[0], nx_+1, ny_+1);
hu0_ptr_, hu0_pitch_, readBlock<BLOCK_WIDTH+2, BLOCK_HEIGHT+2>(hu0_ptr_, hu0_pitch_, Q[1], nx_+1, ny_+1);
hv0_ptr_, hv0_pitch_, readBlock<BLOCK_WIDTH+2, BLOCK_HEIGHT+2>(hv0_ptr_, hv0_pitch_, Q[2], nx_+1, ny_+1);
Q, nx_, ny_);
__syncthreads(); __syncthreads();
//Set boundary conditions //Set boundary conditions

View File

@@ -138,10 +138,9 @@ __global__ void WAFKernel(
//Read into shared memory Q from global memory //Read into shared memory Q from global memory
readBlock2(h0_ptr_, h0_pitch_, readBlock<BLOCK_WIDTH+4, BLOCK_HEIGHT+4>(h0_ptr_, h0_pitch_, Q[0], nx_+3, ny_+3);
hu0_ptr_, hu0_pitch_, readBlock<BLOCK_WIDTH+4, BLOCK_HEIGHT+4>(hu0_ptr_, hu0_pitch_, Q[1], nx_+3, ny_+3);
hv0_ptr_, hv0_pitch_, readBlock<BLOCK_WIDTH+4, BLOCK_HEIGHT+4>(hv0_ptr_, hv0_pitch_, Q[2], nx_+3, ny_+3);
Q, nx_, ny_);
__syncthreads(); __syncthreads();

View File

@@ -50,38 +50,29 @@ inline __device__ __host__ float clamp(const float f, const float a, const float
/** /**
* Reads a block of data with one ghost cell for the shallow water equations * Reads a block of data with one ghost cell for the shallow water equations
*/ */
__device__ void readBlock1(float* h_ptr_, int h_pitch_, template<int sm_width, int sm_height>
float* hu_ptr_, int hu_pitch_, __device__ void readBlock(float* ptr_, int pitch_,
float* hv_ptr_, int hv_pitch_, float shmem[sm_height][sm_width],
float Q[3][BLOCK_HEIGHT+2][BLOCK_WIDTH+2], const int max_x, const int max_y) {
const int nx_, const int ny_) {
//Index of thread within block
const int tx = threadIdx.x;
const int ty = threadIdx.y;
//Index of block within domain //Index of block within domain
const int bx = BLOCK_WIDTH * blockIdx.x; const int bx = blockDim.x * blockIdx.x;
const int by = BLOCK_HEIGHT * blockIdx.y; const int by = blockDim.y * blockIdx.y;
//Read into shared memory //Read into shared memory
for (int j=ty; j<BLOCK_HEIGHT+2; j+=BLOCK_HEIGHT) { for (int j=threadIdx.y; j<sm_height; j+=blockDim.y) {
const int l = clamp(by + j, 0, ny_+1); // Out of bounds const int l = clamp(by + j, 0, max_y); // Clamp out of bounds
//Compute the pointer to current row in the arrays //Compute the pointer to current row in the arrays
float* const h_row = (float*) ((char*) h_ptr_ + h_pitch_*l); const float* const row = (float*) ((char*) ptr_ + pitch_*l);
float* const hu_row = (float*) ((char*) hu_ptr_ + hu_pitch_*l);
float* const hv_row = (float*) ((char*) hv_ptr_ + hv_pitch_*l);
for (int i=tx; i<BLOCK_WIDTH+2; i+=BLOCK_WIDTH) { for (int i=threadIdx.x; i<sm_width; i+=blockDim.x) {
const int k = clamp(bx + i, 0, nx_+1); // Out of bounds const int k = clamp(bx + i, 0, max_x); // clamp out of bounds
Q[0][j][i] = h_row[k]; shmem[j][i] = row[k];
Q[1][j][i] = hu_row[k];
Q[2][j][i] = hv_row[k];
} }
} }
} }
@@ -98,36 +89,16 @@ __device__ void readBlock2(float* h_ptr_, int h_pitch_,
float* hv_ptr_, int hv_pitch_, float* hv_ptr_, int hv_pitch_,
float Q[3][BLOCK_HEIGHT+4][BLOCK_WIDTH+4], float Q[3][BLOCK_HEIGHT+4][BLOCK_WIDTH+4],
const int nx_, const int ny_) { const int nx_, const int ny_) {
//Index of thread within block readBlock<BLOCK_WIDTH+4, BLOCK_HEIGHT+4>(h_ptr_, h_pitch_, Q[0], nx_+3, ny_+3);
const int tx = threadIdx.x; readBlock<BLOCK_WIDTH+4, BLOCK_HEIGHT+4>(hu_ptr_, hu_pitch_, Q[1], nx_+3, ny_+3);
const int ty = threadIdx.y; readBlock<BLOCK_WIDTH+4, BLOCK_HEIGHT+4>(hv_ptr_, hv_pitch_, Q[2], nx_+3, ny_+3);
//Index of block within domain
const int bx = BLOCK_WIDTH * blockIdx.x;
const int by = BLOCK_HEIGHT * blockIdx.y;
//Read into shared memory
for (int j=ty; j<BLOCK_HEIGHT+4; j+=BLOCK_HEIGHT) {
const int l = clamp(by + j, 0, ny_+3); // Out of bounds
//Compute the pointer to current row in the arrays
float* const h_row = (float*) ((char*) h_ptr_ + h_pitch_*l);
float* const hu_row = (float*) ((char*) hu_ptr_ + hu_pitch_*l);
float* const hv_row = (float*) ((char*) hv_ptr_ + hv_pitch_*l);
for (int i=tx; i<BLOCK_WIDTH+4; i+=BLOCK_WIDTH) {
const int k = clamp(bx + i, 0, nx_+3); // Out of bounds
Q[0][j][i] = h_row[k];
Q[1][j][i] = hu_row[k];
Q[2][j][i] = hv_row[k];
}
}
} }
/** /**
* Writes a block of data to global memory for the shallow water equations. * Writes a block of data to global memory for the shallow water equations.
*/ */