-
Notifications
You must be signed in to change notification settings - Fork 0
/
9.py
43 lines (28 loc) · 800 Bytes
/
9.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
import ray
import time
ray.init(num_cpus=4, num_gpus=2, redirect_output=True)
@ray.remote(num_gpus=1)
def f():
time.sleep(0.5)
return ray.get_gpu_ids()
start_time = time.time()
gpu_ids = ray.get([f.remote() for _ in range(3)])
end_time = time.time()
for i in range(len(gpu_ids)):
assert len(gpu_ids[i]) == 1
assert end_time - start_time > 1
print('Sucess! The test passed.')
@ray.remote(num_gpus=1)
class Actor(object):
def __init__(self):
pass
def get_gpu_ids(self):
return ray.get_gpu_ids()
actor = Actor.remote()
gpu_ids = ray.get(actor.get_gpu_ids.remote())
assert len(gpu_ids) == 1
print('Sucess! The test passed.')