The Game of Life in CUDA

OOh, nice one - even runs quite well on my laptop ( with 9300m )

I’ve spent some time optimizing the code and to my surprise it is mostly the display updates that consume a lot of time.

(gtx 260)

I don’t know what optimizations you did, but i got the kernel down to half a milisecond. for a 1024x1024 on a quadro 5800. but just coping the data back takes 3 miliseconds, and rendering … of course using gl interop and vbo rendering will speed stuff up. Oh and in my version the boarders loop around so that what ever goes out the bottem come back from the top and so forth.

down to half a millisecond? how much time was it before? :D

go fourth with the optimisation, and give us some code :D

i tryed to make it looping too…but…damn…for any reason it does not work…

ill post the new code soon, any ways one thing is that you need to switch the buffers for each run, the last out is now the in and the last in is now the out … hope this helps


with your optimisation are you guaranteeing coalesced memory accesses?

nope not really, even if we find a way to do that (which is very tricky on the border cells of a block since they need to read data that belongs to the next block) it would completely screw over the memory reads for the gl draw. but half a millisecond is pretty good. using gl inter-op would give it a much bigger performance boost. I did move to using the shared memory which improved the time from 0.8 ms to 0.5 …

How to get this compiled on Mac OS X ?


I get 6 FPS CPU (C2D 2.8 GHz) and 28 FPS GPU (8800)

(Noob in CUDA programming, new here…)

Well i have a similar problem

I have a project to make :

Write a program in CUDA simulating GAME OF LIFE with the following requirements:

Inputs: 1) number of iterations, t
2) file which contains the starting board (nXn)

Actions: 1) Read the starting board
2) do t iterations
3) Write the final board (nxn) in a new file (to be able to use it as input later)
The calculation-development must use the GPU

Notes: In calculations you must use cyclic boundary conditions (the next cell of n-1 cell is 0 cell, and reverse)
Your program must be able to run successfully using boards (nxn) with n<= 2000 and use Shared memory

Any kind of help appreciated

At the moment trying to work on the given code(attached by erdooom and Snowball_Two) so solutions on it will be preferred

so you preaty much have it all done, all u need is to read the file and write it.

Can someone help me out a little bit? I couldn’t understand whether the automaton’s boundaries were cyclical or not. The Neighbors function got me a little confused. In a previous implementation of Game of Life I had written in C# I had used a a 2d array.

NOTE: I am referring to the code that SNOWBALL TWO posted

I think in snowball two’s code there is no cyclic boundary thing … and in the Dev_Neighbors() , function from conditions like (x+i<SCREENX) && (y+k<SCREENY) i think when it coming to boundaries it doesn’t bother calculating …

Well i’m a little bit confused…

I have to run my project in a UI (linux-based).

In this UI all the appropriate files and libs in order to run CUDA progs are preinstalled.

so i uploaded my project is the exact code uploaded here from erdooom and Snowball_Two)

and tried to compile it but there were lots of errors (concerning mainly OpenGL in some cases)

the command i used was

nvcc -I/usr/local/NVIDIA_CUDA_SDK_2.3/C/common/inc -o test -L/usr/local/NVIDIA_CUDA_SDK_2.3/C/common/lib -lglut

but i got

/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/libglut.a(libglut_la-freeglut_menu.o): In function `fgDisplayMenu':

(.text+0x12ad): undefined reference to `glMatrixMode'

/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/libglut.a(libglut_la-freeglut_menu.o): In function `fgDisplayMenu':

(.text+0x12b2): undefined reference to `glPopMatrix'

/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/libglut.a(libglut_la-freeglut_state.o): In function `fghGetConfig':

(.text+0x2db): undefined reference to `glXGetConfig'

/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/libglut.a(libglut_la-freeglut_state.o): In function `glutGet':

(.text+0x3dd): undefined reference to `XGetWindowAttributes'

/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/libglut.a(libglut_la-freeglut_state.o): In function `glutGet':

(.text+0x480): undefined reference to `XTranslateCoordinates'

/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/libglut.a(libglut_la-freeglut_state.o): In function `glutGet':

(.text+0x4c7): undefined reference to `XTranslateCoordinates'

/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/libglut.a(libglut_la-freeglut_window.o): In function `glutFullScreen':

… and More

trying with glut32

$ nvcc -I/usr/local/NVIDIA_CUDA_SDK_2.3/C/common/inc -o test -L/usr/local/NVIDIA_CUDA_SDK_2.3/C/common/lib/glut32

/tmp/tmpxft_00000867_00000000-11_GoL_perfect.o: In function `computeFPS()':

tmpxft_00000867_00000000-10_GoL_perfect.ii:(.text+0x422): undefined reference to `cutGetTimerValue'

tmpxft_00000867_00000000-10_GoL_perfect.ii:(.text+0x46f): undefined reference to `glutSetWindowTitle'

tmpxft_00000867_00000000-10_GoL_perfect.ii:(.text+0x484): undefined reference to `cutResetTimer'

/tmp/tmpxft_00000867_00000000-11_GoL_perfect.o: In function `display()':

tmpxft_00000867_00000000-10_GoL_perfect.ii:(.text+0x6a9): undefined reference to `cutStartTimer'

tmpxft_00000867_00000000-10_GoL_perfect.ii:(.text+0x6c4): undefined reference to `glMatrixMode'

tmpxft_00000867_00000000-10_GoL_perfect.ii:(.text+0x6c9): undefined reference to `glLoadIdentity'

tmpxft_00000867_00000000-10_GoL_perfect.ii:(.text+0x6fc): undefined reference to `gluOrtho2D'

tmpxft_00000867_00000000-10_GoL_perfect.ii:(.text+0x706): undefined reference to `glClear'

tmpxft_00000867_00000000-10_GoL_perfect.ii:(.text+0x710): undefined reference to `glMatrixMode'

tmpxft_00000867_00000000-10_GoL_perfect.ii:(.text+0x715): undefined reference to `glLoadIdentity'

tmpxft_00000867_00000000-10_GoL_perfect.ii:(.text+0x827): undefined reference to `glFlush'

tmpxft_00000867_00000000-10_GoL_perfect.ii:(.text+0x869): undefined reference to `cutStopTimer'

/tmp/tmpxft_00000867_00000000-11_GoL_perfect.o: In function `main':

tmpxft_00000867_00000000-10_GoL_perfect.ii:(.text+0x9a1): undefined reference to `cutGetCmdLineArgumentstr'

tmpxft_00000867_00000000-10_GoL_perfect.ii:(.text+0xa28): undefined reference to `cutCreateTimer'

tmpxft_00000867_00000000-10_GoL_perfect.ii:(.text+0xa4c): undefined reference to `glutInit'

tmpxft_00000867_00000000-10_GoL_perfect.ii:(.text+0xa56): undefined reference to `glutInitDisplayMode'

tmpxft_00000867_00000000-10_GoL_perfect.ii:(.text+0xa65): undefined reference to `glutInitWindowSize'

tmpxft_00000867_00000000-10_GoL_perfect.ii:(.text+0xa6f): undefined reference to `glutCreateWindow'

tmpxft_00000867_00000000-10_GoL_perfect.ii:(.text+0xafe): undefined reference to `glutMainLoop'

tmpxft_00000867_00000000-10_GoL_perfect.ii:(.text+0xb09): undefined reference to `cutDeleteTimer'

collect2: ld returned 1 exit status

(the above are just small parts of the actual error messages)

so i am wondering :

Which is the exact command to compile my project properly?

It is required to compile and run it on this UI

connecting using PuttY

PS:i am assuming that the problem is with the code line #include <GL/glut.h>

but when i include the folder “inc” and the folder “GL” is its subfolder doesnt mean that all should be ok?(and compiler should recongnize glut.h)

-L path for glut must be added to command line?

This is my makefile which I mostly use this might help you. :rolleyes:

[codebox]SDK_ROOT = /home/bibrak/NVIDIA_GPU_Computing_SDK

CUDA_LIB_PATH = /usr/local/cuda/lib

INLCUDE = -I$(SDK_ROOT)/C/common/inc -I/usr/local/cuda/include

LIBS = -L$(SDK_ROOT)/C/lib -lcutil -lglut

LIBS += -L$(CUDA_LIB_PATH) -lcudart -lcuda




nvcc $(INLCUDE) $(LIBS) $(SRC_CU) $(SRC_CXX)[/codebox]


remember there is a tab before nvcc[/b]

BTW, are you running the GUI through PUTTY ?

I run GUI of a remote linux machine through

ssh -X user@address

i am not sure, if there is a way to doing it on PUTTY.

there is…

My professor who owns the linux server told us to run the project there.

so i am connecting to my UI through Putty (which is ussing ssh btw)


the only info that he gave to me is to install from /root directory the CUDA SDK 2.3 installer into my home directory…

but in the /root directory i only found

so i installed it in ~/NVIDIA_CUDA_SDK folder. Installation seems to ended ok but when i tried to modify the .bash_profile following

nvidia’s README about linux(and taken as granted that drivers and toolkit were already installed by my professor)

i change it and it looks like

# .bash_profile

# Get the aliases and functions

if [ -f ~/.bashrc ]; then

		. ~/.bashrc


# User specific environment and startup programs


export PATH



but when i go further to building the project examples i get errors

/usr/bin/ld: cannot find -lcudart

collect2: ld returned 1 exit status

make[1]: *** [../../bin/linux/release/quasirandomGenerator] Error 1

make[1]: Leaving directory `/export/home/username/NVIDIA_CUDA_SDK/projects/quasirandomGenerator'

make: *** [projects/quasirandomGenerator/Makefile.ph_build] Error 2

so smthn is wrong…

bibrak@bibrak-laptop:/usr/local/cuda/lib$ ls

check for the
if its there then check your compilation command does it include -lcudart

some thing like

nvcc -lcudart

hi all…

I have implemented a different kernel of the Game of Life.

please look at it, and comment on, "Does it make COALESCED memory accesses ? "


path /usr/local/cuda/lib

path /usr/local/cuda/lib64

path /usr/local/cuda/bin

bin2c cudafe++ filehash nvcc.profile

cudafe fatbin nvcc ptxas

with the command nvcc -o test1 -lGL -lglut -lcudart

i get

/tmp/tmpxft_00000332_00000000-11_GoL_perfect.o: In function `computeFPS()':

tmpxft_00000332_00000000-10_GoL_perfect.ii:(.text+0x422): undefined reference to `cutGetTimerValue'

tmpxft_00000332_00000000-10_GoL_perfect.ii:(.text+0x484): undefined reference to `cutResetTimer'

/tmp/tmpxft_00000332_00000000-11_GoL_perfect.o: In function `display()':

tmpxft_00000332_00000000-10_GoL_perfect.ii:(.text+0x6a9): undefined reference to `cutStartTimer'

tmpxft_00000332_00000000-10_GoL_perfect.ii:(.text+0x6fc): undefined reference to `gluOrtho2D'

tmpxft_00000332_00000000-10_GoL_perfect.ii:(.text+0x869): undefined reference to `cutStopTimer'

/tmp/tmpxft_00000332_00000000-11_GoL_perfect.o: In function `main':

tmpxft_00000332_00000000-10_GoL_perfect.ii:(.text+0x9a1): undefined reference to `cutGetCmdLineArgumentstr'

tmpxft_00000332_00000000-10_GoL_perfect.ii:(.text+0xa28): undefined reference to `cutCreateTimer'

tmpxft_00000332_00000000-10_GoL_perfect.ii:(.text+0xb09): undefined reference to `cutDeleteTimer'

collect2: ld returned 1 exit status

try adding -lcutil