У меня есть шаблон C ++ 14 в моем коде Cuda, который основан на лямбда-замыкании и имеет значение __host__
и __device__
, и я получаю предупреждение:
warning: calling a __host__ function("Iter<(bool)1> ::Iter [subobject]")
from a __host__ __device__ function("Horizontal::Horizontal")
is not allowed
Но этоявляется ложным срабатыванием, потому что только экземпляр шаблона __host__
вызывает функцию __host__
, поэтому я хочу подавить это предупреждение только для этого определения одного шаблона.
Я могу добавить это раньшешаблон:
#pragma hd_warning_disable
И предупреждение исчезает, однако меня беспокоит, что я хочу, чтобы оно подавлялось только для этой одной функции шаблона, а не для остальной части модуля компиляции.Я не могу с легкостью переместить функцию шаблона в конец модуля компиляции.
Я бы хотел какой-то толчок и щелчок, но я нигде этого не нахожу.
Есть ли способвключить hd предупреждения с прагмой после определения функции шаблона?
Я пытался:
#pragma hd_warning_enable
Но это не работает:
test.cu:44:0: warning: ignoring #pragma
hd_warning_enable [-Wunknown-pragmas]
#pragma hd_warning_enable
Вотпростой тестовый пример для демонстрации проблемы:
//#pragma hd_warning_disable
template<typename Lambda>
__host__ __device__
int hostDeviceFunction(const Lambda lambda)
{
return lambda();
}
__device__
int deviceFunction()
{
auto lambda = []() { return 0.0; };
return hostDeviceFunction( lambda );
}
__host__
int hostFunction()
{
auto lambda = []() { return 1.0; };
return hostDeviceFunction( lambda );
}
, который выдает следующие предупреждения:
test.cu(7): warning: calling a __host__ function from a __host__ __device__ function is not allowed
detected during instantiation of "int hostDeviceFunction(Lambda) [with Lambda=lambda []()->double]"
(24): here
test.cu(7): warning: calling a __host__ function(" const") from a __host__ __device__ function("hostDeviceFunction< ::> ") is not allowed
test.cu(7): warning: calling a __host__ function from a __host__ __device__ function is not allowed
detected during instantiation of "int hostDeviceFunction(Lambda) [with Lambda=lambda []()->double]"
(24): here
test.cu(7): warning: calling a __host__ function(" const") from a __host__ __device__ function("hostDeviceFunction< ::> ") is not allowed
test.cu(7): warning: calling a __host__ function from a __host__ __device__ function is not allowed
detected during instantiation of "int hostDeviceFunction(Lambda) [with Lambda=lambda []()->double]"
(24): here
test.cu(7): warning: calling a __host__ function(" const") from a __host__ __device__ function("hostDeviceFunction< ::> ") is not allowed
test.cu(7): warning: calling a __host__ function from a __host__ __device__ function is not allowed
detected during instantiation of "int hostDeviceFunction(Lambda) [with Lambda=lambda []()->double]"
(24): here
test.cu(7): warning: calling a __host__ function(" const") from a __host__ __device__ function("hostDeviceFunction< ::> ") is not allowed
test.cu(7): warning: calling a __host__ function from a __host__ __device__ function is not allowed
detected during instantiation of "int hostDeviceFunction(Lambda) [with Lambda=lambda []()->double]"
(24): here
test.cu(7): warning: calling a __host__ function(" const") from a __host__ __device__ function("hostDeviceFunction< ::> ") is not allowed
test.cu(7): warning: calling a __host__ function from a __host__ __device__ function is not allowed
detected during instantiation of "int hostDeviceFunction(Lambda) [with Lambda=lambda []()->double]"
(24): here
test.cu(7): warning: calling a __host__ function(" const") from a __host__ __device__ function("hostDeviceFunction< ::> ") is not allowed
test.cu(7): warning: calling a __host__ function from a __host__ __device__ function is not allowed
detected during instantiation of "int hostDeviceFunction(Lambda) [with Lambda=lambda []()->double]"
(24): here
test.cu(7): warning: calling a __host__ function(" const") from a __host__ __device__ function("hostDeviceFunction< ::> ") is not allowed
test.cu(7): warning: calling a __host__ function from a __host__ __device__ function is not allowed
detected during instantiation of "int hostDeviceFunction(Lambda) [with Lambda=lambda []()->double]"
(24): here
test.cu(7): warning: calling a __host__ function(" const") from a __host__ __device__ function("hostDeviceFunction< ::> ") is not allowed
test.cu(7): warning: calling a __host__ function from a __host__ __device__ function is not allowed
detected during instantiation of "int hostDeviceFunction(Lambda) [with Lambda=lambda []()->double]"
(24): here
test.cu(7): warning: calling a __host__ function(" const") from a __host__ __device__ function("hostDeviceFunction< ::> ") is not allowed
test.cu(7): warning: calling a __host__ function from a __host__ __device__ function is not allowed
detected during instantiation of "int hostDeviceFunction(Lambda) [with Lambda=lambda []()->double]"
(24): here
test.cu(7): warning: calling a __host__ function(" const") from a __host__ __device__ function("hostDeviceFunction< ::> ") is not allowed
test.cu(7): warning: calling a __host__ function from a __host__ __device__ function is not allowed
detected during instantiation of "int hostDeviceFunction(Lambda) [with Lambda=lambda []()->double]"
(24): here
test.cu(7): warning: calling a __host__ function(" const") from a __host__ __device__ function("hostDeviceFunction< ::> ") is not allowed