0

I want to print a stacktrace from my C++/CUDA code. The code I have is:

#define BOOST_STACKTRACE_USE_ADDR2LINE
#include <boost/stacktrace.hpp>
#include <iostream>
#include <string>

void nested_n(int depth){
  if(depth<20){
    nested_n(depth+1);
  } else {
    std::cout << boost::stacktrace::stacktrace() << std::endl;
  }
}

void nested3(){ nested_n(0); }
void nested2(){ nested3(); }
void nested1(){ nested2(); }

int main(){
  nested1();

  return 0;
}

When I compile this with clang using

clang++ -g main.cpp -lboost_stacktrace_basic -ldl

I get a nice stacktrace:

 0# basic_stacktrace at /usr/include/boost/stacktrace/stacktrace.hpp:128
 1# nested_n(int) at /home/rick/projects/facebook/cuda_assertion_stack/main.cpp:9
 2# nested_n(int) at /home/rick/projects/facebook/cuda_assertion_stack/main.cpp:9
 3# nested_n(int) at /home/rick/projects/facebook/cuda_assertion_stack/main.cpp:9
 4# nested_n(int) at /home/rick/projects/facebook/cuda_assertion_stack/main.cpp:9
 5# nested_n(int) at /home/rick/projects/facebook/cuda_assertion_stack/main.cpp:9
...

But, when I compile with NVCC using

nvcc -g main.cpp -lboost_stacktrace_basic -ldl

I get an un-nice stacktrace:

 0# 0x0000561CD50E6EB6 in ./a.out
 1# 0x0000561CD50E6E75 in ./a.out
 2# 0x0000561CD50E6E75 in ./a.out
 3# 0x0000561CD50E6E75 in ./a.out
 4# 0x0000561CD50E6E75 in ./a.out
 5# 0x0000561CD50E6E75 in ./a.out
...

How can I get a nice stacktrace from NVCC?

(I'm on Cuda compilation tools, release 11.2, V11.2.152 with gcc (Ubuntu 10.3.0-1ubuntu1) 10.3.0 as a host compiler running on Ubuntu 21.04 with Boost 1.74.)

Richard
  • 56,349
  • 34
  • 180
  • 251
  • When I compile with CUDA 11.4 on Centos 7/g++ 7.3.1 , with [boost169](https://www.boost.org/users/history/version_1_69_0.html), I got output that is similar to your desired output. Probably need more details about your setup. `$ ./t2042 0# nested_n(int) at /home/user2/misc/t2042.cpp:10 1# nested_n(int) at /home/user2/misc/t2042.cpp:12 ...` – Robert Crovella Jun 23 '22 at 18:46
  • Thanks, @RobertCrovella, I'm on `Cuda compilation tools, release 11.2, V11.2.152` with `gcc (Ubuntu 10.3.0-1ubuntu1) 10.3.0` as a host compiler running on Ubuntu 21.04. – Richard Jun 23 '22 at 18:52
  • boost is involved here also. – Robert Crovella Jun 23 '22 at 18:57
  • Ubuntu 21.04 is not a [supported platform](https://docs.nvidia.com/cuda/archive/11.2.1/cuda-installation-guide-linux/index.html#system-requirements) for CUDA 11.2 development. Nor is gcc 10.x. – Robert Crovella Jun 23 '22 at 19:01
  • @RobertCrovella: Boost 1.74. – Richard Jun 23 '22 at 19:02
  • @RobertCrovella: 20.04 is not an option in my environment, though we are looking at moving to 22.04, but I see that's also unsupported. – Richard Jun 23 '22 at 19:03
  • Using `-ccbin g++-9` produces the same result. `-ccbin g++-11` issues an unsupported compiler error, as does `clang++-12` and `clang++-13`. `g++-10` does not produce an unsupported compiler error. – Richard Jun 23 '22 at 19:07
  • 1
    It seems [evident](https://stackoverflow.com/questions/52583544/boost-stack-trace-not-showing-function-names-and-line-numbers) that this issue is not unique or specific to `nvcc`, and also that boost stacktrace may require some fairly specific conditions in order to print out according to a particular pattern. I haven't been able to come up with a test case that doesn't print the desired pattern. – Robert Crovella Jun 27 '22 at 14:38

0 Answers0