Environment and Feature Detection
A warning, most of these extensions may have extreme security issues currently, they are prototypes after all. Use a separate browser instance and profile for this series.
If you already have a working install of WebCL and River Trail, you can skip this part. Do not assume that you have them just because you have the latest version of your browser, because they are not available yet in any browser without a special build or extension.
The first step is to install OpenCL drivers for all your devices.
If you are running OS X (Snow Leopard or Lion) then all OpenCL drivers are already installed and you're good to go.
If you are running Linux or Windows, then you might need to install some OpenCL drivers. If your CPU is supported by both the AMD and Intel SDKs then I recommend you to install both.
- Intel OpenCL SDK (requires a CPU with support for SSE 4.1, see here)
- AMD APP SDK (requires a CPU with support for SSE 2, see here)
If you have an nVidia or AMD graphics card, you probably already have OpenCL drivers installed for them (they are included in the graphics drivers), but you should make sure they are the latest version.
Now we're onto a few semi-optional tools that you probably want, but can avoid them if you want to,
Git is my version control system of choice, and you will probably want to check out the repositories of examples and on Github.
Now we can start installing the WebCL prototypes.
If you are running Linux or Windows, then you need to first install a 32-bit version of Firefox 10 and make sure that you have installed Firebug into your new profile, then you can install the Nokia WebCL prototype.
If you are running OS X, then you need to install the Samsung WebCL prototype based on WebKit. It is a bit complicated since you need to compile it from scratch.
Just follow the included readme, after a while into the build, you might meet some compilation errors but they are easily fixable.
Installing River Trail
To allow River Trail code to be accelerated via OpenCL you need to install the River Trail extension.
On OS X, the built in OpenCL drivers are fine.
Detecting WebCL and River Trail
So, after installing all that, we need a simple way to check that it is working. The easiest way is to checkout https://github.com/JensNockert/tools-for-the-next-generation with git (or download an archive of the repository from Github).
Under "01 - Feature Detection" there are two html files, webcl.html and rivertrail.html that contain feature detection code. Try both to make sure that your setup works. If everything installed correctly, it will look something like this for River Trail,
And something like this for WebCL,
The code is not really that spectacular, but feel free to check out the source and see my horrible DOM manipulation code. (Hook me up with a pull request if you enjoy that kind of stuff)
Make sure you have webcl.html open in a browser, and make a small note of the structure of the information.
The first level in the output, "Apple" in my screenshot is the OpenCL platform name and underneath all OpenCL devices corresponding to that platform (but a single piece of hardware can be devices under multiple platforms.)
In OpenCL there are two domains where code can execute, the host (in WebCL this is the browser) or on a device which is connected to a host. The code we run on the host we call the 'Application' and on the code on devices we call 'Kernels'.
To summarize on what you should install,
- Browser capable of WebCL
- Browser capable of accelerated River Trail
and make sure they work. The rest is mainly sugar that could help you reach that goal.
I will be using Firefox most of the time, but the example code that does not depend on a specific feature should be portable to most major platforms (Firefox, Chrome, Safari and Opera.)
Any specific feature dependencies will be noted in the corresponding article (and please point it out in the comments if it is not.)
- Updated for Firefox 10