An MDE Approach for Automatic Code Generation from UML/MARTE to OpenCL A dvanced engineering and scientific communities have used parallel programming to solve their large-scale complex problems for a long time. Despite their high-level expertise, developers in these communities often find it hard to implement their parallel applications effectively. Some inherent characteristics of parallel programming contribute to this difficulty, including race conditions, memory access bottleneck, granularity decision, scheduling policy, and thread safety. To facilitate the programming of parallel applications, developers have specified several approaches. The most commonly used standards are Open Message Passing (OpenMP) for shared memory and Message Passing Interface (MPI) for distributed memory programming. These approaches let us express and explore the potential parallelism of applications and architectures. OpenMP adds directives having the same syntax level as the target programming language (C, C++, Fortran), while MPI is implemented as a library to manage communication between nodes. From this viewpoint, these approaches are actually tools to add parallelism resources to a sequential programming model rather than a solution for parallel programming. In December 2008, the consortium managed by the Khronos Group released the Open Computing Language (OpenCL) 1.0 specification. 1 OpenCL is the first open, royalty-free standard for general-purpose parallel programming of heterogeneous systems. It provides a uniform programming environment for software developers to write efficient and portable code for high-performance computing servers, desktop computer systems, and handheld devices using a diverse mix of multicore CPUs, GPUs, cell-type architectures, and other parallel processors such as digital signal processors (DSPs). Here, we present an approach based on modeldriven engineering (MDE) 2 to specify, design, and generate OpenCL applications. This approach relies on the following aspects: • We propose three new metamodels that satisfy essential concerns of a whole applicationscheduling policy, variable definitions, and the OpenCL programming model itself.  • We propose a transformation chain that includes as many model transformations as we need for generating an efficient code (in other words, we concatenate single, specific model transformations to add or change elements designed in an input model to generate intermediate models toward the target code). • Because abstract models don't have all of the necessary information for improving performance based on the target hardware, we include some optimization levels to achieve (whenever possible) automatically generated code that's as efficient as manually written code. To gain a theoretical base for some of the concepts we'll discuss, see the "Background Review" sidebar. Next, we'll discuss our automatic codegeneration approach. Our approach aims to generate effective code for OpenCL as a new branch of our Gaspard2 development environment. 3 During application design, Gaspard2 uses a Unified Modeling Language (UML) profile for modeling and analysis of real-time and embedded (MARTE) systems to define semantics to the application. Then, using transformation chains, it lets us automatically generate code for a chosen target platform. One of the main advantages of MARTE is that it clearly distinguishes the hardware components from the software components. This is done via stereotypes provided in part by the detailed resource modeling (DRM) package, in particular the HwResource and its derived stereotypes. Regarding the hybrid (CPU and compute device) conception, this separation is of prime importance. In fact, in a codesign environment, usually different teams simultaneously create these two parts of the system. For instance, this allows for testing the software on different kinds of hardware architecture, or reusing an architecture (with few or no changes) for different applications. The application model concept is a fundamental modeling process. Indeed, developers will define three main aspects of their application: the tasks and their interconnection; the number of repetitions of a task and its hierarchy, as well as whether it will be instantiated as temporal or spatial modes; and how to express the dataflow. Eventually, to optimize the model, a smart procedure can perform model refactoring, a change made to the internal structure of a model to make it easier to understand and cheaper to modify without changing its observable behavior. 4 This helps us find good trade-offs in the usage of storage and computation resources, as well as in the potential parallelism of tasks and data. To clearly distinguish a host from a compute device, both defined in an OpenCL platform model, a tagged-value description in the HwResource stereotype is assigned either with Host or with Device. This is a valuable definition at design time, because once we have an allocation model, transformations can promptly identify kernels from allocated tasks. The allocation phase is defined in allocation modeling (Alloc) from the MARTE profile. Allocation of functional application parts onto the available resources is the main concern of system design for specific platforms. This includes both spatial distribution and temporal scheduling aspects, to map certain operations onto available computing and communication resources and services. Although MARTE is suitable for modeling purposes, it cannot move from high-level modeling specifications to execution platforms. Gaspard2 fills this gap and introduces additional concepts and semantics to attain this requirement for system codesign. Gaspard2 defines a deployment specification level to generate compilable code from an application model. This level is related to the specification of an elementary component (EC): a basic block having atomic functions. The deployment model lets us describe how the intellectual properties (IPs)-very optimized and normally parameterized functions that depend on the target technology-must be associated to ECs. In MDE, a model transformation is a compilation process that transforms a source model into a target model. The source and target models are respectively conformed to the source and the target metamodels. A model transformation relies on a set of rules. Each rule clearly identifies concepts in the source and the target metamodels. Such a decomposition facilitates the extension and the maintainability of a compilation process: new rules extend the compilation process and each rule can be modified independently from others. The rules are specified in programming languages, which can be either imperative (describing how a rule is executed) or declarative (describing what's created by the rules). Declarative languages are often used in MDE because the rules' objectives can be specified independently from the execution.
Rodrigues et al. REF give an approach to generate OpenCL code from models using MARTE profile.
An MDE Approach for Automatic Code Generation from UML/MARTE to OpenCL
Computing in Science & Engineering
Computing in Science & Engineering
Computer Science