简体   繁体   English

CUDA 错误 C2059:语法错误:“<”

[英]CUDA Error C2059: syntax error: '<'

I have troubles when compiling my code.我在编译代码时遇到了麻烦。

First of all, I have to state something:首先,我必须声明一点:

  1. I have no issues to run other simpler CUDA codes in my GTX650Ti GPU.我在 GTX650Ti GPU 中运行其他更简单的 CUDA 代码没有问题。 Thrust exception: "thrust::system::system_error at memory location 0x00000000" 推力异常:“内存位置 0x00000000 处的推力::系统::系统错误”

  2. I've been working in a class with several methods and for some unknown reason, this program leads me to the error: Error C2059: syntax error: '<'我一直在一个具有多种方法的类中工作,并且出于某种未知原因,该程序导致我出现错误:错误 C2059:语法错误:'<'

This is part of the code:这是代码的一部分:

__global__ void linearSpaceKernel(double *result, double base, double delta, unsigned int size)
{
    unsigned int i = blockDim.x * blockIdx.x + threadIdx.x;
    if (i < size)
        result[i] = base + double(i) * delta;
    cudaThreadSynchronize();
}

void foo::setRange(const double &lower, const double &upper, const unsigned int &samples)
{
    vector<double> result(samples);
    double dx = (upper - lower) / (samples - 1);
    if (isCUDA)
    {
        device_vector<double> dev_result(samples);
        linearSpaceKernel<<<1, samples>>>(raw_pointer_cast(dev_result.data()), lower, dx, samples);
        thrust::copy(dev_result.begin(), dev_result.end(), result.begin());
    }
    else
    {       
        double summation = lower;
        for (unsigned int i = 0; i < samples; i++)
        {
            result[i] = summation;
            summation += dx;
        }       
    }
    dis = result;
}

I omitted the CUDA error functions and the rest of the code to keep my code short and clear.我省略了 CUDA 错误函数和其余代码以保持我的代码简洁明了。

I have to clear that setRange is a class member function of foo that calls the kernel linearSpaceVector() .我必须明确setRangefoo 的一个类成员函数,它调用内核linearSpaceVector() This class provides a Boolean called isCUDA which is used to let the user decide if the execution will be performed in the host or in the device.此类提供了一个名为isCUDA的布尔值,用于让用户决定执行是在主机中还是在设备中执行。 At the end, both execution options update the vector dis , which is a class member vector.最后,两个执行选项都会更新向量dis ,它是一个类成员向量。

The main function is defined in fooTest.cu as follows: main函数在fooTest.cu中定义如下:

#include "foo.cuh"

int main()
{
    CUDAinit();
    foo A;
    A.isCUDA = true;
    A.setRange(0, 1, 100);
    cin.get();
}

The output is the following:输出如下:

1>------ Build started: Project: fs, Configuration: Debug Win32 ------
1>  Compiling CUDA source file ..\..\..\..\..\OneDrive\Documentos\Cátedras CONACyT\UTM\Research\FLS\Programs\fsTest.cu...
1>  
1>  C:\Users\Arturo\Documents\Visual Studio 2013\Projects\fs\fs>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\bin\nvcc.exe" -gencode=arch=compute_20,code=\"sm_20,compute_20\" --use-local-env --cl-version 2013 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin"  -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\include"  -G   --keep-dir Debug -maxrregcount=0  --machine 32 --compile -cudart static  -g   -DWIN32 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /Zi /RTC1 /MDd " -o Debug\fsTest.cu.obj "C:\Users\Arturo\OneDrive\Documentos\Cátedras CONACyT\UTM\Research\FLS\Programs\fsTest.cu" 
1>  fsTest.cu
1>  fs.cu
1>  c:\program files\nvidia gpu computing toolkit\cuda\v7.5\include\thrust\system\detail\error_category.inl(102): warning C4996: 'strerror': This function or variable may be unsafe. Consider using strerror_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>  c:\program files (x86)\microsoft visual studio 12.0\vc\include\string.h(168) : see declaration of 'strerror'
1>  c:\program files\nvidia gpu computing toolkit\cuda\v7.5\include\thrust\system\cuda\detail\bulk\detail\pointer_traits.hpp(55): warning C4800: 'unsigned int' : forcing value to bool 'true' or 'false' (performance warning)
1>  c:\users\arturo\onedrive\documentos\cátedras conacyt\utm\research\fls\programs\fs.cu(332): error C2059: syntax error : '<'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

And the errors are listed as:错误被列为:

3   Error   C2059: syntax error : '<'   c:\users\arturo\onedrive\documentos\cátedras conacyt\utm\research\fls\programs\fs.cu    332 1   fs
4   IntelliSense: expected an expression    c:\Users\Arturo\OneDrive\Documentos\Cátedras CONACyT\UTM\Research\FLS\Programs\fs.cu    332 23  fs
Warning 2   warning C4800: 'unsigned int' : forcing value to bool 'true' or 'false' (performance warning)   c:\program files\nvidia gpu computing toolkit\cuda\v7.5\include\thrust\system\cuda\detail\bulk\detail\pointer_traits.hpp    55  1   fs
Warning 1   warning C4996: 'strerror': This function or variable may be unsafe. Consider using strerror_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.    c:\program files\nvidia gpu computing toolkit\cuda\v7.5\include\thrust\system\detail\error_category.inl 102 1   fs

I already discovered why my code generated that error!我已经发现为什么我的代码会产生那个错误!

This was the problem: I defined a header file called foo.cuh .这就是问题所在:我定义了一个名为foo.cuh的头文件。 I only defined the class foo in there, but all the methods were defined in a separeted file called foo.cu (a source file).我只在那里定义了类 foo,但所有方法都在一个名为foo.cu (源文件)的单独文件中定义。

When I copied all the foo.cu file and pasted it in the header file after the class definition, this error disappeared!!!当我把所有的foo.cu文件复制并粘贴到类定义之后的头文件中时,这个错误就消失了!!!

I think CUDA does not support the use of source files to define the class methods in a separate file.我认为 CUDA 不支持使用源文件在单独的文件中定义类方法。 I mean that the NVCC compiler does not treat the source files;我的意思是 NVCC 编译器不处理源文件; instead of that the C++ compiler tries to compile them.而不是 C++ 编译器尝试编译它们。

What do you think?你怎么认为?

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

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