require_init_gpu() function selects GPU as device and falls back to CPU if none are available (#180)

* require_init_gpu() function selects GPU as device and falls back to CPU if none are available

* Small fix for CPU specific code

* Should work...
This commit is contained in:
Skosh
2020-12-11 19:21:59 +02:00
committed by GitHub
parent c7e95ddb21
commit f4faf401bc

View File

@@ -36,7 +36,10 @@ cl_ctx, cl_queue = None, None
def require_init_gpu():
global cl_ctx, cl_queue
if cl_queue is None:
cl_ctx = cl.create_some_context(interactive=False)
devices = cl.get_platforms()[0].get_devices(device_type=cl.device_type.GPU)
if len(devices) == 0:
devices = cl.get_platforms()[0].get_devices(device_type=cl.device_type.CPU)
cl_ctx = cl.Context(devices=devices)
# this is an in-order command queue
cl_queue = cl.CommandQueue(cl_ctx)