Update august 2012: There is a new post for the latest Linux examples.
Note: these patches won’t work anymore! You can learn from the patches how to fix the latest SDK-code for GCC and Linux/OSX.
Code-examples are not bundled with the Linux OpenCL SDK 1.1 beta. Their focus is primarily Windows, so VisualStudio seems to be a logical target. I just prefer GCC/LLVM which you can get to work with all OSes. After some time trying to find the alternatives for MS-specific calls, I think I managed. Since ShallowWater uses DirectX and is quite extensive, I did not create a patch for that one – sorry for that.
I had a lot of troubles getting the BMP-export to work, because serialisation of the struct added an extra short. Feedback (such as a correct BMP-export of a file) is very welcome, since I the colours are correct. For the rest: most warnings are removed and it just works – tested with g++ (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2 on 64 bit (llvm-g++-4.2 seems to work too, but not fully tested).
THE PATCHES ARE PROVIDED AS IS – NO WARRANTIES!
Getting the OpenCL SDK Examples
From the Intel OpenCL webpage get the Windows OpenCL SDK 1.1 Beta. If you have Windows, install as normal.
For OSX and Linux, open it with Wine 1.2 (configured as “Windows 7”). At the step where asked for where to copy the files, use the a subdirectory ‘samples’ of the SDK-location, as the default will fail the installer. You will then find the files in “~/.wine/drive_c/Program Files/Intel/OpenCL SDK/1.1/samples/“.
Patching
Before continuing, make sure you make a backup! During the patching an .orig-file is created, but just in case. The patches have been tested with the SDK provided at 20-06-2011. Windows needs patch for Windows, OSX options for patching are explained here.
Download Intel OpenCL SDK_GCC_Patches and extract to the directory where the samples are. Go there with a terminal and apply the patches:
patch common/utils.cpp utils.cpp.patch
patch common/utils.h utils.h.patch
patch BitonicSort/BitonicSort.cpp BitonicSort.cpp.patch
patch DotProduct/DotProduct.cpp DotProduct.cpp.patch
patch GodRays/GodRays.cpp GodRays.cpp.patch
patch GodRays/GodRaysNative.cpp GodRaysNative.cpp.patch
patch MedianFilter/MedianFilter.cpp MedianFilter.cpp.patch
patch ToneMapping/ToneMapping.cpp. ToneMapping.cpp.patch
patch ToneMapping/ToneMappingNative.cpp. ToneMappingNative.cpp.patch
If there is a “Hunk #X FAILED at YY.” then something went wrong – please let me know. You can of course always manually patch the files. Be sure to path tools/utils.h and tools/utils.cpp first, before patching a demo of choice.
Compiling
Compiling from the command-line is done without makefile. For example GodRays, with llvm:
llvm-g++-4.2 -lOpenCL -Wall -O3 GodRays.cpp -o GodRays && ./GodRays
or with gcc:
g++ -lOpenCL -Wall -O3 GodRays.cpp -o GodRays && ./GodRays
Output is:
Trying to run on a CPU
Reading file ‘GodRays.cl’ (size 24496 bytes)
Using device Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz…
Using 8 cores…
Expected min alignment for buffers is 128 bytes…
width = 1600
height = 1200
Save Image: GodRaysInput.bmp
BMFH-size = 16
BMIH-size = 40
data-size = 7680000
header-size = 56
total size = 7680056
Input size is 1600 X 1200
Executing OpenCL kernel…
Original global work size 374
Original local work size 1
Corrected global work size 374
Executing reference…
Save Image: GodRaysOutput.bmp
BMFH-size = 16
BMIH-size = 40
data-size = 7680000
header-size = 56
total size = 7680056
Save Image: GodRaysOutputReference.bmp
BMFH-size = 16
BMIH-size = 40
data-size = 7680000
header-size = 56
total size = 7680056
Performing verification…
Verification succeeded.
As I said the colours are totally wrong, but it is independent from the correct working of the OpenCL-kernel. Happy coding! Say thanks if you’re happy by commenting or via Twitter.
for an Intel/Nvidia system, you have to install sdks from both of them. correct
Compile with errors.
exvion@exvion:~/devel/intel_sdk_samples/GodRays$ g++ -lOpenCL -Wall -O3 GodRays.cpp -o GodRays && ./GodRays
GodRays.cpp: In function ‘cl_float* readInput(cl_uint*, cl_uint*)’:
GodRays.cpp:183:53: warning: ignoring return value of ‘size_t fread(void*, size_t, size_t, FILE*)’, declared with attribute warn_unused_result
GodRays.cpp:184:54: warning: ignoring return value of ‘size_t fread(void*, size_t, size_t, FILE*)’, declared with attribute warn_unused_result
GodRays.cpp:213:53: warning: ignoring return value of ‘size_t fread(void*, size_t, size_t, FILE*)’, declared with attribute warn_unused_result
Trying to run on a CPU
Reading file ‘GodRays.cl’ (size 24496 bytes)
ERROR: Failed to build program…
Build Log:
Error: unimplemented function(s) used:
allOne_v4_i32 in function __Vectorized_GodRays
allOne_v4_i32 in function __Vectorized_GodRays
allOne_v4_i32 in function __Vectorized_GodRays
allOne_v4_i32 in function __Vectorized_GodRays
allOne_v4_i32 in function __Vectorized_GodRays
allOne_v4_i32 in function __Vectorized_GodRays
allZero_v4_i32 in function __Vectorized_GodRays
allOne_v4_i32 in function __Vectorized_GodRays
allOne_v4_i32 in function __Vectorized_GodRays
When I look into the code I downloaded from Intel when I wrote this article, there were no “__Vectorized_GodRays” nor “allOne_v4_i32” in the code. This would mean Intel changed the code. I’ve sent you the patched code as I have it here.