Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top