Dec 8

(Imagine the post’s title spoken in Leslie Phillips‘ drawl. This will probably either amuse you or mean absolutely nothing!)

OK. It’s party time! I have two Linux boxes, both apparently with OpenCL SDKs, each with a different GPGPU:

euler – NVidia Tesla 870

crout – AMD/ATI FireStream 9270

The supplied examples work, but they have vendor-specific bits. Can I get a “pure” OpenCL program to compile and run (without modification) on both machines?

Apple provide an example that sets up the environment and runs a small kernel. I had two make two fixes:

#ifdef __APPLE__
#include <OpenCL/opencl.h>
#else
#include <CL/cl.h>
#endif

instead of simply

#include <OpenCL/opencl.h>

Second there was a bug in the call to clGetKernelWorkGroupInfo, that Apple fixed yesterday! (I did this a week ago.) (I also changed the extension from .c to .cpp – this is not critical.)

We also need a Makefile. Both NVidia and AMD provide very complex Makefiles for their examples. Here’s my stripped down version. (Change the commented out paths as needed.)

# NVIDIA directories
# OCLROOTDIR = /usr/local/NVIDIA_GPU_Computing_SDK/OpenCL
# INCLUDEDIR = $(OCLROOTDIR)/inc
# LIBDIR = $(OCLROOTDIR)/lib

# ATI directories
OCLROOTDIR = /usr/local/ati-stream-sdk-v2.0-beta4-lnx64
INCLUDEDIR = $(OCLROOTDIR)/include
LIBDIR = $(OCLROOTDIR)/lib/x86_64

CC = g++
CFLAGS = -c -Wall -I$(INCLUDEDIR)
LDFLAGS = -L$(LIBDIR) -lOpenCL

SOURCES = hello.cpp
OBJECTS = $(SOURCES:.cpp=.o)
EXECUTABLE = hello

all: $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -o $@

.cpp.o:
$(CC) $(CFLAGS) $< -o $@

And it works on both machines!


leave a reply