diff --git a/.github/workflows/master-test-workflow.yml b/.github/workflows/master-test-workflow.yml index 17e8b86..1116b42 100644 --- a/.github/workflows/master-test-workflow.yml +++ b/.github/workflows/master-test-workflow.yml @@ -42,6 +42,8 @@ jobs: - name: Build Pybind11 run: | + /usr/bin/python3 -m pip install --upgrade pip pytest + cd extern/pybind11 mkdir -p build cd build @@ -60,8 +62,6 @@ jobs: EOF echo "PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$(pwd)/mock_install/share/pkgconfig" >> $GITHUB_ENV - - export LD_PRELOAD=/usr/local/lib/libnosv.so - name: Setup run: source /home/hicr/.bashrc && meson setup build -Dbuildtype=debug -Db_coverage=true -DdistributedEngine=mpi -DbuildTests=true -DbuildExamples=true -DcompileWarningsAsErrors=true -DexecutionStateType=nosv,boost -DprocessingUnitType=nosv,pthreads -DbuildPyTaskR=true @@ -71,6 +71,8 @@ jobs: - name: Running tests and creating coverage report shell: bash + env: + LD_PRELOAD: /usr/local/lib/libnosv.so run: | echo "Running Tests..." source /home/hicr/.bashrc diff --git a/.github/workflows/pr-development-workflow.yml b/.github/workflows/pr-development-workflow.yml index b85252f..2c24a6d 100644 --- a/.github/workflows/pr-development-workflow.yml +++ b/.github/workflows/pr-development-workflow.yml @@ -272,6 +272,8 @@ jobs: - name: Build Pybind11 run: | + /usr/bin/python3 -m pip install --upgrade pip pytest + cd extern/pybind11 mkdir -p build cd build @@ -290,8 +292,6 @@ jobs: EOF echo "PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$(pwd)/mock_install/share/pkgconfig" >> $GITHUB_ENV - - export LD_PRELOAD=/usr/local/lib/libnosv.so - name: Setup run: source /home/hicr/.bashrc && meson setup build -Dbuildtype=debug -Db_coverage=true -DdistributedEngine=mpi -DbuildTests=true -DbuildExamples=true -DcompileWarningsAsErrors=true -DexecutionStateType=nosv,boost -DprocessingUnitType=nosv,pthreads -DbuildPyTaskR=true @@ -301,6 +301,8 @@ jobs: - name: Running tests and creating coverage report shell: bash + env: + LD_PRELOAD: /usr/local/lib/libnosv.so run: | echo "Running Tests..." source /home/hicr/.bashrc diff --git a/examples/abcTasks/python/abcTasks.py b/examples/abcTasks/python/abcTasks.py index ddecdf4..00aa1af 100644 --- a/examples/abcTasks/python/abcTasks.py +++ b/examples/abcTasks/python/abcTasks.py @@ -4,9 +4,6 @@ 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()}")) @@ -47,7 +44,7 @@ def abcTasks(runtime): runtime.run() # Waiting current repetition to end - runtime.await_() + runtime.wait() # Finalizing taskr runtime.finalize() \ No newline at end of file diff --git a/examples/abcTasks/python/main.py b/examples/abcTasks/python/main.py index f98711d..aab4cb3 100644 --- a/examples/abcTasks/python/main.py +++ b/examples/abcTasks/python/main.py @@ -4,13 +4,10 @@ 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() + t = taskr.create(backend="threading", num_workers=2) # Running simple example - abcTasks.abcTasks(runtime) + abcTasks.abcTasks(t) if __name__ == "__main__": main() \ No newline at end of file diff --git a/examples/conditionVariable/python/conditionVariableWait.py b/examples/conditionVariable/python/conditionVariableWait.py index 8a8e75f..0ed4fd1 100644 --- a/examples/conditionVariable/python/conditionVariableWait.py +++ b/examples/conditionVariable/python/conditionVariableWait.py @@ -68,7 +68,7 @@ def fc(task): runtime.run() # Waiting for task to finish - runtime.await_() + runtime.wait() # Finalizing taskr runtime.finalize() diff --git a/examples/conditionVariable/python/conditionVariableWaitCondition.py b/examples/conditionVariable/python/conditionVariableWaitCondition.py index 42e2c6a..a2dccb4 100644 --- a/examples/conditionVariable/python/conditionVariableWaitCondition.py +++ b/examples/conditionVariable/python/conditionVariableWaitCondition.py @@ -84,7 +84,7 @@ def fc(task): runtime.run() # Waiting for task to finish - runtime.await_() + runtime.wait() # Finalizing taskr runtime.finalize() diff --git a/examples/conditionVariable/python/conditionVariableWaitFor.py b/examples/conditionVariable/python/conditionVariableWaitFor.py index 7d4e118..e6ff425 100644 --- a/examples/conditionVariable/python/conditionVariableWaitFor.py +++ b/examples/conditionVariable/python/conditionVariableWaitFor.py @@ -97,7 +97,7 @@ def fc(task): runtime.run() # Waiting for task to finish - runtime.await_() + runtime.wait() # Finalizing taskr runtime.finalize() diff --git a/examples/conditionVariable/python/conditionVariableWaitForCondition.py b/examples/conditionVariable/python/conditionVariableWaitForCondition.py index 93b107b..296904e 100644 --- a/examples/conditionVariable/python/conditionVariableWaitForCondition.py +++ b/examples/conditionVariable/python/conditionVariableWaitForCondition.py @@ -130,7 +130,7 @@ def fc(task): runtime.run() # Waiting for task to finish - runtime.await_() + runtime.wait() # Finalizing taskr runtime.finalize() diff --git a/examples/conditionVariable/python/main.py b/examples/conditionVariable/python/main.py index cba7c78..88dbd81 100644 --- a/examples/conditionVariable/python/main.py +++ b/examples/conditionVariable/python/main.py @@ -26,12 +26,9 @@ def main(): # Initialize taskr with the wanted compute manager backend and number of PUs - t = taskr.taskr() + t = taskr.create() - # Get the runtime - runtime = t.get_runtime() - - runtime.setTaskCallbackHandler(taskr.TaskCallback.onTaskSuspend, lambda task : runtime.resumeTask(task)) + t.setTaskCallbackHandler(taskr.TaskCallback.onTaskSuspend, lambda task : t.resumeTask(task)) # Get the enviromnent variable for which function to call test_function_name = os.getenv('__TEST_FUNCTION_') @@ -40,11 +37,11 @@ def main(): test_function = globals()[test_function_name] # Call the function - test_function(runtime) + test_function(t) # Overwrite the onTaskSuspend fc to be None such that runtime no longer has - # a dependency to the previous fc and runtime can call the destructor - runtime.setTaskCallbackHandler(taskr.TaskCallback.onTaskSuspend, None) + # a dependency to the previous fc and can call the destructor + t.setTaskCallbackHandler(taskr.TaskCallback.onTaskSuspend, None) if __name__ == "__main__": diff --git a/examples/energySaver/python/energySaver.py b/examples/energySaver/python/energySaver.py index f404aa5..ef234fd 100644 --- a/examples/energySaver/python/energySaver.py +++ b/examples/energySaver/python/energySaver.py @@ -81,7 +81,7 @@ def energySaver(runtime, workTaskCount, secondsDelay, iterations): # Running taskr print("Starting (open 'htop' in another console to see the workers going to sleep during the long task)...\n") runtime.run() - runtime.await_() + runtime.wait() print("Finished.\n") # Finalizing taskr diff --git a/examples/energySaver/python/main.py b/examples/energySaver/python/main.py index c74f87c..94d25bf 100644 --- a/examples/energySaver/python/main.py +++ b/examples/energySaver/python/main.py @@ -30,13 +30,10 @@ def main(): print(sys.argv, workTaskCount, secondsDelay, iterations) # Initialize taskr with the wanted compute manager backend and number of PUs - t = taskr.taskr(taskr.HiCRBackend.threading) - - # Get the runtime - runtime = t.get_runtime() + t = taskr.create(backend="threading") # Running simple example - energySaver.energySaver(runtime, workTaskCount, secondsDelay, iterations) + energySaver.energySaver(t, workTaskCount, secondsDelay, iterations) if __name__ == "__main__": main() \ No newline at end of file diff --git a/examples/fibonacci/python/fibonacci.py b/examples/fibonacci/python/fibonacci.py index 1ef6175..b14e9a6 100644 --- a/examples/fibonacci/python/fibonacci.py +++ b/examples/fibonacci/python/fibonacci.py @@ -92,7 +92,7 @@ def Fc(task): # Running taskr startTime = time.time() runtime.run() - runtime.await_() + runtime.wait() endTime = time.time() computeTime = endTime - startTime diff --git a/examples/fibonacci/python/fibonacci_mutex.py b/examples/fibonacci/python/fibonacci_mutex.py index 024c39a..3bd0c5a 100644 --- a/examples/fibonacci/python/fibonacci_mutex.py +++ b/examples/fibonacci/python/fibonacci_mutex.py @@ -97,7 +97,7 @@ def Fc(task): # Running taskr startTime = time.time() runtime.run() - runtime.await_() + runtime.wait() endTime = time.time() computeTime = endTime - startTime diff --git a/examples/fibonacci/python/main.py b/examples/fibonacci/python/main.py index 4da0092..fc0cbb8 100644 --- a/examples/fibonacci/python/main.py +++ b/examples/fibonacci/python/main.py @@ -25,14 +25,11 @@ def main(): if len(sys.argv) > 1: initialValue = int(sys.argv[1]) # Initialize taskr with the wanted compute manager backend and number of PUs - t = taskr.taskr(taskr.HiCRBackend.nosv) - - # Get the runtime - runtime = t.get_runtime() + t = taskr.create() # Running Fibonacci example # result = fibonacci.fibonacciDriver(initialValue, runtime) - result = fibonacci_mutex.fibonacciDriver(initialValue, runtime) + result = fibonacci_mutex.fibonacciDriver(initialValue, t) # Printing result print(f"Fib({initialValue}) = {result}") diff --git a/examples/manyParallel/python/main.py b/examples/manyParallel/python/main.py index 92932be..b80361c 100644 --- a/examples/manyParallel/python/main.py +++ b/examples/manyParallel/python/main.py @@ -26,13 +26,10 @@ def main(): if len(sys.argv) > 2: branchCount = int(sys.argv[2]) # Initialize taskr with the wanted compute manager backend and number of PUs - t = taskr.taskr(taskr.HiCRBackend.threading) - - # Get the runtime - runtime = t.get_runtime() + t = taskr.create("threading") # Running simple example - manyParallel.manyParallel(runtime, taskCount, branchCount) + manyParallel.manyParallel(t, taskCount, branchCount) if __name__ == "__main__": main() \ No newline at end of file diff --git a/examples/manyParallel/python/manyParallel.py b/examples/manyParallel/python/manyParallel.py index 0b55372..2e50518 100644 --- a/examples/manyParallel/python/manyParallel.py +++ b/examples/manyParallel/python/manyParallel.py @@ -44,7 +44,7 @@ def manyParallel(runtime, branchCount, taskCount): # Running taskr for the current repetition startTime = time.time() runtime.run() - runtime.await_() + runtime.wait() endTime = time.time() computeTime = endTime - startTime print(f"Running Time: {computeTime:0.5f}s") diff --git a/examples/matmul/python/main.py b/examples/matmul/python/main.py index 88d987d..c1a558c 100644 --- a/examples/matmul/python/main.py +++ b/examples/matmul/python/main.py @@ -19,15 +19,12 @@ def main(): # Initialize taskr with the wanted compute manager backend and number of PUs - t = taskr.taskr(taskr.HiCRBackend.nosv, 2) - - # Get the runtime - runtime = t.get_runtime() + t = taskr.create(backend="nosv", num_workers=2) # Running matmul example - matmul_cpp_Driver(runtime) + matmul_cpp_Driver(t) - # matmul_numpy_Driver(runtime) + # matmul_numpy_Driver(t) if __name__ == "__main__": diff --git a/examples/matmul/python/matmul.py b/examples/matmul/python/matmul.py index cfdf2c3..de0aeeb 100644 --- a/examples/matmul/python/matmul.py +++ b/examples/matmul/python/matmul.py @@ -36,7 +36,7 @@ def matmul_cpp_Driver(runtime): runtime.run() # Waiting current repetition to end - runtime.await_() + runtime.wait() print(f"total time: {time.time() - t_start}") # Finalizing taskr @@ -76,7 +76,7 @@ def matmul_numpy(task): runtime.run() # Waiting current repetition to end - runtime.await_() + runtime.wait() print(f"total time: {time.time() - t_start}") # Finalizing taskr diff --git a/examples/multiJob/python/main.py b/examples/multiJob/python/main.py index a653ff6..9ee7dd0 100644 --- a/examples/multiJob/python/main.py +++ b/examples/multiJob/python/main.py @@ -22,26 +22,23 @@ def main(): # Initialize taskr with the wanted compute manager backend and number of PUs - t = taskr.taskr(taskr.HiCRBackend.threading) - - # Get the runtime - runtime = t.get_runtime() + t = taskr.create(backend="threading") # Running multiJob example - job1.job1(runtime) - job2.job2(runtime) + job1.job1(t) + job2.job2(t) # Initializing taskr - runtime.initialize() + t.initialize() # Running taskr for the current repetition - runtime.run() + t.run() # Waiting current repetition to end - runtime.await_() + t.wait() # Finalizing taskr - runtime.finalize() + t.finalize() if __name__ == "__main__": main() \ No newline at end of file diff --git a/examples/mutex/python/main.py b/examples/mutex/python/main.py index 6a7f00a..7dd17f4 100644 --- a/examples/mutex/python/main.py +++ b/examples/mutex/python/main.py @@ -20,13 +20,10 @@ def main(): # Initialize taskr with the wanted compute manager backend and number of PUs - t = taskr.taskr(taskr.HiCRBackend.threading) - - # Get the runtime - runtime = t.get_runtime() + t = taskr.create("threading") # Running mutex example - mutex.mutex(runtime) + mutex.mutex(t) if __name__ == "__main__": main() \ No newline at end of file diff --git a/examples/mutex/python/mutex.py b/examples/mutex/python/mutex.py index f6d9539..bb776a3 100644 --- a/examples/mutex/python/mutex.py +++ b/examples/mutex/python/mutex.py @@ -52,7 +52,7 @@ def fc(task): runtime.run() # Waiting current repetition to end - runtime.await_() + runtime.wait() # Finalizing taskr runtime.finalize() diff --git a/examples/pendingOperation/python/main.py b/examples/pendingOperation/python/main.py index 10fd765..76deb28 100644 --- a/examples/pendingOperation/python/main.py +++ b/examples/pendingOperation/python/main.py @@ -20,13 +20,10 @@ def main(): # Initialize taskr with the wanted compute manager backend and number of PUs - t = taskr.taskr(taskr.HiCRBackend.nosv) - - # Get the runtime - runtime = t.get_runtime() + t = taskr.create() # Running pendingOperation example - pendingOperation.pendingOperation(runtime) + pendingOperation.pendingOperation(t) if __name__ == "__main__": main() \ No newline at end of file diff --git a/examples/pendingOperation/python/pendingOperation.py b/examples/pendingOperation/python/pendingOperation.py index 81208a0..d218bfe 100644 --- a/examples/pendingOperation/python/pendingOperation.py +++ b/examples/pendingOperation/python/pendingOperation.py @@ -73,7 +73,7 @@ def pendingOperation(runtime): runtime.run() # Waiting current repetition to end - runtime.await_() + runtime.wait() # Finalizing taskr runtime.finalize() diff --git a/examples/resourceList/python/main.py b/examples/resourceList/python/main.py index bca700c..a73a5a0 100644 --- a/examples/resourceList/python/main.py +++ b/examples/resourceList/python/main.py @@ -25,9 +25,6 @@ def main(): if len(sys.argv) > 1: workTaskCount = int(sys.argv[1]) if len(sys.argv) > 2: iterations = int(sys.argv[2]) - - - # Getting the core subset from the argument list (could be from a file too) coreSubset = {0, 1, 2, 3} if len(sys.argv) > 3: @@ -41,10 +38,7 @@ def main(): sys.exit(1) # Initialize taskr with the wanted compute manager backend and number of PUs - t = taskr.taskr(taskr.HiCRBackend.threading, coreSubset) - - # Get the runtime - runtime = t.get_runtime() + t = taskr.create("threading", coreSubset) # Creating task function taskFunction = taskr.Function(lambda task : workTask.work(iterations)) @@ -53,22 +47,22 @@ def main(): print(f"Running {workTaskCount} work tasks with {len(coreSubset)} processing units...") for i in range(workTaskCount): task = taskr.Task(i, taskFunction) - runtime.addTask(task) + t.addTask(task) # Initializing taskR - runtime.initialize() + t.initialize() # Running taskr only on the core subset t0 = time.time() - runtime.run() - runtime.await_() + t.run() + t.wait() tf = time.time() dt = tf - t0 print(f"Finished in {dt:.3} seconds.") # Finalizing taskR - runtime.finalize() + t.finalize() if __name__ == "__main__": main() \ No newline at end of file diff --git a/examples/simple/python/main.py b/examples/simple/python/main.py index 696f2ec..f874142 100644 --- a/examples/simple/python/main.py +++ b/examples/simple/python/main.py @@ -17,17 +17,12 @@ import simple -NWORKERS = 4 - def main(): # Initialize taskr with the wanted HiCR backend and number of Workers - t = taskr.taskr(backend=taskr.HiCRBackend.nosv, num_workers=NWORKERS) - - # Get the runtime - runtime = t.get_runtime() + t = taskr.create(backend="nosv", num_workers=4) # Running simple example - simple.simple(runtime) + simple.simple(t) if __name__ == "__main__": main() \ No newline at end of file diff --git a/examples/simple/python/simple.py b/examples/simple/python/simple.py index 84f283a..a69e605 100644 --- a/examples/simple/python/simple.py +++ b/examples/simple/python/simple.py @@ -33,7 +33,7 @@ def simple(runtime): runtime.run() # Waiting current repetition to end - runtime.await_() + runtime.wait() # Finalizing taskr runtime.finalize() \ No newline at end of file diff --git a/examples/suspend/python/main.py b/examples/suspend/python/main.py index aed145d..8f0b2fa 100644 --- a/examples/suspend/python/main.py +++ b/examples/suspend/python/main.py @@ -27,13 +27,10 @@ def main(): if len(sys.argv) > 2: branchCount = int(sys.argv[2]) # Initialize taskr with the wanted compute manager backend and number of PUs - t = taskr.taskr(taskr.HiCRBackend.nosv) - - # Get the runtime - runtime = t.get_runtime() + t = taskr.create() # Running simple example - suspend.suspend(runtime, branchCount, taskCount) + suspend.suspend(t, branchCount, taskCount) if __name__ == "__main__": main() \ No newline at end of file diff --git a/examples/suspend/python/suspend.py b/examples/suspend/python/suspend.py index dd50854..72df5a4 100644 --- a/examples/suspend/python/suspend.py +++ b/examples/suspend/python/suspend.py @@ -51,7 +51,7 @@ def fc(task): # Running taskr for the current repetition startTime = time.time() runtime.run() - runtime.await_() + runtime.wait() endTime = time.time() computeTime = endTime - startTime diff --git a/examples/workerSpecific/python/main.py b/examples/workerSpecific/python/main.py index 9c53839..0aa201f 100644 --- a/examples/workerSpecific/python/main.py +++ b/examples/workerSpecific/python/main.py @@ -20,15 +20,12 @@ def main(): # Initialize taskr with the wanted compute manager backend and number of PUs - t = taskr.taskr() - - # Get the runtime - runtime = t.get_runtime() + t = taskr.create() num_workers = t.get_num_workers() # Running workerSpecific example - workerSpecific.workerSpecific(runtime, num_workers) + workerSpecific.workerSpecific(t, num_workers) if __name__ == "__main__": main() \ No newline at end of file diff --git a/examples/workerSpecific/python/workerSpecific.py b/examples/workerSpecific/python/workerSpecific.py index 6513640..4ecce9c 100644 --- a/examples/workerSpecific/python/workerSpecific.py +++ b/examples/workerSpecific/python/workerSpecific.py @@ -70,7 +70,7 @@ def workerSpecific(runtime, workerCount): runtime.run() # Waiting for taskr to finish - runtime.await_() + runtime.wait() # Finalizing taskr runtime.finalize() diff --git a/include/pytaskr/meson.build b/include/pytaskr/meson.build index eefc64c..ae3a3b9 100644 --- a/include/pytaskr/meson.build +++ b/include/pytaskr/meson.build @@ -12,8 +12,12 @@ endif pybind11_dep = dependency('pybind11', required: true) +message('Python binary: ' + py.path()) +message('Python install dir: ' + py.get_install_dir()) + py.extension_module('taskr', ['pytaskr.cpp'], install: true, + install_dir: py.get_install_dir(), dependencies : [TaskRBuildDep, pybind11_dep], ) \ No newline at end of file diff --git a/include/pytaskr/pyruntime.hpp b/include/pytaskr/pyruntime.hpp index 42b7d13..e1d81b8 100644 --- a/include/pytaskr/pyruntime.hpp +++ b/include/pytaskr/pyruntime.hpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -34,19 +35,6 @@ namespace taskr { -enum backend_t -{ - /** - * HiCR's nOS-V backend with the executionStates and ProcessingUnits being nOS-V - */ - nosv, - - /** - * executionStates are Boost and ProcessingUnits are Pthreads - */ - threading -}; - /** * TaskR Runtime class python wrapper. It simplifies the user for constructing the TaskR Runtime */ @@ -57,11 +45,11 @@ class PyRuntime /** * Constructor with num_workers being an interger value. If 0, initialize all. */ - PyRuntime(const backend_t &backend_type = backend_t::nosv, size_t num_workers = 0) + PyRuntime(const std::string &backend_type = "nosv", size_t num_workers = 0) : _backend_type(backend_type) { // Specify the compute Managers - if (_backend_type == backend_t::nosv) + if (_backend_type == "nosv") { // Initialize nosv check(nosv_init()); @@ -75,12 +63,12 @@ class PyRuntime _executionStateComputeManager = std::make_unique(); _processingUnitComputeManager = std::make_unique(); } - else if (_backend_type == backend_t::threading) + else if (_backend_type == "threading") { _executionStateComputeManager = std::make_unique(); _processingUnitComputeManager = std::make_unique(); } - else { HICR_THROW_LOGIC("'%d' is not a known HiCR backend. Try 'nosv' or 'threading'\n", _backend_type); } + else { HICR_THROW_LOGIC("'%s' is not a known HiCR backend. Try 'nosv' or 'threading'\n", _backend_type); } // Reserving memory for hwloc hwloc_topology_init(&_topology); @@ -117,14 +105,14 @@ class PyRuntime /** * Constructor with num_workers being a set of integers. The set specifies which process affinity to use (if available). */ - PyRuntime(const backend_t &backend_type, const std::set &workersSet) + PyRuntime(const std::string &backend_type, const std::set &workersSet) : _backend_type(backend_type) { // Check if the workerSet is not empty if (workersSet.empty()) { HICR_THROW_LOGIC("Error: no compute resources provided\n"); } // Specify the compute Managers - if (_backend_type == backend_t::nosv) + if (_backend_type == "nosv") { // Initialize nosv check(nosv_init()); @@ -138,12 +126,12 @@ class PyRuntime _executionStateComputeManager = std::make_unique(); _processingUnitComputeManager = std::make_unique(); } - else if (_backend_type == backend_t::threading) + else if (_backend_type == "threading") { _executionStateComputeManager = std::make_unique(); _processingUnitComputeManager = std::make_unique(); } - else { HICR_THROW_LOGIC("'%d' is not a known HiCR backend. Try 'nosv' or 'threading'\n", _backend_type); } + else { HICR_THROW_LOGIC("'%s' is not a known HiCR backend. Try 'nosv' or 'threading'\n", _backend_type); } // Reserving memory for hwloc hwloc_topology_init(&_topology); @@ -189,7 +177,7 @@ class PyRuntime // Freeing up memory hwloc_topology_destroy(_topology); - if (_backend_type == backend_t::nosv) + if (_backend_type == "nosv") { // Detaching the main thread check(nosv_detach(NOSV_DETACH_NONE)); @@ -199,13 +187,83 @@ class PyRuntime } } + /** + * + */ Runtime &get_runtime() { return *_runtime; } + /** + * + */ const size_t get_num_workers() { return _num_workers; } + /** + * + */ + __INLINE__ void setTaskCallbackHandler(const HiCR::tasking::Task::callback_t event, HiCR::tasking::callbackFc_t fc) + { + _runtime->setTaskCallbackHandler(event, fc); + } + + /** + * + */ + __INLINE__ void setServiceWorkerCallbackHandler(const HiCR::tasking::Worker::callback_t event, HiCR::tasking::callbackFc_t fc) + { + _runtime->setServiceWorkerCallbackHandler(event, fc); + } + + /** + * + */ + __INLINE__ void setTaskWorkerCallbackHandler(const HiCR::tasking::Worker::callback_t event, HiCR::tasking::callbackFc_t fc) + { + _runtime->setTaskWorkerCallbackHandler(event, fc); + } + + /** + * + */ + __INLINE__ void addTask(taskr::Task *const task) { _runtime->addTask(task); } + + /** + * + */ + __INLINE__ void resumeTask(taskr::Task *const task) { _runtime->resumeTask(task); } + + /** + * + */ + __INLINE__ void initialize() { _runtime->initialize(); } + + /** + * + */ + __INLINE__ void run() { _runtime->run(); } + + /** + * + */ + __INLINE__ void await() { _runtime->await(); } + + /** + * + */ + __INLINE__ void finalize() { _runtime->finalize(); } + + /** + * + */ + __INLINE__ void setFinishedTask(taskr::Task *const task) { _runtime->setFinishedTask(task); } + + /** + * + */ + __INLINE__ void addService(taskr::service_t *service) { _runtime->addService(service); } + private: - backend_t _backend_type; + std::string _backend_type; size_t _num_workers; diff --git a/include/pytaskr/pytaskr.cpp b/include/pytaskr/pytaskr.cpp index cd229c5..fe00f1e 100644 --- a/include/pytaskr/pytaskr.cpp +++ b/include/pytaskr/pytaskr.cpp @@ -33,28 +33,22 @@ PYBIND11_MODULE(taskr, m) { m.doc() = "pybind11 plugin for TaskR"; - py::enum_(m, "HiCRBackend").value("nosv", backend_t::nosv).value("threading", backend_t::threading).export_values(); - - // pyTaskR's PyRuntime class - py::class_(m, "taskr") - .def(py::init(), py::arg("backend") = backend_t::nosv, py::arg("num_workers") = 0) - .def(py::init &>(), py::arg("backend") = backend_t::nosv, py::arg("workersSet")) - .def("get_runtime", &PyRuntime::get_runtime, py::return_value_policy::reference_internal) - .def("get_num_workers", &PyRuntime::get_num_workers); - - // TaskR's Runtime class - py::class_(m, "Runtime") - .def("setTaskCallbackHandler", &Runtime::setTaskCallbackHandler) - .def("setServiceWorkerCallbackHandler", &Runtime::setServiceWorkerCallbackHandler) - .def("setTaskWorkerCallbackHandler", &Runtime::setTaskWorkerCallbackHandler) - .def("initialize", &Runtime::initialize) - .def("addTask", &Runtime::addTask, py::keep_alive<1, 2>(), py::arg("task")) // keep_alive as the task should be alive until runtime's destructor - .def("resumeTask", &Runtime::resumeTask) - .def("run", &Runtime::run, py::call_guard()) - .def("await_", &Runtime::await, py::call_guard()) // Release GIL is important otherwise non-finished tasks are getting blocked - .def("finalize", &Runtime::finalize) - .def("setFinishedTask", &Runtime::setFinishedTask) - .def("addService", &Runtime::addService); + // pyTaskR's PyRuntime class (Wrapper class for the TaskR Runtime) + py::class_(m, "create") + .def(py::init(), py::arg("backend") = "nosv", py::arg("num_workers") = 0) + .def(py::init &>(), py::arg("backend") = "nosv", py::arg("workersSet")) + .def("get_num_workers", &PyRuntime::get_num_workers) + .def("setTaskCallbackHandler", &PyRuntime::setTaskCallbackHandler) + .def("setServiceWorkerCallbackHandler", &PyRuntime::setServiceWorkerCallbackHandler) + .def("setTaskWorkerCallbackHandler", &PyRuntime::setTaskWorkerCallbackHandler) + .def("addTask", &PyRuntime::addTask, py::keep_alive<1, 2>(), py::arg("task")) // keep_alive as the task should be alive until runtime's destructor + .def("resumeTask", &PyRuntime::resumeTask) + .def("initialize", &PyRuntime::initialize) + .def("run", &PyRuntime::run, py::call_guard()) + .def("wait", &PyRuntime::await, py::call_guard()) // Release GIL is important otherwise non-finished tasks are getting blocked + .def("finalize", &PyRuntime::finalize) + .def("setFinishedTask", &PyRuntime::setFinishedTask) + .def("addService", &PyRuntime::addService); // TaskR's Function class py::class_(m, "Function").def(py::init(), py::arg("fc")); @@ -62,7 +56,7 @@ PYBIND11_MODULE(taskr, m) // TaskR's Task class py::class_(m, "Task") .def(py::init(), py::arg("fc"), py::arg("workerAffinity") = -1) - .def(py::init(), py::arg("label"), py::arg("taskfc"), py::arg("workerAffinity") = -1) + .def(py::init(), py::arg("ID"), py::arg("taskfc"), py::arg("workerAffinity") = -1) .def("getLabel", &Task::getLabel) .def("setLabel", &Task::setLabel) .def("getWorkerAffinity", &Task::getWorkerAffinity) diff --git a/tests/pyruntime_test.cpp b/tests/pyruntime_test.cpp index 52664a7..5314e32 100644 --- a/tests/pyruntime_test.cpp +++ b/tests/pyruntime_test.cpp @@ -20,13 +20,10 @@ int main(int argc, char **argv) { // Creating taskr instance - taskr::PyRuntime pytaskr(taskr::backend_t::nosv, 0); - - // Getting the runtime - taskr::Runtime &runtime = pytaskr.get_runtime(); + taskr::PyRuntime pytaskr("nosv", 0); // Printing runtime - printf("I got the runtime with nOS-V backend: %p\n", &runtime); + printf("I got the runtime with nOS-V backend: %p and num_workers: %ld\n", &pytaskr, pytaskr.get_num_workers()); return 0; }