Skip to content

Commit 22ed7e1

Browse files
authored
Python api (#10)
* adding pybind11 as an extern libary * adding meson stuff for pybind11 * creating a PyRuntime wrapper class for pybind11 * naming the whole thing pyTaskR and minor code improvements * adding first little example in 'simple' * PyRuntime and Runtime working, now it is up to the Task class to be pybind11 * finally working, now, more tests and more methods * updating the extern submodules and adding ABC example * suspend works (if only one task, now it should work for multiple tasks)! * added conditionVariable example (xxWaitCondition works atm) * example energySaver and Fibonacci included. Fib(n>3) fails. * created more examples * adding some working examples * minor correction on some examples * all the current examples work if nosv is used * fibonacci also with mutex.lock? * redundant python path removed * merging main * fixing code style * adding enumerate method for choosing backend * adding a method to add your own cpp functions to be executed over pytaskr * fixing style * removing redundant code * code documentation and binding more TaskR methods * renamed a lot of files and minor corrections (all from the first review) * old approach of adding a cpp function * remaking the binding now. Now, the user has to create his own pybind
1 parent c794e1e commit 22ed7e1

File tree

156 files changed

+2779
-229
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+2779
-229
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ build
44
.vscode
55
atlas_*.sh
66
**/matrix/
7+
**/__pycache__/
8+
**/ovni/

.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

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@
66
path = extern/hicr
77
url = https://github.com/Algebraic-Programming/HiCR.git
88
branch = master
9+
[submodule "extern/pybind11"]
10+
path = extern/pybind11
11+
url = https://github.com/pybind/pybind11.git
12+
branch = stable
File renamed without changes.
File renamed without changes.
File renamed without changes.

examples/abcTasks/meson.build

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
testSuite = [ 'examples', 'abcTasks' ]
2+
3+
if 'boost' in get_option('executionStateType') and 'pthreads' in get_option('processingUnitType')
4+
threading = executable('threading', [ 'cpp/pthreads.cpp'], dependencies: [ TaskRBuildDep ])
5+
6+
if get_option('buildTests')
7+
test('threading', threading, args : [ ], suite: testSuite, workdir: threading.path() + '.p' )
8+
endif
9+
endif
10+
11+
if 'nosv' in get_option('executionStateType') and 'nosv' in get_option('processingUnitType')
12+
nosv = executable('nosv', [ 'cpp/nosv.cpp'], dependencies: [ TaskRBuildDep ])
13+
14+
if get_option('buildTests')
15+
test('nosv', nosv, args : [ ], is_parallel : false, suite: testSuite, workdir: nosv.path() + '.p')
16+
endif
17+
endif
18+
19+
if get_option('buildPyTaskR') and get_option('buildTests')
20+
test('pyTaskR',
21+
py,
22+
args : [ 'python/main.py' ],
23+
is_parallel : false,
24+
env: ['PYTHONPATH=' + meson.project_build_root() + '/include/pytaskr/'],
25+
suite: testSuite,
26+
workdir: meson.current_source_dir())
27+
endif
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import taskr
2+
3+
REPETITIONS = 5
4+
ITERATIONS = 100
5+
6+
def abcTasks(runtime):
7+
# TODO: Setting onTaskFinish callback to free up task memory when it finishes (not sure if we will have this)
8+
# runtime.setTaskCallbackHandler(HiCR::tasking::Task::callback_t::onTaskFinish, [&taskr](taskr::Task *task) { delete task; })
9+
# runtime.setTaskCallbackHandler(taskr.onTaskFinish, lambda task : del task)
10+
11+
# Create the taskr Tasks
12+
taskAfc = taskr.Function(lambda task : print(f"Task A {task.getLabel()}"))
13+
taskBfc = taskr.Function(lambda task : print(f"Task B {task.getLabel()}"))
14+
taskCfc = taskr.Function(lambda task : print(f"Task C {task.getLabel()}"))
15+
16+
# Initializing taskr
17+
runtime.initialize()
18+
19+
# Our connection with the previous iteration is the last task C, null in the first iteration
20+
prevTaskC = taskr.Task(0, taskCfc)
21+
22+
# Creating the execution units (functions that the tasks will run)
23+
for r in range(REPETITIONS):
24+
# Calculating the base task id for this repetition
25+
repetitionLabel = r * ITERATIONS * 3
26+
27+
for i in range(ITERATIONS):
28+
29+
taskA = taskr.Task(repetitionLabel + i * 3 + 0, taskAfc)
30+
taskB = taskr.Task(repetitionLabel + i * 3 + 1, taskBfc)
31+
taskC = taskr.Task(repetitionLabel + i * 3 + 2, taskCfc)
32+
33+
# Creating dependencies
34+
if i > 0: taskA.addDependency(prevTaskC)
35+
taskB.addDependency(taskA)
36+
taskC.addDependency(taskB)
37+
38+
# Adding to taskr runtime
39+
runtime.addTask(taskA)
40+
runtime.addTask(taskB)
41+
runtime.addTask(taskC)
42+
43+
# Refreshing previous task C
44+
prevTaskC = taskC
45+
46+
# Running taskr for the current repetition
47+
runtime.run()
48+
49+
# Waiting current repetition to end
50+
runtime.await_()
51+
52+
# Finalizing taskr
53+
runtime.finalize()

examples/abcTasks/python/main.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import taskr
2+
import abcTasks
3+
4+
def main():
5+
6+
# Initialize taskr with the wanted compute manager backend and number of PUs
7+
t = taskr.taskr(taskr.HiCRBackend.threading, 2)
8+
9+
# Get the runtime
10+
runtime = t.get_runtime()
11+
12+
# Running simple example
13+
abcTasks.abcTasks(runtime)
14+
15+
if __name__ == "__main__":
16+
main()

0 commit comments

Comments
 (0)