PyOpenCL returns errors the first run, then only &

2019-08-09 01:23发布

问题:

I am trying to run an OpenCL kernel using the pyOpenCL bindings, to run on the GPU. I was trying to load the kernel to my program. I ran my program once and got an error. I ran it again without changing the code and got a different, 'invalid program' error.

This keeps happening to my own programs using pyOpenCL and also on example programs. I am able to use OpenCL through the C++ bindings, on both the CPU and GPU, with no problems. So I think this is a problem specific to the pyOpenCL bindings.

My OS is Linux Mint 17.1 64 bit. My GPU is an Intel HD graphics 4000 3rd Gen processor. I got the OpenCL support for it by installing beignet (see here). I am using python 2.7 and OpenCL 1.2.

The first time I ran my program, I got this error:

File "/usr/lib/python2.7/dist-packages/pyopencl/__init__.py", line 463, in kernel_call
    self.set_args(*args)
File "/usr/lib/python2.7/dist-packages/pyopencl/__init__.py", line 488, in kernel_set_args
    % (len(args), self.num_args))
AssertionError: length of argument list (4) and CL-generated number of arguments (9) do not agree

But then I ran it again, and started getting this different error:

File "/usr/lib/python2.7/dist-packages/pyopencl/__init__.py", line 206, in _build_and_catch_errors
    raise err
pyopencl.RuntimeError: clBuildProgram failed: invalid program - 

Build on <pyopencl.Device 'Intel HD Graphics Family' on 'Experiment Intel Gen OCL Driver' at 0x7fb77bf21720>:

(options: -I /usr/lib/python2.7/dist-packages/pyopencl/cl)
(source saved as /tmp/tmplLRgy9.cl)

I downloaded one of the pyOpenCL examples for here but I got the same problem: the first time I ran it, I got:

File "/usr/lib/python2.7/dist-packages/pyopencl/__init__.py", line 436, in __getattr__
    return self.event.get_profiling_info(inf_attr)
pyopencl.RuntimeError: clGetEventProfilingInfo failed: profiling info not available

...and then I run it again, and I got the same 'invalid program' error from before.

I don't understand why the error changes the second time I run the programs, since I didn't change anything in the code in between runs.

Hope this is clear enough, thank you.

回答1:

I solved it (sort of) by uninstalling beignet and installing the latest version, beignet 1.1.0, found here.

However, the only way to get the programs to detect my GPU device and work with no problems is by running them as root. Will probably post a different question for that specific issue.