gpt4 book ai didi

c++ - 无法打开 .cu 中的包含文件

转载 作者:行者123 更新时间:2023-11-28 08:14:11 29 4
gpt4 key购买 nike

我有一个包含 cuda 文件的 visual studio c++ 项目(使用 VS 2010 和 insight 2)。这是代码

你好.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;
}

你好.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

我的问题是,当我构建项目时,它给我这个错误:

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

但是,当我右键单击“include “Hello.h””时,它发现该文件很好。

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

我不知道这是否更多的是我忘记的 c++ 东西的配置问题...

最佳答案

您的 .cu 文件很可能具有使用 NVCC 的自定义构建规则。右键单击 .cu 文件并查看其属性。构建规则将再次包含一个用于附加包含目录的部分。确保包含标题的目录也存在于那里。

关于c++ - 无法打开 .cu 中的包含文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8168337/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com