mirror of
https://github.com/tinygrad/tinygrad.git
synced 2026-06-13 00:15:35 +08:00
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:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user