简体   繁体   English

可能由于错误的实现而导致带有推力::: complex的推力:: device_vector的错误

[英]Compile error with thrust::device_vector of thrust::complex, possibly due to a wrong implementation

I'm actually learning CUDA and thrust , and I'm trying to make a project with .cpp , .hpp files and .cu , .cuh files. 我实际上正在学习CUDA推力 ,并且正在尝试使用.cpp.hpp文件和.cu.cuh文件制作项目。 Therefore, I have done a first little implementation (see code below), however I have a compile error. 因此,我已经完成了第一个小实现(请参见下面的代码),但是出现编译错误。 Here is the output of my compile error. 这是我的编译错误的输出

Honestly, I don't know exactly what this kind of error means, but I found out that this came from this line: 老实说,我不确切知道这种错误是什么意思,但是我发现这来自以下行:

thrust::device_vector<thrust::complex<T>> deviceVec_;

because when I comment out this line there is no compile error anymore. 因为当我注释掉这一行时,不再有编译错误。 Therefore, I assume that this is due to the content of the implementation of thrust::device_vector and the fact that I included the .cuh file in the .hpp file and since my main.cpp is handled by g++ the preprocessing will be performed by g++ instead of nvcc . 因此,我认为这是由于thrust::device_vector的实现内容以及我在.cuh文件中包括了.hpp文件并且由于我的main.cpp是由g++处理的这一事实所.cuh ,因此, g++代替nvcc

Content of my main.cpp file: 我的main.cpp文件的内容:

#include "QGPU.hpp"
int main()
{
     QGPU::GPU<double>  gpu;
     return (0);
}

Content of my .hpp file: 我的.hpp文件的内容:

#pragma once

# include "QCUDA.cuh"

namespace QGPU {

 template<typename T>
 class GPU {
 private:
  QCUDA::CUDAGPU<T> cgpu_;
 public:
  GPU();
  virtual ~GPU();

};

template<typename T>
GPU<T>::GPU()
{};

template<typename T>
GPU<T>::~GPU()
{};

};

Content of my .cuh file: 我的.cuh文件的内容:

#pragma once

# include <thrust/host_vector.h>
# include <thrust/device_vector.h>
# include <thrust/complex.h>

namespace QCUDA {

 template<typename T>
 class CUDAGPU {
 private:
  thrust::host_vector<thrust::complex<T>> hostVec_;
  thrust::device_vector<thrust::complex<T>> deviceVec_;
 public:
  CUDAGPU();
  virtual ~CUDAGPU();
 };

 template<typename T>
 CUDAGPU<T>::CUDAGPU()
 {};

 template<typename T>
 CUDAGPU<T>::~CUDAGPU()
 {};

};

Thus, my question is: 因此,我的问题是:

Is there a way to solve this compile error, and therefore, maintaining this implementation ? 有没有办法解决此编译错误,并因此维持该实现?

Or I must change my vision on how I should implement a project where .cpp , .hpp files and .cu , .cuh files are mixed together ? 还是我必须改变对如何实施将.cpp.hpp文件和.cu.cuh文件混合在一起的项目的.hpp

If I must change my implementation, there is a possibility to get a similar example of what would be a good implementation by following my attention ? 如果我必须更改自己的实现,那么有可能通过关注我得到一个类似的例子,说明一个好的实现是什么?

NB: I'm actually working with a GTX 1060 with the cuda version: 注意:我实际上正在使用带有cuda版本的GTX 1060:

$nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2018 NVIDIA Corporation
Built on Wed_Apr_11_23:16:29_CDT_2018
Cuda compilation tools, release 9.2, V9.2.88

You need to rename main.cpp to main.cu to make this work. 您需要将main.cpp重命名为main.cu才能完成此工作。 Otherwise you are importing CUDA code into a plain .cpp file, and the host C++ will fail to compile the code. 否则,您要将CUDA代码导入到普通的.cpp文件中,并且主机C ++将无法编译该代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM