Getting CLsmith and building
- Linux OS
- gcc (>=4.8)
- An OpenCL implementation (vendors such as Intel or AMD provide their own)
- Python (>=2.7) (not required, but recommended)
In order to get the source code for CLsmith, you will need to clone the git repository available here:
- git clone https://github.com/ChrisLidbury/CLSmith
The directory in which the repository has been clone will be refered to as <CLsmith-dir>
- cd <CLsmith-dir>
- cd src/CLSmith
When running make the first time, the linking will fail; this is expected.
After this step, you should have cl_launcher and CLSmith in <CLsmith-dir>/src/CLSmith.
To setup a testing directory (requires Python):
- cd <CLsmith-dir>/scripts
- ./cl_setup_test.py <test-dir>
This will create the folder $HOME/<test-dir>
and move all required files in it.
To generate a random OpenCL kernel:
- cd <CLsmith-dir>/src/CLSmith or cd <test-dir>
This will produce CLProg.c
, containing the random kernel.
To execute the generated kernel:
- cd <test-dir>
- ./cl_launcher -f CLProg.c -d 0 -p 0
The expected output is a comma-separated list of hexadecimal numbers. Each number corresponds to the result of a thread. The d
parameters of cl_launcher
control the platform and device index to be used by OpenCL. If you have multiple OpenCL compatible devices available, you can use these parameters to control which to use.
In order to execute a kernel without having run the Python setup script, move the following files to a folder and run cl_launcher as above:
For information about options available to pass to the generator and others, click here.
A way to test out the tool without having access to an OpenCL device is with Oclgrind, an OpenCL emulator. Obtain it by following the instructions available at its Github page. After installation, the only change in regards to CLsmith is, during execution, the way to run cl_launcher with Oclgrind is by:
- oclgrind ./cl_launcher -f CLProg.c -d 0 -p 0