mirror of https://github.com/Nonannet/copapy.git
add_read_value_remote backend function renamed and docstring updated
This commit is contained in:
parent
0f5bb86bd4
commit
d394b2d249
|
|
@ -7,6 +7,7 @@ from ._basic_types import Net, Node, Store, CPConstant, Op, transl_type
|
|||
|
||||
def stable_toposort(edges: Iterable[tuple[Node, Node]]) -> list[Node]:
|
||||
"""Perform a stable topological sort on a directed acyclic graph (DAG).
|
||||
|
||||
Arguments:
|
||||
edges: Iterable of (u, v) pairs meaning u -> v
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,15 @@ TRet = TypeVar("TRet", Iterable[int | float], int, float)
|
|||
_jit_cache: dict[Any, tuple['Target', tuple[value[Any] | Iterable[value[Any]], ...], NumLike | Iterable[NumLike]]] = {}
|
||||
|
||||
|
||||
def add_read_command(dw: binw.data_writer, variables: dict[Net, tuple[int, int, str]], net: Net) -> None:
|
||||
def add_read_value_remote(dw: binw.data_writer, variables: dict[Net, tuple[int, int, str]], net: Net) -> None:
|
||||
"""Adds a read memory to stdout command to the data_writer dw.
|
||||
|
||||
Arguments:
|
||||
dw: data_writer to add the command to
|
||||
variables: A dict for looking up variables by Net. The value is a tuple.
|
||||
of relative address in memory, size in bytes and data type.
|
||||
net: Variable specified by Net to read from memory and write to stdout.
|
||||
"""
|
||||
assert net in variables, f"Variable {net} not found in data writer variables"
|
||||
addr, lengths, _ = variables[net]
|
||||
dw.write_com(binw.Command.READ_DATA)
|
||||
|
|
@ -188,5 +196,5 @@ class Target():
|
|||
def read_value_remote(self, variable: value[Any]) -> None:
|
||||
"""Reads the raw data of a value by the runner."""
|
||||
dw = binw.data_writer(self.sdb.byteorder)
|
||||
add_read_command(dw, self._values, variable.net)
|
||||
add_read_value_remote(dw, self._values, variable.net)
|
||||
assert coparun(self._context, dw.get_data()) > 0
|
||||
|
|
|
|||
|
|
@ -3,14 +3,14 @@ Backend module for Copapy: contains internal data types
|
|||
and give access to compiler internals and debugging tools.
|
||||
"""
|
||||
|
||||
from ._target import add_read_command
|
||||
from ._target import add_read_value_remote
|
||||
from ._basic_types import Net, Op, Node, CPConstant, Store, stencil_db_from_package
|
||||
from ._compiler import compile_to_dag, \
|
||||
stable_toposort, get_const_nets, get_all_dag_edges, add_load_ops, get_all_dag_edges_between, \
|
||||
add_store_ops, get_dag_stats
|
||||
|
||||
__all__ = [
|
||||
"add_read_command",
|
||||
"add_read_value_remote",
|
||||
"Net",
|
||||
"Op",
|
||||
"Node",
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
from copapy import value
|
||||
from copapy.backend import Store, compile_to_dag, add_read_command
|
||||
from copapy.backend import Store, compile_to_dag, add_read_value_remote
|
||||
import copapy as cp
|
||||
import subprocess
|
||||
from copapy import _binwrite
|
||||
import copapy.backend
|
||||
import pytest
|
||||
|
||||
|
||||
|
|
@ -24,7 +23,7 @@ def test_compile():
|
|||
|
||||
out = [Store(r) for r in ret_test]
|
||||
|
||||
il, variables = compile_to_dag(out, copapy.generic_sdb)
|
||||
il, variables = compile_to_dag(out, cp.generic_sdb)
|
||||
|
||||
# run program command
|
||||
il.write_com(_binwrite.Command.RUN_PROG)
|
||||
|
|
@ -32,7 +31,7 @@ def test_compile():
|
|||
|
||||
for v in ret_test:
|
||||
assert isinstance(v, value)
|
||||
add_read_command(il, variables, v.net)
|
||||
add_read_value_remote(il, variables, v.net)
|
||||
|
||||
il.write_com(_binwrite.Command.END_COM)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
from copapy import NumLike
|
||||
from copapy.backend import Store, compile_to_dag, add_read_command
|
||||
from copapy.backend import Store, compile_to_dag, add_read_value_remote
|
||||
import copapy as cp
|
||||
import subprocess
|
||||
import struct
|
||||
from copapy import _binwrite
|
||||
import copapy.backend
|
||||
import pytest
|
||||
|
||||
|
||||
|
|
@ -60,14 +59,14 @@ def test_compile():
|
|||
|
||||
out = [Store(r) for r in ret]
|
||||
|
||||
il, variables = compile_to_dag(out, copapy.generic_sdb)
|
||||
il, variables = compile_to_dag(out, cp.generic_sdb)
|
||||
|
||||
# run program command
|
||||
il.write_com(_binwrite.Command.RUN_PROG)
|
||||
|
||||
for v in ret:
|
||||
assert isinstance(v, cp.value)
|
||||
add_read_command(il, variables, v.net)
|
||||
add_read_value_remote(il, variables, v.net)
|
||||
|
||||
il.write_com(_binwrite.Command.END_COM)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from copapy import NumLike
|
||||
from copapy.backend import Store, compile_to_dag, add_read_command
|
||||
from copapy.backend import Store, compile_to_dag, add_read_value_remote
|
||||
import subprocess
|
||||
from copapy import _binwrite
|
||||
import copapy.backend as backend
|
||||
|
|
@ -62,7 +62,7 @@ def test_compile():
|
|||
|
||||
for v in ret:
|
||||
assert isinstance(v, cp.value)
|
||||
add_read_command(il, variables, v.net)
|
||||
add_read_value_remote(il, variables, v.net)
|
||||
|
||||
il.write_com(_binwrite.Command.END_COM)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from copapy import NumLike
|
||||
from copapy.backend import Store, compile_to_dag, add_read_command
|
||||
from copapy.backend import Store, compile_to_dag, add_read_value_remote
|
||||
import subprocess
|
||||
from copapy import _binwrite
|
||||
import copapy.backend as backend
|
||||
|
|
@ -63,7 +63,7 @@ def test_compile():
|
|||
|
||||
for v in ret:
|
||||
assert isinstance(v, cp.value)
|
||||
add_read_command(il, variables, v.net)
|
||||
add_read_value_remote(il, variables, v.net)
|
||||
|
||||
il.write_com(_binwrite.Command.END_COM)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from copapy import value, NumLike
|
||||
from copapy.backend import Store, compile_to_dag, add_read_command
|
||||
import copapy
|
||||
from copapy.backend import Store, compile_to_dag, add_read_value_remote
|
||||
import copapy as cp
|
||||
import subprocess
|
||||
from copapy import _binwrite
|
||||
import pytest
|
||||
|
|
@ -28,14 +28,14 @@ def test_compile():
|
|||
|
||||
out = [Store(r) for r in ret]
|
||||
|
||||
il, vars = compile_to_dag(out, copapy.generic_sdb)
|
||||
il, vars = compile_to_dag(out, cp.generic_sdb)
|
||||
|
||||
# run program command
|
||||
il.write_com(_binwrite.Command.RUN_PROG)
|
||||
|
||||
for v in ret:
|
||||
assert isinstance(v, value)
|
||||
add_read_command(il, vars, v.net)
|
||||
add_read_value_remote(il, vars, v.net)
|
||||
|
||||
il.write_com(_binwrite.Command.END_COM)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
from copapy import value
|
||||
from copapy.backend import Store, compile_to_dag, add_read_command
|
||||
from copapy.backend import Store, compile_to_dag, add_read_value_remote
|
||||
import copapy as cp
|
||||
import subprocess
|
||||
from copapy import _binwrite
|
||||
import copapy.backend
|
||||
import pytest
|
||||
|
||||
|
||||
|
|
@ -23,14 +22,14 @@ def test_compile_sqrt():
|
|||
|
||||
out = [Store(r) for r in ret]
|
||||
|
||||
il, variables = compile_to_dag(out, copapy.generic_sdb)
|
||||
il, variables = compile_to_dag(out, cp.generic_sdb)
|
||||
|
||||
# run program command
|
||||
il.write_com(_binwrite.Command.RUN_PROG)
|
||||
|
||||
for v in ret:
|
||||
assert isinstance(v, value)
|
||||
add_read_command(il, variables, v.net)
|
||||
add_read_value_remote(il, variables, v.net)
|
||||
|
||||
il.write_com(_binwrite.Command.END_COM)
|
||||
|
||||
|
|
@ -57,14 +56,14 @@ def test_compile_log():
|
|||
|
||||
out = [Store(r) for r in ret]
|
||||
|
||||
il, variables = compile_to_dag(out, copapy.generic_sdb)
|
||||
il, variables = compile_to_dag(out, cp.generic_sdb)
|
||||
|
||||
# run program command
|
||||
il.write_com(_binwrite.Command.RUN_PROG)
|
||||
|
||||
for v in ret:
|
||||
assert isinstance(v, value)
|
||||
add_read_command(il, variables, v.net)
|
||||
add_read_value_remote(il, variables, v.net)
|
||||
|
||||
il.write_com(_binwrite.Command.END_COM)
|
||||
|
||||
|
|
@ -91,14 +90,14 @@ def test_compile_sin():
|
|||
|
||||
out = [Store(r) for r in ret]
|
||||
|
||||
il, variables = compile_to_dag(out, copapy.generic_sdb)
|
||||
il, variables = compile_to_dag(out, cp.generic_sdb)
|
||||
|
||||
# run program command
|
||||
il.write_com(_binwrite.Command.RUN_PROG)
|
||||
|
||||
for v in ret:
|
||||
assert isinstance(v, copapy.value)
|
||||
add_read_command(il, variables, v.net)
|
||||
assert isinstance(v, cp.value)
|
||||
add_read_value_remote(il, variables, v.net)
|
||||
|
||||
il.write_com(_binwrite.Command.END_COM)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from copapy import NumLike, iif, value
|
||||
from copapy.backend import Store, compile_to_dag, add_read_command
|
||||
from copapy.backend import Store, compile_to_dag, add_read_value_remote
|
||||
import subprocess
|
||||
from copapy import _binwrite
|
||||
import copapy.backend as backend
|
||||
|
|
@ -109,7 +109,7 @@ def test_compile():
|
|||
|
||||
for v in ret_test:
|
||||
assert isinstance(v, value)
|
||||
add_read_command(dw, variables, v.net)
|
||||
add_read_value_remote(dw, variables, v.net)
|
||||
|
||||
#dw.write_com(_binwrite.Command.READ_DATA)
|
||||
#dw.write_int(0)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from copapy import NumLike, iif, value
|
||||
from copapy.backend import Store, compile_to_dag, add_read_command
|
||||
from copapy.backend import Store, compile_to_dag, add_read_value_remote
|
||||
import subprocess
|
||||
from copapy import _binwrite
|
||||
import copapy.backend as backend
|
||||
|
|
@ -111,7 +111,7 @@ def test_compile():
|
|||
|
||||
for v in ret_test:
|
||||
assert isinstance(v, value)
|
||||
add_read_command(dw, variables, v.net)
|
||||
add_read_value_remote(dw, variables, v.net)
|
||||
|
||||
#dw.write_com(_binwrite.Command.READ_DATA)
|
||||
#dw.write_int(0)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from copapy import NumLike, iif, value
|
||||
from copapy.backend import Store, compile_to_dag, add_read_command
|
||||
from copapy.backend import Store, compile_to_dag, add_read_value_remote
|
||||
import subprocess
|
||||
from copapy import _binwrite
|
||||
import copapy.backend as backend
|
||||
|
|
@ -111,7 +111,7 @@ def test_compile():
|
|||
|
||||
for v in ret_test:
|
||||
assert isinstance(v, value)
|
||||
add_read_command(dw, variables, v.net)
|
||||
add_read_value_remote(dw, variables, v.net)
|
||||
|
||||
#dw.write_com(_binwrite.Command.READ_DATA)
|
||||
#dw.write_int(0)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
from copapy import NumLike, iif, value
|
||||
from copapy.backend import Store, compile_to_dag, add_read_command
|
||||
from copapy.backend import Store, compile_to_dag, add_read_value_remote
|
||||
import subprocess
|
||||
from copapy import _binwrite
|
||||
import copapy.backend as backend
|
||||
|
|
@ -122,7 +122,7 @@ def test_compile():
|
|||
|
||||
for v in ret_test:
|
||||
assert isinstance(v, value)
|
||||
add_read_command(dw, variables, v.net)
|
||||
add_read_value_remote(dw, variables, v.net)
|
||||
|
||||
#dw.write_com(_binwrite.Command.READ_DATA)
|
||||
#dw.write_int(0)
|
||||
|
|
@ -196,7 +196,7 @@ def test_vector_compile():
|
|||
|
||||
for v in ret:
|
||||
assert isinstance(v, cp.value)
|
||||
add_read_command(il, variables, v.net)
|
||||
add_read_value_remote(il, variables, v.net)
|
||||
|
||||
il.write_com(_binwrite.Command.END_COM)
|
||||
|
||||
|
|
@ -258,7 +258,7 @@ def test_sinus():
|
|||
|
||||
for v in ret_test:
|
||||
assert isinstance(v, value)
|
||||
add_read_command(dw, variables, v.net)
|
||||
add_read_value_remote(dw, variables, v.net)
|
||||
|
||||
#dw.write_com(_binwrite.Command.READ_DATA)
|
||||
#dw.write_int(0)
|
||||
|
|
|
|||
Loading…
Reference in New Issue