2
votes

I am new to OpenCL and have some problems with setting up a OpenCL program. To illustrate my problem please look at the code (taken from https://github.com/benshope/PyOpenCL-Tutorial):

# Use OpenCL To Add Two Random Arrays (This Way Hides Details)

import pyopencl as cl  # Import the OpenCL GPU computing API
import pyopencl.array as pycl_array  # Import PyOpenCL Array (a Numpy array plus an OpenCL buffer object)
import numpy as np  # Import Numpy number tools

context = cl.create_some_context()  # Initialize the Context
queue = cl.CommandQueue(context)  # Instantiate a Queue

a = pycl_array.to_device(queue, np.random.rand(50000).astype(np.float32))
b = pycl_array.to_device(queue, np.random.rand(50000).astype(np.float32))  
# Create two random pyopencl arrays
c = pycl_array.empty_like(a)  # Create an empty pyopencl destination array

program = cl.Program(context, """
__kernel void sum(__global const float *a, __global const float *b, __global float *c)
{
  int i = get_global_id(0);
  c[i] = a[i] + b[i];
}""").build()  # Create the OpenCL program

program.sum(queue, a.shape, None, a.data, b.data, c.data)  # Enqueue the program for execution and store the result in c

print("a: {}".format(a))
print("b: {}".format(b))
print("c: {}".format(c))  
# Print all three arrays, to show sum() worked

If I execute the script I get the following error:

"C:\Program Files\WinPython-64bit-2.7.6.3\python-2.7.6.amd64\python.exe" D:/python/openCL/020_array_sum.py
Traceback (most recent call last):
   File "D:/python/openCL/020_array_sum.py", line 20, in <module>
}""").build() # Create the OpenCL program
   File "C:\Program Files\WinPython-64bit-2.7.6.3\python-2.7.6.amd64\lib\site-packages\pyopencl\__init__.py", line 166, in build
options=options, source=self._source)
   File "C:\Program Files\WinPython-64bit-2.7.6.3\python-2.7.6.amd64\lib\site-packages\pyopencl\__init__.py", line 206, in _build_and_catch_errors
     raise err
pyopencl.RuntimeError: clBuildProgram failed: invalid build options - 


(options: -I c:\program files\winpython-64bit-2.7.6.3\python-2.7.6.amd64\lib\site-packages\pyopencl\cl)
(source saved as c:\appdata\local\temp\tmp0bj_ij.cl)

Process finished with exit code 1

As far as I understood it, this is caused by the build() function, but I do not understand why. In one forum they suggested to define the kernel with only one " instead of """. This also did not help.

I use WinPython-64bit-2.7.6.3 and pycharm-community-3.1.1. For the openCL i have installed: AMD-APP-SDK-v2.9-Windows-641, Mako-0.9.1.win-amd64-py2.7, pytools-2014.1.2.win-amd64-py2.7 and pyopencl-2013.2.win-amd64-py2.7.

My graphics card is a Radeon HD 7850 and I have a AMD PhenomII processor.

P.S.: When I compile in Spyder, the error message reads:

>>> runfile('D:/python/openCL/020_array_sum.py', wdir=r'D:/python/openCL')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Program Files\WinPython-64bit-2.7.6.3\python-2.7.6.amd64\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 540, in runfile
execfile(filename, namespace)
File "D:/python/openCL/020_array_sum.py", line 20, in <module>
}""").build() # Create the OpenCL program
File "C:\Program Files\WinPython-64bit-2.7.6.3\python-2.7.6.amd64\lib\site-packages\pyopencl\__init__.py", line 166, in build
options=options, source=self._source)
File "C:\Program Files\WinPython-64bit-2.7.6.3\python-2.7.6.amd64\lib\site-packages\pyopencl\__init__.py", line 206, in _build_and_catch_errors
raise err
pyopencl.RuntimeError: clBuildProgram failed: invalid build options - 


(options: -I c:\program files\winpython-64bit-2.7.6.3\python-2.7.6.amd64\lib\site-packages\pyopencl\cl)
(source saved as c:\users\andreas\appdata\local\temp\tmpzrgacv.cl)

Edit: I have now also tested it on another PC: same error. It also has an Nvidia graphics card. What both have in commen, is that they are only specified with OpenCL 1.1. Could it be, that I need OpenCL 1.2?

2
Do the examples that are included with PyOpenCL work? I wrote that tutorial informally - so the code at github.com/pyopencl/pyopencl/tree/master/examples are better scripts to run, to see if your system is set up right. - benshope
@benshope: The examples at github.com/pyopencl/pyopencl/tree/master/examples result in the same error. I have used the benchmark.py script. All prints where executed prior to the build() function where the program crashes. By now I am also pretty sure I set up something incorrectly, just haven't yet figured out what. - user3413108
@benshope: Sorry, forgot to mention that no example I have found so far worked. - user3413108
This may be unhelpful, but if you completely run out of options - perhaps dual-boot your machine to Ubuntu. The software center in Ubuntu has a package that I consider the easiest way to get PyOpenCL 'just working'. - benshope
You have to look for the python code that launches the build of the kernel. It is probably being controlled by some defines that you can control from the outside. You will probably have to disable/enable some of them in order to change the default behaviour, since a falg of the default options is making your platform compiler complain. You can also try to install another updated driver for your OpenCL that may include a newer compiler. You can also try with .build("") - DarkZeros

2 Answers

3
votes

I think I found the problem. I changed the installtion directory of WinPython such that the path no longer includes spaces, now C:\WinPython-64bit-2.7.6.3. Then it worked. Thanks again for all your suggestions and your time.

0
votes

This worked for me, I disabled caching of built kernels. My solution is useful if you are using pyopencl

import os
os.environ['PYOPENCL_NO_CACHE'] = '1'