#include <stdio.h>
#define CHECK_CUDA(call) \
{ \
cudaError_t err = call; \
if (cudaSuccess != err) { \
fprintf(stderr, "Cuda error in file '%s' in line %i : %s.\n", __FILE__, \
__LINE__, cudaGetErrorString(err)); \
exit(EXIT_FAILURE); \
} \
}
struct d{
int s;
int e;
int id;
};
__global__ void test()
{
d da{0, 256, 192};
printf("%d,%d,%d\n", da.s, da.e, da.id);
}
int main()
{
test<<<1,256>>>();
CHECK_CUDA(cudaDeviceSynchronize());
}
In this example, if I set a breakpoint to the printf
statement in the kernel and print the struct instance da
(cuda-gdb) p da
$1 = {s = 0, e = 256, id = 192}
I get the correct result
But if I print only one element I would get incorrect result
(cuda-gdb) p da.id
$2 = 2013397007
(cuda-gdb) p da.e
$3 = -469760013
Why can’t I query each member of the struct like this and get the correct value?
cuda-gdb version :
cuda-gdb --version
NVIDIA (R) CUDA Debugger
11.5 release
Portions Copyright (C) 2007-2021 NVIDIA Corporation
GNU gdb (GDB) 10.1
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.