Browse Source

Small renaming of buffer to ipc buffer to make ipc buffer more explicit

tags/0.3.8-rc
haixuanTao 1 year ago
parent
commit
b0e6a160fe
7 changed files with 9 additions and 8 deletions
  1. +2
    -2
      apis/python/node/dora/cuda.py
  2. +0
    -0
      examples/cuda-benchmark/README.md
  3. +0
    -0
      examples/cuda-benchmark/cpu_bench.yml
  4. +0
    -0
      examples/cuda-benchmark/cuda_bench.yml
  5. +4
    -3
      examples/cuda-benchmark/cuda_receiver.py
  6. +3
    -3
      examples/cuda-benchmark/cuda_sender.py
  7. +0
    -0
      examples/cuda-benchmark/helper.py

+ 2
- 2
apis/python/node/dora/cuda.py View File

@@ -11,7 +11,7 @@ from numba.cuda.cudadrv.devicearray import DeviceNDArray
from numba.cuda import to_device


def torch_to_buffer(tensor: torch.TensorType) -> tuple[pa.array, dict]:
def torch_to_ipc_buffer(tensor: torch.TensorType) -> tuple[pa.array, dict]:
"""Converts a Pytorch tensor into a pyarrow buffer containing the IPC handle and its metadata."""
device_arr = to_device(tensor)
cuda_buf = pa.cuda.CudaBuffer.from_numba(device_arr.gpu_data)
@@ -24,7 +24,7 @@ def torch_to_buffer(tensor: torch.TensorType) -> tuple[pa.array, dict]:
return pa.array(handle_buffer, type=pa.uint8()), metadata


def buffer_to_ipc_handle(handle_buffer: pa.array) -> cuda.IpcMemHandle:
def ipc_buffer_to_ipc_handle(handle_buffer: pa.array) -> cuda.IpcMemHandle:
"""Converts a buffer containing a serialized handler into cuda IPC MemHandle."""
handle_buffer = handle_buffer.buffers()[1]
ipc_handle = pa.cuda.IpcMemHandle.from_buffer(handle_buffer)


examples/cuda-latency/README.md → examples/cuda-benchmark/README.md View File


examples/cuda-latency/cpu_bench.yml → examples/cuda-benchmark/cpu_bench.yml View File


examples/cuda-latency/cuda_bench.yml → examples/cuda-benchmark/cuda_bench.yml View File


examples/cuda-latency/cuda_receiver.py → examples/cuda-benchmark/cuda_receiver.py View File

@@ -8,7 +8,7 @@ import time
import pyarrow as pa
from tqdm import tqdm
from dora import Node
from dora.cuda import buffer_to_ipc_handle, cudabuffer_to_torch
from dora.cuda import ipc_buffer_to_ipc_handle, cudabuffer_to_torch
from helper import record_results
import torch

@@ -43,9 +43,10 @@ while True:
else:
# AFTER
# storage needs to be spawned in the same file as where it's used. Don't ask me why.
ipc_handle = buffer_to_ipc_handle(event["value"])
ipc_handle = ipc_buffer_to_ipc_handle(event["value"])
cudabuffer = ctx.open_ipc_buffer(ipc_handle)
torch_tensor = cudabuffer_to_torch(cudabuffer, event["metadata"])
torch_tensor = cudabuffer_to_torch(cudabuffer, event["metadata"]) # on cuda
print(torch_tensor[0])
else:
break
t_received = time.perf_counter_ns()

examples/cuda-latency/cuda_sender.py → examples/cuda-benchmark/cuda_sender.py View File

@@ -6,7 +6,7 @@ import os
import numpy as np
import pyarrow as pa
from dora import Node
from dora.cuda import torch_to_buffer
from dora.cuda import torch_to_ipc_buffer
import torch

torch.tensor([], device="cuda")
@@ -36,10 +36,10 @@ for size in SIZES:
node.send_output("latency", pa.array(torch_tensor.numpy()), metadata)
else:
# AFTER
buffer, metadata = torch_to_buffer(torch_tensor)
ipc_buffer, metadata = torch_to_ipc_buffer(torch_tensor)
metadata["time"] = t_send
metadata["device"] = "cuda"
node.send_output("latency", buffer, metadata)
node.send_output("latency", ipc_buffer, metadata)

# Wait before sending next output
node.next()

examples/cuda-latency/helper.py → examples/cuda-benchmark/helper.py View File


Loading…
Cancel
Save