Ubuntu 20.04 with an NVIDIA Quadro M1200, Lenovo P51
The software integration got a lot better since I had last tried, so I will do an update.
First, at least for graphics, I needed to tweak some BIOS settings as mentioned at, not sure needed for OpenCL: https://askubuntu.com/questions/973605/ubuntu-17-10-boot-stuck-at-message-started-nvidia-persistence-daemon-after-ins/976578#976578
Then, I find and install the latest driver available:
apt-cache search nvidia-driver
sudo apt install nvidia-driver-435 nvidia-opencl-dev
You can also search under:
software-properties-gtk
in the "Additional Drivers" tab.
Now I can compile and run the following test program:
main.c
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#define CL_TARGET_OPENCL_VERSION 220
#define CL_USE_DEPRECATED_OPENCL_1_2_APIS
#include <CL/cl.h>
int main() {
cl_command_queue command_queue;
cl_context context;
cl_device_id device;
cl_int input = 1;
cl_int kernel_result = 0;
cl_kernel kernel;
cl_mem buffer;
cl_platform_id platform;
cl_program program;
const char *source = "__kernel void increment(int in, __global int* out) { out[0] = in + 1; }";
clGetPlatformIDs(1, &platform, NULL);
clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, 1, &device, NULL);
context = clCreateContext(NULL, 1, &device, NULL, NULL, NULL);
command_queue = clCreateCommandQueue(context, device, 0, NULL);
buffer = clCreateBuffer(context, CL_MEM_READ_WRITE | CL_MEM_ALLOC_HOST_PTR, sizeof(cl_int), NULL, NULL);
program = clCreateProgramWithSource(context, 1, &source, NULL, NULL);
clBuildProgram(program, 1, &device, "", NULL, NULL);
kernel = clCreateKernel(program, "increment", NULL);
clSetKernelArg(kernel, 0, sizeof(cl_int), &input);
clSetKernelArg(kernel, 1, sizeof(cl_mem), &buffer);
clEnqueueTask(command_queue, kernel, 0, NULL, NULL);
clFlush(command_queue);
clFinish(command_queue);
clEnqueueReadBuffer(command_queue, buffer, CL_TRUE, 0, sizeof (cl_int), &kernel_result, 0, NULL, NULL);
assert(kernel_result == 2);
return EXIT_SUCCESS;
}
GitHub upstream
with:
gcc -ggdb3 -O0 -Wall -Wextra -pthread -std=c11 \
-pedantic-errors -o main.out main.c -lm -pthread -lOpenCL
./main.out
Notes:
Ubuntu 15.10 with an NVIDIA NVS 5400M, Lenovo T430
sudo apt-get install nvidia-352 nvidia-352-dev nvidia-prime nvidia-modprobe
sudo ln -s /usr/include/nvidia-352/GL /usr/local/include
sudo ln -s /usr/lib/x86_64-linux-gnu/libOpenCL.so.1 /usr/local/lib/libOpenCL.so
Then use the header as:
#include <CL/cl.h>
And compile with:
gcc -o main main.c -lOpenCL
Notes:
- do not install the
nvidia-current
package. It is old. Either apt-cache search nvidia
and get the latest one, or use software-properties-gtk
"Additional Drivers" tab.
I really recommend upgrading to 15.10 to get this to work: I had never managed before.