Framester
Framester

Reputation: 35451

How to include the OpenCL libraries to produce a stand alone application?

I tried to show a colleague the fancy stuff I can do with OpenCL, but the exec would not run on her computer. Some libopencl.so (or similar) files were missing (i.e. she did not have OpenCL installed). So my probably rather basic (Linux) question is, How do I include all the necessary so files that my little C + OpenCL program will also run on machines without OpenCL?

Upvotes: 3

Views: 4556

Answers (1)

Quantumboredom
Quantumboredom

Reputation: 1466

As Damon's comment already states, this is not possible to do in a general way, since each kind of device has its own vendor and that vendor has its own implementation of OpenCL. However, if what you want to do is simply to have a "portable" copy of your OpenCL application that will run on most Linux computers, there is a way to achieve that.

  1. Download the AMD APP SDK (currently version 2.4). I'll be assuming its the 64-bit version but it should be pretty much identical for 32-bit or other version numbers, just change the corresponding strings.

  2. Extract the SDK to a subdirectory of your applications executable. So for instance if the application is in $HOME/myapp, then the SDK files should be in $HOME/myapp/AMD-APP-SDK-v2.4-lnx64.

  3. Extract the ICD files from the icd-registration.tgz archive into a folder named icd. So we should have $HOME/myapp/AMD-APP-SDK-v2.4-lnx64/icd/amdocl32.icd (and amdocl64.icd).

Now we have the workings of a portable installation of the AMD APP SDK, which should work on most x86-processors. We just need to set the appropriate environment variables before launching the application. Since I am not a GNU/Linux person and don't know bash very well I have hardcoded the path to our portable directory. Presumably it is somehow possible to get the current location automatically, which would obviously be much nicer.

#!/bin/bash
DIRECTORY=$HOME/myapp
export OPENCL_VENDOR_PATH=$DIRECTORY/AMD-APP-SDK-v2.4-lnx64/icd
export AMDAPPSDKROOT=$DIRECTORY/AMD-APP-SDK-v2.4-lnx64
export LD_LIBRARY_PATH=$AMDAPPSDKROOT/lib/x86_64:$LD_LIBRARY_PATH
./myapp

The above script should be placed in the root directory of your application, i.e. $HOME/myapp/scriptname. Thus we can launch the portable application by doing ./scriptname. As I said since I don't know bash very well the above script could certainly be much nicer, handling arguments to the program and automatically figuring out the scripts location. But it should show the general idea of how to do this.

Upvotes: 2

Related Questions