@@ -39,8 +39,7 @@ const int mx = 64, my = 64, mz = 64;
3939const int sPencils = 4 ; // small # pencils
4040const int lPencils = 32 ; // large # pencils
4141
42- dim3 grid_sp[3 ], block_sp[3 ];
43- dim3 grid_lp[3 ], block_lp[3 ];
42+ dim3 grid[3 ][2 ], block[3 ][2 ];
4443
4544// stencil coefficients
4645__constant__ float c_ax, c_bx, c_cx, c_dx;
@@ -97,26 +96,26 @@ void setDerivativeParameters()
9796
9897 // Execution configurations for small and large pencil tiles
9998
100- grid_sp [0 ] = dim3 (my / sPencils , mz, 1 );
101- block_sp [0 ] = dim3 (mx, sPencils , 1 );
99+ grid[ 0 ] [0 ] = dim3 (my / sPencils , mz, 1 );
100+ block[ 0 ] [0 ] = dim3 (mx, sPencils , 1 );
102101
103- grid_lp[ 0 ] = dim3 (my / lPencils, mz, 1 );
104- block_lp[ 0 ] = dim3 (mx, sPencils , 1 );
102+ grid[ 0 ][ 1 ] = dim3 (my / lPencils, mz, 1 );
103+ block[ 0 ][ 1 ] = dim3 (mx, sPencils , 1 );
105104
106- grid_sp[ 1 ] = dim3 (mx / sPencils , mz, 1 );
107- block_sp[ 1 ] = dim3 (sPencils , my, 1 );
105+ grid[ 1 ][ 0 ] = dim3 (mx / sPencils , mz, 1 );
106+ block[ 1 ][ 0 ] = dim3 (sPencils , my, 1 );
108107
109- grid_lp [1 ] = dim3 (mx / lPencils, mz, 1 );
108+ grid[ 1 ] [1 ] = dim3 (mx / lPencils, mz, 1 );
110109 // we want to use the same number of threads as above,
111110 // so when we use lPencils instead of sPencils in one
112111 // dimension, we multiply the other by sPencils/lPencils
113- block_lp [1 ] = dim3 (lPencils, my * sPencils / lPencils, 1 );
112+ block[ 1 ] [1 ] = dim3 (lPencils, my * sPencils / lPencils, 1 );
114113
115- grid_sp[ 2 ] = dim3 (mx / sPencils , my, 1 );
116- block_sp[ 2 ] = dim3 (sPencils , mz, 1 );
114+ grid[ 2 ][ 0 ] = dim3 (mx / sPencils , my, 1 );
115+ block[ 2 ][ 0 ] = dim3 (sPencils , mz, 1 );
117116
118- grid_lp[ 2 ] = dim3 (mx / lPencils, my, 1 );
119- block_lp[ 2 ] = dim3 (lPencils, mz * sPencils / lPencils, 1 );
117+ grid[ 2 ][ 1 ] = dim3 (mx / lPencils, my, 1 );
118+ block[ 2 ][ 1 ] = dim3 (lPencils, mz * sPencils / lPencils, 1 );
120119}
121120
122121void initInput (float *f, int dim)
@@ -429,39 +428,37 @@ void runTest(int dimension)
429428 sPencils , mz,
430429 lPencils, mz };
431430
432- float milliseconds;
433- cudaEvent_t startEvent, stopEvent;
434- checkCuda ( cudaEventCreate (&startEvent) );
435- checkCuda ( cudaEventCreate (&stopEvent) );
436-
437- double error, maxError;
438-
439- printf (" %c derivatives\n\n " , (char )(0x58 + dimension));
440-
441431 float f[mx*my*mz];
442432 float df[mx*my*mz];
443433 float sol[mx*my*mz];
444434
445435 initInput (f, dimension);
446436 initSol (sol, dimension);
447437
448- const int nReps = 20 ;
449-
450438 // device arrays
451439 int bytes = mx*my*mz * sizeof (float );
452440 float *d_f, *d_df;
453441 checkCuda ( cudaMalloc ((void **)&d_f, bytes) );
454442 checkCuda ( cudaMalloc ((void **)&d_df, bytes) );
455443
456- for (int fp = 0 ; fp < 2 ; fp++) {
457-
444+ const int nReps = 20 ;
445+ float milliseconds;
446+ cudaEvent_t startEvent, stopEvent;
447+ checkCuda ( cudaEventCreate (&startEvent) );
448+ checkCuda ( cudaEventCreate (&stopEvent) );
449+
450+ double error, maxError;
451+
452+ printf (" %c derivatives\n\n " , (char )(0x58 + dimension));
453+
454+ for (int fp = 0 ; fp < 2 ; fp++) {
458455 checkCuda ( cudaMemcpy (d_f, f, bytes, cudaMemcpyHostToDevice) );
459456 checkCuda ( cudaMemset (d_df, 0 , bytes) );
460457
461- fpDeriv[fp]<<<grid_sp [dimension],block_sp [dimension]>>> (d_f, d_df); // warm up
458+ fpDeriv[fp]<<<grid [dimension][fp],block [dimension][fp ]>>> (d_f, d_df); // warm up
462459 checkCuda ( cudaEventRecord (startEvent, 0 ) );
463460 for (int i = 0 ; i < nReps; i++)
464- fpDeriv[fp]<<<grid_sp [dimension],block_sp [dimension]>>> (d_f, d_df);
461+ fpDeriv[fp]<<<grid [dimension][fp],block [dimension][fp ]>>> (d_f, d_df);
465462
466463 checkCuda ( cudaEventRecord (stopEvent, 0 ) );
467464 checkCuda ( cudaEventSynchronize (stopEvent) );
0 commit comments