From f9ce4d046b6db527688ae6d60c6dda1be6f16476 Mon Sep 17 00:00:00 2001 From: Antoniu Pop Date: Thu, 4 Aug 2022 13:45:08 +0100 Subject: [PATCH] fix(testing-dfr): fix startup and ternimation call parameters to allow sequential test execution on root node when the runtime is instantiated for distributed execution. --- .../concretelang/Runtime/runtime_api.h | 6 +-- .../RT/Analysis/LowerDataflowTasksToRT.cpp | 19 +++++++--- compiler/lib/Runtime/DFRuntime.cpp | 38 ++++++++++--------- 3 files changed, 36 insertions(+), 27 deletions(-) diff --git a/compiler/include/concretelang/Runtime/runtime_api.h b/compiler/include/concretelang/Runtime/runtime_api.h index a3ed68a65..4c1d2d6fd 100644 --- a/compiler/include/concretelang/Runtime/runtime_api.h +++ b/compiler/include/concretelang/Runtime/runtime_api.h @@ -26,9 +26,9 @@ void _dfr_deallocate_future(void *); void _dfr_deallocate_future_data(void *); /* Initialisation & termination. */ -void _dfr_start_c(void *); -void _dfr_start(int); -void _dfr_stop(int); +void _dfr_start_c(int64_t, void *); +void _dfr_start(int64_t); +void _dfr_stop(int64_t); void _dfr_terminate(); } diff --git a/compiler/lib/Dialect/RT/Analysis/LowerDataflowTasksToRT.cpp b/compiler/lib/Dialect/RT/Analysis/LowerDataflowTasksToRT.cpp index d478ddacc..126da23f6 100644 --- a/compiler/lib/Dialect/RT/Analysis/LowerDataflowTasksToRT.cpp +++ b/compiler/lib/Dialect/RT/Analysis/LowerDataflowTasksToRT.cpp @@ -468,14 +468,21 @@ struct LowerDataflowTasksPass (dfr::_dfr_is_root_node()) ? mlir::FunctionType::get( entryPoint->getContext(), - {entryPoint.getArgument(ctxIndex).getType()}, {}) - : mlir::FunctionType::get(entryPoint->getContext(), {}, {}); + {useDFRVal.getType(), + entryPoint.getArgument(ctxIndex).getType()}, + {}) + : mlir::FunctionType::get(entryPoint->getContext(), + {useDFRVal.getType()}, {}); (void)insertForwardDeclaration(entryPoint, builder, "_dfr_start_c", startFunTy); - builder.create( - entryPoint.getLoc(), "_dfr_start_c", mlir::TypeRange(), - (dfr::_dfr_is_root_node()) ? entryPoint.getArgument(ctxIndex) - : mlir::ValueRange()); + (dfr::_dfr_is_root_node()) + ? builder.create( + entryPoint.getLoc(), "_dfr_start_c", mlir::TypeRange(), + mlir::ValueRange( + {useDFRVal, entryPoint.getArgument(ctxIndex)})) + : builder.create(entryPoint.getLoc(), + "_dfr_start_c", + mlir::TypeRange(), useDFRVal); } else { auto startFunTy = mlir::FunctionType::get(entryPoint->getContext(), {useDFRVal.getType()}, {}); diff --git a/compiler/lib/Runtime/DFRuntime.cpp b/compiler/lib/Runtime/DFRuntime.cpp index 4bec7ea28..f055f2d54 100644 --- a/compiler/lib/Runtime/DFRuntime.cpp +++ b/compiler/lib/Runtime/DFRuntime.cpp @@ -1131,7 +1131,7 @@ static inline void _dfr_start_impl(int argc, char *argv[]) { /* Start/stop functions to be called from within user code (or during JIT invocation). These serve to pause/resume the runtime scheduler and to clean up used resources. */ -void _dfr_start(int use_dfr_p) { +void _dfr_start(int64_t use_dfr_p) { BEGIN_TIME(&mlir::concretelang::dfr::whole_timer); if (use_dfr_p) { BEGIN_TIME(&mlir::concretelang::dfr::init_timer); @@ -1167,30 +1167,32 @@ void _dfr_start(int use_dfr_p) { } // Startup entry point when a RuntimeContext is used -void _dfr_start_c(void *ctx) { +void _dfr_start_c(int64_t use_dfr_p, void *ctx) { _dfr_start(2); - if (mlir::concretelang::dfr::num_nodes > 1) { - BEGIN_TIME(&mlir::concretelang::dfr::broadcast_timer); - new mlir::concretelang::dfr::RuntimeContextManager(); - mlir::concretelang::dfr::_dfr_node_level_runtime_context_manager - ->setContext(ctx); + if (use_dfr_p) { + if (mlir::concretelang::dfr::num_nodes > 1) { + BEGIN_TIME(&mlir::concretelang::dfr::broadcast_timer); + new mlir::concretelang::dfr::RuntimeContextManager(); + mlir::concretelang::dfr::_dfr_node_level_runtime_context_manager + ->setContext(ctx); - // If this is not JIT, then the remote nodes never reach _dfr_stop, - // so root should not instantiate this barrier. - if (mlir::concretelang::dfr::_dfr_is_root_node() && - mlir::concretelang::dfr::_dfr_is_jit()) - mlir::concretelang::dfr::_dfr_startup_barrier->wait(); - END_TIME(&mlir::concretelang::dfr::broadcast_timer, "Key broadcasting"); + // If this is not JIT, then the remote nodes never reach _dfr_stop, + // so root should not instantiate this barrier. + if (mlir::concretelang::dfr::_dfr_is_root_node() && + mlir::concretelang::dfr::_dfr_is_jit()) + mlir::concretelang::dfr::_dfr_startup_barrier->wait(); + END_TIME(&mlir::concretelang::dfr::broadcast_timer, "Key broadcasting"); + } + BEGIN_TIME(&mlir::concretelang::dfr::compute_timer); } - BEGIN_TIME(&mlir::concretelang::dfr::compute_timer); } // This function cannot be used to terminate the runtime as it is // non-decidable if another computation phase will follow. Instead the // _dfr_terminate function provides this facility and is normally // called on exit from "main" when not using the main wrapper library. -void _dfr_stop(int use_dfr_p) { +void _dfr_stop(int64_t use_dfr_p) { if (use_dfr_p) { if (mlir::concretelang::dfr::num_nodes > 1) { // Non-root nodes synchronize here with the root to mark the point @@ -1310,11 +1312,11 @@ bool _dfr_use_omp() { return use_omp_p; } } // namespace concretelang } // namespace mlir -void _dfr_start(int use_dfr_p) { +void _dfr_start(int64_t use_dfr_p) { BEGIN_TIME(&mlir::concretelang::dfr::compute_timer); } -void _dfr_start_c(void *ctx) { _dfr_start(2); } -void _dfr_stop(int use_dfr_p) { +void _dfr_start_c(int64_t use_dfr_p, void *ctx) { _dfr_start(2); } +void _dfr_stop(int64_t use_dfr_p) { END_TIME(&mlir::concretelang::dfr::compute_timer, "Compute"); }