结构问题,CUDA C/C++和VS 2008

发布于 2024-10-04 06:22:07 字数 1180 浏览 0 评论 0原文

嘿那里...所以我在这里使用 VS2008,使用 CUDA C 进行编程。我已经安装并运行了 3.2 工具包。

现在我的问题是,我有一个这样的文件:

#ifndef _cuda_rng_cu_included_
#define _cuda_rng_cu_included_

#include <stdio.h>


static void HandleError( cudaError_t err,
                         const char *file,
                         int line ) {
    if (err != cudaSuccess) {
        printf( "%s in %s at line %d\n", cudaGetErrorString( err ),
                file, line );
        exit( EXIT_FAILURE );
    }
}
#define HANDLE_ERROR( err ) (HandleError( err, __FILE__, __LINE__ ))

//some other struct

我从 CUDA 书中得到了这个代码,所以它应该可以工作..但是当我点击构建时我得到这个错误(第一个):

error C2065: ' cudaError_t' :未声明的标识符

,然后附加了海啸般的错误,例如未找到 uint2 类型和未声明变量。

可能是什么问题? cudaError_t 在 $(CUDA_PATH_V3_2)\include 中定义,该路径位于我所需的包含目录中。

文件属性设置如下: Tool: CUDA Runtime API

我把#ifndef 放在因为我还没有弄清楚如何使用普通 C++ 和 CUDA C 之间的链接器。就像如果我有一个具有 CUDA C(__global__` __device__)和一些普通方法的结构体。如果我将此文件命名为 .cu,那么在使用该结构的普通 C++ 代码中,会打印一个错误,指出它未声明。

我尝试手动包含 driver_types.h 和大量其他标头,但编译器找不到它们。

抱歉,如果我没说清楚,我很困。

Hey there... so I am here using VS2008, programming with CUDA C. I have the 3.2 toolkit installed and working.

Now my problem is, i have a file with this:

#ifndef _cuda_rng_cu_included_
#define _cuda_rng_cu_included_

#include <stdio.h>


static void HandleError( cudaError_t err,
                         const char *file,
                         int line ) {
    if (err != cudaSuccess) {
        printf( "%s in %s at line %d\n", cudaGetErrorString( err ),
                file, line );
        exit( EXIT_FAILURE );
    }
}
#define HANDLE_ERROR( err ) (HandleError( err, __FILE__, __LINE__ ))

//some other struct

I got this code from the book CUDA by example, so it should work.. but when i hit build i get this error (the first):

error C2065: 'cudaError_t' : undeclared identifier

and then a tsunami of errors are appended, like uint2 type not being found and variables not being declared.

What could be the problem? cudaError_t is defined in $(CUDA_PATH_V3_2)\include and this path is in my required include directory.

The file property is set like to: Tool: CUDA Runtime API

I put that #ifndef because i haven't figured out how to work with the linker between normal C++ and CUDA C. Like if i have a struct with both CUDA C (__global__ and ` __device__) and some normal methods. If i name this file .cu then in the normal C++ code that uses this struct an error is printed saying it wasn't declared.

I tried to manually include driver_types.h and tons of other headers, but none of them are found by the compiler.

Sorry if i wasn't clear, i'm sleepy.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谜兔 2024-10-11 06:22:07

扩展名为 .cu 的文件由 nvcc 处理,它会自动包含 CUDA 特定的标头,以便声明 CUDA 类型。当您将其命名为 .c/.cpp 时,您需要包含相关标头以获取类型。由于您使用的是运行时 API,因此请尝试包含 cuda_runtime_api.h

您没有找到它们的事实表明您的路径设置不正确。尝试将 $(CUDA_PATH)\include 添加到包含路径中(请参阅 这篇文章了解更多详情)。

话虽如此,这里还是有一些问题......

您不需要将结构(或类)声明为 __global____device__,该结构只是一种类型并且类型是跨平台的。您需要这些声明的地方就是隐含存储的地方,即当您创建结构体的实例或创建必须为设备编译的代码时。

如果您只是声明一个结构,那么您应该能够在头文件中声明它并将其包含在 .cpp.cu 文件中,没有任何问题,并且如果那么无论如何不要发布一个包含更多细节的单独问题。

Files with the .cu extension are handled by nvcc which automatically includes the CUDA-specific headers such that the CUDA types are declared. When you name it .c/.cpp you need to include the relevant header to get the types. Since you're using the runtime API, try include cuda_runtime_api.h.

The fact that you're not finding them suggests your paths have not been set correctly. Try adding $(CUDA_PATH)\include to the include paths (see this post for more details).

Having said that, there are concerns here...

You don't need to declare a struct (or a class) as __global__ or __device__, the struct is just a type and the type is cross-platform. Where you need those declarations is where storage is implied, i.e. when you create an instance of the struct or where you are creating code that must be compiled for the device.

If you are simply declaring a struct then you should be able to declare it in a header file and include it in both .cpp and .cu files with no problems, and if not then by all means post a separate question with more details.

滿滿的愛 2024-10-11 06:22:07

您是否正确设置了包含路径?这可以解释为什么编译器找不到包含文件。

Do you have the include paths set correctly? That would explain why the compiler doesn't find the include files.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文