scieee AI-readable full text Open interactive document viewer

Code generation for the openmp 4.0 accelerator model onto ompss

Ozen, Guray

Abstract

I present a MACC compiler which is partial implementation of this specification in the OmpSs programming model in order to show code generation for hardware accelerators.

Full text

CODE GENERATION COMPILER FOR THE OPENMP 4.0 ACCELERATOR MODEL ONTO OMPSS Guray Ozen FACULTAT D'INFORMÀTICA DE BARCELONA Master in Innovation and Research in Informatics High Performance Computing Program Universitat Politecnica de Catalunya (UPCBarcelonaTECH) Master of Sciences Advisors: Prof Jesus Labarta Prof Eduard Ayguade Barcelona, UPC, 2014 "Premature optimization is the root of all evil." — Donald Knuth Thanks my mother... Acknowledgements Foremost, I would like to express my sincere gratitude to my advisors Prof. Jesus Labarta and Prof. Eduard Ayguade for the continuous support of my Master Thesis study and research, for their patience, motivation, enthusiasm, and immense knowledge. Their guidance helped me in all the time of research and writing of this thesis. I could not have imagined having a better advisor and mentor for my Master Thesis study. I thank also Programming Models group, especially Compiler team in Barcelona Supercomputer center. Last but not the least, I would like to thank my family: for giving birth to me at the first place and supporting me spiritually throughout my life. Barcelona, 01 June 2014 Guray Ozen i Abstract The aim of OpenMP which is a well known shared memory programming API, is using shared memory multiprocessor programming with pragma directives easily. Up till now, its interface consisted of task and iteration level parallelism for general purpose CPU. However OpenMP includes in its latest 4.0 specification the accelerator model. OmpSs is an OpenMP extended parallel programming model developed at the Barcelona Supercomputing Center and it have already supported accelerators without code generation. The main objective of OmpSs is to orchestrate different kind of tasks. The design of OmpSs is highly biassed to delegate most of the decisions to the runtime system, which based on the task graph built at runtime (depend clauses) is able to schedule tasks in a data flow way to the available processors and accelerator devices and orchestrate data transfers and reuse among multiple address spaces. In this thesis i present a MACC compiler which is partial implementation of this specification in the OmpSs programming model with the aim of identifying which should be the roles of the programmer, the compiler and the runtime system in order to facilitate the asynchronous execution of tasks in architectures with multiple accelerator devices and processors. For this reason implementation of thesis is partial, just considering from 4.0 those directives that enable the compiler the generation of the so called “kernels” to be executed on the target device. Several extensions to the current specification are also presented, such as the specification of tasks in “native” CUDA and OpenCL or how to specify the device and data privatization in the target construct. Finally, the paper also discusses some challenges found in code generation and a preliminary performance evaluation with some kernel applications. Before starting issues about GPU code generation, PURE GPU programming models are discussed and are showed their pears and pitfalls. Besides all these, challenges of GPU programming are discussed such as memory usage, multi gpu and streaming. Based upon these experience, some methods are developed and they are applied onto MACC compiler. Basically MACC’s extension from OpenMP 4.0 is based on these methods. Key words: Compiler, Accelerators, OpenMP, OmpSs, GPGPU, Code generation, Source-to- source compiler, SYCL, CUDA, OpenCL iii Contents Acknowledgements i Abstract iii List of figures vii 1 Introduction 1 1.1 Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1.2 Thesis Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.3 Thesis Organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 2 GPU As An Parallel Computation Target 5 2.1 CUDA Hardware Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 2.1.1 Execution Units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 2.1.2 Memory Hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 2.2 CUDA Programming Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 2.2.1 Streaming & Concurrency . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.2.2 Runtime & Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 2.3 Accelerator Programming with Intermediate Languages . . . . . . . . . . . . . . 12 3 Related Works & State of Arts 15 3.1 Source–to–Source Transformations . . . . . . . . . . . . . . . . . . . . . . . . . . 16 3.2 Directive Based Standards OpenMP 4.0 & OpenACC . . . . . . . . . . . . . . . . 20 3.3 OmpSs Heterogeneous Hardware Support . . . . . . . . . . . . . . . . . . . . . . 23 3.3.1 Nanos++ Runtime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 3.3.2 GPU support for OmpSs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 3.4 C++11 Extended Code Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 4 MACC: Mercurium ACCelerator Compiler 31 4.1 Basis on Mercurium & MACC Compiler . . . . . . . . . . . . . . . . . . . . . . . . 31 4.1.1 Parsing & Mercurium IR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 4.1.2 Mercurium Compiler Work Flow . . . . . . . . . . . . . . . . . . . . . . . . 33 4.1.3 MACC Phases Pipeline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 4.1.4 MACC Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 4.2 ACCelerator Code Generation Phase . . . . . . . . . . . . . . . . . . . . . . . . . . 37 v 2GPU As An Parallel Computation Target GPU is a multi-threaded, many-core, massively parallel processor. It is designed principally for computing graphic operation. Obviously these different can be seen at Figure 2.1. In order to fully take advantage of this incomparable strength of GPU, recently, graphic card company NVidia is announced its new general purposed computing architecture "CUDA" which enables dramatically increases in computing performance the computing power of GPU. In addition, Nvidia published CUDA SDK, programming interfaces, super powerful environments such as profiler, debugger and many libraries. In this chapter CUDA hardware and programming model is mentioned in order to do initial declaration for thesis. First section is going to explain CUDA hardware. Following sections explains its programming model and runtime briefly. Figure 2.1 – GPU vs CPU 5 Chapter 2. GPU As An Parallel Computation Target 2.1 CUDA Hardware Model GPU hardware is quite different than usual CPU hardware. Principally they were not designed for general purpose application. GPUs have many small cores and those can be run in parallel way. Because in order to process graphics big cores are not necessary. Besides communication bus can be PCI-E, if they are not part of CPU. No wonder there are other architecture way though PCI-E is main communication way in HPC area. However in every case GPUs have own memory system and it need to be configured and managed by programmer. In brief GPU has two number of key blocks; Execution Units which are Streaming Multiprocessor (Parallel Execution Unit) and Streaming Processors (Cores) and Memory. 2.1.1 Execution Units One of main components is streaming multiprocessors (SM) where is performed actual computations. Each SM consist SP/DP Cuda Cores, Load/Store unit, Warp Scheduler, Special Function Unit, several caches and one interface to access upper level memory. They supports instruction level parallelism but they don’t have branch predictor or speculative execution. Consisted cores is quite small. It has floating and integer unit, logic unit, move/compare unit and small branch unit. GPU is responsible for scheduling the blocks/threads, each block/thread can be scheduled on any available multiprocessor and core, concurrently or sequentially. Therefore execution order of blocks and threads are undefined. In addition, the execution of threads block works completely independently of each other. Since this feature brings to computation to be transparent scalable, since GPUs with different number of multiprocessors can automatically assign each block to any available multiprocessor without worrying about the entanglement between different blocks. CUDA threads are scheduled in a groups of warps and they are run within a warp as SIMT (Single-Instruction Multiple Thread) way. This work is managed by streaming multiprocessors. Warp is one of the taxonomy in CUDA. In the kepler architecture, 32 threads is bunched by 6 2.1. CUDA Hardware Model 1 t id = blockDim . x *blockIdx . x + threadIdx . x ; 2i f ( array [ tid ] > 0 ) 3 \\ < .. computation . . > 1 t id = blockDim . x *blockIdx . x + threadIdx . x ; 2i f ( array [ tid ] > 0 ) 3 \\ < .. computation . . > 4else 5 \\ < .. computation . . > 1 endId = array [blockDim . x *blockIdx . x + threadIdx . x ] ; 2for (int i = 0; i < endId ; ++ i ) 3 \\ < .. computation . . > Figure 2.2 – Common scenarios of thread divergency one warp. Bunch-able number of threads depends on CUDA architecture. Bunched threads can be run at the same pipeline like SIMD fashion. Therefore all threads in the warp executes same instruction at the same time. In here there is a big problem for GPU programmers. However devil is in the details. Because if one thread in the warp encounters branch, its future instructions may going to be different than rest of threads. If so, there are two different instruction way in the warp. Since warp’s instructions are run at the same time, one of them is stalled. A stalled warp is ineligible to be selected by the warp scheduler. On Fermi it is useful to have at least 2 eligible warps per cycle so that the warp scheduler can issue an instruction. This problem is called thread divergency. It may cause %50 performance loss. In order to clarify this problem, Figure 2.2 shows possible cases. In general using irregular accessing to array as branch condition may cause divergency problem. On the other hand, NVIDIA GPU has coalesced memory access. When all threads in a warp execute a load instruction, the hardware detects whether the threads access consecutive memory locations. The most favorable global memory access is achieved when the same instruction for all threads in a warp accesses global memory locations. In this favorable case, the hardware coalesces all memory accesses into a consolidated access to consecutive DRAM locations by the special hardware in CUDA GPUs, global memory loads and stores issued by threads of a warp into as few transactions as possible to minimize DRAM bandwidth (on older hardware of compute capability less than 2.0, transactions are coalesced within half warps of 16 threads rather than whole warps). 2.1.2 Memory Hierarchy In CUDA architecture, host and device have separate memory spaces. All threads in the device are only running on the device memory, the programmer is responsible for allocating the necessary device spaces, transferring the related data between host and device memory, and cleaning up all of the unnecessary device memory. CUDA run time system provides 7 Chapter 2. GPU As An Parallel Computation Target programmers with APIs to perform all of these activities. Figure 2.3 is illustrated as a device. 1. Registers: Registers are the fastest memory, accessible without any latency on each clock cycle, just as on a regular CPU. A thread’s registers cannot be shared with other threads. 2. Shared Memory: It is comparable to L1 cache memory on a regular CPU. It resides close to the multiprocessor, and has very short access times. Shared memory is shared among all the threads of a given block. 3. Global memory: It resides on the device, but off chip from the multiprocessors, so that access times to global memory can be 100 times greater than to shared memory. All threads in the kernel have access to all data in global memory. 4. Local Memory: Thread-specific memory stored where global memory is stored. Variables are stored in a thread’s local memory if the compiler decides that there are not enough registers to hold the thread’s data. This memory is slow, even though it’s called "local". 5. Constant Memory: 64k of Constant memory resides off-chip from the multiprocessors, and is read-only. The host code writes to the device’s constant memory before launching the kernel, and the kernel may then read this memory. Constant memory access is cached each multiprocessor can cache up to 8k of constant memory, so that subsequent reads from constant memory can be very fast. All threads have access to constant memory. 6. Texture Memory: It likes constant memory, texture memory is cached on chip, so in some situations it will provide higher effective bandwidth by reducing memory requests to off-chip DRAM. Specifically, texture caches are designed for graphics applications where memory access patterns exhibit a great deal of spatial locality 2.2 CUDA Programming Model CUDA provides programming model that is ANSI C, extend several keywords and constructs. Programmers writes a single source program that contains both host (CPU) and device(GPU) code. These two parts automatically separated compiled by the CUDA compiler tool chain. CUDA program which is callable is called as kernel. As it is mentioned before CUDA architecture is designed to run instructions in parallel way. Therefore it can be run as massively parallel. 8 2.2. CUDA Programming Model Figure 2.3 – CUDA Memory Model Figure 2.4 is illustrated CUDA thread hierarchy. As it seen, grids and blocks can be configured multi dimensional. This approach is used to leverage data locality by coalesced access pattern. However these dimensions need to be configured manually by programmers. There is no auto decision mechanism in order to find optimum number of thread size. Figure 2.5 shows sample CUDA program with host program. Line 47-48 finds number of block and grid. However this calculation may be change each CUDA program. On the other hand, CUDA programming model programmers need to manage memory allocation and flow. During the execution, each thread may access data from different types of device memory Figure 2.3. First of all, all threads in all blocks can read and write the global memory which is allocated and released by calling the cudaMalloc and cudaFree functions respectively. In the simple cuda example Figure 2.5 is handled at Line 40–41, 44, 45 and 54. Kernel is invoked at line 50 with parameters which are couple pointers which holds address at GPU and kernel dimensions which are calculated at line 47-48. When examined CUDA kernel starts with Line 1, using shared memory rules can be seen. While line 4-5 allocates area from shared memory, line 12–19 fills these areas from global memory. 2.2.1 Streaming & Concurrency CUDA programming model is not totally data parallel programming model. In fact it supports concurrency by task level parallelism. When examined parallelism context, a task can be many different things. For instance, an CUDA application can be executing two tasks: some computation with one thread while downloading something with another thread. These tasks proceed in parallel, despite having nothing in common. Although the task parallelism on 9 Chapter 2. GPU As An Parallel Computation Target Figure 2.4 – CUDA Thread Hierarchy GPUs is not currently as flexible as a general-purpose processor’s, it still provides opportunities for us as programmers to extract even more speed from our GPU-based implementations. These facility can be used if GPU’s computation capability is higher than 2.0. 2.2.2 Runtime & Environment In favor of programmability, the latest releases of the Nvidia CUDA architecture improved programming productivity by moving some of the burden to the CUDA runtime, including Unified Virtual Addressing (CUDA 4) to provide a single virtual memory address space for all memory in the system (enabling pointers to be accessed from GPU) no matter where in the system they reside) and Unified Memory (CUDA 6) to automatically migrate data at the level of individual pages between host and devices, freeing programmers from the need of allocating and copying device memory. Although it may be seen as a need for beginners, it makes it possible to share complex data structures and eliminate the need to handle "deep copies" in the presence of pointed data inside structured data. Carefully tuned CUDA codes may still use streams and asynchronous transfers to efficiently overlap computation with data movement when the CUDA runtime is unable to do it appropriately due to lack of lookahead. Figure 2.6 shows both of approach. 10 2.2. CUDA Programming Model 1 __global__ void matrixMultiply ( float *A, float *B, float *C, int numARows, int NCA, \ 2int numBRows, int NCB, int numCRows, int numCColumns) 3 { 4 __shared__ float ds_M[ TILE ] [ TILE ] ; 5 __shared__ float ds_N[ TILE ] [ TILE ] ; 6 7int bx = blockIdx . x , by = blockIdx . y , tx = threadIdx . x , ty = threadIdx . y , 8 Row = by *TILE + ty , Col = bx *TILE + tx ; 9float Pvalue = 0; 10 11 for (int m = 0; m < (NCA−1)/TILE+1; ++m) { 12 i f (Row < numARows && m*TILE+tx < NCA) 13 ds_M[ ty ] [ tx ] = A[Row*NCA+m*TILE+tx ] ; 14 else 15 ds_M[ ty ] [ tx ] = 0; 16 i f ( Col < NCB && m*TILE+ty < numBRows) 17 ds_N[ ty ] [ tx ] = B [ (m*TILE+ty ) *NCB+Col ] ; 18 else 19 ds_N[ ty ] [ tx ] = 0 ; 20 21 __syncthreads ( ) ; 22 for (int k = 0; k < TILE ; ++k) 23 Pvalue += ds_M[ ty ] [ k ] *ds_N[ k ] [ tx ] ; 24 __syncthreads ( ) ; 25 } 26 i f (Row < numCRows && Col < numCColumns) 27 C[Row*numCColumns+Col ] = Pvalue ; 28 } 29 30 int main( int argc , char *argv [ ] ) { 31 int NRA= 3000,NCA =4000 NCB =5000; 32 33 float *d_a , *d_b , *d_c ; 34 float *h_a=( float *) malloc (NRA*NCA*sizeof (float) ) ; 35 float *h_b=( float *) malloc (NCA*NCB*sizeof (float) ) ; 36 float *h_c=( float *) malloc (NRA*NCB*sizeof (float) ) ; 37 38 i n i t ( a , b) ; 39 40 cudaMalloc(&d_a , NRA*NCA*sizeof (float ) ) ; 41 cudaMalloc(&d_b , NCA*NCB*sizeof (f loat ) ) ; 42 cudaMalloc(&d_c , NRA*NCB*sizeof (float ) ) ; 43 44 cudaMemcpy( d_a , h_a , NRA*NCA*sizeof (float) , cudaMemcpyHostToDevice) ; 45 cudaMemcpy( d_b , h_b , NCA*NCB*sizeof (float) , cudaMemcpyHostToDevice) ; 46 47 dim3 dimGrid ( (NCB−1)/TILE+1 , (NRA−1)/TILE+1 , 1) ; 48 dim3 dimBlock (TILE , TILE , 1) ; 49 50 matmul<<<dimGrid , dimBlock>>> ( d_a , d_b , d_c ,NRA,NCA,NCA,NCB,NRA,NCB) ; 51 52 cudaThreadSynchronize ( ) ; 53 54 cudaMemcpy(h_c , d_c , NRA*NCB*sizeof (float) , cudaMemcpyDeviceToHost) ; 55 56 check_result ( h_c) ; 57 } Figure 2.5 – Altogether CUDA application 11 Chapter 2. GPU As An Parallel Computation Target Figure 2.6 – CUDA Execution Model 2.3 Accelerator Programming with Intermediate Languages Another novel approach for developing accelerator program is using intermediate language. Currently there are two approaches such as PTX(Parallel Thread eXecution)[ 13 ] and SPIR(Standard Portable Intermediate Representation) [ 17 ]. Main idea of both is providing instruction set for accelerators. PTX belongs to NVidia and it can be used only NVidia accelerators. The goals for PTX include the following: • Provide a stable ISA that spans multiple GPU generations. • Achieve performance in compiled applications comparable to native GPU performance. • Provide a machine-independent ISA for C/C++ and other compilers to target. • Provide a code distribution ISA for application and middleware developers. • Provide a common source-level ISA for optimizing code generators and translators, which map PTX to specific target machines. • Facilitate hand-coding of libraries, performance kernels, and architecture tests. • Provide a scalable programming model that spans GPU sizes from a single unit to many parallel units. 12 2.3. Accelerator Programming with Intermediate Languages On the other hand, the SPIR belongs to Khronos group, therefore it is able to use for every vendor. In short SPIR: • Vendor neutral • Is not C source code • Supports all core features and KHR extensions for version 1.2 of OpenCL C • Is designed to support vendor extensions. • Is compact. • Is designed to be efficiently loaded by an OpenCL implementation. 13 Chapter 3. Related Works & State of Arts 3.2 Directive Based Standards OpenMP 4.0 & OpenACC OpenMP is a standards of API that supports shared memory multiprocessor programming by C, C++, Fortran. It managed by nonprofit OpenMP Architecture Review Board. The consortium decides and announces standards, then compilers programmers develop OpenMP onto own compiler. OpenMP was supporting only shared memory multiprocessors until version 4.0. However then they decided to supports accelerator devices with version 4.0. On the other hand, although OpenACC is a standards like OpenMP, they only focused accelerators. Therefore even if it is newer than OpenMP, couple of compilers support their standards to code generation for accelerator. In the following subsections, OpenMP 4.0 and OpenACC constructs are going to been summarized briefly with the aim of identifying those functionalities. Offloading, kernel configuration and loop execution OpenMP 4.0 offers the target directive to start parallel execution on the accelerator device. Similarly, OpenACC offers the parallel directive with the same purpose. In OpenACC these regions can be declared asynchronous removing the implicit barrier at the end of the accelerator parallel region, allowing the host to continue with the code following the region. Inside these regions, the programmer can specify teams, representing a hierarchy of resources in the accelerator: a league of num_teams thread teams, each with thread_limit threads. The execution in the teams region initially starts in the master thread of each team. Later, the distribute and parallel for directives can be used to specify the mapping of iterations in different loops to the resources available on the accelerator. OpenACC offers kernels, i.e. regions that the compiler should translate into a sequence of kernels for execution on the accelerator device. Typically, each loop nest will be a distinct kernel. OpenACC also includes the loop directive to describe what type of parallelism to use to execute a loop and declare loop-private variables and arrays and reduction operations. Inside kernels and loops resources are organized in gangs, workers and vectors (indicated with the num_gangs,num_workers and vector_length clauses, respectively), similar to the teams and threads in OpenMP 4.0. Line 9–10 in Figure 3.3 shows a simple OpenMP 4.0 code where the programmer defines the thread hierarchy and maps to it the execution of the loop in line 11. The target region is inside atask, so in this case the execution in the device is asynchronous to the execution of the master thread in the processor. 20 3.2. Directive Based Standards OpenMP 4.0 & OpenACC 1for ( begin=0 ; begin < n; begin+=stri de ) 2 { 3int end = begin + stride −1; 4int dev_id = ( begin / st ride ) % omp_get_num_devices ( ) ; 5 6 #pragma omp task 7 #pragma omp target device ( dev_id ) \ 8map( to : y [ begin : end ] , x [ begin : end ] ) map( from : z [ begin : end ] ) 9 #pragma omp teams num_teams(16) thread_limit (32) 10 #pragma omp distribute parallel for 11 for ( i = 0; i < stride ; ++i ) 12 z [ i ] = a *x [ i ] + y[ i ] ; 13 } Figure 3.3 – Simple code in OpenMP 4.0 using multiple accelerator devices The target directive in OpenMP 4.0 includes the device clause, which offloads the execution of the region kernel to a given psychical device (indicated by the integer value in the clause). This direct mapping makes it difficult to write applications that dynamically offload work to accelerators in order to achieve load balancing or adapt to device adaptability. The use of multiple accelerators within a target data region is not clear since at most one device clause can appear on the directive. Figure 3.3 shows how the programmer could statically map consecutive target regions to the accelerators available in the target architecture (line 4 to compute the device identifier and device clause in line 7. Observe that the iteration range for the for loop at Line 11 goes from 0 to stride, so the program is not sequentially equivalent since it should iterate from begin to end. I assume that this has been done in this way to ease code generation by the compiler at the expenses of reducing code portability and reusability, in addition to potential programming errors. Data motion Data copying clauses may appear on the target,target data and target update constructs in OpenMP 4.0 and parallel,kernels and data constructs in OpenACC . The programmer specifies the data motion needed to bring in and out the data for the execution of the region in the accelerator. For the data items (including array regions) that appear in an OpenMP 4.0 map clause, corresponding new data items are created in the device data environment associated with the construct. Each data item has an associated map type which specifies the data copying on entry and exit (to,from or tofrom) or just allocation (alloc). OpenACC offers similar clauses (copying,copyout,copy and create) and some additional ones (present_or_ to tell) the implementation to test if data is already present in the accelerator memory. With all this information, 21 Chapter 3. Related Works & State of Arts Example 1 – OpenMP 4.0 1void calculate ( double *a) { 2 #pragma omp target map( to : a) 3/ / <.. code to offload .. > 4 } 5 6void foo ( double *a ) { 7 #pragma omp target data map( to : a ) 8 { 9/ / <.. calculation and offload .. > 10 11 fill_oncpu ( a ) ; 12 13 #pragma omp target update to ( a) 14 calculate (a) ; 15 } 16 } 17 18 void foo_2(double *a) { 19 calculate (a) ; 20 } Example 2 – OpenACC 1void calculate ( double *a) { 2 #pragma acc data pcopyin ( a ) 3/ / <.. code to offload .. > 4 } 5 6void foo ( double *a ) { 7 #pragma acc data copyin ( a) 8 { 9/ / <.. calculation and offload .. > 10 11 fill_oncpu ( a ) ; 12 13 #pragma acc update device ( a) 14 calculate (a) ; 15 } 16 } 17 18 void foo_2 ( double *a) { 19 calculate (a) ; 20 } Figure 3.4 – Another simple code in OpenMP 4.0 and OpenACC to show data regions. the compiler inserts the associated data allocations and transfers, if they are necessary, to be performed in the most appropriate moment. Both OpenMP 4.0 and OpenACC offer the possibility of defining data environments in the accelerator for the extend of a region: target data and data, respectively. Inside one of these regions, multiple kernel offloading actions may occur. An executable directive (target update in OpenMP 4.0 and update in OpenACC ) is offered to the programmer to update, inside the scope of a data region, the data from the host to the device or vice-versa. The example in Figure 3.3 shows the use of the map clause in Line 8. It is important to notice that map(to: ...) forces the movement of data when the target region is found; similarly for map(from: ...) which copies from device to host when the target region finishes. The new example in Figure 3.4 shows the use of data regions and the use of the present_or_ clauses in OpenACC to instruct the compiler about the use of presence checks. In this simple code, function calculate can be invoked from a previously created data region or not. But array a is in already device at one of them with target data directive. Other function have only one copy of array a in the main memory. Therefore user should extra definition to copy for array a. Besides, there are two different array a after target data directive at foo function. And fill_oncpu changes values of array a which is in main memory. Programmers should be aware if you want to use same data which is in main memory at the device. Thus they use extra directive as target update to notify compiler at Line 13. 22 3.3. OmpSs Heterogeneous Hardware Support 1#pragma omp target map( to : u [ 0 : n] ) map( tofrom : error) 2#pragma omp teams reduction (+: error) 3#pragma omp distribute private (th_err) 4for ( i = 1; i < (n −1) ; i ++) { 5 th_err = 0 . 0; 6 #pragma omp parallel for private (resid) reduction (+: th_err ) 7for ( j = 1; j < (m −1) ; j ++) { 8 reside = / / < . . . computation . . . > 9 th_error = th_error + resid ; 10 } 11 error = error + th_err ; 12 u[ i ] = error ; 13 } Figure 3.5 – Use of private variables and team/thread level reductions in Jacobi Memory hierarchy in the accelerator device Finally, lets comment that private,firstprivate and reduction clauses in distribute and parallel for directives give the compiler hints about the use of the memory hierarchy inside the accelerator. Again, OpenMP 4.0 and OpenACC rely on the programmer for the management of the memory hierarchy, having a direct impact in the quality of the kernel codes to be executed on the accelerator device. The simple code in Figure 3.5 shows the use of some of these clauses. Current Compilers There is no OpenMP 4.0 compiler which supports accelerators. However OpenACC has 3 different options. PGI, CAPS and CRAY has OpenACC compiler which provide 2.0 version. 3.3 OmpSs Heterogeneous Hardware Support 3.3.1 Nanos++ Runtime Nanos++[ 3 ] is a runtime which has been developing in order to provide parallel environments. It’s also main part of OmpSs suite. Data parallelism is also supported by means of services mapped on top of its task support. Nanos++ also provides support for maintaining coherence across different address spaces (such as with GPUs or cluster nodes). It provides software directory and cache modules to this end. 23 Chapter 3. Related Works & State of Arts Figure 3.6 – NANOS++ Runtime Structure The main purpose of Nanos++ is to be used in research of parallel programming environments. As such it is designed to be extensible by means of plug-ins. Figure 3.6 shows independent components/plug-ins of Nanos. Currently, runtime plug-ins can be added (and selected for each execution) for: • Task scheduling policy • Thread barrier • Device support • Instrumentation formats • Dependences approach • Throttling policies Several of such plugins are already available from the library distribution: different scheduling and throttling policies. In particular, device support for CUDA tasks and execution in a Cluster environment. Figure 3.7 shows Nanos++ behaviour. Basically when Nanos++ will handle a task, firstly it follows these rules respectively: task generation, data dependency analysis, task scheduling. It supports different address spaces such as CPU, GPU and Clusters. Moreover it can handle 24 3.3. OmpSs Heterogeneous Hardware Support automatically multi gpu and gpu concurrency by using streams. By OmpSs directives as is seen at Figure 3.8 at Line 4, it can do transparently data-management on GPU side (allocation, transfers, ...) and synchronization. One manager thread in the host per GPU which responsible for: Transferring data from/to GPUs, Executing GPU tasks, Synchronization. Figure 3.7 – NANOS++ Behaviour 3.3.2 GPU support for OmpSs With the device clause the programmer informs the compiler and runtime system about the kind of device that can execute the task, not an integer number that explicitly maps the offloading to a certain device as done in OpenMP 4.0. This is a big difference that improves programming productivity when targeting systems with different number and type of accelerators and regular cores. Figure 3.8 illustrates the use of multiple devices in OmpSs. Observe that the programmer does not need to map iterations to devices as was done in the same example in Figure 3.3. The runtime system schedules tasks dynamically in order to make use of all devices available in that moment in the system and to achieve load balancing. The acc device type is used to specify that the task will make use of OpenMP 4.0 directives 1for ( begin =0; begin < n; begin += s tride ) { 2int end = begin + stride −1; 3 4 #pragma omp target device (acc )copy_in( y [ begin : end ] , x [ begin : end ] ) copy_out( z [ begin : end ] ) 5 #pragma omp task 6 #pragma omp teams num_teams(16) thread_limit (32) 7 #pragma omp distribute parallel 8for ( i = 0; i < stride ; ++i ) 9 z [ i ] = a *x [ i ] + y [ i ] ; 10 } Figure 3.8 – Using multiple accelerators in OmpSs 25 Chapter 3. Related Works & State of Arts to specify what to execute on the accelerator device, relying on the compiler to generate the kernel code to be executed on the device. I will describe in more detail the current MACC implementation in Section 4. The accelerator support in the OmpSs programming model leverages the tasking model with data directionality annotations already available in the model (that influenced the new depend clause in OpenMP 4.0) used to compute task dependences at execution time. OmpSs offers target directive with the following syntax: #pragma omp target [clauses] task construct | function definition | function header where clauses specify: • devicethe kind of devices that can execute the construct (smp, cuda, opencl or acc). • copy_in - shared data that needs to be available in the device before the construct can be executed. • copy_out - shared data that will be available after the construct is executed. • copy_inout - a combination of copy_in and copy_out above. • copy_deps - copy semantics for the directionality clauses in the associated task construct (i.e., in will also be considered copy_in, output will also be considered copy_out and inout as copy_inout). • implements - an alternative implementation of the function whose name specified in the clause for a specific kind of device. • ndrange - specification of the dimensionality, iteration space and blocking size to replicate the execution of the CUDA or OpenCL kernel. • shmem - data that should be mapped into shared–memory among teams in the device. 26 3.3. OmpSs Heterogeneous Hardware Support 1#pragma omp target device (cuda ) ndrange(1 , na*na , na) copy_deps 2#pragma omp task in ( vec_a [ 0 : s tr id e ] , vec_b [ 0 : s t ri d e ] ) out ( vec_c [ 0 : s tr id e ] ) 3 __global__ void saxpy \ 4 (double *vec_a , double *vec_b , double *vec_c , inr st ride ) 5 { 6/ / <.. CUDA kernel codes . . > 7 } 8 9#pragma omp target device (smp) copy_deps implements( saxpy ) 10 #pragma omp task in ( vec_a [ 0 : s tr id e ] , vec_b [ 0 : s t ri d e ] ) out ( vec_c [ 0 : s tr id e ] ) 11 __global__ void saxpy_smp \ 12 (double *vec_a , double *vec_b , double *vec_c , inr stride ) 13 { 14 / / <.. CPU kernel codes . . > 15 } 16 17 #pragma omp target device (smp) copy_deps 18 #pragma omp task in ( s ta t ic _c o rr ec t _r e su lt [ 0 : s tr id e ] , vec_c [ 0 : s t ri de ] ) 19 void check_results ( double *precalc_result , double *vec_c , int s tride ) 20 { 21 / / <.. CPU codes . . > 22 } 23 24 int main ( int argc , char ** argv ) { 25 26 double vec_a [ SIZE ] , vec_b [ SIZE ] , vec_c [ SIZE ] ; 27 28 for ( begin=0 ; begin < nX ; begin+=s trid e ) 29 saxpy(&vec_a [ begin ] , &vec_b [ begin ] , &vec_c [ begin ] , stri de ) ; 30 31 for ( begin=0 ; begin < nX ; begin+=s trid e ) 32 check_results (&precalc_result [ begin ] , &vec_c [ begin ] , SIZE ) ; 33 } Figure 3.9 – Heterogeneous task example with OmpSs The support for accelerators in OmpSs is rooted on the tasking model and directionality information provided for each task. That information is used by the runtime system to dynamically build the dependence task graph for the program and to schedule the execution of tasks to the available resources, including accelerator devices. The argument directionality information is also used by the runtime, together with the lookahead provided by the availability of the task graph dynamically generated, to schedule data copying actions between address spaces (movements between host and accelerator or between two accelerator devices if needed). This is the purpose of the copydeps clause. If not specified in the task, the programmer can still specify copying actions using the copy_in,copy_out and copy_inout clauses. Figure 3.9 shows a simple example based on SAXPY. In this example, the task computing saxpy is offloaded to a device using the CUDA architecture while the task check_results is executed in the host. Observe that the output of CUDA task instances are inputs of SMP task instances. The dependences computed at runtime will honor these dependences and the runtime system will take care of doing the data copying operations based on the information contained in the task graph dynamically generated at runtime. The ndrange clause is used to replicate the execution of the CUDA kernel in the device block/thread hierarchy (one dimension with na * na iterations in total to distribute among teams of na iterations in this example). Multiple implementations tailored to different accelerators/cores can be specified for the same task (currently only available for tasks that are specified at the function declaration/defi- 27 Chapter 3. Related Works & State of Arts nition). In this case, the programmer is delegating in the runtime system the responsibility of dynamically selecting the most appropriate device/core to execute each task instance, based on for example the availability of resources or the availability of the data needed to execute the task in the device. With the implements clause the programmer can indicate alternative implementations for a task function tailored to different devices (accelerator or host). Figure 3.9 shows the use of the implements clause: the saxpy_smp function in Line 11 is defined as an alternative implementation to the CUDA implementation of saxpy at Line 3. Observe that the programmer simply invokes saxpy in Line 29, delegating in the runtime the selection of the most appropriate implementation for each task instance. 3.4 C++11 Extended Code Generation Yet another accelerator code generation model is performing with C++11 lambda facilities. Basically this approach almost same with directive based as one code base idea. However when considering lambda function, it can be say that these are more flexible than directive based. At the first glance, no need to add new directives for every mechanism. The another usable thing is that C++ enable in accelerator. Currently there is only one release implementation which is SYCL is announced recently by Khronos Group[ 6 ]. Another similar approach is from NVIDIA, however their implementation is draft currently. According to the description, SYCL is abstraction layer to provide portability, efficiency of OpenCL while adding easy-of-use and flexible C++. Basically it supports homogeneous code base it means one code base. Developing accelerator code is performed by new C++ facilities. The another thing lies behind of the its is using SPIR backend. Section 2.3 explains what is it and how it works. On the other hand, NVidia has idea[ 9 ] which is almost same with SYCL such as one code base and taking advantage C++. There are no clear information about it, since it is still draft. Figure 3.11 shows several function signatures belong to STD library of C++. Calculation has done by passing function as f parameter. 28 3.4. C++11 Extended Code Generation 1#include <CL/ sycl .hpp> 2#include <iostream> 3using namespace cl : : sycl ; 4 5 constexpr size_ t N = 3; 6using Vector = float [N] ; 7 8int main ( ) { 9 Vector a = { 1 , 2 , 3 } ; 10 Vector b = { 5 , 6 , 8 } ; 11 12 float c [N] ; 13 { 14 queue myQueue; 15 16 buffer <float> A ( std : : begin ( a ) , std : : end(a) ) ; 17 buffer <float> B { std : : begin (b) , std : : end(b) } ; 18 19 buffer <float> C( c , N) ; 20 21 command_group (myQueue, [&] ( ) { 22 auto ka = A . get_access <access : : read >() ; 23 auto kb = B. get_access <access : : read >( ) ; 24 auto kc = C. get_access <access : : write > () ; 25 26 p ar al l el _f or ( range <1> { N } , 27 kernel_lambda<class vector_add >([= ] ( id <1> index ) { 28 std : : cout << index . get (0) << " " ; 29 kc [ index ] = ka [ index ] + kb[ index ] ; 30 } ) ) ; 31 } ) ; 32 } 33 34 std : : cout << " Result : " << std : : endl ; 35 for (int i = 0; i < N; i ++) 36 std : : cout << c [ i ] << " " ; 37 std : : cout << std : : endl ; 38 39 return 0; 40 } Figure 3.10 – Vector Addition Example by SYCL 1 std : : vector <int > vec = . . . 2 3/ / previous standard sequential loop 4 std : : for_each (vec . begin ( ) , vec . end ( ) , f ) ; 5 6/ / e x p l i c i t l y seque ntia l loop 7 std : : for_each ( std : : seq , vec . begin ( ) , vec . end( ) , f ) ; 8 9/ / permitting parall el execution 10 std : : for_each ( std : : par , vec . begin ( ) , vec . end ( ) , f ) ; Figure 3.11 – C++ Parallel Algorithms Library Progress 29 Chapter 4. MACC: Mercurium ACCelerator Compiler with OpenMP 4.0 accelerator model. The effects of directives may be slightly change. For instance omp for is a most common directive will effects CUDA threads instead of CPU threads if it’s used inside of the teams / distribute directive. In this case MACC compiler leaves these as they are. They will be handled at last step. Nanox SMP support : SMP 2 is a kind of device and used in order to define to run task on SMP. This phase is used by Nanox phases to implement SMP device support. MACC Phase : Thus far every phases are already involved by Mercurium. This phase is defined in the MACC compiler that allows applying code generation for accelerator by high level directives. A new directive lowerer and code generator are also implemented for this step. In addition, CUDA and OpenCL tasks can be used in the MACC as well by existed Mercurium phases. In this case MACC will invoke their phases after Nanos++ lowering phase as Nanox SMP support is invoked. 4.1.4 MACC Configuration As mentioned above, Mercurium is a dynamically configurable compiler. Compiler pipeline phases, back end compilers, linker, environment variables, compilation parameters and etc. can be configurable in the special format configuration file. By this mean, compiler developers can manage dynamically phases and generate new compiler work flow with existed phases without the need for any developing. Moreover the configuration files are inheritable each other. Since MACC is a extension of OpenMP 4.0 accelerator model, it should support existed directives. Besides MACC involve OmpSs task facility. Hence it can be said that MACC is a new phase to generate CUDA codes based on current OmpSs platform. Figure 4.4 shows MACC compiler configuration file. The macc which is compiler executable name at the same time, is inherited from omp-base at Line 2 in order to support existed OmpSs directives and previous OpenMP version than 4.0 accelerator model. In addition back end compiler and preprocessor are defined as nvcc with some special parameters. And input 2SMP is abbreviation of Shared Memory Processor". 36 4.2. ACCelerator Code Generation Phase 1#OpenMP 4.0 HWA support 2 [macc : omp−base] 3 language = C 4 options = −−cuda −−accgen −− variable=acc_enabled :1 5 preprocessor_name = / usr / lo cal /cuda/bin/nvcc 6 preprocessor_options = −D__CUDABE__ −I / usr / lo ca l /cuda/include −include nanos−gpu . h 7 compiler_name = /usr / local /cuda/bin/nvcc 8 compiler_options = −arch sm_20 9 linker_name = /usr/ local /cuda/bin/nvcc 10 linker_options = −lnanox−gpu−api −Xlinker −lnanox−ss 11 compiler_phase = libtlnanox−acc . so Figure 4.4 – MACC configuration file language is indicated as C. It will run C parser inside of the compiler. And what’s more in this configuration file, special MACC compilation phase is indicated with a dynamic library at Line 11. 4.2 ACCelerator Code Generation Phase A new compilation phase MACC has been included in the Mercurium compiler supporting the OpenMP 4.0 accelerator model in an integrated way with OmpSs. MACC takes care of kernel configuration, loop scheduling and use of shared memory for those tasks whose target device is set to acc, leveraging the functionalities already available in the NANOS++[ 3 ] runtime and. Therefore in this chapter, first of all is going to mention OmpSs platform and its compiler and runtime. 4.2.1 MACC Accelerator Directives The main intention of MACC is to provide code generation for accelerator by CUDA. While it’s doing this, OpenMP 4.0 directives is used. OpenMP is chose because it’s quite standard among programmers. Moreover many programmers already used them. On the other hand, OmpSs suite has already supported OpenMP directives as it explained Section 3.3. Therefore directives of OpenMP 4.0 is used in this thesis in order to allow to programmers to express own code scopes and offloaded codes. Some of the OpenMP 4.0 directives for accelerators are simply ignored because OmpSs can delegate their functionality by the NANOS++ runtime, mostly those related with data copying. Figure 4.5 identifies them (extended, implemented, ignored). The main differences and implementation decisions are explained in the following subsections. 37 Chapter 4. MACC: Mercurium ACCelerator Compiler OpenMP 4.0 MACC target extended (implements ndrange for CUDA and OpenCL kernels) map(to/from/tofrom) implemented but different names (copy_in/out/inout) map(alloc) ignored target data currently ignored target update ignored first_/private implemented device(int) extended teams implemented distribute new clause dist_private parallel for implemented distribute parallel for implemented dist_first/last_/private added Figure 4.5 – Comparing Pragma Directives: MACC vs OpenMP 4.0 4.2.2 Kernel Configuration When generating kernel code MACC needs to decide: 1) the dimensionality of the resources hierarchy (one-, two- or three-dimension team and thread) and 2) the size in each dimension (number of teams and threads in each dimension). In order to support the organization of the threads in two- and threedimensions MACC allows the nesting of parallel for directives inside atarget region (dimensionality equals the nesting degree). Other proposals considered the use of collapse which includes an integer to specify the number of nested loops with the same purpose. As i will see in the experimental section, deciding which loop in the nest is mapped to each dimension of the thread hierarchy has an impact, and this seems to be out of control from the programmer in the current OpenMP 4.0 specification (OpenACC has three clauses such as gang,worker and vector in order to directly assign iteration), being the responsibility of the compiler. In our current implementation i do not support nesting of distribute directives, which could be useful to decide the dimensionality of the blocks organization. In order to decide size, MACC takes into account the restrictions of the device (for example maximum number of blocks and threads warp size in the CUDA computing capability) and the information provided by the programmer in the num_teams or max_threads clauses; if not specified, MACC will try to generate as much of possible (e.g. one iteration per block and one iteration per thread), depending on the iteration count of the associated loops. It starts to association with first dimension of threads or blocks. By this means primarily first dimensions are created during kernel configuration by MACC. However starting with second dimension of threads is also experimented as it is seen in the evaluation section. 38 4.2. ACCelerator Code Generation Phase Example 3 – 1D thread blocks 1#pragma omp target device (acc ) 2#pragma omp teams thread_limit (512) 3#pragma omp distribute 4for ( i = 0; i < n ; i ++) 5 { 6 #pragma omp parallel for 7for ( j = 0; j < m ; j ++) 8 b[ i ] [ j ] = a [ i ] [ j ] *NX; 9 } Example 4 – 2D thread blocks 1#pragma omp target device (acc ) 2#pragma omp teams thread_limit (512) 3#pragma omp distribute parallel for 4for ( i = 0; i < n ; i ++) 5 { 6 #pragma omp parallel for 7for ( j = 0; j < m; j ++) 8 b[ i ] [ j ] = a [ i ] [ j ] *NX; 9 } Example 5 – 2D thread blocks 1#define nX 4 2#define nelem 12000 3 4#pragma omp target device (acc ) 5#pragma omp teams thread_limit (64) 6#pragma omp distribute parallel for 7for ( i =0; i < nelem ; i ++) { 8 #pragma omp parallel for private (k) 9for ( j =0; j < nX*nX; j ++) { 10 for ( k=0; k < nX; k++) 11 / / <.. calculations . . > 12 } 13 #pragma omp parallel for 14 for ( j =0; j < nX*nX; j ++) { 15 / / <.. calculations . . > 16 } 17 } Figure 4.6 – MACC - Deciding dimensionality of the kernels Figure 4.8 shows three simple examples that are mapped into one- and two-dimensional thread organizations. In particular, for the third code MACC decides to generate a twodimensional thread organization because of the nesting of parallel for directives in Lines 8 and 13 inside Line 6. The total number of threads is 64 threads (as specified in the thread_limit clause in Line 5), divided in 4 and 16 threads in the first and second dimension, respectively (this is a compiler decision based on the iteration count for the loops). Teams are organized in a single dimension, generating in total 3000 teams in order to execute the 12000 iterations in the loop in Line 7. 4.2.3 Loop Scheduling & Thread Mapping MACC compiler follows one iteration for one block/thread rules while it’s generating CUDA kernel configurator which is called as kerneler. In CUDA accessing global memory is often exploited by warps with coalesced access. In order to exploit data locality, MACC uses cyclic distribution rather than in a block manner. While MACC is doing cyclic loop scheduling, it takes into account conditional and increment expressions. 39 Chapter 4. MACC: Mercurium ACCelerator Compiler 1#define nX 4 2#define nelem 90000 3#define SIZE (nelem*nX*nX) 4#define CHUNK 256 5#define NUM_TEAMS 5625 6 7for ( i t =0; it <nit ; i t ++) 8 { 9 #pragma omp target device (acc )copy_deps 10 #pragma omp task inout ( f lx [ 0: SIZE ] , f ly [ 0: SIZE ] ) 11 #pragma omp teams num_teams(NUM_TEAMS) private( grad ) firstprivate(delta) 12 #pragma omp distribute parallel for dist_first_lastprivate ( f l x [CHUNK] , f ly [CHUNK] ) 13 for ( ie =0; ie < nelem ; ie ++) 14 { 15 #pragma omp parallel for private ( j , i ) 16 for ( i i =0; i i < nX*nX; i i ++) { 17 int k = i i % nX; 18 int l = i i / nX; 19 double s2 = 0 . 0; 20 double s1 = 0 . 0; 21 22 #pragma unroll 23 for ( j =0; j < nX; j ++) 24 { 25 s1 = 0; 26 #pragma unroll 27 for (int i =0; i < nX; i ++) 28 s1 = s1 + ( delta [ j *nX+ l ]*f l x [ ie *nX*nX+i+j *nX] 29 *der [ k*nX+ i ]+ delta [ k*nX+ i ] 30 *f l y [ ie *nX*nX+i+j *nX] 31 *der [ l *nX+ j ] ) 32 *gw[ i ] ; 33 34 s2 = s2 + s1 *gw[ j ] ; 35 } 36 grad [ i i ] = s2 ; 37 } 38 39 #pragma omp parallel for 40 for ( j =0; j < nX*nX; j ++) { 41 f l x [ ie *nX*nX+ i i ] = f l x [ ie *nX*nX+ i i ] + dt *grad [ i i ] ; 42 f l y [ i e *nX*nX+ i i ] = f l y [ i e *nX*nX+ i i ] + dt *grad [ i i ] ; 43 } 44 } 45 } Figure 4.7 – DG–Kernel Application in MACC way In order to exemplifying, DG application is used. DG which is a kernel version of a climate benchmark[ 25 ] developed by National Center for Atmospheric Research. Moreover this thesis evaluates different kind of DG application at Section 5.3. Before consideration of evaluation results, DG in MACC way and generated CUDA codes are shown. Figure 4.7 shows original DG application with MACC directives. As is seen, only number of team clause is used at line 11. However since MACC maps each iteration with one threads, it generates kerneler. It can be seen at Figure 4.8. Line 7–10 shows MACC calculation in order to find proper number of threads and blocks. since teams size is indicated as 5625 at Line 5 Figure 4.7, MACC generates 16 threads at the first dimension of threads. Because iteration at Line 13 is mapped with one thread/block. It corresponds with a formula at Line 9 Figure 4.8. Besides, other iterations at Line 15 & 39 which are used with omp parallel for has same iteration count. Therefore MACC compiler generates nX*nX threads for second dimension as it seen at Line 10 Figure 4.8. On the other hand, if the iteration count is equal to the number of team/thread among which it is distributed, MACC removes the for-iteration and directly assigns the current dimension of threadIdx or blockIdx to an induction variable. As is seen at Figure 4.7 there are 3 iterations 40 4.2. ACCelerator Code Generation Phase 1void macc_acc_ol_main_0_unpacked ( int *const nelem , int *const nXa, int *const j , int *const _macc_nXa, \ 2int *const ii , int *const ie , double * * const delta , double ** const grad) 3 { 4/*Mercurium ACCelerator Compiler −KERNELER */ 5 6 dim3 gridDim , blockDim ; 7 gridDim . x = MIN(_CUDA_MAX_TEAM,5625) ; 8 gridDim . y = 1; 9 blockDim . x = MIN(_CUDA_MAX_THREAD, c e i l (nelem / gridDim . x ) ) ; 10 blockDim . y = MIN(_CUDA_MAX_THREAD , nX*nX) ; 11 int _macc_dynamic_shared_memory_size 12 = (8) *( (nX) −(0) + 1) 13 +(8) *( (nX *nX) −(0) + 1) 14 +(8) *( (nX *nX) −(0) + 1) 15 +(8) *(CHUNK + 1) 16 +(8) *(CHUNK + 1) ; 17 18 macc_acc_ol_main_0_unpacked_kernel<<<gridDim , blockDim , _macc_dynamic_shared_memory_size , 19 nanos_get_kernel_execution_stream ( ) >>> (nelem , dt , nXa , j , i i , ie , *delta , *grad ) ; 20 } Figure 4.8 – Generated MACC Kerneler to configurate kernel from Figure 4.7 which are used with OpenMP accelerator model pragma directives at respectively at Line 13, 16 and 40. As mentioned at Section 2.1.1 NVidia GPUs don’y have higher capability branch predictor. Therefore MACC compiler has removing redundant for iteration optimization. Figure 4.10 is a generated CUDA kernel code by MACC from Figure 4.7. MACC could map each iteration with block/thread since thread and block size is enough. As is seen at Figure 4.10 there is only one iteration which corresponds actually with nested for iteration at the Line 23 Figure 4.7 ( The other iteration at Line 83 is used for dist_last_private. It will be explained next section. ) . In the generated CUDA kernel, induction variables are privatized with a prefix as textbf_macc_. Starting from here, it can be said that in fact _macc_ie and two _macc_ii are induction variable. They are mapped directly CUDA threads/blocks and MACC could remove for iteration which will be redundant. 4.2.4 Device Local Memory MACC is able to decide the use of shared memory for threads in a team based on the specification of private and firstprivate data structures in the teams and distribute directive, so that each team will have a private copy in its own shared memory. MACC compiler analyzes the size of the data structure to be privatized and generates code for its allocation and copying from global memory in the device to shared memory in each team. 41 Chapter 4. MACC: Mercurium ACCelerator Compiler 4.2.5 New data sharing attributes for distribute directive MACC extends the current OpenMP 4.0 specification with three data sharing clauses in order to exploit further shared memory. These directives can be used with two ways which are with chunk_size or dist_schedule(static,chunk_size). Because i wanted to use shared memory partially because of limitation and thus i made indication chunk_size in two way obligatory to allow to divide each of array into chunks and send each chunk to different team. While programmers are using shared memory, they should make sure that part of array which each team will access must be equal with chunk_size each team has. • dist_private(list) : only allocates shared memory up to indicated chunk_size in the beginning of the kernel. • dist_firstprivate(list) : allocates shared memory up to indicated chunk_size and fills it own part of array from global memory in the beginning of the kernel. • dist_lastprivate(list) : allocates shared memory up to indicated chunk_size and fills own part of global memory from own shared memory at the end of the kernel. The main difference about using data sharing attributes with between distribute and team is that MACC allocates and copies all size of array when clauses are used with teams. If clauses are used with distribute, MACC has a chunk size and it can allocate and copy only size of chunk from shared memory. As i mentioned, using lastprivate is available. Figure 4.7 shows dist_lastprivate proposal and use of team memory with an example. In this example, delta and grad are arrays specified as private and firstprivate, respectively, with teams directive at Line 11 in Figure 4.7. Besides, flx–fly are specified as dist_first_lastprivate with a chunk size at Line 12. MACC compiler need analysis size of data shared variables since shared memory size is indicated before kernel execution. Figure 4.8 at Line 11–16 shows calculation. Right after that, it is passed as kernel invocation parameter inside of the "«< ... »>" at Line 18. On the kernel side, compiler generated a code started with identifying pointers for team level values at Line 8, 11 and 14 Figure 4.10. Then after these pointers are filled from global memory. In addition to every thread in the same team has a same pointer since CUDA block uses same 42 4.2. ACCelerator Code Generation Phase 1#pragma omp target device (acc )copy_deps 2#pragma omp task in (nk , key_buff2 [ 0 : nk ] ) inout( key_buff1 [ 0 :mk] ) 3#pragma omp teams num_teams(16) thread_limit (32) 4#pragma omp distribute parallel for 5for ( i =0; i <nk ; i ++ ) 6 { 7 #pragma omp atomic 8 key_buff1 [ key_buff2 [ i ] ]++ ; 9 } Figure 4.9 – Using Atomic (NAS - IS) shared memory. After the kernel execution MACC compiler generated iteration in order to fill global memory from shared memory. These codes are run at Line 83–87 Figure 4.10 for dist_last_private clause. 4.2.6 Reductions and Atomic Operations Another OpenMP 4.0 features are the reductions and atomic operations. Macc compiler supports two level reduction such as thread and block level as specified at OpenMP 4.0 standard. Besides i implemented 2 way for atomic operations because of computation capability insufficiency. If the capability of device is compatible to use atomic functions which are provided by CUDA, our compiler generates kernel with these functions. Otherwise it generates its own atomic function with mutex on software level. In addition CUDA doesn’t has atomic functions for every data type. In these cases, i also generates own atomic function. Figure 4.9 shows an example about usage of atomic directive. In this example compiler generates code depends on data type of key_buff1. 43 Chapter 4. MACC: Mercurium ACCelerator Compiler 1 __global__ void macc_acc_ol_main_0_unpacked_kernel( int *nelem , double *dt , int *nXa, int *j , int *i i , \ 2int *ie , double *grad , int *iebs , double *gw, double *der , double *delta , double *flx , double *f l y ) 3 { 4 __int32_t _macc_sh_iter = 0; 5 __int32_t _macc_sh_var_size = 0; 6 __int32_t _macc_sh_offset = 0; 7 8double *_macc_grad = ( double *) get_shared_memory ( _macc_sh_offset ) ; 9 _macc_sh_offset += (8) *( ( *nXa * *nXa) −(0) + 1) / 8; 10 11 double *_macc_flx = (double *) get_shared_memory (32) ; 12 _macc_sh_offset += (8) *( ( BS) −(0 ) + 1) / 8; 13 14 double *_macc_fly = (double *) get_shared_memory(32+BS) ; 15 _macc_sh_offset += (8) *( ( BS) −(0 ) + 1) / 8; 16 17 for ( _macc_sh_iter = ( threadIdx . y *blockDim . x + threadIdx . x ) ; _macc_sh_iter < BS; _macc_sh_iter+=(blockDim . x *blockDim . y ) ) 18 { 19 _macc_flx [ _macc_sh_iter ] = f l x [ _macc_sh_iter + BS *blockIdx . x ] ; 20 _macc_fly [ _macc_sh_iter ] = f ly [ _macc_sh_iter + BS *blockIdx . x ] ; 21 } 22 23 macc_sync ( ) ; 24 25 int _macc_ie = 0; 26 int _macc_ii = 0; 27 { 28 _macc_ie = blockIdx . x *blockDim . y + threadIdx . y ; 29 { 30 int _macc_j = 0; 31 _macc_ii = threadIdx . x ; 32 int k ; 33 int l ; 34 k = _macc_ii % 4; 35 l = _macc_ii / 4; 36 double s2 = 0.00000000000000000000000000000000000000000000000000000e+00; 37 double s1 = 0.00000000000000000000000000000000000000000000000000000e+00; 38 39 #pragma unroll 40 for ( _macc_j = 0; _macc_j < 4; _macc_j++) 41 { 42 int i = 0; 43 s1 = ( delt a [ _macc_j *4 + l ] 44 *_macc_flx [ ( _macc_ie *4*4 + i + _macc_j *4) −BS *blockIdx . x ] 45 *der [ k *4 + i ] + delta [ k *4 + i ] 46 *_macc_fly [ ( _macc_ie *4*4 + i + _macc_j *4) −BS *blockIdx . x ] 47 *der [ l *4 + _macc_j ] ) 48 *gw[ i ] ; 49 i ++; 50 s1 = s1 + ( delta [ _macc_j *4 + l ] 51 *_macc_flx [ ( _macc_ie *4*4 + i + _macc_j *4) −BS *blockIdx . x ] 52 *der [ k *4 + i ] + delta [ k *4 + i ] 53 *_macc_fly [ ( _macc_ie *4*4 + i + _macc_j *4) −BS *blockIdx . x ] 54 *der [ l *4 + _macc_j ] ) 55 *gw[ i ] ; 56 i ++; 57 s1 = s1 + ( delta [ _macc_j *4 + l ] 58 *_macc_flx [ ( _macc_ie *4*4 + i + _macc_j *4) −BS *blockIdx . x ] 59 *der [ k *4 + i ] + delta [ k *4 + i ] 60 *_macc_fly [ ( _macc_ie *4*4 + i + _macc_j *4) −BS *blockIdx . x ] 61 *der [ l *4 + _macc_j ] ) 62 *gw[ i ] ; 63 i ++; 64 s1 = s1 + ( delta [ _macc_j *4 + l ] 65 *_macc_flx [ ( _macc_ie *4*4 + i + _macc_j *4) −BS *blockIdx . x ] 66 *der [ k *4 + i ] + delta [ k *4 + i ] 67 *_macc_fly [ ( _macc_ie *4*4 + i + _macc_j *4) −BS *blockIdx . x ] 68 *der [ l *4 + _macc_j ] ) 69 *gw[ i ] ; 70 71 s2 = s2 + s1 *gw[ _macc_j ] ; 72 } 73 _macc_grad [ _macc_ii ] = s2 ; 74 } 75 { 76 _macc_ii = threadIdx . x ; 77 _macc_flx [ ( _macc_ie *4*4 + _macc_ii ) −BS *blockIdx . x ] 78 = _macc_flx [ ( _macc_ie *4*4 + _macc_ii ) −BS *blockIdx . x ] + *dt *_macc_grad[ _macc_ii ] ; 79 _macc_fly [ ( _macc_ie *4*4 + _macc_ii ) −BS *blockIdx . x ] 80 = _macc_fly [ ( _macc_ie *4*4 + _macc_ii ) −BS *blockIdx . x ] + *dt *_macc_grad[ _macc_ii ] ; 81 } 82 } 83 for ( _macc_sh_iter = ( threadIdx . y *blockDim . x + threadIdx . x ) ; _macc_sh_iter < BS; _macc_sh_iter+=(blockDim . x *blockDim . y ) ) 84 { 85 f l x [ _macc_sh_iter + BS *blockIdx . x ] = _macc_flx [ _macc_sh_iter ] ; 86 f l y [ _macc_sh_iter + BS *blockIdx . x ] = _macc_fly [ _macc_sh_iter ] ; 87 } 88 } Figure 4.10 – Generated MACC CUDA Kernel from Figure 4.7 44 5Evaluations The objective of the performance evaluation in this section is to show how the OmpSs proposal to program accelerators behaves, which just integrates those directives from OpenMP 4.0 that are used to specify the kernel computations. For the evaluation i use three simple codes: Jacobi, DG_kernel [25] and CG from NAS Parallel Benchmark [7]. For the experimental evaluation i have used a node with 2 Intel Xeon E5649 sockets (12 cores in total) running at 2.53 GHz and with 24 GB of main memory, and two Nvidia Tesla M2090 GPU devices (512 CUDA cores, compute capability 2.0) running at 1.3GHZ and with 6GB of memory per device. For the compilation of OpenACC codes i have used the HMPP (version 3.2.3) compiler from CAPS [ 4 ]. For the compilation of OmpSs codes i have used the Mercurium/Nanos environment [ 3 ]. GCC 4.6.1 has been used as back-end compiler for CPU code generation and the CUDA 5.0 toolkit for device code generation. Performance is reported in terms of execution time for the kernels generated and speed–up, with respect to sequential execution on a single core, for the complete application. In order to obtain these performance metrics i have used nvprof from CUDA 5.0 toolkit. 45 Chapter 5. Evaluations OmpSs/MACC for a single device 1#pragma omp target device (acc )copy_deps 2#pragma omp task \ 3in ( a [ 0 : nz ] , p[ 0 : na ] , col idx [ 0 : nz ] , rowstr [ 0 : na ] ,sum) out (q [ 0 : na ] , w[ 0 : na ] ) 4#pragma omp teams 5#pragma omp distribute private (sum) 6for ( j = 1; j <= lastrow−firstrow +1; j ++) { 7 sum = 0.0; 8 #pragma omp parallel for reduction ( + :sum) 9for ( k = rowstr [ j ] ; k < rowstr [ j +1]; k++) 10 sum = sum + a[k ]*p[ colidx [ k ] ] ; 11 w[ j ] = sum; 12 q[ j ] = sum; 13 } OmpSs/MACC for 2 devices using unrolling 1stati c double *q_1= &q [ 0 ] ; 2stati c double *q_2= &q[mid ] ; 3stati c double *w_1= &w[ 0 ] ; 4stati c double *w_2= &w[mid ] ; 5#pragma omp target device (acc )copy_deps 6#pragma omp task in ( a [ 0 : nz ] , p [ 0 : na] , co lidx [ 0 : nz ] , rowstr [ 0 : na ] ,sum) out ( q_1 [ 0 :mid] , w_1 [ 0: mid ] ) 7#pragma omp teams 8#pragma omp distribute private (sum) 9for ( j = 1; j < mid ; j ++)vc { 10 sum = 0.0; 11 #pragma omp parallel for reduction ( +:sum) 12 for ( k = rowstr [ j ] ; k < rowstr [ j +1]; k++) 13 sum = sum + a[k ]*p[ colidx [ k ] ] ; 14 w_1[ j ] = sum; 15 q_1 [ j ] = sum; 16 } 17 18 #pragma omp target device (acc )copy_deps 19 #pragma omp task in ( a [ 0 : nz ] , p [ 0 : na] , co lidx [ 0 : nz ] , rowstr [ 0 : na ] ,sum) out ( q_2 [ 0 :mid] , w_2 [ 0: mid ] ) 20 #pragma omp teams 21 #pragma omp distribute private (sum) 22 for ( j = 0; j <= mid; j ++) { 23 sum = 0.0; 24 #pragma omp parallel for reduction ( +:sum) 25 for ( k = rowstr [ j +smid ] ; k < rowstr [ j +smid +1]; k++) 26 sum = sum + a[k ]*p[ colidx [ k ] ] ; 27 q_2 [ j ] = sum; 28 w_2[ j ] = sum; 29 } Figure 5.7 – Annotated codes for NAS CG benchmark The code in the top part of Figure 5.7 corresponds to the main computational loop, annotated with the OmpSs/MACC directives. This code is written to run in a single device because there is a single task. By simply applying blocking to the jloop, the code would be ready to be executed on multiple devices (code not included due to page limits, to be included in final version if accepted). However, the fact that kernels in OpenMP 4.0 always iterate from 0 forced us to apply unrolling instead, making the code transformation dependent of the number of devices. The resulting code is shown in the lower part of the same Figure. By using paraver[ 14 ] profiler application, MACC compiler generated traces in order to show task distribution when multi gpus are used for same program. The Upper side of the Figure 5.8 shows how to MACC do task scheduling by NANOS++ runtime. Tasks at last 2 rows are run on GPU, rest of them are run on CPU. In these figures, meaning of light blue is idle. So density of tasks for GPUs seems quite good. When is zoomed at selection area, the below figure is caught. In this figure, big green and red are shows most expensive tasks. In fact they are at OmpSs/MACC for 2 devices using unrolling at Figure 5.7. When the original task is separated into 2 tasks at the Figure 5.7, MACC compiler can distribute concurrently on multi GPUs using NANOS++ runtime. 52 5.5. EP Application from NASA Parallel Benchmark Suite Figure 5.8 – Profiling CG - NAS by Paraver The performance plot in Figure 5.9 shows the speed–up of the GPU accelerated version of NAS CG (bars HMPP, MACC and MACC/2 GPU) and the speed–up using 8 processors in the host, for three different classes of NAS CG. The speed–up with 2 GPU is significant although i only refined one of the loops given the very simple source code transformation. Note that data transfers between GPUs will take place, automatically handled by the runtime. 5.5 EP Application from NASA Parallel Benchmark Suite In the EP which is embarrassingly parallel benchmark, two-dimensional statistics are accumulated from a large number of Gaussian pseudo random numbers, which are generated according to a particular scheme that is well suited for parallel computation. EP is a simple and small kernel that generates pairs of Gaussian random numbers according to a specific scheme. EP is characterized by the fact that no inner-communication is required among all processors. EP gives a good estimate to the maximum floating point performance can be achieved. EP kernel is a communication-less application. What i se in the table is a pure execution time. By this reason, it can be get quite well speedup. The EP program which is developed by MACC 53 Chapter 5. Evaluations Figure 5.9 – CG - NAS Application pragma can see at Figure 5.10. Ass it seen this figure, there is one main iteration inside of main computation area. It uses 3 different arrays at different time. There are no data dependencies between these arrays inside main iteration. Therefore this application is called Embrassingly Parallel Application. Its speedup can reach up to number of the computation cores. The performance plot in Figure 5.11 shows the speed–up of the GPU accelerated version of NAS EP (bars HMPP, MACC). As it seen in this figure, speedup of MACC and HMPP are almost same. Because the application is already parallelised maximum. 54 5.5. EP Application from NASA Parallel Benchmark Suite 1#pragma omp target device (acc )copy_deps 2#pragma omp task in (qq) out (x) 3#pragma omp team reduction (+: sx , sy ) 4#pragma omp distribute private ( kk , t1 , t2 , t3 , k_offset ,an, ik ) 5for ( k = 1; k <= np; k++) { 6 kk = k_offset + k ; 7 t1 = S ; 8 t2 = an ; 9 10 #pragma omp parallel for 11 for ( i = 1; i <= 100; i ++) { 12 ik = kk / 2; 13 i f ((2 *ik ) != kk ) t3 = randlc(&t1 , t2 ) ; 14 i f ( ik == 0) break ; 15 t3 = randlc(&t2 , t2 ) ; 16 kk = ik ; 17 } 18 19 20 double vx1 , vx2 , vt2 , vz , vt3 , vt4 , vt1 , va1 , a2 ; 21 vt1 = r23 *A; 22 va1 = ( int ) vt1 ; 23 a2 = A −t23 *va1 ; 24 double loc_x = t1 ; 25 26 #pragma omp parallel for private ( vx1 , vx2 , vt2 , vz , vt3 , vt4 , vt1 , va1 , a2 ; ) 27 for ( i = 0; i < 2 *NK; i ++ ) { 28 vt1 = r23 *( loc_x ) ; 29 vx1 = ( int ) vt1 ; 30 vx2 = loc_x −t23 *vx1 ; 31 vt1 = va1 *vx2 + a2 *vx1 ; 32 vt2 = ( int ) ( r23 *vt1 ) ; 33 vz = vt1 −t23 *vt2 ; 34 vt3 = t23 *vz + a2 *vx2 ; 35 vt4 = ( int ) ( r46 *vt3 ) ; 36 loc_x = vt3 −t46 *vt4 ; 37 x [ i ] = r46 *( loc_x ) ; 38 } 39 40 double psx , psy ; 41 psx = psy = 0 . 0; 42 43 #pragma parallel for reduction ( + : psx , psy ) private( x1 , x2 , t1 , t2 , t3 , t4 , l ) 44 for ( i = 0; i < NK; i ++) { 45 x1 = 2.0 *x [ 2*i ] −1.0; 46 x2 = 2.0 *x [ 2*i +1] −1.0; 47 t1 = ( x1 *x1 ) + ( x2 *x2 ) ; 48 i f ( t1 <= 1.0) { 49 t2 = sqrt ( −2.0 *log ( t1 ) / t1 ) ; 50 t3 = ( x1 *t2 ) ; 51 t4 = ( x2 *t2 ) ; 52 l = max( fabs ( t3 ) , fabs ( t4 ) ) ; 53 qq[ l ] = qq[ l ] + 1 . 0 ; 54 psx = psx + t3 ; 55 psy = psy + t4 ; 56 } 57 } 58 59 sx += psx ; 60 sy += psy ; 61 } Figure 5.10 – Annotated codes for NAS EP benchmark 55 Chapter 5. Evaluations Figure 5.11 – Performance evaluation for NAS EP 56 6Conclusion 6.1 Summary Source–to–source translation for accelerators are already reviewed at the other studies[ 22 , 23 , 24 ]. Moreover many companies which are leading HPC area such as PGI[ 15 ], CAPS[ 4 ] and CRAY present own OpenACC compiler. In fact HPC scientists or engineers are using directive based programming for heterogeneous architectures in the real life. In addition Intel also published own OpenMP 4.0 compiler for Xeon PHI co processors. When they are compared each other, most of them are focused only for code generation of the accelerator. Only early experiences OpenMP model[ 24 ] studied current OpenMP directives HiCUDA CETUS ROSE OpenACC SYCL OmpSs MACC Knowledge yes no no no no - no Offload yes yes yes yes yes yes yes Code Gen yes yes yes yes yes no yes Runtime no no no Depends yes yes yes Annotation pragma pragma pragma pragma C++11 pragma pragma Thread Map explicit implicit implicit explicit explicit - explicit Shmem explicit implicit implicit implicit explicit - Both Figure 6.1 – Comparing Discussed Compilers and MACC 57 Chapter 6. Conclusion but there is no real compiler that currently supports task model of 4.0 and memory model, they only analysed particular area of the accelerator. This thesis got interested about that what happened when new task model and accelerator code generation model are integrated. Because currently, accelerator programming have to been managed by host. Also everybody knows about this handwritten CUDA program usually better if it is developed optimized. Therefore i wanted to exploit OmpSs advantage to get close CUDA performance. In order to summarize all accelerator model approaches which are mentioned in this thesis, Figure 6.1 shows main differencies which were discussed in the thesis between accelerator programming environments. 6.2 Conclusion After long years of existence, the CUDA programming framework has become a significant part of HPC programming. Each version of CUDA brings important features and support for the new available products, but is still in a constant evolution. Therefore developing logic of CUDA program is usually changing. Moreover, writing CUDA code can gain good performance from the GPU acceleration remains a painstaking job for the programmer. Therefore MACC compiler is presented as source–to–source compiler model in order to deal with this kind of problems. MACC compiler model for translating standard OpenMP 4.0 directives onto OmpSs into CUDA based GPGPU programs is explained. In addition, the compiler model of this thesis has some advantages when compared OpenMP 4.0 standard (e.g. more flexibility in the use of multiple GPU, shared memory, data managing, ...). The OpenMP accelerator model is based on CPU likely accelerator. This thesis is working with different architectures and different memory areas. Therefore assumption of the user about the output code is becoming more difficult day by day. However, in any case in order to develop high performance applications, user should know the target architecture. Because this issue is same on the CPU. Programmers sometimes need to change their own algorithm to leverage parallel multiprocessor performance when they are using OpenMP. Due to the these reasons this thesis is going to work on new directives to allow editing transformation to user. In addition, generally difference about usage shared memory is encountered. According to the CUDA model, shared memory is used in order to fill from global memory or to fill to global memory. By this means, user gains a significant performance as speed up. In the MACC compiler model already presented using shared memory to fill from global memory. And 58 6.2. Conclusion the effect of using shared memory is analysed. In fact, this kind of data variable usage is like lastprivate clause logic. However OpenMP 4.0 doesn’t have lastprivate clause for the team directive, therefore this kind of usage haven’t been implemented yet. In conclusion briefly, in this thesis presents the main design considerations that are embedded in our current implementation of the OpenMP 4.0 [ 12 ] accelerator model in OmpSs, making emphasizing on the roles of the programmer, compiler and runtime system in the whole picture. The compiler plays a key role and for this reason previous efforts have been devoted to the automatic generation of device–specific programs from high-level programs annotations such as OpenMP and OpenACC [ 11 ], including both research efforts at academia [ 22 , 23 , 24 ] as well as commercial implementations [ 4 , 15 ]. Our compiler implementation in Mercurium [ 2 ] has been useful to experiment with different code generation strategies, trying to foresee the need for new clauses in current OpenMP 4.0 specification. OmpSs [ 19 ] is strongly rooted on the assumption that the runtime system should play a key role, making appropriate use of the information that can be gathered at execution time. In this thesis emphasizing this aspect supported by an experimental evaluation on three application kernels is tried. 59 Bibliography [1] Bison - gnu parser generator. "http://www.gnu.org/software/bison/". [2] Bsc - parallel programming models group: "mercuirum is source-to-source compiler". "http://pm.bsc.es/mcxx". [3] Bsc - parallel programming models group: "nanos++ runtime library". "http://pm.bsc. es/nanos". [4] Caps entreprise, caps compilers-3.3 hmppcg directives reference-manual, 2012. "http: //pm.bsc.es/nanos". [5] flex: The fast lexical analyzer. http://flex.sourceforge.net/. [6] Khronos group. "http://www.khronos.org/". [7] Nas division. nas parallel benchmarks. "http://www.nas.nasa.gov/Resources/Software/ npb.html". [8] Nvidia cuda programming guide v5.5. "http://docs.nvidia.com/cuda/ cuda-c-programming-guide". [9] Nvidia dynamic parallel library. http://www.openstd.org/jtc1/sc22/wg21/docs/papers/2014/n3960.pdf. [10] Open computing language (opencl). "http://www.khronos.org/opencl/". [11] Openacc: Directives for accelerators. "http://www.openacc-standard.org". [12] The openmp api specification for parallel programming. http://www.openmp.org. [13] Parallel thread execution isa version 4.0. "http://docs.nvidia.com/cuda/ parallel-thread-execution/". [14] Performance analysis tools: Details and intelligence. http://www.bsc.es/computersciences/performance-tools/paraver. 61