I
I
Ilya Kaznacheev2015-02-04 23:48:33
Python
Ilya Kaznacheev, 2015-02-04 23:48:33

Error when starting PyOpenCL - what to do?

I installed OpenCL, PyOpenCL, AMD APP SDK on Ubuntu, all dependencies - in theory, it should work.
I'm running a test case from here :

import numpy as np
import pyopencl as cl

a_np = np.random.rand(50000).astype(np.float32)
b_np = np.random.rand(50000).astype(np.float32)

ctx = cl.create_some_context()
queue = cl.CommandQueue(ctx)

mf = cl.mem_flags
a_g = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=a_np)
b_g = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=b_np)

prg = cl.Program(ctx, """
__kernel void sum(__global const float *a_g, __global const float *b_g, __global float *res_g) {
  int gid = get_global_id(0);
  res_g[gid] = a_g[gid] + b_g[gid];
}
""").build()

res_g = cl.Buffer(ctx, mf.WRITE_ONLY, a_np.nbytes)
prg.sum(queue, a_np.shape, None, a_g, b_g, res_g)

res_np = np.empty_like(a_np)
cl.enqueue_copy(queue, res_np, res_g)

# Check on CPU with Numpy:
print(res_np - (a_np + b_np))
print(np.linalg.norm(res_np - (a_np + b_np)))

I am getting an error:
Traceback (most recent call last):
  File "test.py", line 10, in <module>
    ctx = cl.create_some_context()
  File "/usr/lib/python2.7/dist-packages/pyopencl/__init__.py", line 767, in create_some_context
    platforms = get_platforms()
pyopencl.LogicError: clGetPlatformIDs failed: platform not found khr

By all inquiries, google says that this is an nvidia bug, and how it can be fixed.
But I have AMD!
I don't really know how to approach the question. Please help. What could be the problem on AMD?
--- Issue resolved. Below are the approximate steps after which everything worked. ---
Thanks to Vlad Gver for the help!
I got the instructions here . But I installed the packages a little differently:
  1. Download AMD-APP-SDK from here . I took version 2.9.1, since 3.0 is in beta at the moment, and it didn’t work out for me. Installed
  2. Made sudo apt-get -f installto satisfy lost dependencies
  3. Made
    sudo apt-get install linux-headers-generic fglrx fglrx-amdcccle
    to install the AMD driver from the turnip, since the driver from the site did not get up, apparently due to disagreements with the fglrx version
  4. Madesudo apt-get install python-pyopencl
  5. reboot
  6. The test case from the PyOpenCL page works

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladlen Grachev, 2015-02-05
@Color

The problem may be that your OpenCL is not hooked, for example. Does the video card support it?
The easiest way to check is to install darktable (it should pull up from the repositories without problems) and run "sudo darktable -d opencl". If there are no errors, then the problem is still somewhere in Python. There will also be information about all devices that support OpenCL. If he swears at something, OpenCL is probably not hooked.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question