Skip to content

Instantly share code, notes, and snippets.

/failure.py Secret
Created Sep 20, 2013

Embed
What would you like to do?
Failure case for pyopencl
#!/usr/bin/python
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:
try:
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?
continue
def initOCL(dev_id):
devices = getDevices()
device = devices[dev_id]
# different devices in each thread
print devices[dev_id]
try:
# fails here
context = cl.Context([device])
except Exception as e:
print e
queue = cl.CommandQueue(context, device,
properties=cl.command_queue_properties.PROFILING_ENABLE)
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))
p_pool.map(initOCL, 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.