Skip to content

Instantly share code, notes, and snippets.

@Brainiarc7
Last active May 3, 2021 08:36
Show Gist options
  • Star 23 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save Brainiarc7/dc80b023af5b4e0d02b33923de7ba1ed to your computer and use it in GitHub Desktop.
Save Brainiarc7/dc80b023af5b4e0d02b33923de7ba1ed 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.

Copy link

ghost commented Mar 2, 2019

Hey, thanks!

@Brainiarc7
Copy link
Author

You're welcome!

@xakepp35
Copy link

What does produce text (with cpu/gpu/ps metrics), just over the wallpaper, on the right part of your screen?

@Brainiarc7
Copy link
Author

@xakepp35 its' conky

@tmnnt
Copy link

tmnnt commented Aug 26, 2019

Hey, absolutely loved the instructions! I have a question though. How do I run other OpenCL programs/benchmarks with this installation?

@Brainiarc7
Copy link
Author

Hello @tmnnt what benchmarks, to be specific?
If you're looking at benchmark profiles for OpenCL-based workloads, try this suite: https://openbenchmarking.org/suite/pts/opencl

@Brainiarc7
Copy link
Author

Hello @tmnnt what benchmarks, to be specific?
If you're looking at benchmark profiles for OpenCL-based workloads, try this suite: https://openbenchmarking.org/suite/pts/opencl

@tmnnt
Copy link

tmnnt commented Aug 27, 2019

Hey @Brainiarc7, thanks for the reply. That was not what I was looking for.

I want to know if there are any workflows/ tutorials for running OCL programs using Pyrit.

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