forked from M-Labs/artiq
1
0
Fork 0

test: fixed test_performance

Added more tests and use normal rpc instead of async rpc.

Async RPC does not represent the real throughput which is limited by the
hardware and the network. Normal RPC which requires a response from the
remote is closer to real usecases.
This commit is contained in:
pca006132 2020-08-18 16:29:28 +08:00 committed by Sébastien Bourdeauducq
parent eb350c3459
commit cfddc13294
1 changed files with 79 additions and 8 deletions

View File

@ -1,6 +1,7 @@
import os
import time
import unittest
import numpy
from artiq.experiment import *
from artiq.test.hardware_testbench import ExperimentCase
@ -15,13 +16,29 @@ class _Transfer(EnvExperiment):
def source(self) -> TBytes:
return self.data
@rpc(flags={"async"})
def sink(self, data):
assert data == self.data
@rpc
def source_byte_list(self) -> TList(TBool):
return [True] * (1 << 15)
@rpc(flags={"async"})
@rpc
def source_list(self) -> TList(TInt32):
return [123] * (1 << 15)
@rpc
def source_array(self) -> TArray(TInt32):
return numpy.array([0] * (1 << 15), numpy.int32)
@rpc
def sink(self, data):
pass
@rpc
def sink_list(self, data):
pass
@rpc
def sink_array(self, data):
assert data == [0]*(1 << 15)
pass
@kernel
def host_to_device(self):
@ -30,6 +47,27 @@ class _Transfer(EnvExperiment):
t1 = self.core.get_rtio_counter_mu()
return len(data)/self.core.mu_to_seconds(t1-t0)
@kernel
def host_to_device_list(self):
t0 = self.core.get_rtio_counter_mu()
data = self.source_list()
t1 = self.core.get_rtio_counter_mu()
return 4 * len(data)/self.core.mu_to_seconds(t1-t0)
@kernel
def host_to_device_array(self):
t0 = self.core.get_rtio_counter_mu()
data = self.source_array()
t1 = self.core.get_rtio_counter_mu()
return 4 * len(data)/self.core.mu_to_seconds(t1-t0)
@kernel
def host_to_device_byte_list(self):
t0 = self.core.get_rtio_counter_mu()
data = self.source_byte_list()
t1 = self.core.get_rtio_counter_mu()
return len(data)/self.core.mu_to_seconds(t1-t0)
@kernel
def device_to_host(self):
t0 = self.core.get_rtio_counter_mu()
@ -38,10 +76,19 @@ class _Transfer(EnvExperiment):
return len(self.data)/self.core.mu_to_seconds(t1-t0)
@kernel
def device_to_host_array(self):
def device_to_host_list(self):
#data = [[0]*8 for _ in range(1 << 12)]
data = [0]*(1 << 15)
t0 = self.core.get_rtio_counter_mu()
self.sink_list(data)
t1 = self.core.get_rtio_counter_mu()
return ((len(data)*4) /
self.core.mu_to_seconds(t1-t0))
@kernel
def device_to_host_array(self):
data = self.source_array()
t0 = self.core.get_rtio_counter_mu()
self.sink_array(data)
t1 = self.core.get_rtio_counter_mu()
return ((len(data)*4) /
@ -55,12 +102,36 @@ class TransferTest(ExperimentCase):
print(host_to_device_rate/(1024*1024), "MiB/s")
self.assertGreater(host_to_device_rate, 2.0e6)
def test_host_to_device_byte_list(self):
exp = self.create(_Transfer)
host_to_device_rate = exp.host_to_device_byte_list()
print(host_to_device_rate/(1024*1024), "MiB/s")
self.assertGreater(host_to_device_rate, 2.0e6)
def test_host_to_device_list(self):
exp = self.create(_Transfer)
host_to_device_rate = exp.host_to_device_list()
print(host_to_device_rate/(1024*1024), "MiB/s")
self.assertGreater(host_to_device_rate, 2.0e6)
def test_host_to_device_array(self):
exp = self.create(_Transfer)
host_to_device_rate = exp.host_to_device_array()
print(host_to_device_rate/(1024*1024), "MiB/s")
self.assertGreater(host_to_device_rate, 2.0e6)
def test_device_to_host(self):
exp = self.create(_Transfer)
device_to_host_rate = exp.device_to_host()
print(device_to_host_rate/(1024*1024), "MiB/s")
self.assertGreater(device_to_host_rate, 2.2e6)
def test_device_to_host_list(self):
exp = self.create(_Transfer)
rate = exp.device_to_host_list()
print(rate/(1024*1024), "MiB/s")
self.assertGreater(rate, .15e6)
def test_device_to_host_array(self):
exp = self.create(_Transfer)
rate = exp.device_to_host_array()