[flang-commits] [flang] [llvm] [flang][runtime] Replace recursion with iterative work queue (WORK IN PROGRESS) (PR #137727)
Andre Kuhlenschmidt via flang-commits
flang-commits at lists.llvm.org
Wed Apr 30 11:03:28 PDT 2025
================
@@ -0,0 +1,289 @@
+//===-- include/flang-rt/runtime/work-queue.h -------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// Internal runtime utilities for work queues that replace the use of recursion
+// for better GPU device support.
+//
+// A work queue is a list of tickets. Each ticket class has a Begin()
+// member function that is called once, and a Continue() member function
+// that can be called zero or more times. A ticket's execution terminates
+// when either of these member functions returns a status other than
+// StatOkContinue, and if that status is not StatOk, then the whole queue
+// is shut down.
+//
+// By returning StatOkContinue from its Continue() member function,
+// a ticket suspends its execution so that any nested tickets that it
+// may have created can be run to completion. It is the reponsibility
+// of each ticket class to maintain resumption information in its state
+// and manage its own progress. Most ticket classes inherit from
+// class ComponentTicketBase, which implements an outer loop over all
+// components of a derived type, and an inner loop over all elements
+// of a descriptor, possibly with multiple phases of execution per element.
+//
+// Tickets are created by WorkQueue::Begin...() member functions.
+// There is one of these for each "top level" recursive function in the
+// Fortran runtime support library that has been restructured into this
+// ticket framework.
+//
+// When the work queue is running tickets, it always selects the last ticket
+// on the list for execution -- "work stack" might have been a more accurate
----------------
akuhlens wrote:
Might consider calling the class WorkLIFOQueue or WorkStack then. I immediately thought it would be a FIFO queue for some reason, not sure if others will have the same intuition.
https://github.com/llvm/llvm-project/pull/137727
More information about the flang-commits
mailing list