[Openmp-commits] [openmp] [Draft][OpenMP] Openmp taskgraph bug fix (PR #136837)

Josep Pinot via Openmp-commits openmp-commits at lists.llvm.org
Wed Apr 23 02:59:37 PDT 2025


https://github.com/jpinot created https://github.com/llvm/llvm-project/pull/136837

None

>From 4affdd43ceccb74e83f3f62bf3f72fb1033def0d Mon Sep 17 00:00:00 2001
From: jpinot <josep.pinot at bsc.es>
Date: Thu, 10 Apr 2025 15:00:43 +0200
Subject: [PATCH 1/4] [openmp] Fix corrupted read of is_taskgraph
 (uninitialized bool)

---
 openmp/runtime/src/kmp_tasking.cpp | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/openmp/runtime/src/kmp_tasking.cpp b/openmp/runtime/src/kmp_tasking.cpp
index 563aa29f6265e..f97944d744371 100644
--- a/openmp/runtime/src/kmp_tasking.cpp
+++ b/openmp/runtime/src/kmp_tasking.cpp
@@ -1586,6 +1586,10 @@ kmp_task_t *__kmp_task_alloc(ident_t *loc_ref, kmp_int32 gtid,
   taskdata->td_task_team = thread->th.th_task_team;
   taskdata->td_size_alloc = shareds_offset + sizeof_shareds;
   taskdata->td_flags.tasktype = TASK_EXPLICIT;
+#if OMPX_TASKGRAPH
+  taskdata->is_taskgraph = 0;
+  taskdata->tdg = nullptr;
+#endif
   // If it is hidden helper task, we need to set the team and task team
   // correspondingly.
   if (flags->hidden_helper) {

>From f25cd7e9a12a19952cc2921393f4f06b732f144a Mon Sep 17 00:00:00 2001
From: jpinot <josep.pinot at bsc.es>
Date: Mon, 21 Apr 2025 11:25:57 +0200
Subject: [PATCH 2/4] [openmp] Fix invalid data access in
 __kmpc_omp_task_with_deps

---
 openmp/runtime/src/kmp_taskdeps.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/openmp/runtime/src/kmp_taskdeps.cpp b/openmp/runtime/src/kmp_taskdeps.cpp
index e002877aaead2..281580d8f08dd 100644
--- a/openmp/runtime/src/kmp_taskdeps.cpp
+++ b/openmp/runtime/src/kmp_taskdeps.cpp
@@ -698,9 +698,9 @@ kmp_int32 __kmpc_omp_task_with_deps(ident_t *loc_ref, kmp_int32 gtid,
       __kmp_tdg_is_recording(new_taskdata->tdg->tdg_status)) {
     kmp_tdg_info_t *tdg = new_taskdata->tdg;
     // extend record_map if needed
-    if (new_taskdata->td_task_id >= tdg->map_size) {
+    if (new_taskdata->td_tdg_task_id >= tdg->map_size) {
       __kmp_acquire_bootstrap_lock(&tdg->graph_lock);
-      if (new_taskdata->td_task_id >= tdg->map_size) {
+      if (new_taskdata->td_tdg_task_id >= tdg->map_size) {
         kmp_uint old_size = tdg->map_size;
         kmp_uint new_size = old_size * 2;
         kmp_node_info_t *old_record = tdg->record_map;

>From 03d511789004831c32c62cdf46c09e1e4ce006b6 Mon Sep 17 00:00:00 2001
From: jpinot <josep.pinot at bsc.es>
Date: Wed, 23 Apr 2025 09:25:25 +0200
Subject: [PATCH 3/4] [openmp] Fix re-allocation of task successors when
 taskgraph

---
 openmp/runtime/src/kmp_taskdeps.cpp | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/openmp/runtime/src/kmp_taskdeps.cpp b/openmp/runtime/src/kmp_taskdeps.cpp
index 281580d8f08dd..2630164024721 100644
--- a/openmp/runtime/src/kmp_taskdeps.cpp
+++ b/openmp/runtime/src/kmp_taskdeps.cpp
@@ -244,10 +244,14 @@ static inline void __kmp_track_dependence(kmp_int32 gtid, kmp_depnode_t *source,
     if (!exists) {
       if (source_info->nsuccessors >= source_info->successors_size) {
         source_info->successors_size = 2 * source_info->successors_size;
+        kmp_uint old_size = source_info->successors_size;
+        kmp_uint new_size = source_info->successors_size * 2;
         kmp_int32 *old_succ_ids = source_info->successors;
-        kmp_int32 *new_succ_ids = (kmp_int32 *)__kmp_allocate(
-            source_info->successors_size * sizeof(kmp_int32));
+        kmp_int32 *new_succ_ids =
+            (kmp_int32 *)__kmp_allocate(new_size * sizeof(kmp_int32));
+        KMP_MEMCPY(new_succ_ids, old_succ_ids, old_size * sizeof(kmp_int32));
         source_info->successors = new_succ_ids;
+        source_info->successors_size = new_size;
         __kmp_free(old_succ_ids);
       }
 

>From 352ab253fa1202d08eeac478e501342ffb6a91e2 Mon Sep 17 00:00:00 2001
From: jpinot <josep.pinot at bsc.es>
Date: Tue, 11 Mar 2025 14:30:49 +0100
Subject: [PATCH 4/4] [OpenMP] Fix task record/replay comments

---
 openmp/runtime/src/kmp_tasking.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/openmp/runtime/src/kmp_tasking.cpp b/openmp/runtime/src/kmp_tasking.cpp
index f97944d744371..4eefa9a9fafc1 100644
--- a/openmp/runtime/src/kmp_tasking.cpp
+++ b/openmp/runtime/src/kmp_tasking.cpp
@@ -5456,7 +5456,6 @@ bool __kmpc_omp_has_task_team(kmp_int32 gtid) {
 
 #if OMPX_TASKGRAPH
 // __kmp_find_tdg: identify a TDG through its ID
-// gtid:   Global Thread ID
 // tdg_id: ID of the TDG
 // returns: If a TDG corresponding to this ID is found and not
 // its initial state, return the pointer to it, otherwise nullptr
@@ -5509,7 +5508,7 @@ void __kmp_print_tdg_dot(kmp_tdg_info_t *tdg, kmp_int32 gtid) {
   KA_TRACE(10, ("__kmp_print_tdg_dot(exit): T#%d tdg_id=%d \n", gtid, tdg_id));
 }
 
-// __kmp_start_record: launch the execution of a previous
+// __kmp_exec_tdg: launch the execution of a previous
 // recorded TDG
 // gtid:   Global Thread ID
 // tdg:    ID of the TDG



More information about the Openmp-commits mailing list