Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poz1/e8487a235840615aa1665f8647a574ae to your computer and use it in GitHub Desktop.
Save poz1/e8487a235840615aa1665f8647a574ae to your computer and use it in GitHub Desktop.
Preparing Ubuntu 18.04LTS as an OpenCL development platform, with a sample build target provided by Pyrit to demonstrate OpenCL ICD coexistence.

Preparing Ubuntu 18.04LTS as an OpenCL development platform:

With OpenCL, the installable client drivers (ICDs) are normally issued with the accelerator's device drivers, namely:

  1. The NVIDIA CUDA toolkit (and the device driver) for NVIDIA GPUs.
  2. AMD's RoCM for GCN-class AMD hardware.
  3. Intel's beignet and the newer Neo compute runtime.

The purpose of the installable client driver model is to allow multiple OpenCL platforms to coexist on the same platform. That way, multiple OpenCL accelerators, be they discrete GPUs paired with a combination of FPGAs and integrated GPUs can all coexist.

However, for linkage purposes, you'll require the ocl-icd package, which can be installed by:

sudo apt install ocl-icd-* opencl-headers

Why ocl-icd? Simple: Whereas other ICDs may permit you to link against them directly, it is discouraged so as to limit the risk of unexpected runtime behavior. Assume ocl-icd to be the gold link target if your goal is to be platform-neutral as possible.

Practical example: Deploying Pyrit, a WPA precomputed cracker that has accelerated backends in OpenCL (and CUDA):

Fetch the source:

git clone https://github.com/JPaulMora/Pyrit.git

Install build dependencies:

sudo pip install psycopg2 scapy 
sudo apt-get install libpcap-dev

Configure the build:

cd Pyrit
python setup.py clean
python setup.py build
sudo python setup.py install

Extra modules:

For OpenCL:

cd Pyrit/modules/cpyrit_opencl
python setup.py build
sudo python setup.py install

To test:

Run:

pyrit list_cores

Should list OpenCL cores.

Optionally, for CUDA:

cd modules/cpyrit-cuda/
python setup.py build
sudo python setup.py install

Configuring which accelerator to use:

To enable GPU computing, you must edit your config file located at ~/.pyrit/config and set either CUDA or OpenCl to 'true' like so:

use_CUDA = false
use_OpenCL = true

If limit_ncpus is set to a number below zero (say, -1), Pyrit will disable all CPU cores, piping the work to the GPU, which is usually more (power and performance) efficient.

An example of expected output is shown below.

See both GPUs being put to use with independent OpenCL runtimes. That's why the ICD model exists: It allows for multiple OpenCL platforms to co-exist on the same system, as shown here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment