Функция-член Cuda __device__ с явным объявлением шаблонаC++

Программы на C++. Форум разработчиков
Ответить Пред. темаСлед. тема
Гость
 Функция-член Cuda __device__ с явным объявлением шаблона

Сообщение Гость »


I have a templated struct and I want to speed compilation times by separating declaration and implementation, using explicit template declaration (I'm using Kokkos 4.1, with Cuda backend, GCC 11.3 and Cuda 11.8).

I have a struct that looks like this:

Код: Выделить всё

template struct Orbit {     MetricsAndFields fields;     Parameters params;     Orbit() = default;     Orbit(MetricsAndFields fields, Parameters params) : fields(fields), params(params) {}          __host__ __device__  T eom_denominator(const Particle& p); }; 
Now in my .cpp file, I explicitely declare the struct as needed:

Код: Выделить всё

template struct Orbit; // #ifdef ENABLE_GPU template struct Orbit; 
and obviously implement the function:

Код: Выделить всё

template __host__ __device__ T Orbit::eom_denominator(const Particle& p) {     // Implementation } 
When compiling, I get the following linker error:

Код: Выделить всё

ptxas fatal   : Unresolved extern function '_ZN5OrbitIL9OrbitType1ELb0E8MyReaderIdN6Kokkos9CudaSpaceEEdS3_E15eom_denominatorERK8ParticleIdE'
which means that it doesn't find my templated member function.

When I drop the device qualifier of my function, then it compiles just fine (by warning that I'm not allowed to call host function from device code). So, the problem comes from

Код: Выделить всё

__device__
. I tried to use

Код: Выделить всё

__noinline__
, but I still get the linker error.

Is there any way around that? Or am I forced to have slow compilation times?


Источник: https://stackoverflow.com/questions/781 ... eclaration
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C++»