我有init函数er_const.cu
__device__ __constant__ __extended_range_struct ER_ONE_CONST;
__device__ __constant__ __extended_range_struct ER_HALF_CONST;
__device__ __constant__ __extended_range_struct ER_SERIES_PREC_CONST;
namespace cuda {
void er_const_init() {
er_ptr one_host;
one_host = new __extended_range_struct;
*one_host = (__extended_range_struct) {1.0, 0};
gpuErrchk(cudaMemcpyToSymbol(ER_ONE_CONST, one_host, sizeof(__extended_range_struct)));
gpuErrchk(cudaDeviceSynchronize());
er_ptr half_host;
half_host = new __extended_range_struct;
er_set_d(half_host, 0.5);
gpuErrchk(cudaMemcpyToSymbol(ER_HALF_CONST, half_host, sizeof(__extended_range_struct)));
gpuErrchk(cudaDeviceSynchronize());
er_ptr series_prec_host;
series_prec_host = new __extended_range_struct;
er_set_d(series_prec_host, ER_SERIES_PREC);
gpuErrchk(cudaMemcpyToSymbol(ER_SERIES_PREC_CONST, series_prec_host, sizeof(__extended_range_struct)));
gpuErrchk(cudaDeviceSynchronize());
delete one_host;
delete half_host;
delete series_prec_host;
}
}
__attribute__ ((constructor)) void premain()
{
//cuda::er_const_init();
}
和它的头文件er_const.cuh
extern __device__ __constant__ __extended_range_struct ER_ONE_CONST;
extern __device__ __constant__ __extended_range_struct ER_HALF_CONST;
extern __device__ __constant__ __extended_range_struct ER_SERIES_PREC_CONST;
namespace cuda {
void er_const_init();
}
如果我在main()中调用此函数它的工作,但如果我尝试在er_const.cu中创建函数wich在main()之前调用我有错误: “无效的设备符号”