Skip to content

Commit 8152da7

Browse files
committed
Ctypes prototype
1 parent b5b502e commit 8152da7

File tree

2 files changed

+160
-1
lines changed

2 files changed

+160
-1
lines changed

cfaasm/tester.py

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
import ctypes
2+
3+
SUPPORTING_LIBS = [
4+
"libpistache.so",
5+
"libfaabricmpi.so",
6+
]
7+
8+
HOST_INTERFACE_LIB = "libemulator.so"
9+
10+
11+
# For a tutorial on ctypes, see here:
12+
# https://docs.python.org/3/library/ctypes.html
13+
#
14+
# Faasm host interface:
15+
# https://github.com/faasm/faasm/blob/master/include/faasm/host_interface.h
16+
17+
_host_interface = None
18+
19+
20+
def init_host_interface():
21+
global _host_interface
22+
23+
if _host_interface is None:
24+
# Load all supporting libs as globally linkable
25+
for lib in SUPPORTING_LIBS:
26+
ctypes.CDLL(lib, mode=ctypes.RTLD_GLOBAL)
27+
28+
# Load main Faasm host interface lib
29+
_host_interface = ctypes.CDLL("libemulator.so")
30+
print("Loaded Faasm host interface: {}".format(_host_interface))
31+
32+
33+
def append_state():
34+
pass
35+
36+
37+
def await_call():
38+
pass
39+
40+
41+
def await_call_output():
42+
pass
43+
44+
45+
def chain_name():
46+
pass
47+
48+
49+
def chain_ptr():
50+
pass
51+
52+
53+
def chain_py():
54+
pass
55+
56+
57+
def clear_appended_state():
58+
pass
59+
60+
61+
def conf_flag():
62+
pass
63+
64+
65+
def get_py_entry():
66+
pass
67+
68+
69+
def get_py_func():
70+
pass
71+
72+
73+
def lock_state_global():
74+
pass
75+
76+
77+
def lock_state_read():
78+
pass
79+
80+
81+
def lock_state_write():
82+
pass
83+
84+
85+
def push_state(key):
86+
_host_interface.__faasm_push_state(key)
87+
88+
89+
def pull_state():
90+
pass
91+
92+
93+
def push_state_partial():
94+
pass
95+
96+
97+
def read_appended_state():
98+
pass
99+
100+
101+
def read_input():
102+
return _host_interface.__faasm_read_input()
103+
104+
105+
def read_state(key, state_size):
106+
buff = ctypes.create_string_buffer(state_size)
107+
_host_interface.__faasm_read_state(key, buff, state_size)
108+
return buff
109+
110+
111+
def read_state_offset():
112+
pass
113+
114+
115+
def read_state_ptr():
116+
pass
117+
118+
119+
def read_state_offset_ptr():
120+
pass
121+
122+
123+
def unlock_state_global():
124+
pass
125+
126+
127+
def unlock_state_read(key_bytes):
128+
_host_interface.__faasm_unlock_state_read(key_bytes)
129+
130+
131+
def unlock_state_write(key_bytes):
132+
_host_interface.__faasm_unlock_state_write(key_bytes)
133+
134+
135+
def write_output(byte_data):
136+
_host_interface.__faasm_write_output(byte_data)
137+
138+
139+
def write_state(key, bytes_data):
140+
_host_interface.__faasm_write_state(key, bytes_data, len(bytes_data))
141+
142+
143+
def write_state_offset():
144+
pass
145+
146+
147+
if __name__ == "__main__":
148+
key = b"foobar"
149+
full_value = b"0123456789"
150+
151+
init_host_interface()
152+
153+
write_state(key, full_value)
154+
push_state(key)
155+
156+
actual = read_state(key, len(full_value))
157+
print(actual)

docker-compose.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ services:
77
cli:
88
image: ${CPYTHON_CLI_IMAGE}
99
volumes:
10-
- .:/code/faasm-cpython
10+
- /var/run/docker.sock:/var/run/docker.sock
11+
- /usr/bin/docker:/usr/bin/docker
12+
- .:/code/faasm-cpython
1113
working_dir: /code/faasm-cpython
1214
stdin_open: true
1315
tty: true

0 commit comments

Comments
 (0)