Skip to content

Instantly share code, notes, and snippets.

/ Secret
Created Sep 20, 2013

What would you like to do?
Failure case for pyopencl
import pyopencl as cl
import operator
import itertools
import multiprocessing
def getDevices():
dev_type = cl.device_type.GPU
platforms = cl.get_platforms()
for pp in platforms:
devices = pp.get_devices(device_type=dev_type)
return devices
except cl.RuntimeError as e:
# why does it throw an exception instead of just returning nothing?
def initOCL(dev_id):
devices = getDevices()
device = devices[dev_id]
# different devices in each thread
print devices[dev_id]
# fails here
context = cl.Context([device])
except Exception as e:
print e
queue = cl.CommandQueue(context, device,
print "done using", device
if __name__ == '__main__':
devices = getDevices()
assert(len(devices) > 0)
# will only run 1 for each device available
p_pool = multiprocessing.Pool(len(devices))
dev_idxs = xrange(len(devices)), dev_idxs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.