Parting big CU project to small C++ files + cu

Hey , this one is driving me really crazy.

i’ve so far coded to 1 big CU file which included both C++ and Cuda code.

im trying to split the big CU file to a C++ files which will hold CPP code only.

but im facing many GL.h errors : for example :

1>  Compiling CUDA source file core.cu...

1>  

1>  C:\Users\igal\Desktop\prj trying to devide files\graph>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\bin\nvcc.exe" -gencode=arch=compute_10,code=\"sm_10,compute_10\" --use-local-env --cl-version 2010 -ccbin "c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin"  -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\include"  -G0  --keep-dir "Debug" -maxrregcount=0  --machine 32 --compile  -D_NEXUS_DEBUG -g    -Xcompiler "/EHsc /nologo /Od /Zi  /MDd " -o "Debug\core.cu.obj" "C:\Users\igal\Desktop\prj trying to devide files\graph\core.cu" 

1>c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\GL/gl.h(1152): error : this declaration has no storage class or type specifier

1>c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\GL/gl.h(1152): error : expected a ";"

1>c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\GL/gl.h(1153): error : this declaration has no storage class or type specifier

1>c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\GL/gl.h(1153): error : variable "WINGDIAPI" has already been defined

1>c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\GL/gl.h(1153): error : expected a ";"

1>c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\GL/gl.h(1154): error : variable "WINGDIAPI" is not a type name

1>c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\GL/gl.h(1154): error : "GLboolean" has already been declared in the current scope

1>c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\GL/gl.h(1154): error : expected a ";"

1>c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\GL/gl.h(1155): error : this declaration has no storage class or type specifier

1>c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\GL/gl.h(1155): error : variable "WINGDIAPI" has already been defined

1>c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\GL/gl.h(1155): error : expected a ";"

1>c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\GL/gl.h(1156): error : this declaration has no storage class or type specifier

1>c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\GL/gl.h(1156): error : variable "WINGDIAPI" has already been defined

1>c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\GL/gl.h(1156): error : expected a ";"

1>c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\GL/gl.h(1157): error : this declaration has no storage class or type specifier

1>c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\GL/gl.h(1157): error : variable "WINGDIAPI" has already been defined

1>c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\GL/gl.h(1157): error : expected a ";"

1>c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\GL/gl.h(1158): error : this declaration has no storage class or type specifier

1>c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\GL/gl.h(1158): error : variable "WINGDIAPI" has already been defined

1>c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\GL/gl.h(1158): error : expected a ";"

1>c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\GL/gl.h(1159): error : this declaration has no storage class or type specifier

1>c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\GL/gl.h(1159): error : variable "WINGDIAPI" has already been defined

1>c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\GL/gl.h(1159): error : expected a ";"

1>c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\GL/gl.h(1160): error : this declaration has no storage class or type specifier

1>c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\GL/gl.h(1160): error : variable "WINGDIAPI" has already been defined

1>c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\GL/gl.h(1160): error : expected a ";"

1>c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\GL/gl.h(1161): error : this declaration has no storage class or type specifier

1>c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\GL/gl.h(1161): error : variable "WINGDIAPI" has already been defined

what’s wrong here?

thanks for your help!

Import windows.h before gl.h

hey thanks for your reply…

i managed to do the following thing :

my CU file :

#ifdef _WIN32

#include <windows.h>

#endif

#include <cuda.h>

#include <device_launch_parameters.h>

//#include <device_functions.h>

//#include <cuda_gl_interop.h>

int ITERA =  120;

const int devider = 60;

__global__ void CoreLoop(float *p,float nmIteration , float xld, float yld, float xru, float yru, int MAXX, int MAXY)

{

    float re,im,rez,imz;

    float t1, t2, o1, o2;

    int k;

    unsigned result = 0;

    unsigned idx = blockIdx.x*blockDim.x + threadIdx.x;

    int y = idx / MAXX;

    int x = idx % MAXX;

	int iterCounter = (int) nmIteration;

    re = (float) xld + (xru-xld)*x/MAXX;

    im = (float) yld + (yru-yld)*y/MAXY;

rez = 0.0f;

    imz = 0.0f;

k = 0;

	while (k < iterCounter) 

	{

		o1 = rez * rez;

		o2 = imz * imz;

		t2 = 2 * rez * imz;

		t1 = o1 - o2;

		rez = t1 + re;

		imz = t2 + im;

		if (o1 + o2 > 4)

		{  //change somehow...

			result = k;

			break;

		}

	k++;

    }

	//p[y*MAXX + x].x = re;

	//p[y*MAXX + x].y = im;  

	p[y*MAXX + x] = k;   // lookup[result];

	//p[y*MAXX + x].w = lookup[result];

}

extern "C" void CoreLoopOnDev(int nBlocks , int nThreads , float *p,float nmIteration , float xld, float yld, float xru, float yru, int MAXX, int MAXY )

{

	CoreLoop<<< nBlocks, nThreads >>>(p, nmIteration /*ITERA * glbl_precentage*/ ,  xld, yld, xru, yru, MAXX, MAXY);

}

but now im getting :

1>  Compiling CUDA source file kernel.cu...

1>  

1>  C:\Users\igal\Desktop\prj GRAPH - Copy\graph>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\bin\nvcc.exe" -gencode=arch=compute_10,code=\"sm_10,compute_10\" --use-local-env --cl-version 2010 -ccbin "c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin"  -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v4.0\include"  -G0  --keep-dir "Debug" -maxrregcount=0  --machine 32 --compile  -D_NEXUS_DEBUG -g    -Xcompiler "/EHsc /nologo /Od /Zi  /MDd " -o "Debug\kernel.cu.obj" "C:\Users\igal\Desktop\prj GRAPH - Copy\graph\kernel.cu" 

1>C:/Users/igal/Desktop/prj GRAPH - Copy/graph/kernel.cu(21): warning : variable "result" was set but never used

1>C:/Users/igal/Desktop/prj GRAPH - Copy/graph/kernel.cu(21): warning : variable "result" was set but never used

1>  tmpxft_00001f64_00000000-11_kernel.ii

1>  mainPrj.cpp

1>c:\program files\nvidia gpu computing toolkit\cuda\v4.0\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 10.0\vc\include\string.h(157) : see declaration of 'strerror'

1>  Note: including lib: glut32.lib

1>  

1>c:\users\igal\desktop\prj graph - copy\graph\kernel.cu(57): error C2059: syntax error : '<'

1>c:\users\igal\desktop\prj graph - copy\graph\kernel.cu(106): error C2059: syntax error : '<'

1>c:\users\igal\desktop\prj graph - copy\graph\mainprj.cpp(37): error C2374: 'ITERA' : redefinition; multiple initialization

1>          c:\users\igal\desktop\prj graph - copy\graph\kernel.cu(13) : see declaration of 'ITERA'

1>c:\users\igal\desktop\prj graph - copy\graph\mainprj.cpp(213): warning C4018: '<' : signed/unsigned mismatch

1>c:\users\igal\desktop\prj graph - copy\graph\mainprj.cpp(327): error C2664: 'cudaMemcpyToSymbol' : cannot convert parameter 1 from 'unsigned int [256]' to 'const char *'

1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Hi!

try to fix errors :) They are quite trivial.
Use “extern” in .cpp file for ITERA
check the first parameter for cudaMemcpyToSymbol call in .cpp file. Perhaps you need co make a cast.

Pay spatial attention on warnings. They could be potential errors.

good luck