mirror of
https://github.com/tinygrad/tinygrad.git
synced 2026-06-24 02:14:17 +00: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:
parent
c7e95ddb21
commit
f4faf401bc
1 changed files with 4 additions and 1 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue