-1

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. Thrust exception: "thrust::system::system_error at memory location 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: '<'

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.

I have to clear that setRange is a class member function of foo that calls the kernel 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. At the end, both execution options update the vector dis, which is a class member vector.

The main function is defined in fooTest.cu as follows:

#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
Community
  • 1
  • 1
Vitrion
  • 405
  • 5
  • 14
  • Your problem resembles the one discussed here: http://stackoverflow.com/questions/18200952/how-to-separate-the-kernel-file-cuda-with-the-main-cpp-file – WhiteViking Nov 06 '15 at 15:34
  • I have to clear something else. I have renamed my codes to .cu and .cuh and the result is the same. As the code shows, the main function is defined in fooTest.cu. – Vitrion Nov 06 '15 at 16:22
  • 1
    The error message should indicate *where* the error is. –  Nov 06 '15 at 16:28
  • (also, I assume it is s**y**ntax error, not s**i**ntax error?) –  Nov 06 '15 at 16:29
  • Error is in the triple angle brackets. Also, I tried making a little project to test this function separating that part of my project code. It works perfectly. I don't understand why! What is my mistake? – Vitrion Nov 06 '15 at 17:06
  • 1
    Sounds like you're not using the cuda compiler to compile this file, then. I've not used cuda through MSVC, so I can't suggest what you might be doing wrong configuring your project. –  Nov 06 '15 at 18:01
  • Indeed. The triple angle brackets are not C++ but it looks like they end up getting fed to the C++ compiler after all. You will need to post full output from the tool chain you are using: complete details of what commands are run with what arguments. Hopefully someone will then see what goes wrong. – WhiteViking Nov 06 '15 at 18:05
  • I would understand that, Hurkyl, but other smaller projects can be compiled with VS. I will try to check the CUDA conifguration in my project again. – Vitrion Nov 06 '15 at 22:51

1 Answers1

1

I already discovered why my code generated that error!

This was the problem: I defined a header file called 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).

When I copied all the foo.cu file and pasted it in the header file after the class definition, this error disappeared!!!

I think CUDA does not support the use of source files to define the class methods in a separate file. I mean that the NVCC compiler does not treat the source files; instead of that the C++ compiler tries to compile them.

What do you think?

Vitrion
  • 405
  • 5
  • 14