Skip to content

Commit 75091e8

Browse files
committed
code documentation and binding more TaskR methods
1 parent bcad9f6 commit 75091e8

4 files changed

Lines changed: 41 additions & 8 deletions

File tree

.gitlab-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ build:
1111
- source /home/hicr/.hicr-env.sh
1212
- echo "Building TaskR..."
1313
- mkdir build
14-
- meson setup build -Dbuildtype=debug -Db_coverage=true -DbuildTests=true -DbuildExamples=true -DdistributedEngine=mpi -DexecutionStateType=boost,nosv -DprocessingUnitType=pthreads,nosv -DbuildInstrumentation=true -DcompileWarningsAsErrors=true
14+
- meson setup build -Dbuildtype=debug -Db_coverage=true -DbuildTests=true -DbuildExamples=true -DdistributedEngine=mpi -DexecutionStateType=boost,nosv -DprocessingUnitType=pthreads,nosv -DbuildInstrumentation=true -DbuildPyTaskR=true -DcompileWarningsAsErrors=true
1515
- meson compile -C build
1616
- echo "Running tests..."
1717
- meson test -C build

include/pytaskr/pyruntime.hpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,15 @@ enum backend_t
4747
threading
4848
};
4949

50+
/**
51+
* TaskR Runtime class python wrapper. It simplifies the user for constructing the TaskR Runtime
52+
*/
5053
class PyRuntime
5154
{
5255
public:
5356

5457
/**
55-
*
58+
* Constructor with num_workers being an interger value. If 0, initialize all.
5659
*/
5760
PyRuntime(const backend_t &backend_type = backend_t::nosv, size_t num_workers = 0)
5861
: _backend_type(backend_type)
@@ -112,7 +115,7 @@ class PyRuntime
112115
}
113116

114117
/**
115-
*
118+
* Constructor with num_workers being a set of integers. The set specifies which process affinity to use (if available).
116119
*/
117120
PyRuntime(const backend_t &backend_type, const std::set<int> &workersSet)
118121
: _backend_type(backend_type)
@@ -169,13 +172,16 @@ class PyRuntime
169172

170173
if (!_computeResources.size()) { HICR_THROW_LOGIC("Error: non-existing compute resources provided\n"); }
171174

175+
// Store the number of initialized workers
172176
_num_workers = _computeResources.size();
173177

178+
// Initialize the runtime
174179
_runtime = std::make_unique<Runtime>(_executionStateComputeManager.get(), _processingUnitComputeManager.get(), _computeResources);
175180
}
176181

177182
/**
178-
* Destructor
183+
* Destructor of PyRuntime
184+
*
179185
* Destroying topology and shutting down nOS-V if nosv backend have been used.
180186
*/
181187
~PyRuntime()

include/pytaskr/pytaskr.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,23 @@ namespace py = pybind11;
2828
namespace taskr
2929
{
3030

31+
/**
32+
* Vector to keep track which cpp functions to register
33+
*/
3134
std::vector<FunctionRegistration> &get_registry()
3235
{
3336
static std::vector<FunctionRegistration> reg;
3437
return reg;
3538
}
3639

40+
/**
41+
* Function to store the cpp function with a given naming
42+
*/
3743
void register_function(const std::string &name, function_t fc) { get_registry().push_back({name, fc}); }
3844

39-
// TODO: add all methods of all classes
40-
45+
/**
46+
* Pybind11 module for binding taskr stuff
47+
*/
4148
PYBIND11_MODULE(taskr, m)
4249
{
4350
m.doc() = "pybind11 plugin for TaskR";
@@ -66,25 +73,36 @@ PYBIND11_MODULE(taskr, m)
6673
// TaskR's Runtime class
6774
py::class_<Runtime>(m, "Runtime")
6875
.def("setTaskCallbackHandler", &Runtime::setTaskCallbackHandler)
76+
.def("setServiceWorkerCallbackHandler", &Runtime::setServiceWorkerCallbackHandler)
77+
.def("setTaskWorkerCallbackHandler", &Runtime::setTaskWorkerCallbackHandler)
6978
.def("initialize", &Runtime::initialize)
7079
.def("addTask", &Runtime::addTask, py::keep_alive<1, 2>()) // keep_alive as the task should be alive until runtime's destructor
7180
.def("resumeTask", &Runtime::resumeTask)
7281
.def("run", &Runtime::run, py::call_guard<py::gil_scoped_release>())
7382
.def("await_", &Runtime::await, py::call_guard<py::gil_scoped_release>()) // Release GIL is important otherwise non-finished tasks are getting blocked
74-
.def("finalize", &Runtime::finalize);
83+
.def("finalize", &Runtime::finalize)
84+
.def("setFinishedTask", &Runtime::setFinishedTask)
85+
.def("addService", &Runtime::addService);
7586

7687
// TaskR's Function class
7788
py::class_<Function>(m, "Function").def(py::init<const function_t>());
7889

7990
// TaskR's Task class
8091
py::class_<Task>(m, "Task")
92+
.def(py::init<Function *, const workerId_t>(), py::arg("fc"), py::arg("workerAffinity") = -1)
8193
.def(py::init<const label_t, Function *, const workerId_t>(), py::arg("label"), py::arg("fc"), py::arg("workerAffinity") = -1)
8294
.def("getLabel", &Task::getLabel)
8395
.def("setLabel", &Task::setLabel)
8496
.def("getWorkerAffinity", &Task::getWorkerAffinity)
8597
.def("setWorkerAffinity", &Task::setWorkerAffinity)
8698
.def("addDependency", &Task::addDependency)
99+
.def("getDependencyCount", &Task::getDependencyCount)
100+
.def("incrementDependencyCount", &Task::incrementDependencyCount)
101+
.def("decrementDependencyCount", &Task::decrementDependencyCount)
102+
.def("addOutputDependency", &Task::addOutputDependency)
103+
.def("getOutputDependencies", &Task::getOutputDependencies)
87104
.def("addPendingOperation", &Task::addPendingOperation)
105+
.def("getPendingOperations", &Task::getPendingOperations)
88106
.def("suspend", &Task::suspend, py::call_guard<py::gil_scoped_release>());
89107

90108
py::enum_<Task::callback_t>(m, "TaskCallback")
@@ -95,7 +113,7 @@ PYBIND11_MODULE(taskr, m)
95113
.export_values();
96114

97115
// TaskR's Mutex class
98-
py::class_<Mutex>(m, "Mutex").def(py::init<>()).def("lock", &Mutex::lock).def("unlock", &Mutex::unlock);
116+
py::class_<Mutex>(m, "Mutex").def(py::init<>()).def("lock", &Mutex::lock).def("unlock", &Mutex::unlock).def("ownsLock", &Mutex::ownsLock).def("trylock", &Mutex::trylock);
99117

100118
// TaskR's ConditionVariable class
101119
py::class_<ConditionVariable>(m, "ConditionVariable")

include/pytaskr/pytaskr.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,23 @@
2222
namespace taskr
2323
{
2424

25+
/**
26+
* Struct with the cpp funcion and the given name
27+
*/
2528
struct FunctionRegistration
2629
{
2730
std::string name;
2831
function_t fc;
2932
};
3033

34+
/**
35+
* Vector to keep track which cpp functions to register
36+
*/
3137
std::vector<FunctionRegistration> &get_registry();
3238

39+
/**
40+
* Function to store the cpp function with a given naming
41+
*/
3342
void register_function(const std::string &name, function_t fc);
3443

3544
} // namespace taskr

0 commit comments

Comments
 (0)