2011-11-17 120 views
0

我有一个包含cuda文件的Visual Studio C++项目(包含VS 2010和insight 2)。下面的代码无法在.cu中打开包含文件

Hello.h:

#pragma once 

#pragma warning(push) 
#pragma warning(disable:4996) 
#include "thrust\device_vector.h" 
#pragma warning(pop) 

class Hello 
{ 
public: 
    Hello(const thrust::host_vector<unsigned long>& data); 
    unsigned long Sum(); 
    unsigned long Max(); 

private: 
    thrust::device_vector<unsigned long> m_data; 
} 

Hello.cu:

#include "thrust\host_vector.h" 
#include "thrust\device_vector.h" 
#include "thrust\extrema.h" 

#include "Hello.h" 

using namespace ::thrust; 

Hello::Hello(const thrust::host_vector<unsigned long>& data) 
    : m_data(data.cbegin(), data.cend()) 
{ 
} 

unsigned long 
Hello::Sum() 
{ 
    return(reduce(m_data.cbegin(), m_data.cend(), 
     (unsigned long)0, 
     plus<unsigned long>())); 
} 

unsigned long 
Hello::Max() 
{ 
    return(*max_element(m_data.cbegin(), m_data.cend())); 
} 

最后的main.cpp:

#ifdef _WIN32 
    #define WINDOWS _LEAN_AND_MEAN 
    #define NOMINMAX 
    #include <Windows.h> 
#endif 

#include <stdlib.h> 
#include <stdio.h> 
#include <string.h> 
#include <math.h> 
#include <ppl.h> //parallel patterns library 

#include "Hello.h" 

using namespace ::Concurrency; 

int 
main(int argc, char** argv) 
{ 
    printf("Generating data...\n"); 
    thrust::host_vector<unsigned long> host_data(100000); 
    thrust::generate(host_data.begin(), host_data.end(), rand); 
    printf("generated %d numbers\n", host_data.size()); 

    parallel_invoke(
     [host_data]() 
    { 
     printf("\nRunning host code...\n"); 
     unsigned long host_result = thrust::reduce(host_data.cbegin(), 
      host_data.cend(), 0, thrust::plus<unsigned long>()); 
     printf("The sum is %d\n", host_result); 

     host_result = *thrust::max_element(host_data.cbegin(), 
      host_data.cend(), thrust::less<unsigned long>()); 
     printf("The max is %d\n", host_result); 
    }, 
     [host_data]() 
    { 
     printf("\nCopying data to device...\n"); 
     Hello hello(host_data); 

     printf("\nRunning CUDA device code...\n"); 
     unsigned long device_result = hello.Sum(); 
     printf("The sum is %d\n", device_result); 

     printf("\nRunning CUDA device code...\n"); 
     device_result = hello.Max(); 
     printf("The max is %d\n", device_result); 
    } 
    ); 

    return(0); 
} 

代码来自:here

M Ÿ问题是,当我生成项目,它给了我这个错误:

Hello.cu(5): fatal error C1083: Cannot open include file: 'Hello.h': No such file or directory 

然而,当我用鼠标右键点击“包括‘Hello.h’”找到文件就好了。

我已经添加了我的.h文件夹在项目的其他include目录中。所以我真的不知道为什么它无法打开文件。

我不知道这是否是更大的配置问题,只是也许一个C++件事我忘了...

回答

1

你.CU文件将最有可能有一个自定义生成规则,以充分利用NVCC的。右键单击.cu文件并查看其属性。构建规则将再次包含其他包含目录的部分。确保包含标题的目录也存在。

+0

非常感谢,正是我所需要的 – nevero

相关问题