I’ve been testing some recursive methods and I’m having a difficult time trying to increase the stack size. I just have 3 functions
__device__ void rec1(list_t p1, list_t* p2, int depth, cell_t p3, cell_t p4) {
printf("depth %d\n", depth);
if (depth == MAX_DEPTH)
return;
else
rec2(p1, p2, depth + 1, p3, p4);
}
__device__ void rec2(list_t p1, list_t* p2, int depth, cell_t p3, cell_t p4) {
printf("depth %d\n", depth);
if (depth == MAX_DEPTH)
return;
else
rec1(p1, p2, depth + 1, p3, p4);
}
__global__ void kernel() {
list_t p1;
list_t* p2;
int depth = 0;
cell_t p3;
cell_t p4;
rec1(p1, p2, depth, p3, p4);
}
and in my main method I try increasing the stack size
int main() {
cudaError_t error;
error = cudaDeviceSetLimit(cudaLimitStackSize, 256 * 1024);
if (error != cudaSuccess) {
printf("cudaDeviceSetLimit failed with %d, line(%d)\n", error, __LINE__);
exit(EXIT_FAILURE);
}
size_t p_val;
error = cudaDeviceGetLimit(&p_val, cudaLimitStackSize);
if (error != cudaSuccess) {
printf("cudaDeviceGetLimit failed with %d, line(%d)\n", error, __LINE__);
exit(EXIT_FAILURE);
}
printf("stack size limit: %d\n", p_val);
//dim3 block_dim(N, M, 1);
dim3 block_dim(1, 1, 1);
dim3 grid_dim(1, 1, 1);
kernel<<<grid_dim, block_dim>>>();
}
the structures are just placeholders from my actual code
typedef struct generic_list {
void* list;
int size;
} list_t;
typedef struct cell {
int x;
int y;
} cell_t;
typedef struct cell_level {
cell_t cell;
int level;
} cell_level_t;
I have MAX_DEPTH set to 15 right now and it only makes it to a depth of 12 (at which point I get a StackOverflow) regardless of what I set the stack size to. The default stack size is 1024 B.