[Openmp-commits] [openmp] Draft: Update OpenMP runtime to adopt taskgraph clause from 6.0 Specs (PR #130751)

Josep Pinot via Openmp-commits openmp-commits at lists.llvm.org
Tue Mar 11 03:55:40 PDT 2025


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

None

>From c4b84470d2c1a23d5d308c0acf7c741122194afa Mon Sep 17 00:00:00 2001
From: jpinot <josep.pinot at bsc.es>
Date: Mon, 10 Mar 2025 12:18:25 +0100
Subject: [PATCH 1/7] [wip][openmp] Fix taskgraph tdg_id to not function as an
 idx

Tdg_id was implementatd as an idx, this implementation needs an
update in order to match the OpenMP spcs 6.0, were a graph_id
clause have been introduced. This MR assumes that the tdg_id is
generatd in LLVM CG and the runtime just gets a hashed id were
region/graph_id have taken into account.

This chenge is backwards compatible
---
 openmp/runtime/src/kmp.h           |  2 +
 openmp/runtime/src/kmp_global.cpp  |  2 +
 openmp/runtime/src/kmp_tasking.cpp | 59 ++++++++++++++++++------------
 3 files changed, 40 insertions(+), 23 deletions(-)

diff --git a/openmp/runtime/src/kmp.h b/openmp/runtime/src/kmp.h
index 36656325be4bd..a7748a6c58332 100644
--- a/openmp/runtime/src/kmp.h
+++ b/openmp/runtime/src/kmp.h
@@ -2647,10 +2647,12 @@ typedef struct kmp_tdg_info {
   kmp_int32 rec_num_taskred;
 } kmp_tdg_info_t;
 
+
 extern int __kmp_tdg_dot;
 extern kmp_int32 __kmp_max_tdgs;
 extern kmp_tdg_info_t **__kmp_global_tdgs;
 extern kmp_int32 __kmp_curr_tdg_idx;
+extern kmp_tdg_info_t* __kmp_curr_tdg;
 extern kmp_int32 __kmp_successors_size;
 extern std::atomic<kmp_int32> __kmp_tdg_task_id;
 extern kmp_int32 __kmp_num_tdg;
diff --git a/openmp/runtime/src/kmp_global.cpp b/openmp/runtime/src/kmp_global.cpp
index 52e0fdbdfb1da..0bf5c034ad64a 100644
--- a/openmp/runtime/src/kmp_global.cpp
+++ b/openmp/runtime/src/kmp_global.cpp
@@ -556,6 +556,8 @@ kmp_int32 __kmp_max_tdgs = 100;
 kmp_tdg_info_t **__kmp_global_tdgs = NULL;
 kmp_int32 __kmp_curr_tdg_idx =
     0; // Id of the current TDG being recorded or executed
+kmp_tdg_info_t* __kmp_curr_tdg =
+    NULL; // Current TDG being recorded or executed
 kmp_int32 __kmp_num_tdg = 0;
 kmp_int32 __kmp_successors_size = 10; // Initial succesor size list for
                                       // recording
diff --git a/openmp/runtime/src/kmp_tasking.cpp b/openmp/runtime/src/kmp_tasking.cpp
index 3e229b517cfcd..26b42290ff294 100644
--- a/openmp/runtime/src/kmp_tasking.cpp
+++ b/openmp/runtime/src/kmp_tasking.cpp
@@ -1651,11 +1651,12 @@ kmp_task_t *__kmp_task_alloc(ident_t *loc_ref, kmp_int32 gtid,
   }
 
 #if OMPX_TASKGRAPH
-  kmp_tdg_info_t *tdg = __kmp_find_tdg(__kmp_curr_tdg_idx);
+  /* kmp_tdg_info_t *tdg = __kmp_find_tdg(__kmp_curr_tdg_idx); */
+  kmp_tdg_info_t *tdg = __kmp_curr_tdg;
   if (tdg && __kmp_tdg_is_recording(tdg->tdg_status) &&
       (task_entry != (kmp_routine_entry_t)__kmp_taskloop_task)) {
     taskdata->is_taskgraph = 1;
-    taskdata->tdg = __kmp_global_tdgs[__kmp_curr_tdg_idx];
+    taskdata->tdg = __kmp_curr_tdg;
     taskdata->td_task_id = KMP_ATOMIC_INC(&__kmp_tdg_task_id);
   }
 #endif
@@ -2576,13 +2577,13 @@ without help of the runtime library.
 */
 void *__kmpc_task_reduction_init(int gtid, int num, void *data) {
 #if OMPX_TASKGRAPH
-  kmp_tdg_info_t *tdg = __kmp_find_tdg(__kmp_curr_tdg_idx);
+  kmp_tdg_info_t *tdg = __kmp_curr_tdg;
   if (tdg && __kmp_tdg_is_recording(tdg->tdg_status)) {
-    kmp_tdg_info_t *this_tdg = __kmp_global_tdgs[__kmp_curr_tdg_idx];
-    this_tdg->rec_taskred_data =
+    /* kmp_tdg_info_t *this_tdg = __kmp_global_tdgs[__kmp_curr_tdg_idx]; */
+    tdg->rec_taskred_data =
         __kmp_allocate(sizeof(kmp_task_red_input_t) * num);
-    this_tdg->rec_num_taskred = num;
-    KMP_MEMCPY(this_tdg->rec_taskred_data, data,
+    tdg->rec_num_taskred = num;
+    KMP_MEMCPY(tdg->rec_taskred_data, data,
                sizeof(kmp_task_red_input_t) * num);
   }
 #endif
@@ -2603,13 +2604,13 @@ has two parameters, pointer to object to be initialized and pointer to omp_orig
 */
 void *__kmpc_taskred_init(int gtid, int num, void *data) {
 #if OMPX_TASKGRAPH
-  kmp_tdg_info_t *tdg = __kmp_find_tdg(__kmp_curr_tdg_idx);
+  kmp_tdg_info_t *tdg = __kmp_curr_tdg;
   if (tdg && __kmp_tdg_is_recording(tdg->tdg_status)) {
-    kmp_tdg_info_t *this_tdg = __kmp_global_tdgs[__kmp_curr_tdg_idx];
-    this_tdg->rec_taskred_data =
+    /* kmp_tdg_info_t *this_tdg = __kmp_global_tdgs[__kmp_curr_tdg_idx]; */
+    tdg->rec_taskred_data =
         __kmp_allocate(sizeof(kmp_task_red_input_t) * num);
-    this_tdg->rec_num_taskred = num;
-    KMP_MEMCPY(this_tdg->rec_taskred_data, data,
+    tdg->rec_num_taskred = num;
+    KMP_MEMCPY(tdg->rec_taskred_data, data,
                sizeof(kmp_task_red_input_t) * num);
   }
 #endif
@@ -2661,8 +2662,7 @@ void *__kmpc_task_reduction_get_th_data(int gtid, void *tskgrp, void *data) {
 
 #if OMPX_TASKGRAPH
   if ((thread->th.th_current_task->is_taskgraph) &&
-      (!__kmp_tdg_is_recording(
-          __kmp_global_tdgs[__kmp_curr_tdg_idx]->tdg_status))) {
+      (!__kmp_tdg_is_recording(__kmp_curr_tdg->tdg_status))) {
     tg = thread->th.th_current_task->td_taskgroup;
     KMP_ASSERT(tg != NULL);
     KMP_ASSERT(tg->reduce_data != NULL);
@@ -5460,6 +5460,7 @@ bool __kmpc_omp_has_task_team(kmp_int32 gtid) {
 // its initial state, return the pointer to it, otherwise nullptr
 static kmp_tdg_info_t *__kmp_find_tdg(kmp_int32 tdg_id) {
   kmp_tdg_info_t *res = nullptr;
+  kmp_int32 i = 0;
   if (__kmp_max_tdgs == 0)
     return res;
 
@@ -5467,9 +5468,15 @@ static kmp_tdg_info_t *__kmp_find_tdg(kmp_int32 tdg_id) {
     __kmp_global_tdgs = (kmp_tdg_info_t **)__kmp_allocate(
         sizeof(kmp_tdg_info_t *) * __kmp_max_tdgs);
 
-  if ((__kmp_global_tdgs[tdg_id]) &&
-      (__kmp_global_tdgs[tdg_id]->tdg_status != KMP_TDG_NONE))
-    res = __kmp_global_tdgs[tdg_id];
+  for (i = 0; i <= __kmp_num_tdg; i++) {
+    if (__kmp_global_tdgs[i] &&
+        __kmp_global_tdgs[i]->tdg_id == tdg_id) {
+      if (__kmp_global_tdgs[i]->tdg_status != KMP_TDG_NONE) { //XXX: Do I really need this?
+        res = __kmp_global_tdgs[i];
+      }
+      break;
+    }
+  }
   return res;
 }
 
@@ -5507,7 +5514,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
@@ -5569,7 +5576,10 @@ static inline void __kmp_start_record(kmp_int32 gtid,
                                       kmp_int32 tdg_id) {
   kmp_tdg_info_t *tdg =
       (kmp_tdg_info_t *)__kmp_allocate(sizeof(kmp_tdg_info_t));
-  __kmp_global_tdgs[__kmp_curr_tdg_idx] = tdg;
+  __kmp_global_tdgs[__kmp_num_tdg] = tdg;
+  __kmp_curr_tdg = tdg;
+  __kmp_num_tdg++;
+  // TODO: separate to new method
   // Initializing the TDG structure
   tdg->tdg_id = tdg_id;
   tdg->map_size = INIT_MAPSIZE;
@@ -5594,7 +5604,8 @@ static inline void __kmp_start_record(kmp_int32 gtid,
     KMP_ATOMIC_ST_RLX(&this_record_map[i].npredecessors_counter, 0);
   }
 
-  __kmp_global_tdgs[__kmp_curr_tdg_idx]->record_map = this_record_map;
+  /* __kmp_global_tdgs[__kmp_curr_tdg_idx]->record_map = this_record_map; */
+  __kmp_curr_tdg->record_map = this_record_map;
 }
 
 // __kmpc_start_record_task: Wrapper around __kmp_start_record to mark
@@ -5624,14 +5635,16 @@ kmp_int32 __kmpc_start_record_task(ident_t *loc_ref, kmp_int32 gtid,
 
   __kmpc_taskgroup(loc_ref, gtid);
   if (kmp_tdg_info_t *tdg = __kmp_find_tdg(tdg_id)) {
+    printf("===> TDG exists\n");
     // TODO: use re_record flag
     __kmp_exec_tdg(gtid, tdg);
     res = 0;
   } else {
-    __kmp_curr_tdg_idx = tdg_id;
-    KMP_DEBUG_ASSERT(__kmp_curr_tdg_idx < __kmp_max_tdgs);
+    /* __kmp_curr_tdg_idx = tdg_id; */
+    /* __kmp_curr_tdg = tdg; */
+    /* KMP_DEBUG_ASSERT(__kmp_curr_tdg_idx < __kmp_max_tdgs); */
     __kmp_start_record(gtid, flags, tdg_id);
-    __kmp_num_tdg++;
+    /* __kmp_num_tdg++; */
     res = 1;
   }
   KA_TRACE(10, ("__kmpc_start_record_task(exit): T#%d TDG %d starts to %s\n",

>From ab886a618141cb59f2030defdd271f7c9e8ec562 Mon Sep 17 00:00:00 2001
From: jpinot <josep.pinot at bsc.es>
Date: Mon, 10 Mar 2025 18:41:39 +0100
Subject: [PATCH 2/7] [wip][openmp] Add method to alloc a tdg and

---
 openmp/runtime/src/kmp_tasking.cpp | 46 ++++++++++++++++++++++++------
 1 file changed, 38 insertions(+), 8 deletions(-)

diff --git a/openmp/runtime/src/kmp_tasking.cpp b/openmp/runtime/src/kmp_tasking.cpp
index 26b42290ff294..ebb479e87e5e1 100644
--- a/openmp/runtime/src/kmp_tasking.cpp
+++ b/openmp/runtime/src/kmp_tasking.cpp
@@ -5454,7 +5454,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
@@ -5468,12 +5467,42 @@ static kmp_tdg_info_t *__kmp_find_tdg(kmp_int32 tdg_id) {
     __kmp_global_tdgs = (kmp_tdg_info_t **)__kmp_allocate(
         sizeof(kmp_tdg_info_t *) * __kmp_max_tdgs);
 
-  for (i = 0; i <= __kmp_num_tdg; i++) {
+  for (i = 0; i < __kmp_num_tdg; i++) {
     if (__kmp_global_tdgs[i] &&
         __kmp_global_tdgs[i]->tdg_id == tdg_id) {
       if (__kmp_global_tdgs[i]->tdg_status != KMP_TDG_NONE) { //XXX: Do I really need this?
         res = __kmp_global_tdgs[i];
       }
+      // XXX: Probably cleanup if statue == KMP_TDG_NONE
+      break;
+    }
+  }
+  return res;
+}
+
+// __kmp_alloc_tdg: returns a new tdg TODO: complete message
+// 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
+static kmp_tdg_info_t *__kmp_alloc_tdg(kmp_int32 tdg_id) {
+  kmp_tdg_info_t *res = nullptr;
+  kmp_int32 i = 0;
+  if ((res = __kmp_find_tdg(tdg_id))) { // XXX: should I remove?
+    return res;
+  }
+  if (__kmp_num_tdg > __kmp_max_tdgs) {
+    return res;
+  }
+
+  for (i = 0; i <= __kmp_max_tdgs; i++) {
+    if (!__kmp_global_tdgs[i]) {
+      kmp_tdg_info_t *tdg =
+        (kmp_tdg_info_t *)__kmp_allocate(sizeof(kmp_tdg_info_t));
+      __kmp_global_tdgs[i] = tdg;
+      __kmp_curr_tdg = tdg;
+      __kmp_curr_tdg_idx = i;
+      /* __kmp_num_tdg++; */
+      res = __kmp_global_tdgs[i];
       break;
     }
   }
@@ -5574,11 +5603,12 @@ void __kmp_exec_tdg(kmp_int32 gtid, kmp_tdg_info_t *tdg) {
 static inline void __kmp_start_record(kmp_int32 gtid,
                                       kmp_taskgraph_flags_t *flags,
                                       kmp_int32 tdg_id) {
-  kmp_tdg_info_t *tdg =
-      (kmp_tdg_info_t *)__kmp_allocate(sizeof(kmp_tdg_info_t));
-  __kmp_global_tdgs[__kmp_num_tdg] = tdg;
-  __kmp_curr_tdg = tdg;
-  __kmp_num_tdg++;
+  kmp_tdg_info_t *tdg = __kmp_alloc_tdg(tdg_id);
+  /* kmp_tdg_info_t *tdg = */
+  /*     (kmp_tdg_info_t *)__kmp_allocate(sizeof(kmp_tdg_info_t)); */
+  /* __kmp_global_tdgs[__kmp_num_tdg] = tdg; */
+  /* __kmp_curr_tdg = tdg; */
+  /* __kmp_num_tdg++; */
   // TODO: separate to new method
   // Initializing the TDG structure
   tdg->tdg_id = tdg_id;
@@ -5644,7 +5674,7 @@ kmp_int32 __kmpc_start_record_task(ident_t *loc_ref, kmp_int32 gtid,
     /* __kmp_curr_tdg = tdg; */
     /* KMP_DEBUG_ASSERT(__kmp_curr_tdg_idx < __kmp_max_tdgs); */
     __kmp_start_record(gtid, flags, tdg_id);
-    /* __kmp_num_tdg++; */
+    __kmp_num_tdg++;
     res = 1;
   }
   KA_TRACE(10, ("__kmpc_start_record_task(exit): T#%d TDG %d starts to %s\n",

>From 94c9f5a43613fc7697537097e7ff5d3006173a2c Mon Sep 17 00:00:00 2001
From: jpinot <josep.pinot at bsc.es>
Date: Tue, 11 Mar 2025 07:52:37 +0100
Subject: [PATCH 3/7] [wip][openmp] Fix __kmp_find_tdg to look for all elements

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

diff --git a/openmp/runtime/src/kmp_tasking.cpp b/openmp/runtime/src/kmp_tasking.cpp
index ebb479e87e5e1..cb4ee9db109ca 100644
--- a/openmp/runtime/src/kmp_tasking.cpp
+++ b/openmp/runtime/src/kmp_tasking.cpp
@@ -5467,7 +5467,7 @@ static kmp_tdg_info_t *__kmp_find_tdg(kmp_int32 tdg_id) {
     __kmp_global_tdgs = (kmp_tdg_info_t **)__kmp_allocate(
         sizeof(kmp_tdg_info_t *) * __kmp_max_tdgs);
 
-  for (i = 0; i < __kmp_num_tdg; i++) {
+  for (i = 0; i < __kmp_max_tdgs; i++) {
     if (__kmp_global_tdgs[i] &&
         __kmp_global_tdgs[i]->tdg_id == tdg_id) {
       if (__kmp_global_tdgs[i]->tdg_status != KMP_TDG_NONE) { //XXX: Do I really need this?

>From 7ff7b829bc1157853d0d4b49e3eabf1fd48ccf9c Mon Sep 17 00:00:00 2001
From: jpinot <josep.pinot at bsc.es>
Date: Tue, 11 Mar 2025 09:40:59 +0100
Subject: [PATCH 4/7] [xxx][wip][openmp] Add comments remainder of leak when
 using _kmp_find_tdg

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

diff --git a/openmp/runtime/src/kmp_tasking.cpp b/openmp/runtime/src/kmp_tasking.cpp
index cb4ee9db109ca..6bce5e3dc70bc 100644
--- a/openmp/runtime/src/kmp_tasking.cpp
+++ b/openmp/runtime/src/kmp_tasking.cpp
@@ -5455,6 +5455,7 @@ bool __kmpc_omp_has_task_team(kmp_int32 gtid) {
 #if OMPX_TASKGRAPH
 // __kmp_find_tdg: identify a TDG through its ID
 // tdg_id: ID of the TDG
+// XXX: This methods leaks __kmp_global_tdgs on upstream/main
 // returns: If a TDG corresponding to this ID is found and not
 // its initial state, return the pointer to it, otherwise nullptr
 static kmp_tdg_info_t *__kmp_find_tdg(kmp_int32 tdg_id) {

>From 11ad18ec037dc6dac5601869e695bfdfeb1506a0 Mon Sep 17 00:00:00 2001
From: jpinot <josep.pinot at bsc.es>
Date: Tue, 11 Mar 2025 10:32:31 +0100
Subject: [PATCH 5/7] [wip][openmp] Fix __kmp_alloc_tdg for iteration

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

diff --git a/openmp/runtime/src/kmp_tasking.cpp b/openmp/runtime/src/kmp_tasking.cpp
index 6bce5e3dc70bc..26b19d4c6d827 100644
--- a/openmp/runtime/src/kmp_tasking.cpp
+++ b/openmp/runtime/src/kmp_tasking.cpp
@@ -5495,7 +5495,7 @@ static kmp_tdg_info_t *__kmp_alloc_tdg(kmp_int32 tdg_id) {
     return res;
   }
 
-  for (i = 0; i <= __kmp_max_tdgs; i++) {
+  for (i = 0; i < __kmp_max_tdgs; i++) {
     if (!__kmp_global_tdgs[i]) {
       kmp_tdg_info_t *tdg =
         (kmp_tdg_info_t *)__kmp_allocate(sizeof(kmp_tdg_info_t));

>From 4659438b095dca00baac5a4581b4d37f7c8f5649 Mon Sep 17 00:00:00 2001
From: jpinot <josep.pinot at bsc.es>
Date: Tue, 11 Mar 2025 11:16:43 +0100
Subject: [PATCH 6/7] [wip][openmp] Add reset parameter to start_record_task

A new input parameter have been added to reset a taskgraph record
fllowing graph_reset cluase functionallity from OpenMP spcs 6.0,
This chenges are not backwards compatible due to a chenge on the
__kmpc_start_record_task input parameters.
---
 openmp/runtime/src/kmp.h           |  2 +-
 openmp/runtime/src/kmp_tasking.cpp | 56 ++++++++++++++++++++++++++----
 2 files changed, 50 insertions(+), 8 deletions(-)

diff --git a/openmp/runtime/src/kmp.h b/openmp/runtime/src/kmp.h
index a7748a6c58332..77b519764ccf0 100644
--- a/openmp/runtime/src/kmp.h
+++ b/openmp/runtime/src/kmp.h
@@ -4386,7 +4386,7 @@ static inline bool __kmp_tdg_is_recording(kmp_tdg_status_t status) {
 
 KMP_EXPORT kmp_int32 __kmpc_start_record_task(ident_t *loc, kmp_int32 gtid,
                                               kmp_int32 input_flags,
-                                              kmp_int32 tdg_id);
+                                              kmp_int32 tdg_id, bool reset);
 KMP_EXPORT void __kmpc_end_record_task(ident_t *loc, kmp_int32 gtid,
                                        kmp_int32 input_flags, kmp_int32 tdg_id);
 #endif
diff --git a/openmp/runtime/src/kmp_tasking.cpp b/openmp/runtime/src/kmp_tasking.cpp
index 26b19d4c6d827..e1f5c299c0f28 100644
--- a/openmp/runtime/src/kmp_tasking.cpp
+++ b/openmp/runtime/src/kmp_tasking.cpp
@@ -5510,6 +5510,42 @@ static kmp_tdg_info_t *__kmp_alloc_tdg(kmp_int32 tdg_id) {
   return res;
 }
 
+// __kmp_free_tdg: free a tdg if exists TODO: complete message
+// 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
+
+/* ==618292==    definitely lost: 28,512 bytes in 99 blocks */
+/* ==618292==    indirectly lost: 890,604 bytes in 5,148 blocks */
+/* ==618292==      possibly lost: 13,046 bytes in 58 blocks */
+/* ==618292==    still reachable: 1,944 bytes in 7 blocks */
+/* ==618292==         suppressed: 0 bytes in 0 blocks */
+
+static bool __kmp_free_tdg(kmp_int32 tdg_id) {
+  kmp_tdg_info_t *tdg = nullptr;
+  kmp_int32 i = 0;
+  if (__kmp_global_tdgs == NULL)
+    return false;
+
+  for (i = 0; i < __kmp_max_tdgs; i++) {
+    if (__kmp_global_tdgs[i] &&
+        __kmp_global_tdgs[i]->tdg_id == tdg_id) {
+      tdg = __kmp_global_tdgs[i];
+      for (kmp_int i = 0; i < tdg->map_size; i++) {
+        __kmp_free(tdg->record_map[i].successors);
+      }
+      __kmp_free(tdg->record_map);
+      if (tdg->root_tasks)
+        __kmp_free(tdg->root_tasks);
+
+      __kmp_free(tdg);
+      __kmp_global_tdgs[i] = NULL;
+      return true;
+    }
+  }
+  return false;
+}
+
 // __kmp_print_tdg_dot: prints the TDG to a dot file
 // tdg:    ID of the TDG
 // gtid:   Global Thread ID
@@ -5644,27 +5680,33 @@ static inline void __kmp_start_record(kmp_int32 gtid,
 // loc_ref:     Location of TDG, not used yet
 // gtid:        Global Thread ID of the encountering thread
 // input_flags: Flags associated with the TDG
-// tdg_id:      ID of the TDG to record, for now, incremental integer
+// tdg_id:      ID of the TDG to record, XXX:
+// reset:       Reset flag, XXX:
 // returns:     1 if we record, otherwise, 0
 kmp_int32 __kmpc_start_record_task(ident_t *loc_ref, kmp_int32 gtid,
-                                   kmp_int32 input_flags, kmp_int32 tdg_id) {
+                                   kmp_int32 input_flags, kmp_int32 tdg_id,
+                                   bool reset) {
 
   kmp_int32 res;
   kmp_taskgraph_flags_t *flags = (kmp_taskgraph_flags_t *)&input_flags;
   KA_TRACE(10,
-           ("__kmpc_start_record_task(enter): T#%d loc=%p flags=%d tdg_id=%d\n",
-            gtid, loc_ref, input_flags, tdg_id));
+           ("__kmpc_start_record_task(enter): T#%d loc=%p flags=%d tdg_id=%d\n "
+            "reset=%d\n", gtid, loc_ref, input_flags, tdg_id, reset));
 
   if (__kmp_max_tdgs == 0) {
     KA_TRACE(
         10,
-        ("__kmpc_start_record_task(abandon): T#%d loc=%p flags=%d tdg_id = %d, "
-         "__kmp_max_tdgs = 0\n",
-         gtid, loc_ref, input_flags, tdg_id));
+        ("__kmpc_start_record_task(abandon): T#%d loc=%p flags=%d "
+         "tdg_id = %d reset = %d, __kmp_max_tdgs = 0\n",
+         gtid, loc_ref, input_flags, tdg_id, reset));
     return 1;
   }
 
   __kmpc_taskgroup(loc_ref, gtid);
+  if (reset) {
+    __kmp_free_tdg(tdg_id);
+    __kmp_num_tdg--;
+  }
   if (kmp_tdg_info_t *tdg = __kmp_find_tdg(tdg_id)) {
     printf("===> TDG exists\n");
     // TODO: use re_record flag

>From 15e587e41a7c648491b6a7810e50f06cf4d3fb29 Mon Sep 17 00:00:00 2001
From: jpinot <josep.pinot at bsc.es>
Date: Tue, 11 Mar 2025 11:33:56 +0100
Subject: [PATCH 7/7] [wip][openmp] Update record/replay with reset flag

---
 openmp/runtime/test/tasking/omp_record_replay.cpp           | 4 ++--
 openmp/runtime/test/tasking/omp_record_replay_deps.cpp      | 4 ++--
 openmp/runtime/test/tasking/omp_record_replay_multiTDGs.cpp | 6 +++---
 openmp/runtime/test/tasking/omp_record_replay_print_dot.cpp | 4 ++--
 openmp/runtime/test/tasking/omp_record_replay_taskloop.cpp  | 4 ++--
 5 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/openmp/runtime/test/tasking/omp_record_replay.cpp b/openmp/runtime/test/tasking/omp_record_replay.cpp
index 69ad98003a0d6..7779d27ca1788 100644
--- a/openmp/runtime/test/tasking/omp_record_replay.cpp
+++ b/openmp/runtime/test/tasking/omp_record_replay.cpp
@@ -13,7 +13,7 @@ typedef struct ident {
 #ifdef __cplusplus
 extern "C" {
   int __kmpc_global_thread_num(ident_t *);
-  int __kmpc_start_record_task(ident_t *, int, int, int);
+  int __kmpc_start_record_task(ident_t *, int, int, int, bool);
   void __kmpc_end_record_task(ident_t *, int, int , int);
 }
 #endif
@@ -30,7 +30,7 @@ int main() {
   #pragma omp single
   for (int iter = 0; iter < NT; ++iter) {
     int gtid = __kmpc_global_thread_num(nullptr);
-    int res =  __kmpc_start_record_task(nullptr, gtid, /* kmp_tdg_flags */ 0, /* tdg_id */0);
+    int res =  __kmpc_start_record_task(nullptr, gtid, /* kmp_tdg_flags */ 0, /* tdg_id */0, /* reset */ false);
     if (res) {
       num_tasks++;
       #pragma omp task 
diff --git a/openmp/runtime/test/tasking/omp_record_replay_deps.cpp b/openmp/runtime/test/tasking/omp_record_replay_deps.cpp
index 9b6b370b30efc..05318e4e2cc08 100644
--- a/openmp/runtime/test/tasking/omp_record_replay_deps.cpp
+++ b/openmp/runtime/test/tasking/omp_record_replay_deps.cpp
@@ -16,7 +16,7 @@ typedef struct ident {
 #ifdef __cplusplus
 extern "C" {
   int __kmpc_global_thread_num(ident_t *);
-  int __kmpc_start_record_task(ident_t *, int, int, int);
+  int __kmpc_start_record_task(ident_t *, int, int, int, bool);
   void __kmpc_end_record_task(ident_t *, int, int, int);
 }
 #endif
@@ -44,7 +44,7 @@ int main() {
   #pragma omp single
   for (int iter = 0; iter < NT; ++iter) {
     int gtid = __kmpc_global_thread_num(nullptr);
-    int res =  __kmpc_start_record_task(nullptr, gtid, /* kmp_tdg_flags */0, /* tdg_id */0);
+    int res =  __kmpc_start_record_task(nullptr, gtid, /* kmp_tdg_flags */0, /* tdg_id */0, /* reset */ false);
     if (res) {
       #pragma omp task depend(out:y)
       add();
diff --git a/openmp/runtime/test/tasking/omp_record_replay_multiTDGs.cpp b/openmp/runtime/test/tasking/omp_record_replay_multiTDGs.cpp
index 03252843689c4..8edfa4e7ada84 100644
--- a/openmp/runtime/test/tasking/omp_record_replay_multiTDGs.cpp
+++ b/openmp/runtime/test/tasking/omp_record_replay_multiTDGs.cpp
@@ -15,7 +15,7 @@ int val;
 #ifdef __cplusplus
 extern "C" {
   int __kmpc_global_thread_num(ident_t *);
-  int __kmpc_start_record_task(ident_t *, int, int, int);
+  int __kmpc_start_record_task(ident_t *, int, int, int, bool);
   void __kmpc_end_record_task(ident_t *, int, int , int);
 }
 #endif
@@ -43,7 +43,7 @@ int main() {
   #pragma omp single
   for (int iter = 0; iter < NT; ++iter) {
     int gtid = __kmpc_global_thread_num(nullptr);
-    int res =  __kmpc_start_record_task(nullptr, gtid, /* kmp_tdg_flags */ 0, /* tdg_id */0);
+    int res =  __kmpc_start_record_task(nullptr, gtid, /* kmp_tdg_flags */0, /* tdg_id */0, /* reset */ false);
     if (res) {
       num_tasks++;
       #pragma omp task depend(out:y)
@@ -54,7 +54,7 @@ int main() {
       mult();
     }
     __kmpc_end_record_task(nullptr, gtid, /* kmp_tdg_flags */0, /* tdg_id */0);
-    res =  __kmpc_start_record_task(nullptr, gtid, /* kmp_tdg_flags */ 0, /* tdg_id */1);
+    res =  __kmpc_start_record_task(nullptr, gtid, /* kmp_tdg_flags */0, /* tdg_id */1, /* reset */ false);
     if (res) {
       num_tasks++;
       #pragma omp task depend(out:y)
diff --git a/openmp/runtime/test/tasking/omp_record_replay_print_dot.cpp b/openmp/runtime/test/tasking/omp_record_replay_print_dot.cpp
index 2fe55f0815429..b32c42b659fa7 100644
--- a/openmp/runtime/test/tasking/omp_record_replay_print_dot.cpp
+++ b/openmp/runtime/test/tasking/omp_record_replay_print_dot.cpp
@@ -13,7 +13,7 @@ typedef struct ident {
 #ifdef __cplusplus
 extern "C" {
   int __kmpc_global_thread_num(ident_t *);
-  int __kmpc_start_record_task(ident_t *, int, int, int);
+  int __kmpc_start_record_task(ident_t *, int, int, int, bool);
   void __kmpc_end_record_task(ident_t *, int, int , int);
 }
 #endif
@@ -48,7 +48,7 @@ int main() {
   #pragma omp single
   {
     int gtid = __kmpc_global_thread_num(nullptr);
-    int res = __kmpc_start_record_task(nullptr, gtid, /* kmp_tdg_flags */ 0, /* tdg_id */ 0);
+    int res = __kmpc_start_record_task(nullptr, gtid, /* kmp_tdg_flags */0, /* tdg_id */0, /* reset */ false);
     if (res) {
       #pragma omp task depend(out : x)
       func(&num_exec);
diff --git a/openmp/runtime/test/tasking/omp_record_replay_taskloop.cpp b/openmp/runtime/test/tasking/omp_record_replay_taskloop.cpp
index 3d88faeeb28ee..2d50a9d41ac16 100644
--- a/openmp/runtime/test/tasking/omp_record_replay_taskloop.cpp
+++ b/openmp/runtime/test/tasking/omp_record_replay_taskloop.cpp
@@ -14,7 +14,7 @@ typedef struct ident {
 #ifdef __cplusplus
 extern "C" {
   int __kmpc_global_thread_num(ident_t *);
-  int __kmpc_start_record_task(ident_t *, int, int, int);
+  int __kmpc_start_record_task(ident_t *, int, int, int, bool);
   void __kmpc_end_record_task(ident_t *, int, int , int);
 }
 #endif
@@ -31,7 +31,7 @@ int main() {
   #pragma omp single
   for (int iter = 0; iter < NT; ++iter) {
     int gtid = __kmpc_global_thread_num(nullptr);
-    int res =  __kmpc_start_record_task(nullptr, gtid, /* kmp_tdg_flags */0,  /* tdg_id */0);
+    int res =  __kmpc_start_record_task(nullptr, gtid, /* kmp_tdg_flags */0, /* tdg_id */0, /* reset */ false);
     if (res) {
       num_tasks++;
       #pragma omp taskloop reduction(+:sum) num_tasks(4096)



More information about the Openmp-commits mailing list