forked from M-Labs/artiq
1
0
Fork 0

test_performance: port imports and type annotations to NAC3

This commit is contained in:
Sebastien Bourdeauducq 2022-02-26 18:52:15 +08:00
parent 6eb1c4e138
commit 0e20058da3
1 changed files with 25 additions and 24 deletions

View File

@ -2,6 +2,7 @@ import os
import time import time
import unittest import unittest
import numpy import numpy
from numpy import int32, float64
from artiq.experiment import * from artiq.experiment import *
from artiq.test.hardware_testbench import ExperimentCase from artiq.test.hardware_testbench import ExperimentCase
@ -14,8 +15,8 @@ bytes_small = b"\x00" * (1 << 10)
list_large = [123] * (1 << 18) list_large = [123] * (1 << 18)
list_small = [123] * (1 << 8) list_small = [123] * (1 << 8)
array_large = numpy.array(list_large, numpy.int32) array_large = numpy.array(list_large, int32)
array_small = numpy.array(list_small, numpy.int32) array_small = numpy.array(list_small, int32)
byte_list_large = [True] * (1 << 20) byte_list_large = [True] * (1 << 20)
byte_list_small = [True] * (1 << 10) byte_list_small = [True] * (1 << 10)
@ -32,35 +33,35 @@ class _Transfer(EnvExperiment):
self.d2h = [0.0] * self.count self.d2h = [0.0] * self.count
@rpc @rpc
def get_bytes(self, large: TBool) -> TBytes: def get_bytes(self, large: bool) -> bytes:
if large: if large:
return bytes_large return bytes_large
else: else:
return bytes_small return bytes_small
@rpc @rpc
def get_list(self, large: TBool) -> TList(TInt32): def get_list(self, large: bool) -> list[int32]:
if large: if large:
return list_large return list_large
else: else:
return list_small return list_small
@rpc @rpc
def get_byte_list(self, large: TBool) -> TList(TBool): def get_byte_list(self, large: bool) -> list[bool]:
if large: if large:
return byte_list_large return byte_list_large
else: else:
return byte_list_small return byte_list_small
@rpc @rpc
def get_array(self, large: TBool) -> TArray(TInt32): def get_array(self, large: bool) -> numpy.ndarray: # NAC3TODO: [int32]
if large: if large:
return array_large return array_large
else: else:
return array_small return array_small
@rpc @rpc
def get_string_list(self) -> TList(TStr): def get_string_list(self) -> list[str]:
return string_list return string_list
@rpc @rpc
@ -77,7 +78,7 @@ class _Transfer(EnvExperiment):
time_end = time.time() time_end = time.time()
@rpc @rpc
def get_async_throughput(self) -> TFloat: def get_async_throughput(self) -> float:
return 128.0 / (time_end - time_start) return 128.0 / (time_end - time_start)
@kernel @kernel
@ -171,8 +172,8 @@ class TransferTest(ExperimentCase):
def test_bytes_large(self): def test_bytes_large(self):
exp = self.create(_Transfer) exp = self.create(_Transfer)
results = exp.test_bytes(True) results = exp.test_bytes(True)
host_to_device = (1 << 20) / numpy.array(results[0], numpy.float64) host_to_device = (1 << 20) / numpy.array(results[0], float64)
device_to_host = (1 << 20) / numpy.array(results[1], numpy.float64) device_to_host = (1 << 20) / numpy.array(results[1], float64)
host_to_device /= 1024*1024 host_to_device /= 1024*1024
device_to_host /= 1024*1024 device_to_host /= 1024*1024
self.results.append(["Bytes (1MB) H2D", host_to_device.mean(), self.results.append(["Bytes (1MB) H2D", host_to_device.mean(),
@ -183,8 +184,8 @@ class TransferTest(ExperimentCase):
def test_bytes_small(self): def test_bytes_small(self):
exp = self.create(_Transfer) exp = self.create(_Transfer)
results = exp.test_bytes(False) results = exp.test_bytes(False)
host_to_device = (1 << 10) / numpy.array(results[0], numpy.float64) host_to_device = (1 << 10) / numpy.array(results[0], float64)
device_to_host = (1 << 10) / numpy.array(results[1], numpy.float64) device_to_host = (1 << 10) / numpy.array(results[1], float64)
host_to_device /= 1024*1024 host_to_device /= 1024*1024
device_to_host /= 1024*1024 device_to_host /= 1024*1024
self.results.append(["Bytes (1KB) H2D", host_to_device.mean(), self.results.append(["Bytes (1KB) H2D", host_to_device.mean(),
@ -195,8 +196,8 @@ class TransferTest(ExperimentCase):
def test_byte_list_large(self): def test_byte_list_large(self):
exp = self.create(_Transfer) exp = self.create(_Transfer)
results = exp.test_byte_list(True) results = exp.test_byte_list(True)
host_to_device = (1 << 20) / numpy.array(results[0], numpy.float64) host_to_device = (1 << 20) / numpy.array(results[0], float64)
device_to_host = (1 << 20) / numpy.array(results[1], numpy.float64) device_to_host = (1 << 20) / numpy.array(results[1], float64)
host_to_device /= 1024*1024 host_to_device /= 1024*1024
device_to_host /= 1024*1024 device_to_host /= 1024*1024
self.results.append(["Bytes List (1MB) H2D", host_to_device.mean(), self.results.append(["Bytes List (1MB) H2D", host_to_device.mean(),
@ -207,8 +208,8 @@ class TransferTest(ExperimentCase):
def test_byte_list_small(self): def test_byte_list_small(self):
exp = self.create(_Transfer) exp = self.create(_Transfer)
results = exp.test_byte_list(False) results = exp.test_byte_list(False)
host_to_device = (1 << 10) / numpy.array(results[0], numpy.float64) host_to_device = (1 << 10) / numpy.array(results[0], float64)
device_to_host = (1 << 10) / numpy.array(results[1], numpy.float64) device_to_host = (1 << 10) / numpy.array(results[1], float64)
host_to_device /= 1024*1024 host_to_device /= 1024*1024
device_to_host /= 1024*1024 device_to_host /= 1024*1024
self.results.append(["Bytes List (1KB) H2D", host_to_device.mean(), self.results.append(["Bytes List (1KB) H2D", host_to_device.mean(),
@ -219,8 +220,8 @@ class TransferTest(ExperimentCase):
def test_list_large(self): def test_list_large(self):
exp = self.create(_Transfer) exp = self.create(_Transfer)
results = exp.test_list(True) results = exp.test_list(True)
host_to_device = (1 << 20) / numpy.array(results[0], numpy.float64) host_to_device = (1 << 20) / numpy.array(results[0], float64)
device_to_host = (1 << 20) / numpy.array(results[1], numpy.float64) device_to_host = (1 << 20) / numpy.array(results[1], float64)
host_to_device /= 1024*1024 host_to_device /= 1024*1024
device_to_host /= 1024*1024 device_to_host /= 1024*1024
self.results.append(["I32 List (1MB) H2D", host_to_device.mean(), self.results.append(["I32 List (1MB) H2D", host_to_device.mean(),
@ -231,8 +232,8 @@ class TransferTest(ExperimentCase):
def test_list_small(self): def test_list_small(self):
exp = self.create(_Transfer) exp = self.create(_Transfer)
results = exp.test_list(False) results = exp.test_list(False)
host_to_device = (1 << 10) / numpy.array(results[0], numpy.float64) host_to_device = (1 << 10) / numpy.array(results[0], float64)
device_to_host = (1 << 10) / numpy.array(results[1], numpy.float64) device_to_host = (1 << 10) / numpy.array(results[1], float64)
host_to_device /= 1024*1024 host_to_device /= 1024*1024
device_to_host /= 1024*1024 device_to_host /= 1024*1024
self.results.append(["I32 List (1KB) H2D", host_to_device.mean(), self.results.append(["I32 List (1KB) H2D", host_to_device.mean(),
@ -243,8 +244,8 @@ class TransferTest(ExperimentCase):
def test_array_large(self): def test_array_large(self):
exp = self.create(_Transfer) exp = self.create(_Transfer)
results = exp.test_array(True) results = exp.test_array(True)
host_to_device = (1 << 20) / numpy.array(results[0], numpy.float64) host_to_device = (1 << 20) / numpy.array(results[0], float64)
device_to_host = (1 << 20) / numpy.array(results[1], numpy.float64) device_to_host = (1 << 20) / numpy.array(results[1], float64)
host_to_device /= 1024*1024 host_to_device /= 1024*1024
device_to_host /= 1024*1024 device_to_host /= 1024*1024
self.results.append(["I32 Array (1MB) H2D", host_to_device.mean(), self.results.append(["I32 Array (1MB) H2D", host_to_device.mean(),
@ -255,8 +256,8 @@ class TransferTest(ExperimentCase):
def test_array_small(self): def test_array_small(self):
exp = self.create(_Transfer) exp = self.create(_Transfer)
results = exp.test_array(False) results = exp.test_array(False)
host_to_device = (1 << 10) / numpy.array(results[0], numpy.float64) host_to_device = (1 << 10) / numpy.array(results[0], float64)
device_to_host = (1 << 10) / numpy.array(results[1], numpy.float64) device_to_host = (1 << 10) / numpy.array(results[1], float64)
host_to_device /= 1024*1024 host_to_device /= 1024*1024
device_to_host /= 1024*1024 device_to_host /= 1024*1024
self.results.append(["I32 Array (1KB) H2D", host_to_device.mean(), self.results.append(["I32 Array (1KB) H2D", host_to_device.mean(),