简体   繁体   English

CUDA似乎没有编译

[英]CUDA does not seem to compile

I am currently running the CUDA 5.0 Toolkit on my Visual Studio 2012 Express. 我目前在Visual Studio 2012 Express上运行CUDA 5.0工具包。

I attempted to run the following code 我试图运行以下代码

I have searched high and low for methods of compiling .cu on Visual Studio but to no avail 我在上下搜索了在Visual Studio上编译.cu的方法,但无济于事

Code I have attempted to compile: 我尝试编译的代码:

    //CUDA.cu
    #include <iostream>
    #include <cuda.h>
    #include <cuda_runtime.h>
    #include <device_launch_parameters.h>

    using namespace std;

    __global__ void Add(int* a, int* b)
    {
    a[0] += b[0];
    }

int main()
{
    int a = 5, b = 9;
    int *d_a, *d_b;

    cudaMalloc(&d_a, sizeof(int));
    cudaMalloc(&d_b, sizeof(int));

    cudaMemcpy(d_a, &a, sizeof(int), cudaMemcpyHostToDevice);
    cudaMemcpy(d_b, &b, sizeof(int), cudaMemcpyHostToDevice);

    Add<<< 1 , 1 >>>(d_a, d_b);

    cudaMemcpy(&a, d_a, sizeof(int) , cudaMemcpyDeviceToHost);

    cout << a << endl;

    return 0;
}

The compiler shows an error in the line 编译器在一行中显示错误

Add<<< 1 , 1 >>>(d_a, d_b);

Where it says "Error:expected an expression" 它说"Error:expected an expression"

Any attempts to compile this code results in a success. 任何尝试编译此代码的尝试都会成功。 but no .exe is to be found hence I cannot debug whatsoever. 但找不到.exe,因此我无法进行任何调试。

Unable to start program 'C:\Users\...\CUDATest3.exe'
The system cannot find the file specified

Any help whatsoever is VERY MUCH appreciated. 任何帮助非常感谢。 Thanks 谢谢

CK CK

Although I would love to understand as to WHY in my computer CUDA decided that VS is a deplorable program to be married to, I have taken a shortcut by handcuffing both of said program by means of copying from the templates provided by the CUDA installation toolkit. 尽管我很想了解为什么我的计算机上CUDA决定VS是值得嫁给的一个令人遗憾的程序,但我还是通过从CUDA安装工具箱提供的模板中复制了这两个程序的方式将其扣上了手铐。 (The CUDA samples.) (CUDA示例。)

Apparently those samples have everything already set up and ready to go; 显然,这些样本已经准备就绪,可以开始使用了。 all you need to do is edit the code from inside the solution itself. 您需要做的就是从解决方案本身内部编辑代码。 For some reason the code would not work if I had written all of the code from square one. 由于某种原因,如果我从方格一开始编写了所有代码,则该代码将无法正常工作。

I still have no idea as to why I am unable to get it to run from scratch but I guess 我仍然不知道为什么我无法使其从头开始运行,但是我想

editing the sample templates would give a much satisfactory result 编辑样本模板将提供令人满意的结果

if one does not have the time for it. 如果没有时间的话。

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

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