Installation:
- Download and install llvm+clang from http://releases.llvm.org/6.0.0/clang+llvm-6.0.0-aarch64-linux-gnu.tar.xz
- Download and install hwloc v1.0 or newer from https://www.open-mpi.org/software/hwloc/v1.0/
- Download and install ocl-icd from https://forge.imag.fr/projects/ocl-icd/
- Download pocl by running “git clone https://github.com/pocl/pocl.git”
- Go to the pocl directory
- Create a directory called build and go to that
- Run these command
- cmake .. -DENABLE_CUDA=ON -DCMAKE_INSTALL_PREFIX=/usr/local/pocl/
- make -j4
- sudo make install
- create a text file with “pocl.icd” at /etc/OpenCL/ path and put the following line in it /usr/local/pocl/lib/libOpenCL.so
Simple test:
Compile and run this simple C code that lists all the enabled devices in the platform
[sourcecode language=”cpp”]
#include
#include
#include
int main() {
int i, j;
char* value;
size_t valueSize;
cl_uint platformCount;
cl_platform_id* platforms;
cl_uint deviceCount;
cl_device_id* devices;
cl_uint maxComputeUnits;
// get all platforms
clGetPlatformIDs(0, NULL, &platformCount);
platforms = (cl_platform_id*) malloc(sizeof(cl_platform_id) * platformCount);
clGetPlatformIDs(platformCount, platforms, NULL);
for (i = 0; i < platformCount; i++) {
// get all devices
clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, 0, NULL, &deviceCount);
devices = (cl_device_id*) malloc(sizeof(cl_device_id) * deviceCount);
clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_ALL, deviceCount, devices, NULL);
// for each device print critical attributes
for (j = 0; j < deviceCount; j++) {
// print device name
clGetDeviceInfo(devices[j], CL_DEVICE_NAME, 0, NULL, &valueSize);
value = (char*) malloc(valueSize);
clGetDeviceInfo(devices[j], CL_DEVICE_NAME, valueSize, value, NULL);
printf("%d. Device: %s\n", j+1, value);
free(value);
// print hardware device version
clGetDeviceInfo(devices[j], CL_DEVICE_VERSION, 0, NULL, &valueSize);
value = (char*) malloc(valueSize);
clGetDeviceInfo(devices[j], CL_DEVICE_VERSION, valueSize, value, NULL);
printf(" %d.%d Hardware version: %s\n", j+1, 1, value);
free(value);
// print software driver version
clGetDeviceInfo(devices[j], CL_DRIVER_VERSION, 0, NULL, &valueSize);
value = (char*) malloc(valueSize);
clGetDeviceInfo(devices[j], CL_DRIVER_VERSION, valueSize, value, NULL);
printf(" %d.%d Software version: %s\n", j+1, 2, value);
free(value);
// print c version supported by compiler for device
clGetDeviceInfo(devices[j], CL_DEVICE_OPENCL_C_VERSION, 0, NULL, &valueSize);
value = (char*) malloc(valueSize);
clGetDeviceInfo(devices[j], CL_DEVICE_OPENCL_C_VERSION, valueSize, value, NULL);
printf(" %d.%d OpenCL C version: %s\n", j+1, 3, value);
free(value);
// print parallel compute units
clGetDeviceInfo(devices[j], CL_DEVICE_MAX_COMPUTE_UNITS,
sizeof(maxComputeUnits), &maxComputeUnits, NULL);
printf(" %d.%d Parallel compute units: %d\n", j+1, 4, maxComputeUnits);
}
free(devices);
}
free(platforms);
return 0;
}
[/sourcecode]
This would be the output
1. Device: pthread-cortex-a57
1.1 Hardware version: OpenCL 1.2 pocl HSTR: pthread-aarch64-unknown-linux-gnu-cortex-a57
1.2 Software version: 1.1
1.3 OpenCL C version: OpenCL C 1.2 pocl
1.4 Parallel compute units: 4
2. Device: NVIDIA Tegra X1
2.1 Hardware version: OpenCL 1.2 pocl HSTR: CUDA-sm_53
2.2 Software version: 1.1
2.3 OpenCL C version: OpenCL C 1.2 pocl
2.4 Parallel compute units: 2
Thansk for the instructions.
Some changes:
For pocl1.3, I had to change “/usr/local/pocl/lib/libOpenCL.so” to “/usr/local/pocl/lib/libpocl.so”. Also the icd file was in “/etc/OpenCL/vendors/pocl.icd”