You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

sender.py 1.2 kB

10 months ago
10 months ago
10 months ago
10 months ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env python
  2. """TODO: Add docstring."""
  3. import os
  4. import time
  5. import numpy as np
  6. import pyarrow as pa
  7. import torch
  8. from dora import Node
  9. from dora.cuda import torch_to_ipc_buffer
  10. torch.tensor([], device="cuda")
  11. SIZES = [10000 * 512]
  12. DEVICE = os.getenv("DEVICE", "cuda")
  13. pa.array([])
  14. node = Node()
  15. time.sleep(4)
  16. # test latency first
  17. for size in SIZES:
  18. for _ in range(100):
  19. now = time.time()
  20. random_data = np.random.randint(1000, size=size, dtype=np.int64)
  21. torch_tensor = torch.tensor(random_data, dtype=torch.int64, device="cuda")
  22. t_send = time.perf_counter_ns()
  23. if DEVICE == "cpu":
  24. # BEFORE
  25. torch_tensor = torch_tensor.to("cpu")
  26. metadata = {}
  27. metadata["time"] = t_send
  28. metadata["device"] = "cpu"
  29. node.send_output("latency", pa.array(torch_tensor.numpy()), metadata)
  30. else:
  31. # AFTER
  32. ipc_buffer, metadata = torch_to_ipc_buffer(torch_tensor)
  33. metadata["time"] = t_send
  34. metadata["device"] = "cuda"
  35. node.send_output("latency", ipc_buffer, metadata)
  36. # Wait before sending next output
  37. node.next()