CUDA By Example problems

Hi.

I am using a Macbook Air with GeForce 320M and Mac OS X Lion.

I am trying to run the Julia set example in chapter 3. I modified the gl_helper file to look like (as suggested in other posts in this forum):

#ifdef(__APPLE__)

#include <GLUT/glut.h>

#else

#include <GL/glut.h>

#include <GL/glext.h>

#include <GL/glx.h>

#endif

And when compiling I tried using several commands like

nvcc JuliaSet.cu -Xlinker -framework GLUT -Xlinker -framework OpenGL

nvcc JuliaSet.cu -Xlinker -framework,GLUT -Xlinker -framework,OpenGL

But I keep getting this error:

nvcc JuliaSet.cu -Xlinker -framework GLUT -Xlinker -framework OpenGL

cuda_by_example/common/cpu_bitmap.h(50): error: identifier "glutInit" is undefined

cuda_by_example/common/cpu_bitmap.h(51): error: identifier "GLUT_SINGLE" is undefined

cuda_by_example/common/cpu_bitmap.h(51): error: identifier "GLUT_RGBA" is undefined

cuda_by_example/common/cpu_bitmap.h(51): error: identifier "glutInitDisplayMode" is undefined

cuda_by_example/common/cpu_bitmap.h(52): error: identifier "glutInitWindowSize" is undefined

cuda_by_example/common/cpu_bitmap.h(53): error: identifier "glutCreateWindow" is undefined

cuda_by_example/common/cpu_bitmap.h(54): error: identifier "glutKeyboardFunc" is undefined

cuda_by_example/common/cpu_bitmap.h(55): error: identifier "glutDisplayFunc" is undefined

cuda_by_example/common/cpu_bitmap.h(56): error: identifier "glutMainLoop" is undefined

cuda_by_example/common/cpu_bitmap.h(79): error: identifier "glClearColor" is undefined

cuda_by_example/common/cpu_bitmap.h(80): error: identifier "GL_COLOR_BUFFER_BIT" is undefined

cuda_by_example/common/cpu_bitmap.h(80): error: identifier "glClear" is undefined

cuda_by_example/common/cpu_bitmap.h(81): error: identifier "GL_RGBA" is undefined

cuda_by_example/common/cpu_bitmap.h(81): error: identifier "GL_UNSIGNED_BYTE" is undefined

cuda_by_example/common/cpu_bitmap.h(81): error: identifier "glDrawPixels" is undefined

cuda_by_example/common/cpu_bitmap.h(82): error: identifier "glFlush" is undefined

16 errors detected in the compilation of "/tmp/tmpxft_00000511_00000000-10_JuliaSet.cpp1.ii".

JuliaSet.cu is just my version of the example given in the book. So I tried running the original julia_gpu.cu given in the example code.

nvcc -o juliagpu julia_gpu.cu -Xlinker -framework,GLUT -Xlinker -framework,OpenGL

../common/cpu_bitmap.h(50): error: identifier "glutInit" is undefined

../common/cpu_bitmap.h(51): error: identifier "GLUT_SINGLE" is undefined

../common/cpu_bitmap.h(51): error: identifier "GLUT_RGBA" is undefined

../common/cpu_bitmap.h(51): error: identifier "glutInitDisplayMode" is undefined

../common/cpu_bitmap.h(52): error: identifier "glutInitWindowSize" is undefined

../common/cpu_bitmap.h(53): error: identifier "glutCreateWindow" is undefined

../common/cpu_bitmap.h(54): error: identifier "glutKeyboardFunc" is undefined

../common/cpu_bitmap.h(55): error: identifier "glutDisplayFunc" is undefined

../common/cpu_bitmap.h(56): error: identifier "glutMainLoop" is undefined

../common/cpu_bitmap.h(79): error: identifier "glClearColor" is undefined

../common/cpu_bitmap.h(80): error: identifier "GL_COLOR_BUFFER_BIT" is undefined

../common/cpu_bitmap.h(80): error: identifier "glClear" is undefined

../common/cpu_bitmap.h(81): error: identifier "GL_RGBA" is undefined

../common/cpu_bitmap.h(81): error: identifier "GL_UNSIGNED_BYTE" is undefined

../common/cpu_bitmap.h(81): error: identifier "glDrawPixels" is undefined

../common/cpu_bitmap.h(82): error: identifier "glFlush" is undefined

16 errors detected in the compilation of "/tmp/tmpxft_0000051e_00000000-4_julia_gpu.cpp1.ii".

What am I doing wrong?

EDIT:

I also tried this in gl_helper.h

#ifdef(__APPLE__)

#include <OpenGL/gl.h>

#include <OpenGL/glu.h>

#include <GLUT/glut.h>

#else

#include <GL/glut.h>

#include <GL/glext.h>

#include <GL/glx.h>

#endif

Look at this thread:

Hi mfatica.

I already tried everything in that post. In case you didn’t notice, I put up the preprocessor directive for identifying that the code is on a mac and I have even mentioned that I am passing linking arguments.

But I am still getting these errors and it baffles me.

I just tried on Lion, CUDA 4.0 and it works for me ( you need to fix an error in julia_gpu.cu, the attached file has the fix)

$ nvcc julia_gpu.cu -Xlinker -framework,GLUT -Xlinker -framework,OpenGL

These are the files I am using.
gl_helper.h (1.82 KB)
julia_gpu.cu (2.6 KB)

Thanks mfatica! It’s working now with those two files.

I feel like such an idiot, I must have accidentally overwritten the the else part just before the #if defined(APPLE). I was able to notice this error while comparing these files with the ones I have on my system.

And I noticed that you changed the constructor for the cuComplex class to work on the device.

Thanks a lot for taking the time to work on this. External Image

Onto chapter 5 then! Wish me luck…