Skip to content

Commit be7ba0f

Browse files
committed
Fixed stack overflow segfault when mx/my/mz increased to 96 or higher on some machines
1 parent e433066 commit be7ba0f

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

series/cuda-cpp/finite-difference/finite-difference.cu

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ cudaError_t checkCuda(cudaError_t result)
4343
}
4444

4545
float fx = 1.0f, fy = 1.0f, fz = 1.0f;
46-
const int mx = 64, my = 64, mz = 64;
46+
const int mx = 96, my = 96, mz = 96;
4747

4848
// shared memory tiles will be m*-by-*Pencils
4949
// sPencils is used when each thread calculates the derivative at one point
@@ -441,10 +441,10 @@ void runTest(int dimension)
441441
sPencils, mz,
442442
lPencils, mz };
443443

444-
float f[mx*my*mz];
445-
float df[mx*my*mz];
446-
float sol[mx*my*mz];
447-
444+
float *f = new float[mx*my*mz];
445+
float *df = new float[mx*my*mz];
446+
float *sol = new float[mx*my*mz];
447+
448448
initInput(f, dimension);
449449
initSol(sol, dimension);
450450

@@ -495,6 +495,10 @@ void runTest(int dimension)
495495

496496
checkCuda( cudaFree(d_f) );
497497
checkCuda( cudaFree(d_df) );
498+
499+
delete [] f;
500+
delete [] df;
501+
delete [] sol;
498502
}
499503

500504

0 commit comments

Comments
 (0)