forked from numba/numba
/
api.py
101 lines (73 loc) · 2.34 KB
/
api.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
'''
Contains CUDA API functions
'''
from __future__ import absolute_import
from contextlib import contextmanager
from .cudadrv.devices import require_context, reset, gpus
from .kernel import FakeCUDAKernel
from numba.typing import Signature
from warnings import warn
from ..args import In, Out, InOut
def select_device(dev=0):
assert dev == 0, 'Only a single device supported by the simulator'
class stream(object):
'''
The stream API is supported in the simulator - however, all execution
occurs synchronously, so synchronization requires no operation.
'''
@contextmanager
def auto_synchronize(self):
yield
def synchronize(self):
pass
def synchronize():
pass
def close():
gpus.closed = True
def declare_device(*args, **kwargs):
pass
def detect():
print('Found 1 CUDA devices')
print('id %d %20s %40s' % (0, 'SIMULATOR', '[SUPPORTED]'))
print('%40s: 5.2' % 'compute capability')
def list_devices():
return gpus
# Events
class Event(object):
'''
The simulator supports the event API, but they do not record timing info,
and all simulation is synchronous. Execution time is not recorded.
'''
def record(self, stream=0):
pass
def wait(self, stream=0):
pass
def synchronize(self):
pass
def elapsed_time(self, event):
warn('Simulator timings are bogus')
return 0.0
event = Event
def jit(func_or_sig=None, device=False, debug=False, argtypes=None,
inline=False, restype=None, fastmath=False, link=None,
boundscheck=None,
):
# Here for API compatibility
if boundscheck is not None:
raise NotImplementedError("bounds checking is not supported for CUDA")
if link is not None:
raise NotImplementedError('Cannot link PTX in the simulator')
# Check for first argument specifying types - in that case the
# decorator is not being passed a function
if func_or_sig is None or isinstance(func_or_sig, (str, tuple, Signature)):
def jitwrapper(fn):
return FakeCUDAKernel(fn,
device=device,
fastmath=fastmath)
return jitwrapper
return FakeCUDAKernel(func_or_sig, device=device)
autojit = jit
@contextmanager
def defer_cleanup():
# No effect for simulator
yield