Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8e7045f
adding pybind11 as an extern libary
noabauma May 16, 2025
9593187
adding meson stuff for pybind11
noabauma May 19, 2025
fbfea43
creating a PyRuntime wrapper class for pybind11
noabauma May 22, 2025
b2f5bef
naming the whole thing pyTaskR and minor code improvements
noabauma May 22, 2025
b3626ae
adding first little example in 'simple'
noabauma May 23, 2025
c785535
PyRuntime and Runtime working, now it is up to the Task class to be p…
noabauma May 26, 2025
5e5c44c
finally working, now, more tests and more methods
noabauma May 28, 2025
41064a8
Merge branch 'main' into python_API
noabauma Jun 2, 2025
942e08a
updating the extern submodules and adding ABC example
noabauma Jun 2, 2025
e1d6231
suspend works (if only one task, now it should work for multiple tasks)!
noabauma Jun 4, 2025
edd528f
added conditionVariable example (xxWaitCondition works atm)
noabauma Jun 5, 2025
66d3440
example energySaver and Fibonacci included. Fib(n>3) fails.
noabauma Jun 6, 2025
2411cf9
created more examples
noabauma Jun 10, 2025
6006f03
adding some working examples
noabauma Jun 12, 2025
9ef9c21
minor correction on some examples
noabauma Jun 12, 2025
5f81826
all the current examples work if nosv is used
noabauma Jun 12, 2025
b2ea6b5
fibonacci also with mutex.lock?
noabauma Jun 13, 2025
eed0423
redundant python path removed
noabauma Jun 13, 2025
eb4fcd9
Merge branch 'main' into python_API
noabauma Jun 13, 2025
4c70dc6
merging main
noabauma Jun 13, 2025
8747407
fixing code style
noabauma Jun 13, 2025
eca1824
adding enumerate method for choosing backend
noabauma Jun 17, 2025
b4e038e
adding a method to add your own cpp functions to be executed over pyt…
noabauma Jun 23, 2025
e6c56b1
fixing style
noabauma Jun 23, 2025
bcad9f6
removing redundant code
noabauma Jun 23, 2025
75091e8
code documentation and binding more TaskR methods
noabauma Jun 24, 2025
c6f298c
renamed a lot of files and minor corrections (all from the first review)
noabauma Jul 2, 2025
f1f7a25
old approach of adding a cpp function
noabauma Jul 2, 2025
a6af873
remaking the binding now. Now, the user has to create his own pybind
noabauma Jul 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ build
.vscode
atlas_*.sh
**/matrix/
**/__pycache__/
**/ovni/
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ build:
- source /home/hicr/.hicr-env.sh
- echo "Building TaskR..."
- mkdir build
- meson setup build -Dbuildtype=debug -Db_coverage=true -DbuildTests=true -DbuildExamples=true -DdistributedEngine=mpi -DexecutionStateType=boost,nosv -DprocessingUnitType=pthreads,nosv -DbuildInstrumentation=true -DcompileWarningsAsErrors=true
- 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
- meson compile -C build
- echo "Running tests..."
- meson test -C build
Expand Down
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@
path = extern/hicr
url = https://github.com/Algebraic-Programming/HiCR.git
branch = master
[submodule "extern/pybind11"]
path = extern/pybind11
url = https://github.com/pybind/pybind11.git
branch = stable
File renamed without changes.
File renamed without changes.
27 changes: 27 additions & 0 deletions examples/abcTasks/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
testSuite = [ 'examples', 'abcTasks' ]

if 'boost' in get_option('executionStateType') and 'pthreads' in get_option('processingUnitType')
threading = executable('threading', [ 'cpp/pthreads.cpp'], dependencies: [ TaskRBuildDep ])

if get_option('buildTests')
test('threading', threading, args : [ ], suite: testSuite, workdir: threading.path() + '.p' )
endif
endif

if 'nosv' in get_option('executionStateType') and 'nosv' in get_option('processingUnitType')
nosv = executable('nosv', [ 'cpp/nosv.cpp'], dependencies: [ TaskRBuildDep ])

if get_option('buildTests')
test('nosv', nosv, args : [ ], is_parallel : false, suite: testSuite, workdir: nosv.path() + '.p')
endif
endif

if get_option('buildPyTaskR') and get_option('buildTests')
test('pyTaskR',
py,
args : [ 'python/main.py' ],
is_parallel : false,
env: ['PYTHONPATH=' + meson.project_build_root() + '/include/pytaskr/'],
suite: testSuite,
workdir: meson.current_source_dir())
endif
53 changes: 53 additions & 0 deletions examples/abcTasks/python/abcTasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import taskr

REPETITIONS = 5
ITERATIONS = 100

def abcTasks(runtime):
# TODO: Setting onTaskFinish callback to free up task memory when it finishes (not sure if we will have this)
# runtime.setTaskCallbackHandler(HiCR::tasking::Task::callback_t::onTaskFinish, [&taskr](taskr::Task *task) { delete task; })
# runtime.setTaskCallbackHandler(taskr.onTaskFinish, lambda task : del task)

# Create the taskr Tasks
taskAfc = taskr.Function(lambda task : print(f"Task A {task.getLabel()}"))
taskBfc = taskr.Function(lambda task : print(f"Task B {task.getLabel()}"))
taskCfc = taskr.Function(lambda task : print(f"Task C {task.getLabel()}"))

# Initializing taskr
runtime.initialize()

# Our connection with the previous iteration is the last task C, null in the first iteration
prevTaskC = taskr.Task(0, taskCfc)

# Creating the execution units (functions that the tasks will run)
for r in range(REPETITIONS):
# Calculating the base task id for this repetition
repetitionLabel = r * ITERATIONS * 3

for i in range(ITERATIONS):

taskA = taskr.Task(repetitionLabel + i * 3 + 0, taskAfc)
taskB = taskr.Task(repetitionLabel + i * 3 + 1, taskBfc)
taskC = taskr.Task(repetitionLabel + i * 3 + 2, taskCfc)

# Creating dependencies
if i > 0: taskA.addDependency(prevTaskC)
taskB.addDependency(taskA)
taskC.addDependency(taskB)

# Adding to taskr runtime
runtime.addTask(taskA)
runtime.addTask(taskB)
runtime.addTask(taskC)

# Refreshing previous task C
prevTaskC = taskC

# Running taskr for the current repetition
runtime.run()

# Waiting current repetition to end
runtime.await_()

# Finalizing taskr
runtime.finalize()
16 changes: 16 additions & 0 deletions examples/abcTasks/python/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import taskr
import abcTasks

def main():

# Initialize taskr with the wanted compute manager backend and number of PUs
t = taskr.taskr(taskr.HiCRBackend.threading, 2)

# Get the runtime
runtime = t.get_runtime()

# Running simple example
abcTasks.abcTasks(runtime)

if __name__ == "__main__":
main()
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
testSuite = [ 'examples', 'local', 'cholesky' ]
testSuite = [ 'examples', 'cholesky' ]

choleskyDep = declare_dependency(
dependencies: [ TaskRBuildDep, dependency('openblas', required: true) ],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
testSuite = [ 'examples', 'local' ]
testSuite = [ 'examples' ]

choleskyompssDep = declare_dependency(
compile_args: ['-fompss-2'],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
testSuite = [ 'examples', 'local' ]
testSuite = [ 'examples' ]

choleskySequentialDep = declare_dependency(
dependencies: [ choleskyDep, dependency('openmp', required: true)]
Expand Down
File renamed without changes.
63 changes: 63 additions & 0 deletions examples/conditionVariable/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
testSuite = [ 'examples', 'conditionVariable' ]

if 'boost' in get_option('executionStateType') and 'pthreads' in get_option('processingUnitType')
threading_conditionVariableWait = executable('threading_conditionVariableWait', [ 'cpp/pthreads.cpp'], dependencies: [ TaskRBuildDep ], cpp_args: [ '-D__TEST_FUNCTION_=conditionVariableWait'] )
threading_conditionVariableWaitFor = executable('threading_conditionVariableWaitFor', [ 'cpp/pthreads.cpp'], dependencies: [ TaskRBuildDep ], cpp_args: [ '-D__TEST_FUNCTION_=conditionVariableWaitFor'] )
threading_conditionVariableWaitCondition = executable('threading_conditionVariableWaitCondition', [ 'cpp/pthreads.cpp'], dependencies: [ TaskRBuildDep ], cpp_args: [ '-D__TEST_FUNCTION_=conditionVariableWaitCondition'] )
threading_conditionVariableWaitForCondition = executable('threading_conditionVariableWaitForCondition', [ 'cpp/pthreads.cpp'], dependencies: [ TaskRBuildDep ], cpp_args: [ '-D__TEST_FUNCTION_=conditionVariableWaitForCondition'] )

if get_option('buildTests')
test('threading_conditionVariableWait', threading_conditionVariableWait, args : [ ], suite: testSuite, workdir: threading_conditionVariableWait.path() + '.p' )
test('threading_conditionVariableWaitFor', threading_conditionVariableWaitFor, args : [ ], suite: testSuite, workdir: threading_conditionVariableWaitFor.path() + '.p' )
test('threading_conditionVariableWaitCondition', threading_conditionVariableWaitCondition, args : [ ], suite: testSuite, workdir: threading_conditionVariableWaitCondition.path() + '.p' )
test('threading_conditionVariableWaitForCondition', threading_conditionVariableWaitForCondition, args : [ ], suite: testSuite, workdir: threading_conditionVariableWaitForCondition.path() + '.p' )
endif
endif

if 'nosv' in get_option('executionStateType') and 'nosv' in get_option('processingUnitType')
nosv_conditionVariableWait = executable('nosv_conditionVariableWait', [ 'cpp/nosv.cpp'], dependencies: [ TaskRBuildDep ], cpp_args: [ '-D__TEST_FUNCTION_=conditionVariableWait'] )
nosv_conditionVariableWaitFor = executable('nosv_conditionVariableWaitFor', [ 'cpp/nosv.cpp'], dependencies: [ TaskRBuildDep ], cpp_args: [ '-D__TEST_FUNCTION_=conditionVariableWaitFor'] )
nosv_conditionVariableWaitCondition = executable('nosv_conditionVariableWaitCondition', [ 'cpp/nosv.cpp'], dependencies: [ TaskRBuildDep ], cpp_args: [ '-D__TEST_FUNCTION_=conditionVariableWaitCondition'] )
nosv_conditionVariableWaitForCondition = executable('nosv_conditionVariableWaitForCondition', [ 'cpp/nosv.cpp'], dependencies: [ TaskRBuildDep ], cpp_args: [ '-D__TEST_FUNCTION_=conditionVariableWaitForCondition'] )

if get_option('buildTests')
test('nosv_conditionVariableWait', nosv_conditionVariableWait, args : [ ], is_parallel : false, suite: testSuite, workdir: nosv_conditionVariableWait.path() + '.p' )
test('nosv_conditionVariableWaitFor', nosv_conditionVariableWaitFor, args : [ ], is_parallel : false, suite: testSuite, workdir: nosv_conditionVariableWaitFor.path() + '.p' )
test('nosv_conditionVariableWaitCondition', nosv_conditionVariableWaitCondition, args : [ ], is_parallel : false, suite: testSuite, workdir: nosv_conditionVariableWaitCondition.path() + '.p' )
test('nosv_conditionVariableWaitForCondition', nosv_conditionVariableWaitForCondition, args : [ ], is_parallel : false, suite: testSuite, workdir: nosv_conditionVariableWaitForCondition.path() + '.p' )
endif
endif

if get_option('buildPyTaskR') and get_option('buildTests')
test('pyTaskR_conditionVariableWait',
py,
args : [ 'python/main.py' ],
is_parallel : false,
env: ['PYTHONPATH=' + meson.project_build_root() + '/include/pytaskr/', '__TEST_FUNCTION_=conditionVariableWait'],
suite: testSuite,
workdir: meson.current_source_dir())

test('pyTaskR_conditionVariableWaitFor',
py,
args : [ 'python/main.py' ],
is_parallel : false,
env: ['PYTHONPATH=' + meson.project_build_root() + '/include/pytaskr/', '__TEST_FUNCTION_=conditionVariableWaitFor'],
suite: testSuite,
workdir: meson.current_source_dir())

test('pyTaskR_conditionVariableWaitCondition',
py,
args : [ 'python/main.py' ],
is_parallel : false,
env: ['PYTHONPATH=' + meson.project_build_root() + '/include/pytaskr/', '__TEST_FUNCTION_=conditionVariableWaitCondition'],
suite: testSuite,
workdir: meson.current_source_dir())

test('pyTaskR_conditionVariableWaitForCondition',
py,
args : [ 'python/main.py' ],
is_parallel : false,
env: ['PYTHONPATH=' + meson.project_build_root() + '/include/pytaskr/', '__TEST_FUNCTION_=conditionVariableWaitForCondition'],
suite: testSuite,
workdir: meson.current_source_dir())
endif
74 changes: 74 additions & 0 deletions examples/conditionVariable/python/conditionVariableWait.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"""
Copyright 2025 Huawei Technologies Co., Ltd.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

import taskr

def conditionVariableWait(runtime):
# Contention value
value = 0

# Mutex for the condition variable
mutex = taskr.Mutex()

# Task-aware conditional variable
cv = taskr.ConditionVariable()

def fc(task):
nonlocal value

# Waiting for the other task's notification
print("Thread 1: I wait for a notification")
mutex.lock(task)
print("before cv.wait(task, mutex)", flush=True)
cv.wait(task, mutex)
print("after cv.wait(task, mutex)", flush=True)
mutex.unlock(task)
value = 1
print("Thread 1: I have been notified")

# Creating task functions
waitFc = taskr.Function(fc)

def fc(task):
nonlocal value

# Notifying the other task
print("Thread 2: Notifying anybody interested")
while value != 1:
cv.notifyOne(task)
print("cv.notifyOne(task)", flush=True)
task.suspend()
print("task.suspend()", flush=True)

notifyFc = taskr.Function(fc)

task1 = taskr.Task(0, waitFc)
task2 = taskr.Task(1, notifyFc)

runtime.addTask(task1)
runtime.addTask(task2)

# Initializing taskr
runtime.initialize()

# Running taskr
runtime.run()

# Waiting for task to finish
runtime.await_()

# Finalizing taskr
runtime.finalize()
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
"""
Copyright 2025 Huawei Technologies Co., Ltd.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

import taskr

def conditionVariableWaitCondition(runtime):
# Contention value
value = 0

# Mutex for the condition variable
mutex = taskr.Mutex()

# Task-aware conditional variable
cv = taskr.ConditionVariable()

def fc(task):
nonlocal value
# Using lock to update the value
print("Thread 1: I go first and set value to 1")
mutex.lock(task)
value += 1
mutex.unlock(task)

# Notifiying the other thread
print("Thread 1: Now I notify anybody waiting")
while value != 1:
cv.notifyOne(task)
task.suspend()

# Waiting for the other thread's update now
print("Thread 1: I wait for the value to turn 2")
mutex.lock(task)
cv.wait(task, mutex, lambda: value == 2)
mutex.unlock(task)
print("Thread 1: The condition (value == 2) is satisfied now")

# Creating task functions
thread1Fc = taskr.Function(fc)

def fc(task):
nonlocal value
# Waiting for the other thread to set the first value
print("Thread 2: First, I'll wait for the value to become 1")
mutex.lock(task)
cv.wait(task, mutex, lambda: value == 1)
mutex.unlock(task)
print("Thread 2: The condition (value == 1) is satisfied now")

# Now updating the value ourselves
print("Thread 2: Now I update the value to 2")
mutex.lock(task)
value += 1
mutex.unlock(task)

# Notifying the other thread
print("Thread 2: Notifying anybody interested")
cv.notifyOne(task)

thread2Fc = taskr.Function(fc)

task1 = taskr.Task(0, thread1Fc)
task2 = taskr.Task(1, thread2Fc)

runtime.addTask(task1)
runtime.addTask(task2)

# Initializing taskr
runtime.initialize()

# Running taskr
runtime.run()

# Waiting for task to finish
runtime.await_()

# Finalizing taskr
runtime.finalize()

# Value should be equal to concurrent task count
expectedValue = 2
print(f"Value {value} / Expected {expectedValue}")

assert value == expectedValue
Loading