There are several good questions and answers about how to print the stack trace from a function in C/C++ like https://stackoverflow.com/a/54365144/2348209, but it seems that this way is not usable in Cuda. While I was able to use the following snippet in C/C++, I could not use it in Cuda.
__device__
void print_trace(void) {
        void *array[10];
        size_t size;
        char **strings;
        size_t i;
        size = backtrace(array, 10);
        strings = backtrace_symbols(array, size);
        printf("Obtained %zd stack frames.\n", size);
        for (i = 0; i < size; i++)
                printf("%s\n", strings[i]);
        free(strings);
}
and received the following error:
calling a __host__ function (*backtrace*) from a __device__ function is not allowed
calling a __host__ function (*backtrace_symbols*) from a __device__ function is not allowed
I was wondering if anybody knows a way to print the stack trace in Cuda at least to see what's the caller function.
 
     
    