dora-rs 0.3.11rc1__cp37-abi3-win_amd64.whl → 0.3.12rc1__cp37-abi3-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of dora-rs might be problematic. Click here for more details.
dora/cuda.py
CHANGED
|
@@ -8,13 +8,19 @@ from numba.cuda import to_device
|
|
|
8
8
|
|
|
9
9
|
# Make sure to install numba with cuda
|
|
10
10
|
from numba.cuda.cudadrv.devicearray import DeviceNDArray
|
|
11
|
+
from numba.cuda.cudadrv.devices import get_context
|
|
12
|
+
from numba.cuda.cudadrv.driver import IpcHandle
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
|
|
15
|
+
import json
|
|
16
|
+
|
|
17
|
+
from contextlib import contextmanager
|
|
18
|
+
from typing import ContextManager
|
|
14
19
|
|
|
15
20
|
|
|
16
21
|
def torch_to_ipc_buffer(tensor: torch.TensorType) -> tuple[pa.array, dict]:
|
|
17
|
-
"""Convert a Pytorch tensor into a pyarrow buffer containing the IPC handle
|
|
22
|
+
"""Convert a Pytorch tensor into a pyarrow buffer containing the IPC handle
|
|
23
|
+
and its metadata.
|
|
18
24
|
|
|
19
25
|
Example Use:
|
|
20
26
|
```python
|
|
@@ -24,75 +30,65 @@ def torch_to_ipc_buffer(tensor: torch.TensorType) -> tuple[pa.array, dict]:
|
|
|
24
30
|
```
|
|
25
31
|
"""
|
|
26
32
|
device_arr = to_device(tensor)
|
|
27
|
-
|
|
28
|
-
|
|
33
|
+
ipch = get_context().get_ipc_handle(device_arr.gpu_data)
|
|
34
|
+
_, handle, size, source_info, offset = ipch.__reduce__()[1]
|
|
29
35
|
metadata = {
|
|
30
36
|
"shape": device_arr.shape,
|
|
31
37
|
"strides": device_arr.strides,
|
|
32
38
|
"dtype": device_arr.dtype.str,
|
|
39
|
+
"size": size,
|
|
40
|
+
"offset": offset,
|
|
41
|
+
"source_info": json.dumps(source_info),
|
|
33
42
|
}
|
|
34
|
-
return pa.array(
|
|
43
|
+
return pa.array(handle, pa.int8()), metadata
|
|
35
44
|
|
|
36
45
|
|
|
37
|
-
def ipc_buffer_to_ipc_handle(handle_buffer: pa.array) ->
|
|
38
|
-
"""Convert a buffer containing a serialized handler into cuda IPC
|
|
46
|
+
def ipc_buffer_to_ipc_handle(handle_buffer: pa.array, metadata: dict) -> IpcHandle:
|
|
47
|
+
"""Convert a buffer containing a serialized handler into cuda IPC Handle.
|
|
39
48
|
|
|
40
49
|
example use:
|
|
41
50
|
```python
|
|
51
|
+
from dora.cuda import ipc_buffer_to_ipc_handle, open_ipc_handle
|
|
42
52
|
|
|
43
|
-
import pyarrow as pa
|
|
44
|
-
from dora.cuda import ipc_buffer_to_ipc_handle, cudabuffer_to_torch
|
|
45
|
-
|
|
46
|
-
ctx = pa.cuda.context()
|
|
47
53
|
event = node.next()
|
|
48
54
|
|
|
49
|
-
ipc_handle = ipc_buffer_to_ipc_handle(event["value"])
|
|
50
|
-
|
|
51
|
-
|
|
55
|
+
ipc_handle = ipc_buffer_to_ipc_handle(event["value"], event["metadata"])
|
|
56
|
+
with open_ipc_handle(ipc_handle, event["metadata"]) as tensor:
|
|
57
|
+
pass
|
|
52
58
|
```
|
|
53
59
|
"""
|
|
54
|
-
|
|
55
|
-
return
|
|
60
|
+
handle = handle_buffer.to_pylist()
|
|
61
|
+
return IpcHandle._rebuild(
|
|
62
|
+
handle,
|
|
63
|
+
metadata["size"],
|
|
64
|
+
json.loads(metadata["source_info"]),
|
|
65
|
+
metadata["offset"],
|
|
66
|
+
)
|
|
56
67
|
|
|
57
68
|
|
|
58
|
-
|
|
59
|
-
|
|
69
|
+
@contextmanager
|
|
70
|
+
def open_ipc_handle(
|
|
71
|
+
ipc_handle: IpcHandle, metadata: dict
|
|
72
|
+
) -> ContextManager[torch.TensorType]:
|
|
73
|
+
"""Open a CUDA IPC handle and return a Pytorch tensor.
|
|
60
74
|
|
|
61
75
|
example use:
|
|
62
76
|
```python
|
|
77
|
+
from dora.cuda import ipc_buffer_to_ipc_handle, open_ipc_handle
|
|
63
78
|
|
|
64
|
-
import pyarrow as pa
|
|
65
|
-
from dora.cuda import ipc_buffer_to_ipc_handle, cudabuffer_to_torch
|
|
66
|
-
|
|
67
|
-
ctx = pa.cuda.context()
|
|
68
79
|
event = node.next()
|
|
69
80
|
|
|
70
|
-
ipc_handle = ipc_buffer_to_ipc_handle(event["value"])
|
|
71
|
-
|
|
72
|
-
|
|
81
|
+
ipc_handle = ipc_buffer_to_ipc_handle(event["value"], event["metadata"])
|
|
82
|
+
with open_ipc_handle(ipc_handle, event["metadata"]) as tensor:
|
|
83
|
+
pass
|
|
73
84
|
```
|
|
74
85
|
"""
|
|
75
86
|
shape = metadata["shape"]
|
|
76
87
|
strides = metadata["strides"]
|
|
77
88
|
dtype = metadata["dtype"]
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
example use:
|
|
85
|
-
```python
|
|
86
|
-
|
|
87
|
-
import pyarrow as pa
|
|
88
|
-
from dora.cuda import ipc_buffer_to_ipc_handle, cudabuffer_to_torch
|
|
89
|
-
|
|
90
|
-
ctx = pa.cuda.context()
|
|
91
|
-
event = node.next()
|
|
92
|
-
|
|
93
|
-
ipc_handle = ipc_buffer_to_ipc_handle(event["value"])
|
|
94
|
-
cudabuffer = ctx.open_ipc_buffer(ipc_handle)
|
|
95
|
-
torch_tensor = cudabuffer_to_torch(cudabuffer, event["metadata"]) # on cuda
|
|
96
|
-
```
|
|
97
|
-
"""
|
|
98
|
-
return torch.as_tensor(cudabuffer_to_numba(buffer, metadata), device="cuda")
|
|
89
|
+
try:
|
|
90
|
+
buffer = ipc_handle.open(get_context())
|
|
91
|
+
device_arr = DeviceNDArray(shape, strides, dtype, gpu_data=buffer)
|
|
92
|
+
yield torch.as_tensor(device_arr, device="cuda")
|
|
93
|
+
finally:
|
|
94
|
+
ipc_handle.close()
|
dora/dora.pyd
CHANGED
|
Binary file
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
dora/__init__.py,sha256=K87kJCx3z_LKKKSikuEIkkAx4h8qZtS6dB-HzFpz4zc,751
|
|
2
|
+
dora/__init__.pyi,sha256=L-MCRPD_K8RGpzWsfrV28lNh0ast3uNq2-UJZzuJwP8,9483
|
|
3
|
+
dora/cuda.py,sha256=WunE7nb13aIFq5cqkSh52dfZ0KfFm18NU4TofPFopx8,2830
|
|
4
|
+
dora/dora.pyd,sha256=HVCDGfxqu6hvslakttSf_JM_7mAgAxFpHxB_llYU4Uw,37786624
|
|
5
|
+
dora_rs-0.3.12rc1.dist-info/METADATA,sha256=tVLKsqktgduAAigy5hXcbumX-_E1_Q3aFSW3wAmZ-C8,647
|
|
6
|
+
dora_rs-0.3.12rc1.dist-info/WHEEL,sha256=G5LfiGOqaNK7XFePKQAOL9sBbuwwBdXf4vgmptkMvPU,94
|
|
7
|
+
dora_rs-0.3.12rc1.dist-info/RECORD,,
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
dora_rs-0.3.11rc1.dist-info/METADATA,sha256=fzb0qk80dZ80NOS2nED13XIcecElFQf0T3-jiKOs74k,647
|
|
2
|
-
dora_rs-0.3.11rc1.dist-info/WHEEL,sha256=GWZFzAhmRLcnnWJFIkiR8k0sjr8iX_MTxF4a-TgOsmk,94
|
|
3
|
-
dora/cuda.py,sha256=g3Ez0KxbPH9a5ok8ouePyeCreEMoQQjbpPZ5Alqxad0,3167
|
|
4
|
-
dora/__init__.py,sha256=K87kJCx3z_LKKKSikuEIkkAx4h8qZtS6dB-HzFpz4zc,751
|
|
5
|
-
dora/__init__.pyi,sha256=L-MCRPD_K8RGpzWsfrV28lNh0ast3uNq2-UJZzuJwP8,9483
|
|
6
|
-
dora/dora.pyd,sha256=y1bn0IZSRmEcG5CplhDE0fAt7AdzfQXYklkN4bm10AE,35266560
|
|
7
|
-
dora_rs-0.3.11rc1.dist-info/RECORD,,
|