我正在尝试通过使用__device__ __host__
函数限定符来创建在cuda和cuda上均可使用的代码。为此,我必须使用设备链接选项-dc
。
执行此操作时,出现错误:fatal error C1041: cannot open program database ... ; if multiple CL.EXE write to the same .PDB file, please use /FS
。
因此,我尝试在nvcc选项中添加/FS
。但是当我这样做时,我得到了错误:nvcc fatal : A single input file is required for a non-link phase when an outputfile is specified
例如,这是我要编译的Vector3类的头文件
#include <cuda.h>
#include <cuda_runtime.h>
#include <device_launch_parameters.h>
class Vector3
{
public:
__device__ __host__ Vector3();
__device__ __host__ Vector3(double const& x, double const& y, double const& z);
__device__ __host__ double get_x() const;
__device__ __host__ double get_y() const;
__device__ __host__ double get_z() const;
__device__ __host__ double get_magnitude() const;
__device__ __host__ void set(double const& x, double const& y, double const& z);
__device__ __host__ void set_x(double const& x);
__device__ __host__ void set_y(double const& y);
__device__ __host__ void set_z(double const& z);
__device__ __host__ Vector3 get_normalized() const;
__device__ __host__ void rotate_x(double const& angle);
__device__ __host__ void rotate_y(double const& angle);
__device__ __host__ void rotate_z(double const& angle);
__device__ __host__ Vector3 operator+(Vector3 const& v) const;
__device__ __host__ Vector3 operator*(double const& v) const;
__device__ __host__ void operator+=(Vector3 const& v);
__device__ __host__ void operator*=(double const& v);
__device__ __host__ double dot(Vector3 const& v) const;
protected:
double x_, y_, z_;
};