mirror of https://github.com/Nonannet/copapy.git
tests updated, setup of test for aarch64
This commit is contained in:
parent
ee351fd864
commit
64726fe86d
|
|
@ -1,6 +1,6 @@
|
||||||
from copapy import variable, NumLike
|
from copapy import variable, NumLike
|
||||||
from copapy.backend import Write, compile_to_dag, add_read_command
|
from copapy.backend import Write, compile_to_dag, add_read_command
|
||||||
import copapy
|
import copapy as cp
|
||||||
import subprocess
|
import subprocess
|
||||||
import struct
|
import struct
|
||||||
from copapy import _binwrite
|
from copapy import _binwrite
|
||||||
|
|
@ -41,12 +41,21 @@ def function(c1: NumLike, c2: NumLike) -> tuple[NumLike, ...]:
|
||||||
|
|
||||||
def test_compile():
|
def test_compile():
|
||||||
|
|
||||||
c1 = variable(4)
|
#c1 = variable(4)
|
||||||
c2 = variable(2)
|
#c2 = variable(2)
|
||||||
|
|
||||||
ret = function(c1, c2)
|
#ret = function(c1, c2)
|
||||||
#ret = [c1 // 3.3 + 5]
|
#ret = [c1 // 3.3 + 5]
|
||||||
|
|
||||||
|
t1 = cp.vector([10, 11, 12]) + cp.vector(cp.variable(v) for v in range(3))
|
||||||
|
t2 = t1.sum()
|
||||||
|
|
||||||
|
t3 = cp.vector(cp.variable(1 / (v + 1)) for v in range(3))
|
||||||
|
t4 = ((t3 * t1) * 2).sum()
|
||||||
|
t5 = ((t3 * t1) * 2).magnitude()
|
||||||
|
|
||||||
|
ret = (t2, t4, t5)
|
||||||
|
|
||||||
out = [Write(r) for r in ret]
|
out = [Write(r) for r in ret]
|
||||||
|
|
||||||
il, variables = compile_to_dag(out, copapy.generic_sdb)
|
il, variables = compile_to_dag(out, copapy.generic_sdb)
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,18 @@
|
||||||
from copapy import variable, NumLike
|
from copapy import variable, NumLike
|
||||||
from copapy.backend import Write, compile_to_dag, add_read_command
|
from copapy.backend import Write, compile_to_dag, add_read_command
|
||||||
import subprocess
|
import subprocess
|
||||||
import struct
|
|
||||||
from copapy import _binwrite
|
from copapy import _binwrite
|
||||||
import copapy.backend as backend
|
import copapy.backend as backend
|
||||||
|
import copapy as cp
|
||||||
import os
|
import os
|
||||||
import pytest
|
import warnings
|
||||||
|
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
# On Windows wsl and qemu-user is required:
|
# On Windows wsl and qemu-user is required:
|
||||||
# sudo apt install qemu-user
|
# sudo apt install qemu-user
|
||||||
qemu_command = ['wsl', 'qemu-aarch64', 'bin/coparun-aarch64', 'bin/test-aarch64.copapy']
|
qemu_command = ['wsl', 'qemu-aarch64']
|
||||||
else:
|
else:
|
||||||
qemu_command = ['qemu-aarch64', 'bin/coparun-aarch64', 'bin/test-aarch64.copapy']
|
qemu_command = ['qemu-aarch64']
|
||||||
|
|
||||||
|
|
||||||
def run_command(command: list[str]) -> str:
|
def run_command(command: list[str]) -> str:
|
||||||
|
|
@ -22,20 +22,13 @@ def run_command(command: list[str]) -> str:
|
||||||
return result.stdout
|
return result.stdout
|
||||||
|
|
||||||
|
|
||||||
def test_example():
|
def check_for_qemu() -> bool:
|
||||||
c1 = 4
|
command = qemu_command + ['--version']
|
||||||
c2 = 2
|
try:
|
||||||
|
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding='utf8', check=False)
|
||||||
i1 = c1 * 2
|
except:
|
||||||
r1 = i1 + 7 + (c2 + 7 * 9)
|
return False
|
||||||
r2 = i1 + 9
|
return result.returncode == 0
|
||||||
|
|
||||||
en = {'little': '<', 'big': '>'}['little']
|
|
||||||
data = struct.pack(en + 'i', r1)
|
|
||||||
print("example r1 " + ' '.join(f'{b:02X}' for b in data))
|
|
||||||
|
|
||||||
data = struct.pack(en + 'i', r2)
|
|
||||||
print("example r2 " + ' '.join(f'{b:02X}' for b in data))
|
|
||||||
|
|
||||||
|
|
||||||
def function(c1: NumLike, c2: NumLike) -> tuple[NumLike, ...]:
|
def function(c1: NumLike, c2: NumLike) -> tuple[NumLike, ...]:
|
||||||
|
|
@ -47,17 +40,19 @@ def function(c1: NumLike, c2: NumLike) -> tuple[NumLike, ...]:
|
||||||
return i1, i2, r1, r2
|
return i1, i2, r1, r2
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skip(reason="no way of currently testing this")
|
|
||||||
def test_compile():
|
def test_compile():
|
||||||
c1 = variable(4)
|
t1 = cp.vector([10, 11, 12]) + cp.vector(cp.variable(v) for v in range(3))
|
||||||
c2 = variable(2)
|
t2 = t1.sum()
|
||||||
|
|
||||||
ret = function(c1, c2)
|
t3 = cp.vector(cp.variable(1 / (v + 1)) for v in range(3))
|
||||||
#ret = [c1 // 3.3 + 5]
|
t4 = ((t3 * t1) * 2).sum()
|
||||||
|
t5 = ((t3 * t1) * 2).magnitude()
|
||||||
|
|
||||||
|
ret = (t2, t4, t5)
|
||||||
|
|
||||||
out = [Write(r) for r in ret]
|
out = [Write(r) for r in ret]
|
||||||
|
|
||||||
sdb = backend.stencil_db_from_package('aarch64', 'O3')
|
sdb = backend.stencil_db_from_package('aarch64')
|
||||||
il, variables = compile_to_dag(out, sdb)
|
il, variables = compile_to_dag(out, sdb)
|
||||||
|
|
||||||
# run program command
|
# run program command
|
||||||
|
|
@ -74,13 +69,21 @@ def test_compile():
|
||||||
|
|
||||||
il.to_file('bin/test-aarch64.copapy')
|
il.to_file('bin/test-aarch64.copapy')
|
||||||
|
|
||||||
result = run_command(qemu_command)
|
if not check_for_qemu():
|
||||||
print('* Output from runner:\n--')
|
warnings.warn("qemu-aarch64 not found, aarch64 test skipped!", UserWarning)
|
||||||
print(result)
|
else:
|
||||||
print('--')
|
command = ['bin/coparun-aarch64', 'bin/test-aarch64.copapy']
|
||||||
|
result = run_command(qemu_command + command)
|
||||||
|
print('* Output from runner:\n--')
|
||||||
|
print(result)
|
||||||
|
print('--')
|
||||||
|
|
||||||
assert 'Return value: 1' in result
|
assert 'Return value: 1' in result
|
||||||
#assert 'END_COM' in result
|
|
||||||
|
# Compare to x86_64 reference results
|
||||||
|
assert " size=4 data=24 00 00 00" in result
|
||||||
|
assert " size=4 data=56 55 25 42" in result
|
||||||
|
assert " size=4 data=B4 F9 C8 41" in result
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
||||||
|
|
@ -36,3 +36,4 @@ def test_compiled_vectors():
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test_compiled_vectors()
|
test_compiled_vectors()
|
||||||
|
print('Finished!')
|
||||||
|
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
import copapy as cp
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
|
|
||||||
def test_vectors_init():
|
|
||||||
tt1 = cp.vector(range(3)) + cp.vector([1.1, 2.2, 3.3])
|
|
||||||
tt2 = cp.vector([1.1, 2, cp.variable(5)]) + cp.vector(range(3))
|
|
||||||
tt3 = (cp.vector(range(3)) + 5.6)
|
|
||||||
tt4 = cp.vector([1.1, 2, 3]) + cp.vector(cp.variable(v) for v in range(3))
|
|
||||||
tt5 = cp.vector([1, 2, 3]).dot(tt4)
|
|
||||||
|
|
||||||
print(tt1, tt2, tt3, tt4, tt5)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.skip(reason="no way of currently testing this")
|
|
||||||
def test_compiled_vectors():
|
|
||||||
t1 = cp.vector([10, 11, 12]) + cp.vector(cp.variable(v) for v in range(3))
|
|
||||||
t2 = t1.sum()
|
|
||||||
|
|
||||||
t3 = cp.vector(cp.variable(1 / (v + 1)) for v in range(3))
|
|
||||||
t4 = ((t3 * t1) * 2).sum()
|
|
||||||
t5 = ((t3 * t1) * 2).magnitude()
|
|
||||||
|
|
||||||
tg = cp.Target('aarch64')
|
|
||||||
tg.compile(t2, t4, t5)
|
|
||||||
tg.run()
|
|
||||||
|
|
||||||
assert isinstance(t2, cp.variable)
|
|
||||||
assert tg.read_value(t2) == 10 + 11 + 12 + 0 + 1 + 2
|
|
||||||
|
|
||||||
assert isinstance(t4, cp.variable)
|
|
||||||
assert tg.read_value(t4) == pytest.approx(((10/1*2) + (12/2*2) + (14/3*2)), 0.001) # pyright: ignore[reportUnknownMemberType]
|
|
||||||
|
|
||||||
assert isinstance(t5, cp.variable)
|
|
||||||
assert tg.read_value(t5) == pytest.approx(((10/1*2)**2 + (12/2*2)**2 + (14/3*2)**2) ** 0.5, 0.001) # pyright: ignore[reportUnknownMemberType]
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
test_compiled_vectors()
|
|
||||||
Loading…
Reference in New Issue