Skip to content

Commit 6bd4195

Browse files
committed
feat: ff_send_out_to support, more conversions in pipeline, refactor of nodes
1 parent 5eb24f3 commit 6bd4195

26 files changed

+1188
-471
lines changed

Makefile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
.PHONY: clean config repara-copy titanic-copy build
22

3-
clean:
4-
rm -rf build
3+
# run source .venv/bin/activate before running make build
4+
build: clean
5+
pip install .
56

67
repara-copy:
7-
rsync -av -e ssh --exclude 'fastflow' --exclude '.git' --exclude '.venv' --exclude '*.egg-info' ./ dferraro@repara.unipi.it:/home/dferraro/fastflow-python
8+
rsync -av -e ssh --exclude 'fastflow' --exclude '.git' --exclude '.venv' --exclude '*.egg-info' --exclude 'build' ./ dferraro@repara.unipi.it:/home/dferraro/fastflow-python
89

910
titanic-copy:
10-
rsync -av -e ssh --exclude 'fastflow' --exclude '.git' --exclude '.venv' --exclude '*.egg-info' ./ dferraro@titanic.unipi.it:/home/dferraro/fastflow-python
11-
12-
build: clean
13-
pip install .
11+
rsync -av -e ssh --exclude 'fastflow' --exclude '.git' --exclude '.venv' --exclude '*.egg-info' --exclude 'build' ./ dferraro@titanic.unipi.it:/home/dferraro/fastflow-python
1412

13+
clean:
14+
rm -rf build

fastflow_module.cpp

Lines changed: 68 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,60 +4,100 @@
44
#include <cstring>
55
#include <ostream>
66
#include <sstream>
7+
#include <ff/ff.hpp>
78
#include "py_ff_a2a.hpp"
89
#include "py_ff_pipeline.hpp"
910
#include "py_ff_farm.hpp"
11+
#include "py_ff_callback.hpp"
12+
#include "process/ff_monode_process.hpp"
13+
#include "process/ff_node_process.hpp"
14+
#include "py_ff_constant.hpp"
1015

11-
// A struct contains the definition of a module
12-
PyModuleDef moduledef = {
13-
PyModuleDef_HEAD_INIT,
14-
"fastflow_module", // Module name
15-
"This is FastFlow's docstring",
16-
-1, // Optional size of the module state memory
17-
NULL, // Optional module methods
18-
NULL, // Optional slot definitions
19-
NULL, // Optional traversal function
20-
NULL, // Optional clear function
21-
NULL // Optional module deallocation function
22-
};
16+
PyDoc_STRVAR(ff_send_out_to_doc, "Send out to a node");
2317

24-
PyMODINIT_FUNC
25-
PyInit_fastflow_module(void) {
26-
PyObject* module = PyModule_Create(&moduledef);
27-
if (module == NULL)
28-
return NULL;
18+
PyObject* empty_ff_send_out_to(PyObject *self, PyObject *args) {
19+
assert(self);
2920

21+
PyErr_SetString(PyExc_Exception, "Operation not available. This is not a multi output node");
22+
return NULL;
23+
}
24+
25+
/* initialization function */
26+
static int
27+
fastflow_module_exec(PyObject *module)
28+
{
3029
// add FFPipeline
3130
if (PyType_Ready(&py_ff_pipeline_type) < 0)
32-
return NULL;
31+
return -1;
3332

3433
if (PyModule_AddObject(module, "FFPipeline", (PyObject *) &py_ff_pipeline_type) < 0) {
35-
Py_DECREF(module);
36-
return NULL;
34+
return -1;
3735
}
3836

3937
// add FFFarm
4038
PyObject *py_ff_farm = PyType_FromSpec(&spec_py_ff_farm);
4139
if (py_ff_farm == NULL){
42-
return NULL;
40+
return -1;
4341
}
4442
Py_INCREF(py_ff_farm);
4543

46-
if (PyModule_AddObject(module, "FFFarm", py_ff_farm) < 0){
44+
if (PyModule_AddObject(module, "FFFarm", py_ff_farm) < 0) {
4745
Py_DECREF(py_ff_farm);
48-
Py_DECREF(module);
49-
return NULL;
46+
return -1;
5047
}
5148

5249
// add FFAllToAll
5350
if (PyType_Ready(&py_ff_a2a_type) < 0)
54-
return NULL;
51+
return -1;
5552

5653
if (PyModule_AddObject(module, "FFAllToAll", (PyObject *) &py_ff_a2a_type) < 0) {
57-
Py_DECREF(module);
58-
return NULL;
54+
return -1;
55+
}
56+
57+
// add the callback object. Do not AddObject,
58+
// to avoid the user instantiating it
59+
if (PyType_Ready(&py_ff_callback_type) < 0) {
60+
return -1;
61+
}
62+
63+
// add fastflow's constant type. Do not AddObject,
64+
// to avoid the user instantiating it
65+
if (PyType_Ready(&py_ff_constant_type) < 0) {
66+
return -1;
67+
}
68+
69+
if (PyModule_AddObject(module, GO_ON_CONSTANT_NAME, build_py_ff_constant(ff::FF_GO_ON)) < 0) {
70+
return -1;
5971
}
60-
return module;
72+
73+
return 0;
74+
}
75+
76+
static PyMethodDef module_methods[] = {
77+
{ "ff_send_out_to", (PyCFunction) empty_ff_send_out_to, METH_VARARGS, ff_send_out_to_doc },
78+
{NULL, NULL} /* Sentinel */
79+
};
80+
81+
static PyModuleDef_Slot module_slots[] = {
82+
{Py_mod_exec, (void*) fastflow_module_exec},
83+
#if PY_MINOR_VERSION >= 12
84+
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
85+
#endif
86+
{0, NULL},
87+
};
88+
89+
static struct PyModuleDef moduledef = {
90+
.m_base = PyModuleDef_HEAD_INIT,
91+
.m_name = "fastflow_module",
92+
.m_doc = "This is FastFlow's docstring",
93+
.m_size = 0,
94+
.m_methods = module_methods,
95+
.m_slots = module_slots,
96+
};
97+
98+
PyMODINIT_FUNC
99+
PyInit_fastflow_module(void) {
100+
return PyModuleDef_Init(&moduledef);
61101
}
62102

63103
// Useful reading

include/error_macros.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#ifndef ERROR_MACROS
22
#define ERROR_MACROS
33

4-
54
#if PY_MINOR_VERSION >= 12
65
#define PRINT_ERROR(descr) \
76
{ PyObject* err = PyErr_GetRaisedException(); \
@@ -12,8 +11,7 @@
1211
PyErr_Clear(); }
1312
#else
1413
#define PRINT_ERROR(descr) \
15-
{ std::cerr << descr << "TODO: get raised exception" << std::endl; \
16-
PyErr_Clear(); }
14+
{ std::cerr << descr << std::endl; PyErr_Print(); }
1715
#endif
1816

1917
#define CHECK_ERROR_THEN(descr, then) if (PyErr_Occurred()) { PRINT_ERROR(descr) { then } }

include/node_utils.hpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
#include <Python.h>
55
#include <ff/ff.hpp>
66
#include "py_ff_node.hpp"
7-
#include "py_ff_node_subint.hpp"
8-
#include "py_ff_node_process.hpp"
7+
#include "subint/ff_monode_subint.hpp"
8+
#include "subint/ff_node_subint.hpp"
9+
#include "process/ff_monode_process.hpp"
10+
#include "process/ff_node_process.hpp"
911

1012
int parse_args(PyObject *args, PyObject *kwds, PyObject **py_node, bool *use_main_thread) {
1113
*use_main_thread = false;
@@ -30,18 +32,18 @@ int parse_args(PyObject *args, PyObject *kwds, PyObject **py_node, bool *use_mai
3032
return 0;
3133
}
3234

33-
ff::ff_node* args_to_node(PyObject *args, PyObject *kwds, bool use_subints) {
35+
ff::ff_node* args_to_node(PyObject *args, PyObject *kwds, bool use_subints, bool multi_output = false) {
3436
PyObject *py_node = NULL;
3537
bool use_main_thread = false;
3638
if (parse_args(args, kwds, &py_node, &use_main_thread) == -1) return NULL;
3739

3840
if (use_subints) {
39-
return new py_ff_node_subint(py_node);
41+
return multi_output ? (ff::ff_node*)new ff_monode_subint(py_node):new ff_node_subint(py_node);
4042
} else if (use_main_thread) {
4143
return new py_ff_node(py_node);
4244
}
4345

44-
return new py_ff_node_process(py_node);
46+
return multi_output ? (ff::ff_node*)new ff_monode_process(py_node):new ff_node_process(py_node);
4547
}
4648

4749
#endif // NODE_UTILS

0 commit comments

Comments
 (0)