scieee AI-readable full text Open interactive document viewer

Task-based programming models for heterogeneous recurrent workloads

Bosch Pons, Jaume,Vidal, Miquel,Filgueras Izquierdo, Antonio,Jiménez González, Daniel,Álvarez Martínez, Carlos,Martorell Bofill, Xavier,Ayguadé Parra, Eduard

Abstract

This paper proposes the extension of task-based programming models with recurrent workloads concepts. The proposal introduces new clauses in the OmpSs task directive to efficiently model recurrent workloads. The clauses define the task period and/or the number of task body repetitions. Despite the new clauses are suitable for any device, their support has been implemented using the capabilities of FPGA devices in embedded systems. These heterogeneous systems are common in industrial applications that usually develop recurrent workloads. The evaluation shows a huge gap in the applications' programmability, saving lines of code, and increasing the code readability. Besides, it shows the efficient management of recurrent tasks when performed in FPGA devices, which can support one order of magnitude finer tasks. All these improvements perfectly suit the needs of cyber-physical heterogeneous systems, which are frequently used in industrial environments to run recurrent workloads.

Full text

Task-Based Programming Models for Heterogeneous Recurrent Workloads Jaume Bosch1,2[0000−0002−4040−3416], Miquel Vidal1[0000−0002−1973−8289], Antonio Filgueras1[0000−0001−6071−3254], Daniel Jim´enez-Gonz´alez2[0000−0001−6064−7883], Carlos ´ Alvarez2[0000−0003−0536−5183], and Xavier Martorell2[0000−0002−0417−3430] Eduard Ayguad´e1,2[0000−0002−5146−103X] 1Barcelona Supercomputing Center, 08034 Barcelona, Spain {jaume.bosch,miquel.vidal,antonio.filgueras,eduard.ayguade}@bsc.es 2Universitat Polit`ecnica de Catalunya, 08034 Barcelona, Spain {djimenez,calvarez,xavim}@ac.upc.edu Abstract. This paper proposes the extension of task-based programming models with recurrent workloads concepts. The proposal introduces new clauses in the OmpSs task directive to efficiently model recurrent workloads. The clauses define the task period and/or the number of task body repetitions. Despite the new clauses are suitable for any device, their support has been implemented using the capabilities of FPGA devices in embedded systems. These heterogeneous systems are common in industrial applications that usually develop recurrent workloads. The evaluation shows a huge gap in the applications’ programmability, saving lines of code, and increasing the code readability. Besides, it shows the efficient management of recurrent tasks when performed in FPGA devices, which can support one order of magnitude finer tasks. All these improvements perfectly suit the needs of cyber-physical heterogeneous systems, which are frequently used in industrial environments to run recurrent workloads. Keywords: Task-Based Parallelism ·Recurrent Workloads ·Heterogeneous computing ·FPGA ·OmpSs ·OpenMP. 1 Introduction Task-based parallel programming models have demonstrated to be a powerful tool to develop applications targeting heterogeneous platforms [12] [4]. There are new parallel programming models with native support for heterogeneous systems (e.g. OpenACC [8] and CUDA [7]). Also, different parallel programming models, which were initially designed for multicore processors, introduced new features to support such heterogeneous systems (e.g. OpenMP [9] and OmpSs [4]). The importance of heterogeneous systems has grown in last years as coprocessors can increase the computational power of systems while keeping the power consumption restricted. The FPGAs are reconfigurable co-processors that Bosch, J. [et al.]. Task-based programming models for heterogeneous recurrent workloads. A: International Symposium on Applied Reconfigurable Computing. "Applied Reconfigurable Computing: Architectures, Tools, and Applications: 17th International Symposium, ARC 2021: virtual event, June 29–30, 2021: proceedings". Springer Nature, 2021, p. 108-122. ISBN 978-3-030-79025-7. The final authenticated version is available online at https://doi.org/10.1007/978-3-030-79025-7_8. 2 J. Bosch et al. allow implementing custom application logic within them. This logic can implement parts of applications, so they are executed faster and with a smaller power consumption than in the general purpose processor of the host. Periodic systems (i.e., recurrent workloads) are a common workload in industrial environments and real-time applications. Those workloads use the task concept to define the different activities that must be executed periodically (after some amount of time). Thereby, task-based parallel programming models are great candidates to support recurrent workloads. We propose extending the current syntax of task-based parallel programming models to define the main recurrent task parameters. Therefore, modeling recurrent workloads can be accomplished efficiently in terms of code lines, and with all parallel capabilities of baseline programming models. Also, we propose using the reconfigurable heterogeneous platforms to efficiently manage these recurrent workloads. These platforms will provide an efficient management of recurrent tasks, keeping the great programmability provided by the parallel programming models. The remainder of the paper is organized as follows. Section 2 describes the OmpSs@FPGA ecosystem. Section 3 describes the proposed programming model extension. Section 4 describes the implementation developed on top of OmpSs@FPGA to support the proposed extensions directly inside the FPGA co-processors. Section 5 presents the evaluation of the new design in an SoC. Finally, section 6 presents the related work and section 7 concludes. 2 Background C/C++ Frontend Phase OmpSs Phase << >> C++C++C++ BIT EXE C/C++ Native Compiler AITFPGA Specific Vendor Tools nan s HLS HLS HLS Fig. 1. OmpSs@FPGA compilation process The OmpSs@FPGA ecosystem is an upgrade of the OmpSs [4] infrastructure (Mercurium source-to-source compiler and Nanos++ runtime) to incorporate FPGA support [2]. OmpSs is a task-based parallel programming model that extends the OpenMP 3.1 syntax and has been an active forerunner of the current tasking capabilities available in OpenMP 5.0. OmpSs@FPGA modifies Mercurium compiler, to support the generation of an independent source code file for each task with the FPGA target; and Nanos++ runtime, to handle the Task-Based Programming Models for Heterogeneous Recurrent Workloads 3 data movements between the host and FPGA memory, and offload the tasks to the device. Moreover, the ecosystem is composed by other tools like AIT (Accelerator Integration Tool), which combines all FPGA files generated by Mercurium and calls specific vendor tools that generate the bitstream; and xTasks library, which provides a common API to Nanos++ for data and task management regardless the communication protocol between the host and the FPGA. The structure of all those tools is shown in figure 1. 1#pragma omp target device(fpga) num_instances(2) \ 2copy_inout([BSIZE]buffer, [1]offset) 3#pragma omp task 4void read_sensor(float *buffer, unsinged int *offset) { 5buffer[*offset] =...; 6*offset += 1; 7} 8int main(...) { 9float buffer[BSIZE]; unsigned int offset = 0; 10 read_sensor(buffer, &offset); 11 #pragma omp taskwait 12 } Listing 1: OmpSs@FPGA task example The definition of an FPGA task in the OmpSs programming model can be seen in listing 1. In contrast to OpenMP, OmpSs supports the annotation of function declarations that result in a task spawn every time the function is called. In listing 1, we can see that function read sensor is annotated with the task and target directives. The device(fpga) clause executes the task in an FPGA device instead of the host processor. The num instances(2) clause defines the number of FPGA task accelerators that should be generated in the FPGA bitstream, which will be available to concurrently execute the instances of this task. The copy inout([BSIZE]buffer, [1]offset) clause defines the data regions accessed by the task body, so the runtime manages a copy of them into FPGA memory before and after each task execution. Also, there are copy in(...) and copy out(...) clauses which only copy the data before or after each task execution respectively. In addition, data regions could be defined in the data dependence clauses (in,inout, and out) which also annotate the regions as task dependences to order the execution of tasks at runtime. The implementation supports task nesting within FPGA tasks. Therefore, FPGA task accelerators may spawn new FPGA/SMP/GPU tasks and synchronize them with the regular taskwait. For each FPGA task in the application, Mercurium compiler isolates its source code in a separate source file and embeds it in a communication wrapper. This wrapper has a common external interface independent of task arguments, and it provides instrumentation capabilities and data caching optimization. Finally, the generated files are provided to AIT which generates an FPGA bitstream with all task accelerators and the management logic. The IP blocks placed in the FPGA design with their interconnections are shown in figure 2. 4 J. Bosch et al. FPGA Task Accelerator SOM CmdIn Manager CmdOut Manager CmdIn Queue CmdOut Queue Accelerators Stats FPGA Task Accelerator X X SpawnIn Queue SpawnOut Queue Taskwait Manager Scheduler Manager SpawnIn Manager Int. CmdIn Queue FPGA Task Accelerator FPGA Task Accelerator X X X Bitinfo Fig. 2. OmpSs@FPGA bitstream organization The FPGA task accelerators are connected with input and output streams to the SOM Hardware Runtime (HWR) [3]. The SOM module handles the commands sent by the host runtime and manages the messages sent by the FPGA task accelerators (task execution finished, task spawn, spawned tasks synchronization, etc.). The communication between the host runtime (through xTasks library) and the HWR is done by commands submitted into the 4 queues shown in figure 2. Each of the queues is managed by an IP block: CmdIn Manager forwards the commands to the FPGA task accelerators, CmdOut Manager notifies about executed commands, Scheduler Manager forwards the tasks spawned within the FPGA (into Int. CmdIn Queue when the task can be executed directly in the FPGA, into SpawnOut Queue otherwise), SpawinIn Manager handles executed task commands for reverse offloaded tasks, Taskwait Manager counts the tasks executed in each context for later synchronization. 3 Programming Model Extension The OmpSs programming model has been extended with new clauses to annotate the recurrent tasks information. Although we present the clauses for the OmpSs programming model, they could also be incorporated in the OpenMP standard with the same semantics. The clauses are intended to provide the information of recurrent tasks which are periodically triggered by a timer. We keep as future work the support for recurrent tasks triggered by external events. The period and num repetitions clauses have been added to the existing task directive. They are optional and only one of both is needed to create a recurrent task. Both clauses take a single expression, which is evaluated as a 32 bits value at runtime. Therefore, the value may be unknown at compile time. The period(N) clause defines the minimum amount of time between the beginning of two task executions. By default, the time is expressed in microseconds, Task-Based Programming Models for Heterogeneous Recurrent Workloads 5 but this may be changed at compile time (using a compiler option). The default (implicit) clause value in a recurrent task is 0, which makes the task start again just after it finishes. The same happens when the task execution takes longer than the period: the next repetition starts just after the former. However, this behavior could be changed in the future with extra clauses or by a runtime option. Other approaches could be: aborting the current repetition, aborting the next repetition, schedule both repetitions in parallel. The num repetitions(N) clause defines the maximum number of times that the task body will be executed. The default (implicit) clause value in a recurrent task is an unlimited number of repetitions. Since 0 repetitions may be a valid amount, the unlimited number of repetitions is represented with the largest representable value (0xFFFFFFFF) which can be specified through OMP REPS UNLIMITED constant. The semantics of other clauses in a recurrent task remain equal to a regular task. The same criteria apply to other programming model directives, like the taskwait. The recurrent tasks will not become finished until all repetitions have been run. Therefore, a taskwait after a recurrent task will not be accomplished until all task repetitions have been run. Also, the data dependences in a recurrent task only postpone the execution of the first repetition but not the others, and the successor tasks of a recurrent task are not ready until all repetitions are executed. However, a recurrent task can periodically spawn a set of child (nested) tasks with dependences between them. This makes possible having data dependences between periodically executed tasks. 1#pragma omp target device(fpga) num_repetitions(reps) period(1000000) \ 2copy_inout([BSIZE]buffer, [1]offset) 3#pragma omp task 4void read_sensor(float *buffer, unsigned int *offset, const int reps); 5 6int main(...) { 7read_sensor(buffer, &offset, 10); 8#pragma omp taskwait 9} Listing 2: OmpSs example with a recurrent task Listing 2 shows the example of listing 1 extended with the new recurrent clauses. The read sensor task has been annotated with the run repetitions and period clauses in line 1. Therefore, the task’s body will be executed reps times (10 as shown in function call of line 7) every 1 second (1000000 microseconds in the clause value). The taskwait in line 8 will be accomplished after all task body repetitions have been executed. Similarly, successor tasks that have a common data dependence on the same element (annotated with in,inout, or out clauses) will be ready to execute once recurrent tasks finish. Two new APIs have been defined in the programming model to control the execution of recurrent tasks. Those APIs must be called within the recurrent tasks and apply to itself. 6 J. Bosch et al. omp get periodic task repetition num returns the current repetition number which is under execution. The first repetition is the number 1, since 0 is returned when the task is non-recurrent. omp cancel periodic task cancels the remaining repetitions of the current recurrent task. It does not cancel the remaining task code after the API call. 4 Implementation The programming model extension has been implemented on top of OmpSs@FPGA. This section presents the modifications that we performed in order to support the recurrent tasks management in the FPGA task accelerators. In addition, the support for critical regions between task accelerators inside the same FPGA device has been introduced. This is very useful to coordinate the different accelerators during the execution as the recurrent tasks start their execution autonomously without any synchronization. 4.1 Mercurium Compiler The OmpSs translation phase has been extended to support the new clauses. The compiler forwards the period and number of repetitions information to the runtime during the task creation if any of the clauses appear. The information is provided using a new runtime API. In contrast, the compiler emits the regular API calls for task creation if the task directive does not contain neither period nor num repetitions clauses. The wrapper generated by the compiler in the C++ HLS intermediate files has been extended. It has to support a new command (similar to the task execution command) with the number of repetitions and period information. The wrapper has to handle the calls to omp get periodic task repetition num and omp cancel periodic task APIs which could be called within the task code. Moreover, the support for critical regions in the FPGA task accelerators requires sending a message to the new Lock Manager of HWR. 4.2 Nanos++ runtime and xTasks library The Nanos++ runtime has been extended with a new API that is called during the task spawn to set the recurrent information. The API is called nanos setwd recurrent and it takes 3 arguments: the reference/pointer of the task being spawned, the minimum period between task executions, and the number of repetitions. The xTasks library has been extended to support the new task information. When a task has to be offloaded to the FPGA and it is a recurrent task, the new command is issued instead of the previous task execution command. Task-Based Programming Models for Heterogeneous Recurrent Workloads 7 4.3 FPGA Design Support The support of the new features only requires minor changes in the FPGA task accelerators and HWR. The main change is the new command that must be supported by the HLS wrapper (generated by Mercurium) and the HWR. Also, the new Lock Manager has been added inside the HWR to manage exclusive access to critical regions. The FPGA task accelerators have been extended to support the new capabilities. The wrapper generation has been modified to implement the repetitions management. In addition, two new ports have been added to delay the task body executions the specified amount of time. The ports are used to read a counter that is incremented every clock cycle, and the frequency of such increment. With this information, the wrapper is able to accurately wait the needed amount of time between repetitions. The lock acquire and release messages, which are sent to support the critical regions on the FPGA task accelerators, are forwarded through the existing interconnections. These interconnections are the ones going between SOM and FPGA task accelerators, and vice-versa. The Lock Manager is a new IP block developed in C++ using HLS tools and added inside the SOM HWR. It has input and output interfaces to receive and acknowledge the messages sent by the FPGA task accelerators. Those streams are connected like Taskwait Manager or Scheduler Manager, as shown in figure 2. The module’s purpose is to keep the state of different locks that may be concurrently acquired and released by the FPGA task accelerators. To this end, the module has an internal table with the state of each lock. The module can receive two types of messages in the input stream: acquire messages and release messages. Whenever it receives a new message, it looks for the lock identifier (sent by the FPGA task accelerator) in the internal table and sets or clears the lock state. The response is successful in the acquire messages when the lock was not previously set and fails when the state is unchanged. The number of entries in the internal lookup table is fixed during the AIT design stage. The current implementation has a direct mapping in the table for each lock ID. However, this could be changed and implement an N-way table. There must be enough entries in the table to ensure that nested locks do not map to the same entry. Otherwise, the system will enter in a deadlock state due to the impossibility of acquiring the inner lock. The CmdIn Manager has been updated to consider the new command format that xTasks library may send to the FPGA task accelerators. The new command has the same format as the previous execute task command but with an extra word (number of repetitions and period) that also has to be forwarded. 5 Evaluation The evaluation of the proposed design and implementation of recurrent tasks has been done in terms of programmability and productivity, limitations of tasks 8 J. Bosch et al. management, and power savings. Section 5.1 presents the experimental setup used in the evaluation. Section 5.2 presents the evaluation of the limitations and management overheads of the proposed design using a synthetic benchmark. Section 5.3 shows the results for a sensor monitoring use case in embedded systems. Finally, section 5.4 presents the evaluation of the proposal for a face detection application. 5.1 Experimental Setup The evaluation of the proposal modifications has been done in a Zedboard with real executions. The board contains a Xilinx Zynq R -7000 All Programmable SoC [1], and it is commonly used in embedded industrial systems as it offers high versatility with reduced power consumption and budget. The SoC is composed of 2 ARM Cortex-A9 cores, that run at 667 MHz, a Xilinx Zynq-7000 FPGA and a main DDR3 memory of 512 MB. The board is booted using the Ubuntu Linux 16.04 operating system. All FPGA bitstreams have been generated and executed at 100 Mhz. The tools used to generate the application bitstream and binaries are: Vivado Design Suite 2020.1, GNU C/C++ Compiler 6.2.0, and PetaLinux Tools 2019.2. The modifications have been developed on top of OmpSs@FPGA release 2.3.0. 5.2 Synthetic benchmark The synthetic benchmark executes a recurrent task NUM REPS times every PERIOD microseconds. The task, called foo, lasts for duration microseconds. With these parameters, we can explore the runtime limits to manage fine-grain recurrent tasks. The NUM REPS and PERIOD information can be provided into the programming model using the proposed clauses or handled at application level without the proposal extensions. Listing 3 shows the pseudo-code of benchmark tasks. The foo task is always used, but without the new clauses (num repetitions and period) in the baseline implementation. The foo manager task is only needed in the baseline implementation to launch and synchronize the recurrent task every PERIOD microseconds from the SMP host threads. In contrast, the foo manager task is not needed with the proposed extensions, and foo is directly called. Implementing the management logic of a recurrent task requires an effort from programmers and additional code. In contrast, the logic can be avoided by just using a couple of programming model clauses. The baseline system requires one extra task of 8 lines for each recurrent task (like foo manager in listing 3). During the period wait, the taskyield directive [9] (line 12) is used to avoid blocking the host thread executing the manager task. However, the task consumes resources and adds pressure to the host runtime. In contrast, the proposal moves the management complexity into the FPGA task accelerator, which only needs to receive the task information with the number of repetitions and the period. This has a minimal footprint in the resources used by the FPGA task accelerator as shown in table 1 (for a 100 Mhz build). In terms of power consumption, the proposal removes the need to use an A9 core for recurrent task Task-Based Programming Models for Heterogeneous Recurrent Workloads 9 1#pragma omp target device(fpga) /* num_repetitions(NUM_REPS) period(PERIOD) */ 2#pragma omp task 3void foo(int duration) { usleep(duration); } 4 5#pragma omp task 6void foo_manager(int duration) { 7for (unsigned int rep=0; rep<NUM_REPS; rep++) { 8double t_ini =wall_time_us(); 9foo(duration); 10 #pragma omp taskwait 11 while ((wall_time_us() -t_ini) <PERIOD && rep <(NUM_REPS - 1)) { 12 #pragma omp taskyield 13 }}} Listing 3: Recurrent synthetic benchmark tasks pseudo-code management, which consumes 277 mW. Indeed, it only increases the FPGA task accelerator power by 1 mW while doing the same work. Both powers are reported by Vivado in the post-implementation power summary. Name BRAM DSP FF LUT Power Zedboard 280 220 106.400 53.200 - ARM A9 Core - - - - 277 mW foo baseline 0 (0%) 2 (0,9%) 593 (0,6%) 478 (0,9%) 7 mW foo proposal 0 (0%) 4 (1,8%) 921 (0,9%) 792 (1,5%) 8 mW Table 1. Vivado resources utilization and power report for Zedboard (100 Mhz) The time devoted to each repetition is PERIOD, or duration if the task execution lasts more than the task’s period (concurrent repetitions are not allowed). Then, the optimal execution time (equation 1) is defined by NUM REPS multiplied by the time devoted to each repetition, except for the last one that only needs to consider the task execution time (duration) as the benchmark can immediately finish. Moreover, the effectiveness of an execution (equation 2) is defined by the ratio between the optimal execution time and the real execution time (100% means optimal). Timeoptimal = (num reps −1) ∗max(duration, period) + duration (1) Effectivenessexec =Timeoptimal/Timeexec (2) Figure 3 shows the effectiveness (y-axis) of the synthetic benchmark when changing the task period (x-axis). Figure 3a shows the results at nanoseconds scale, and figure 3b shows the results at microseconds scale. Each chart has different series that correspond to different task durations. The task durations are labeled in the legend and are only shown for periods equal or larger than them. The number of repetitions is constant in all results at the same scale and proportional between them (10.000.000 in figure 3a and 10.000 in figure 3b). The 16 J. Bosch et al. 13. Vesel´y, J., Basu, A., Bhattacharjee, A., Loh, G.H., Oskin, M., Reinhardt, S.K.: Generic system calls for GPUs. In: 2018 ACM/IEEE 45th Annual International Symposium on Computer Architecture (ISCA). pp. 843–856. IEEE (2018)