From 08735284133b6148595148a458cc87cdd63b9d37 Mon Sep 17 00:00:00 2001 From: "John F. Carr" Date: Fri, 13 Oct 2023 15:47:36 -0400 Subject: [PATCH 1/4] New internal reducer API --- runtime/cilk2c_inlined.c | 19 +++++++++++++++++++ runtime/local-reducer-api.h | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/runtime/cilk2c_inlined.c b/runtime/cilk2c_inlined.c index fd30717e..32f1d86b 100644 --- a/runtime/cilk2c_inlined.c +++ b/runtime/cilk2c_inlined.c @@ -64,6 +64,25 @@ void *__cilkrts_reducer_lookup(void *key, size_t size, (__cilk_reduce_fn)reduce_ptr); } +void *__cilkrts_reducer_lookup_frame(struct __cilkrts_stack_frame *frame, + void *key, size_t size, + void *identity_ptr, void *reduce_ptr) { + // If we're outside a cilkified region, then the key is the view. + // The null test will normally be optimized out. + if (!frame) + return key; + struct local_hyper_table *table = get_local_hyper_table(frame->fh->worker); + struct bucket *b = find_hyperobject(table, (uintptr_t)key); + if (__builtin_expect(!!b, true)) { + // Return the existing view. + return b->value.view; + } + + return __cilkrts_insert_new_view(table, (uintptr_t)key, size, + (__cilk_identity_fn)identity_ptr, + (__cilk_reduce_fn)reduce_ptr); +} + // Begin a Cilkified region. The routine runs on a Cilkifying thread to // transfer the execution of this function to the workers in global_state g. // This routine must be inlined for correctness. diff --git a/runtime/local-reducer-api.h b/runtime/local-reducer-api.h index a4db25c8..c8e67b71 100644 --- a/runtime/local-reducer-api.h +++ b/runtime/local-reducer-api.h @@ -7,7 +7,7 @@ static inline struct local_hyper_table * get_local_hyper_table(__cilkrts_worker *w) { - if (NULL == w->hyper_table) { + if (__builtin_expect(NULL == w->hyper_table, 0)) { w->hyper_table = __cilkrts_local_hyper_table_alloc(); } return w->hyper_table; From 841fdacd6e02f43e70967dc57c8865679ad2380b Mon Sep 17 00:00:00 2001 From: "John F. Carr" Date: Mon, 16 Oct 2023 16:46:27 -0400 Subject: [PATCH 2/4] Improve function name --- runtime/cilk2c_inlined.c | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/runtime/cilk2c_inlined.c b/runtime/cilk2c_inlined.c index 32f1d86b..7f772ed8 100644 --- a/runtime/cilk2c_inlined.c +++ b/runtime/cilk2c_inlined.c @@ -47,26 +47,9 @@ unsigned __cilkrts_get_worker_number(void) { return 0; } -void *__cilkrts_reducer_lookup(void *key, size_t size, - void *identity_ptr, void *reduce_ptr) { - // If we're outside a cilkified region, then the key is the view. - if (__cilkrts_need_to_cilkify) - return key; - struct local_hyper_table *table = get_hyper_table(); - struct bucket *b = find_hyperobject(table, (uintptr_t)key); - if (__builtin_expect(!!b, true)) { - // Return the existing view. - return b->value.view; - } - - return __cilkrts_insert_new_view(table, (uintptr_t)key, size, - (__cilk_identity_fn)identity_ptr, - (__cilk_reduce_fn)reduce_ptr); -} - -void *__cilkrts_reducer_lookup_frame(struct __cilkrts_stack_frame *frame, - void *key, size_t size, - void *identity_ptr, void *reduce_ptr) { +void *__cilkrts_reducer_lookup_in_frame(struct __cilkrts_stack_frame *frame, + void *key, size_t size, + void *identity_ptr, void *reduce_ptr) { // If we're outside a cilkified region, then the key is the view. // The null test will normally be optimized out. if (!frame) From c2c2d2f12eacde36e43e462478c53e80c06ad451 Mon Sep 17 00:00:00 2001 From: Kyle Singer Date: Fri, 20 Oct 2023 11:30:15 -0500 Subject: [PATCH 3/4] Allow for override of architecture flags in runtime cmake --- runtime/CMakeLists.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index 92921f4e..4c2e712e 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -92,8 +92,12 @@ endif() # Add compile flags for Cheetah-runtime compilation that should be # excluded from bitcode compilation -if (CHEETAH_HAS_MAVX_FLAG) - list(APPEND CHEETAH_COMPILE_FLAGS -mavx) +if (DEFINED CHEETAH_ARCH_FLAGS) + list(APPEND CHEETAH_COMPILE_FLAGS ${CHEETAH_ARCH_FLAGS}) +else() + if (CHEETAH_HAS_MAVX_FLAG) + list(APPEND CHEETAH_COMPILE_FLAGS -mavx) + endif() endif() if (APPLE) From 922d12f5ea248caa7ef8b157762c0041d56bc2ef Mon Sep 17 00:00:00 2001 From: "John F. Carr" Date: Sat, 28 Oct 2023 13:44:43 -0400 Subject: [PATCH 4/4] Fix reducer lookup in non-Cilk function in Cilk environment. If the frame argument is null the TLS variable might still be set. --- runtime/cilk2c_inlined.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/runtime/cilk2c_inlined.c b/runtime/cilk2c_inlined.c index 7f772ed8..14db7519 100644 --- a/runtime/cilk2c_inlined.c +++ b/runtime/cilk2c_inlined.c @@ -52,9 +52,12 @@ void *__cilkrts_reducer_lookup_in_frame(struct __cilkrts_stack_frame *frame, void *identity_ptr, void *reduce_ptr) { // If we're outside a cilkified region, then the key is the view. // The null test will normally be optimized out. - if (!frame) - return key; - struct local_hyper_table *table = get_local_hyper_table(frame->fh->worker); + __cilkrts_worker *w; + if (frame) + w = frame->fh->worker; // Never null + else if (!(w = __cilkrts_get_tls_worker())) + return key; + struct local_hyper_table *table = get_local_hyper_table(w); struct bucket *b = find_hyperobject(table, (uintptr_t)key); if (__builtin_expect(!!b, true)) { // Return the existing view.