From cfddc1329410b135f480b0a40e8108e43da060d1 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Tue, 18 Aug 2020 16:29:28 +0800 Subject: [PATCH] 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. --- artiq/test/coredevice/test_performance.py | 87 ++++++++++++++++++++--- 1 file changed, 79 insertions(+), 8 deletions(-) diff --git a/artiq/test/coredevice/test_performance.py b/artiq/test/coredevice/test_performance.py index 071c5d27c..c9ab98b01 100644 --- a/artiq/test/coredevice/test_performance.py +++ b/artiq/test/coredevice/test_performance.py @@ -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,14 +76,23 @@ 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)/ - self.core.mu_to_seconds(t1-t0)) + return ((len(data)*4) / + self.core.mu_to_seconds(t1-t0)) class TransferTest(ExperimentCase): @@ -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()