Skip to content

Commit

Permalink
remove portmap in python binding
Browse files Browse the repository at this point in the history
  • Loading branch information
Xinyu Li committed Apr 5, 2024
1 parent 68b726b commit 69d346e
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 354 deletions.
10 changes: 3 additions & 7 deletions python/ionpy/Builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
ion_builder_load,

ion_builder_run,
ion_builder_run_with_port_map,

)
from .Graph import Graph
from .Node import Node
from .BuilderCompileOption import BuilderCompileOption
from .PortMap import PortMap



class Builder:
Expand Down Expand Up @@ -86,10 +85,7 @@ def load(self, filename: str):
if ret != 0:
raise Exception('Invalid operation')

def run(self, port_map: PortMap = None):
if port_map is None:
ret = ion_builder_run(self.obj)
else:
ret = ion_builder_run_with_port_map(self.obj, port_map.obj)
def run(self):
ret = ion_builder_run(self.obj)
if ret != 0:
raise Exception('Invalid operation')
96 changes: 0 additions & 96 deletions python/ionpy/PortMap.py

This file was deleted.

1 change: 0 additions & 1 deletion python/ionpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from .Node import Node
from .Builder import Builder
from .Buffer import Buffer
from .PortMap import PortMap
from .Graph import Graph
from .Type import Type
from .TypeCode import TypeCode
Expand Down
89 changes: 0 additions & 89 deletions python/ionpy/native.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,6 @@ class c_builder_compile_option_t(ctypes.Structure):
ion_builder_run.restype = ctypes.c_int
ion_builder_run.argtypes = [ c_ion_builder_t ]

# int ion_builder_run(ion_builder_t, ion_port_map_t);
ion_builder_run_with_port_map = ion_core.ion_builder_run_with_port_map
ion_builder_run_with_port_map.restype = ctypes.c_int
ion_builder_run_with_port_map.argtypes = [ c_ion_builder_t, c_ion_port_map_t ]


# int ion_buffer_create(ion_buffer_t *, ion_type_t, int *, int);
ion_buffer_create = ion_core.ion_buffer_create
ion_buffer_create.restype = ctypes.c_int
Expand Down Expand Up @@ -281,86 +275,3 @@ class c_builder_compile_option_t(ctypes.Structure):
ion_graph_destroy=ion_core.ion_graph_destroy
ion_graph_destroy.restype = ctypes.c_int
ion_graph_destroy.argtypes =[ c_ion_graph_t]


# int ion_port_map_create(ion_port_map_t *);
ion_port_map_create = ion_core.ion_port_map_create
ion_port_map_create.restype = ctypes.c_int
ion_port_map_create.argtypes = [ ctypes.POINTER(c_ion_port_map_t) ]

# int ion_port_map_destroy(ion_port_map_t);
ion_port_map_destroy = ion_core.ion_port_map_destroy
ion_port_map_destroy.restype = ctypes.c_int
ion_port_map_destroy.argtypes = [ c_ion_port_map_t ]


# int ion_port_map_set_i8(ion_port_map_t, ion_port_t, int8_t);
ion_port_map_set_i8 = ion_core.ion_port_map_set_i8
ion_port_map_set_i8.restype = ctypes.c_int
ion_port_map_set_i8.argtypes = [ c_ion_port_map_t, c_ion_port_t, ctypes.c_int8 ]

# int ion_port_map_set_i16(ion_port_map_t, ion_port_t, int16_t);
ion_port_map_set_i16 = ion_core.ion_port_map_set_i16
ion_port_map_set_i16.restype = ctypes.c_int
ion_port_map_set_i16.argtypes = [ c_ion_port_map_t, c_ion_port_t, ctypes.c_int16 ]

# int ion_port_map_set_i32(ion_port_map_t, ion_port_t, int32_t);
ion_port_map_set_i32 = ion_core.ion_port_map_set_i32
ion_port_map_set_i32.restype = ctypes.c_int
ion_port_map_set_i32.argtypes = [ c_ion_port_map_t, c_ion_port_t, ctypes.c_int32 ]

# int ion_port_map_set_i64(ion_port_map_t, ion_port_t, int64_t);
ion_port_map_set_i64 = ion_core.ion_port_map_set_i64
ion_port_map_set_i64.restype = ctypes.c_int
ion_port_map_set_i64.argtypes = [ c_ion_port_map_t, c_ion_port_t, ctypes.c_int64 ]


# int ion_port_map_set_u1(ion_port_map_t, ion_port_t, bool);
ion_port_map_set_u1 = ion_core.ion_port_map_set_u1
ion_port_map_set_u1.restype = ctypes.c_int
ion_port_map_set_u1.argtypes = [ c_ion_port_map_t, c_ion_port_t, ctypes.c_bool ]

# int ion_port_map_set_u8(ion_port_map_t, ion_port_t, uint8_t);
ion_port_map_set_u8 = ion_core.ion_port_map_set_u8
ion_port_map_set_u8.restype = ctypes.c_int
ion_port_map_set_u8.argtypes = [ c_ion_port_map_t, c_ion_port_t, ctypes.c_uint8 ]

# int ion_port_map_set_u16(ion_port_map_t, ion_port_t, uint16_t);
ion_port_map_set_u16 = ion_core.ion_port_map_set_u16
ion_port_map_set_u16.restype = ctypes.c_int
ion_port_map_set_u16.argtypes = [ c_ion_port_map_t, c_ion_port_t, ctypes.c_uint16 ]

# int ion_port_map_set_u32(ion_port_map_t, ion_port_t, uint32_t);
ion_port_map_set_u32 = ion_core.ion_port_map_set_u32
ion_port_map_set_u32.restype = ctypes.c_int
ion_port_map_set_u32.argtypes = [ c_ion_port_map_t, c_ion_port_t, ctypes.c_uint32 ]

# int ion_port_map_set_u64(ion_port_map_t, ion_port_t, uint64_t);
ion_port_map_set_u64 = ion_core.ion_port_map_set_u64
ion_port_map_set_u64.restype = ctypes.c_int
ion_port_map_set_u64.argtypes = [ c_ion_port_map_t, c_ion_port_t, ctypes.c_uint64 ]


# int ion_port_map_set_f32(ion_port_map_t, ion_port_t, float);
ion_port_map_set_f32 = ion_core.ion_port_map_set_f32
ion_port_map_set_f32.restype = ctypes.c_int
ion_port_map_set_f32.argtypes = [ c_ion_port_map_t, c_ion_port_t, ctypes.c_float ]


# int ion_port_map_set_f64(ion_port_map_t, ion_port_t, double);
ion_port_map_set_f64 = ion_core.ion_port_map_set_f64
ion_port_map_set_f64.restype = ctypes.c_int
ion_port_map_set_f64.argtypes = [ c_ion_port_map_t, c_ion_port_t, ctypes.c_double ]



# int ion_port_map_set_buffer(ion_port_map_t, ion_port_t, ion_buffer_t);
ion_port_map_set_buffer = ion_core.ion_port_map_set_buffer
ion_port_map_set_buffer.restype = ctypes.c_int
ion_port_map_set_buffer.argtypes = [ c_ion_port_map_t, c_ion_port_t, c_ion_buffer_t ]


# int ion_port_map_set_buffer_array(ion_port_map_t, ion_port_t, ion_buffer_t *, int);
ion_port_map_set_buffer_array = ion_core.ion_port_map_set_buffer_array
ion_port_map_set_buffer_array.restype = ctypes.c_int
ion_port_map_set_buffer_array.argtypes = [ c_ion_port_map_t, c_ion_port_t, ctypes.POINTER(c_ion_buffer_t), ctypes.c_int ]
2 changes: 1 addition & 1 deletion python/ionpy/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.7.0"
__version__ = "2.0.0"
61 changes: 8 additions & 53 deletions python/test/test_all.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,9 @@
# https://github.com/fixstars/ion-csharp/blob/master/test/Test.cs
from ionpy import Node, Builder, Buffer, PortMap, Port, Param, Type, TypeCode
from ionpy import Node, Builder, Buffer, Port, Param, Type, TypeCode
import numpy as np # TODO: rewrite with pure python


def case1():
# Test old API

t = Type(code_=TypeCode.Int, bits_=32, lanes_=1)
input_port = Port(name='input', type=t, dim=2)
value41 = Param(key='v', val='41')

builder = Builder()
builder.set_target(target='host')
# make sure path includes libion-bb-test.so
builder.with_bb_module(path='ion-bb-test')
# builder.with_bb_module(path='ion-bb-test.dll') # for Windows

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

port_map = PortMap()

sizes = (4, 4)
ibuf = Buffer(type=t, sizes=sizes)
obuf = Buffer(type=t, sizes=sizes)

idata = np.full((4*4, ), fill_value=1, dtype=np.int32)
odata = np.full((4*4, ), fill_value=0, dtype=np.int32)

idata_bytes = idata.tobytes(order='C')
odata_bytes = odata.tobytes(order='C')

ibuf.write(data=idata_bytes)
obuf.write(data=odata_bytes)

port_map.set_buffer(port=input_port, buffer=ibuf)
port_map.set_buffer(port=node.get_port(name='output'), buffer=obuf)

builder.run(port_map=port_map)

obuf_bytes = obuf.read(num_data_bytes=len(odata_bytes))
odata = np.frombuffer(obuf_bytes, dtype=np.int32)

for i in range(4*4):
assert odata[i] == 42

def case2():
def test_all():
# Test new Buffer API

input_port = Port(name='input', type=Type.from_dtype(np.dtype(np.int32)), dim=2)
Expand All @@ -56,19 +15,18 @@ def case2():

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

port_map = PortMap()

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)

port_map.set_buffer(port=input_port, buffer=ibuf)
port_map.set_buffer(port=node.get_port(name='output'), buffer=obuf)
input_port.bind(ibuf)
output_port = node.get_port(name='output')
output_port.bind(obuf)

# First run
builder.run(port_map=port_map)
builder.run()

for y in range(4):
for x in range(4):
Expand All @@ -79,12 +37,9 @@ def case2():
for x in range(4):
idata[y][x] = 2

builder.run(port_map=port_map)
builder.run()

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

def test_all():
case1()
case2()
print("passed")
2 changes: 1 addition & 1 deletion python/test/test_binding.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ctypes

from ionpy import Node, Builder, Buffer, PortMap, Port, Param, Type, TypeCode
from ionpy import Node, Builder, Buffer, Port, Param, Type, TypeCode
import numpy as np


Expand Down
Loading

0 comments on commit 69d346e

Please sign in to comment.