CUDA and STL pb with exceptions


I am implementing a library that heavily uses templates.
I then started working from the simpleTemplates example, until I discovered that CUDA and STL are not compatible (exceptions are disabled by nvcc, even in the host code).
To see the problem, try to use std::vector anywhere in the file.

Usually, this is not a problem since the kernels are declared extern, but this is not possible when using templates.

So I have two question :

  • will we be able to use nvcc and the stl together? This means that nvcc would have to support exceptions in the host code, I think.
  • Is there another way to mix CUDA templates and the STL? Maybe via the driver API?

Happy new year to all!

Driver API will certainly solve your problem. When using it you can use nvcc only to generate device code (.cubin file) while the rest of your program (i.e. all host code) can be compiled with your favourite compiler which supports everything you need (i.e. STL), just don’t forget to include cuda.h and link against cuda.lib.

However, using driver API is somewhat more complicated than using simple runtime API, so you may try to find other wokarounds for your problem.

the Cuda sources and C/C++ source are in two distinc compilation process,
Template is a compilation time function. If you want to use template, you have to make a choice :

  1. use template in kernel_function : the specialisation are in a nvcc compilation file
  2. use template specialised in our C/C++ code you have to specialise it outside the code compiled by nvcc (and before call of kernel).