Skip to content

Commit

Permalink
python-port-binding-api
Browse files Browse the repository at this point in the history
  • Loading branch information
Xinyu Li authored and Xinyu Li committed Jan 6, 2024
1 parent 0079760 commit 0ec0e62
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
2 changes: 2 additions & 0 deletions python/test/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,5 @@ def case2():
def test_all():
case1()
case2()

test_all()
42 changes: 42 additions & 0 deletions python/test/test_binding.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from ionpy import Node, Builder, Buffer, PortMap, Port, Param, Type, TypeCode
import numpy as np # TODO: rewrite with pure python

def test_binding():

input_port = Port(name='input', type=Type.from_dtype(np.dtype(np.int32)), dim=2)
value41 = Param(key='v', val='41')

builder = Builder()
builder.set_target(target='host')
builder.with_bb_module(path='ion-bb-test')

node = builder.add('test_inc_i32x2').set_iport([input_port]).set_param(params=[ value41, ])

idata = np.full((4, 4), fill_value=1, dtype=np.int32)
ibuf = Buffer(array=idata)

odata = np.full((4, 4), fill_value=0, dtype=np.int32)
obuf = Buffer(array=odata)


input_port.bind_buffer(ibuf)
output_port = node.get_port(name='output')
output_port.bind_buffer(obuf)

# First run
builder.run()

for y in range(4):
for x in range(4):
assert odata[y][x] == 42

# Second
for y in range(4):
for x in range(4):
idata[y][x] = 2

builder.run()

for y in range(4):
for x in range(4):
assert odata[y][x] == 43

0 comments on commit 0ec0e62

Please sign in to comment.