an opencl-based framework for rapid virtual …users.auth.gr/ksiop/pdf/vipes2016_opencl.pdf · an...

6
An OpenCL-based Framework for Rapid Virtual Prototyping of Heterogeneous Architectures Efstathios Sotiriou-Xanthopoulos * , Leonard Masing ** , Kostas Siozios * , George Economakos * , Dimitrios Soudris * and J¨ urgen Becker ** * School of Electrical and Computer Engineering, National Technical University of Athens, Athens, Greece E-mail: {stasot, ksiop, geconom, dsoudris}@microlab.ntua.gr ** Institute for Information Processing, Karlsruhe Institute of Technology, Karlsruhe, Germany E-mail:{leonard.masing, becker}@kit.edu Abstract—The increasing performance and power require- ments in embedded systems has lead to a variety of heteroge- neous hardware architectures, featuring many different types of processing elements. This heterogeneity however induces extra effort on system development and programming. To address this heterogeneity, OpenCL provides a portable programming model which enables the use of one source code in various architectures featuring different types of processors. Also, such systems impose higher design complexity due to the existence of an increased number of hardware components. Virtual Prototyping aims to alleviate this issue by enabling the hardware modeling in higher abstraction levels. This paper combines the benefits of OpenCL with Virtual Prototyping, by proposing an OpenCL- based framework for rapid prototyping, which (a) automatically derives a virtual prototype from an OpenCL code; (b) executes the OpenCL application by running the host program along with the hardware simulation; and (c) proposes a design flow for faster system evaluation, as compared to state-of-the-art FPGA-based flow. Using a set of OpenCL benchmarks, it is shown that the proposed framework enables faster prototyping by up to 18×, as compared to state-of-the-art flow. I. I NTRODUCTION Due to the ever increasing need for more processing power despite the limited energy budget available, efficient data processing is becoming more and more imperative. Thus, het- erogeneous multi-processor Systems-on-Chip (MPSoC) have been an effective selection, as their hardware components can be customized to the exact application requirements. To exploit their full potential, choosing the right architecture for the running application is a requirement of utmost importance. This however imposes increased design effort for both software and hardware, especially when different types of processors (e.g. CPUs, GPUs, FPGAs etc.) are taken into consideration. To solve the difficulties imposed by the programming heterogeneity of such platforms, OpenCL [1] provides a portable programming model which enables the programming of different types of processing elements, without the need for adapting the source code to each type. Hence, the designer is able to investigate multiple data processing architectures without extra programming effort. Although originally directed to GPU programming, the FPGA community is increasingly adopting OpenCL, thus enabling the easier and more efficient programming of FPGA devices. However in the FPGA or ASIC world these nearly limitless customization options during the MPSoC design increase the design complexity. This is caused by the numerous architec- tural parameters in RTL design (e.g. when using FPGAs). Thus choosing an efficient architecture is a tedious and slow task; doing this task manually by experienced developers can take a This work was partially supported by “TEAChER: TEach AdvanCEd Reconfigurable architectures and tools” project funded by DAAD (2014) CPU Memory FPGA ASIC BUS ARM ARM RAM RAM FPGA (a) (b) (c) (d) Fig. 1. Typical examples of heterogeneous architectures to be taken into consideration during SoC design. Architectures (b), (c) and (d) are not supported by state-of-art OpenCL-based development frameworks. lot of effort and man-month, making it unfeasible for most use cases. Virtual Prototyping has been proposed to alleviate this problem: The hardware is modeled in a software representation called Virtual Platform (VP), typically written in SystemC. The main benefit of such an approach is the hardware modeling in various abstraction levels, in each of which a number of architectural details is removed, thus limiting the architectural parameter combinations, especially in early design stages when some of the architectural details are not yet available. This enables the early software development and design space exploration, targeting to easier bug fixing, better design space coverage and shorter time-to-market. The VP might also serve as a golden reference to the development team. The goal of this work is to propose a rapid Virtual Prototyping framework which (a) enables the automated VP modeling of heterogeneous hardware architectures by taking as input an OpenCL source code; (b) provides a platform- independent simulation environment between the hardware model and the host (i.e. the processor that coordinates the simulated hardware) without the need for real hardware plat- forms; and (c) is accompanied with a design flow that features faster development and evaluation cycles during a design space exploration procedure, as compared to state-of-the-art FPGA- based system design using OpenCL. The paper is structured as follows: Sections II and III present the motivation and the related work of this paper. Section IV explains the proposed methodology. Section V shows the experimental results and discusses the insights gained. Finally, we conclude our work in Section VI. II. MOTIVATION To better clarify the benefits of combining OpenCL with Virtual Prototyping, we consider two scenarios, which are related to state-of-art design flows: (i) OpenCL without using VPs (e.g. using FPGA only) and (ii) VP modeling without using OpenCL (i.e. manual hardware modeling and CPU programming according to the hardware architecture). OpenCL without VPs: The designer would use a FPGA- based platform for the system design and evaluation. This leads

Upload: lytuyen

Post on 12-Oct-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

An OpenCL-based Framework for Rapid VirtualPrototyping of Heterogeneous Architectures

Efstathios Sotiriou-Xanthopoulos∗, Leonard Masing∗∗, Kostas Siozios∗,George Economakos∗, Dimitrios Soudris∗ and Jurgen Becker∗∗

∗School of Electrical and Computer Engineering, National Technical University of Athens, Athens, GreeceE-mail: {stasot, ksiop, geconom, dsoudris}@microlab.ntua.gr

∗∗Institute for Information Processing, Karlsruhe Institute of Technology, Karlsruhe, GermanyE-mail:{leonard.masing, becker}@kit.edu

Abstract—The increasing performance and power require-ments in embedded systems has lead to a variety of heteroge-neous hardware architectures, featuring many different types ofprocessing elements. This heterogeneity however induces extraeffort on system development and programming. To address thisheterogeneity, OpenCL provides a portable programming modelwhich enables the use of one source code in various architecturesfeaturing different types of processors. Also, such systems imposehigher design complexity due to the existence of an increasednumber of hardware components. Virtual Prototyping aimsto alleviate this issue by enabling the hardware modeling inhigher abstraction levels. This paper combines the benefits ofOpenCL with Virtual Prototyping, by proposing an OpenCL-based framework for rapid prototyping, which (a) automaticallyderives a virtual prototype from an OpenCL code; (b) executesthe OpenCL application by running the host program along withthe hardware simulation; and (c) proposes a design flow for fastersystem evaluation, as compared to state-of-the-art FPGA-basedflow. Using a set of OpenCL benchmarks, it is shown that theproposed framework enables faster prototyping by up to 18×, ascompared to state-of-the-art flow.

I. INTRODUCTION

Due to the ever increasing need for more processing powerdespite the limited energy budget available, efficient dataprocessing is becoming more and more imperative. Thus, het-erogeneous multi-processor Systems-on-Chip (MPSoC) havebeen an effective selection, as their hardware components canbe customized to the exact application requirements. To exploittheir full potential, choosing the right architecture for therunning application is a requirement of utmost importance.This however imposes increased design effort for both softwareand hardware, especially when different types of processors(e.g. CPUs, GPUs, FPGAs etc.) are taken into consideration.

To solve the difficulties imposed by the programmingheterogeneity of such platforms, OpenCL [1] provides aportable programming model which enables the programmingof different types of processing elements, without the need foradapting the source code to each type. Hence, the designeris able to investigate multiple data processing architectureswithout extra programming effort. Although originally directedto GPU programming, the FPGA community is increasinglyadopting OpenCL, thus enabling the easier and more efficientprogramming of FPGA devices.

However in the FPGA or ASIC world these nearly limitlesscustomization options during the MPSoC design increase thedesign complexity. This is caused by the numerous architec-tural parameters in RTL design (e.g. when using FPGAs). Thuschoosing an efficient architecture is a tedious and slow task;doing this task manually by experienced developers can take a

This work was partially supported by “TEAChER: TEach AdvanCEdReconfigurable architectures and tools” project funded by DAAD (2014)

CPU Memory FPGA ASIC

BUS

ARM ARM RAM

RAMFPGA

(a) (b) (c) (d)

Fig. 1. Typical examples of heterogeneous architectures to be taken intoconsideration during SoC design. Architectures (b), (c) and (d) are notsupported by state-of-art OpenCL-based development frameworks.

lot of effort and man-month, making it unfeasible for most usecases. Virtual Prototyping has been proposed to alleviate thisproblem: The hardware is modeled in a software representationcalled Virtual Platform (VP), typically written in SystemC. Themain benefit of such an approach is the hardware modelingin various abstraction levels, in each of which a number ofarchitectural details is removed, thus limiting the architecturalparameter combinations, especially in early design stages whensome of the architectural details are not yet available. Thisenables the early software development and design spaceexploration, targeting to easier bug fixing, better design spacecoverage and shorter time-to-market. The VP might also serveas a golden reference to the development team.

The goal of this work is to propose a rapid VirtualPrototyping framework which (a) enables the automated VPmodeling of heterogeneous hardware architectures by takingas input an OpenCL source code; (b) provides a platform-independent simulation environment between the hardwaremodel and the host (i.e. the processor that coordinates thesimulated hardware) without the need for real hardware plat-forms; and (c) is accompanied with a design flow that featuresfaster development and evaluation cycles during a design spaceexploration procedure, as compared to state-of-the-art FPGA-based system design using OpenCL.

The paper is structured as follows: Sections II and IIIpresent the motivation and the related work of this paper.Section IV explains the proposed methodology. Section Vshows the experimental results and discusses the insightsgained. Finally, we conclude our work in Section VI.

II. MOTIVATION

To better clarify the benefits of combining OpenCL withVirtual Prototyping, we consider two scenarios, which arerelated to state-of-art design flows: (i) OpenCL without usingVPs (e.g. using FPGA only) and (ii) VP modeling withoutusing OpenCL (i.e. manual hardware modeling and CPUprogramming according to the hardware architecture).

OpenCL without VPs: The designer would use a FPGA-based platform for the system design and evaluation. This leads

to a vendor-dependent low-level RTL design with a specificsupported architectural scheme, similar to Figure 1a, whichdepicts a typical bus-based SoC with one FPGA fabric anda dual-core ARM. However there might be alternative archi-tectures to be taken into consideration during SoC design: Forexample, Figure 1b depicts a cluster of sub-systems, followingthe architectural pattern of Synopsys HAPS [2]: Each sub-system is similar to the SoC of Figure 1a and executes a dif-ferent set of threads. Figure 1c depicts a SoC where the CPUsand memories are decoupled from the FPGAs, while Figure 1dshows a NoC-based system, quite similar to [3], incorporatingCPUs, FPGAs, ASICs and distributed memory into differentmodules. The architectures of Figures 1b, 1c and 1d are verydifficult to be prototyped in real hardware, especially becauseof the increased cost for acquiring such hardware platforms.Hence, using VPs in OpenCL-based systems (i) facilitatescost-free vendor-independent rapid prototyping, (ii) allows foreasier and faster platform debugging and timing/power metricsevaluation, (iii) provides extensive architectural flexibility and(iv) enables the iterative platform refinement with a small setof architectural details in each design stage.

VP modeling without OpenCL: A typical VP for hetero-geneous MPSoCs requires (a) the software programming, (b)the modeling of computation for hardware accelerators and (c)the modeling of the interconnection. Modifying one of theseelements might result in modifications to the other parts aswell. For example, re-assigning a task to another processortype might lead to software changes for handling the newly-assigned component. In another example, a bus might needdifferent accelerator modeling than a NoC: in the latter case,the accelerator might be adapted in order to exploit transac-tions parallelization. Therefore various portability issues arisebetween different architectural schemes incorporating differentprocessors, memory organization and interconnection schemes.This is alleviated by using OpenCL during prototyping, asOpenCL is able to provide a portable programming andsimulation environment which is adapted to any architecturalscheme, without the need for software or hardware modelmodifications, while also enabling the easy runtime assignmentof the application tasks onto the processing elements.

III. RELATED WORK

Due to its provided functional portability, OpenCL hasbeen extensively supported in GPU programming, in orderto abstract away the complex programming model of GPUs.Typical examples are the OpenCL development environmentsof AMD [4] and NVIDIA [5]. A survey on the performanceand portability of OpenCL in GPUs is provided by [6]. Apartfrom GPUs, an ever-increasing effort is made for adoptingOpenCL in FPGA design. The most typical example is AlteraSDK for OpenCL [7], an OpenCL-based development andexecution environment that allows for the automatic synthesisof OpenCL code down to FPGA bitstream, while includingthe appropriate communication environment between the hostprogram and the FPGA-mapped accelerator(s). Xilinx alsoadopted OpenCL by providing Xilinx SDAccel environment[8], which provides an integrated development and runtimesolution from C, C++ or OpenCL sources down to FPGA-mapped applications [9], as well as by enhancing VivadoHLS tool with OpenCL support (however only for high-levelsynthesis) [10].

Although the above OpenCL-based development environ-ments for FPGA programming are evolving more and more,they suffer from the inherent constraints of FPGA-based sys-tem design: The system design is made in RTL, by executingthe whole flow which is required in order to (a) transform anOpenCL code into a hardware description and (b) map thedescription onto an FPGA, e.g. by using Quartus in case of

Host OpenCL Context

Control CPU

Device (CPU, GPU, HW Accelerator or VP)

Host Memory

Global Memory / Constants

...

Write Buffer

Read Buffer

Kernel Exec.

Sync. Event

Work Group WLocal Memory

Work Item (W-1)*i+1

Work Item W*i

Private Mem.

...

Work Group 2Local Memory

Work Item i+1

Private Mem.

Work Item i+2

Private Mem.

Work Item 2*i

Private Mem.

...Private Mem.

Work Group 1Local Memory

Work Item 1

Private Mem.

Work Item 2

Private Mem.

Work Item i

Private Mem.

...

Fig. 2. OpenCL execution and memory model (for one-dimension indices).

the Altera SDK for OpenCL. Moreover, the system evaluationis only made by using a real (and potentally expensive)FPGA board. Apart from the cost, there is no explicit supportof alternative architectures involving CPUs other than thoseprovided by the SoC fabric of the FPGA board. Last but notleast, Altera SDK for OpenCL requires a license for compilingan OpenCL description of the accelerator, while SDAccel canbe obtained only after contacting Xilinx.

This paper supports that the above issues can be alleviatedby combining the portability of OpenCL with the abstractedhardware modeling of Virtual Prototyping. The most relevantexample of such a combination is the OpenCL emulator ofAltera SDK for OpenCL, which however is suitable onlyfor functional verification. Moreover, prototyping frameworksthat enable the automatic VP creation, e.g. Mentor VistaVirtual Prototyping [11], do not explicitly support OpenCLapplications, while they also focus on software development.To the best of our knowledge, there is no OpenCL-basedframework for virtual prototyping of heterogeneous SoCs inmultiple abstraction levels. On the contrary, our proposedprototyping framework addresses the above issues by (a)providing an automated flow for deriving a SystemC-based VPfrom an OpenCL source, and (b) enabling the VP simulationwith different configurations, without the need for existinghardware. The vendor-independent nature of the frameworkenables the use of numerous different architectural schemeswhich might be difficult to map onto an FPGA.

IV. SYSTEMC PROTOTYPING METHODOLOGY FOROPENCL APPLICATIONS

After a brief background of the OpenCL execution model,this section analyzes the proposed prototyping framework. Thisanalysis includes the framework structure and functionality, aswell as a prototyping flow for converting a set of OpenCLkernels into VP modules.

A. Background on OpenCL execution model

The proposed prototyping framework is based on theOpenCL 1.0 specifications [12], according to which anOpenCL application consists of two main parts: (a) the hostand (b) a number of OpenCL kernels, as the execution modelexample of Figure 2 depicts. The kernels part is organized as anOpenCL context, i.e. a unified environment which contains thekernels executable (a.k.a. program), the kernel instances (a.k.a.work-items), the utilized devices1 and the memories. Therefore,the host controls the kernel instances and the respective deviceswhich are included in this context. Each work-item matchesto a specific part of the kernels execution, such as a singleiteration of a ‘for’ loop or a branch of an ‘if-else’ block.

To define which parts should be executed in each work-item, built-in OpenCL functions return the global and the localindex of the work-item. Although the example of Figure 2

1It is possible to use multiple devices in one context as well.

Host

Inter-Process Communication

OR

Virtual Platform (SystemC)

Wo

rk G

rou

p

Work Item

Work-Item Wrapper

Control handling

Memory

Shared Memory

...Work Item

Work Item

...

PC Execution

(x86)

OpenCL Host API

Software Simulation (OVP)

CPU Model

(e.g. ARM)

Memory Model TLM

IPC2TLM Adapter

OpenCL Host API

Global Data & Constants

Local DataPointers

Sync.

Wo

rk G

rou

p

Work Item

...Work Item

Work Item

SystemC Accelerator

Data I/O RST

ENABLEREADY

CLK

Intercon-nection

Arbiter

Time

Fig. 3. The structure of the proposed OpenCL prototyping framework.

CPU

Work-Items

ß Trigger

ß Trigger

Time waste

Time waste

CPU

Work-Items

Triggerà

ß Trigger

Single Platform

Separate Platforms

TIME

Fig. 4. Using single OVP-based platform versus using separate platforms.

utilizes one-dimension indices, the developer can use up tothree dimensions. The global index distinguishes each work-item from the others. However, the work-items might beorganized in work-groups. In that case, the local index is usedfor identifying a work-item inside a specific work-group. Inthe example of Figure 2, given W work-groups, the globalindex range is 0, ...,W ∗ i− 1, while the local index range foreach work-group is 0, ..., i− 1.

This grouping is related to the OpenCL memory model:There are four distinct memory types: (a) the global memory,which is visible by any work-item, as well as the host; (b)the constant memory, i.e. a read-only global memory; (c)the local memory, which is visible only by the work-itemsof a single work-group (each work-group has its own localmemory); and (d) the private memory, which is used onlyinside a specific work-item. This memory model allows formultiple memory accesses when using local memories fortemporary data sharing, thus leveraging the parallelizationpotential provided by OpenCL. To avoid race conditions,synchronization mechanisms known as barriers can be usedinside the kernel code, for global, local or both memories.

Therefore, within a specific context, (1) the host selectsthe execution of one of the OpenCL kernels and defines a setof buffers for data sending/receiving. (2) After enqueuing2 theinput data to be sent to the global and/or constant memory,(3) the host invokes (i.e. triggers) the kernels by enqueu-ing an “NDRange” command, which involves the creationof an N-dimensional range of work-items and work-groups.Afterwards, (4) the data and the command are flushed to thedeployed devices. (5) When the OpenCL kernel is executed, anevent is returned to the host. (6) The host enqueues a commandfor data reception. This typical flow is repeated for each kernel.

B. Structure for the Proposed Prototyping Framework

Based on the OpenCL execution model of Section IV-A,Figure 3 depicts the main structure of the proposed OpenCL-based virtual prototyping framework, which comprises the hostand the SystemC-based VP part. The host is either a x86 PC oran instruction-set simulator, e.g. provided by OVP [13]. In bothcases, the host software utilizes the OpenCL host API, whichprovides standarized functions for command/data enqueueingand synchronization. The API manipulates an Inter-Process

2This term describes the buffering of data and/or commands. The bufferedcontent may not be sent immediately to the device(s), but only when the hostreaches a specific synchronization point.

Communication (IPC) mechanism for the connection with theVP. If the host is a software simulator, the IPC manipulationis made via a Transaction-Level Modeled (TLM) adapter(IPC2TLM), with which the accesses to specific bus addressesare translated to IPC commands. This scheme enables thedecoupling of the software simulator from the OpenCL work-items, following the concept of Figure 4: In software simula-tors like OVP, each platform component is scheduled in serialfor a specific time quantum. Therefore, in a single platformincluding CPU models and OpenCL work-items, the followingbehaviour is noticed: If a signal is sent from the CPU to thework-items, it will take effect only at the end of the CPU timequantum. The time frame between the signal sending and theend of the quantum will be wasted. This also occurs whenthe work-items send a signal to another component beforethe end of their quantum. To provide a simulator-independentsolution for this issue, this work proposes the use of a separatesoftware simulator (e.g. OVP-based platform with CPU modelsand memories, all connected typically via a TLM bus), whichruns in parallel with the VP. With this scheme, the signalexchange will instantly take effect, based on the event-drivenscheduling of SystemC. In addition, this decoupling enablesthe VP parameterization during the application execution.

For data exchanging between the host and the VP, a sharedmemory segment is allocated into the host. This segmentincludes the global and constant memory for the VP. Inaddition, the shared memory incorporates a 64-bit variablefor the simulated time of the VP. This variable is necessarybecause, during the application execution, the VP may be re-started in order to execute another kernel or different work-items. Hence, in order to avoid the resetting of the simulatedtime, the VP time-stamp is stored into the external timevariable. This variable is also utilized for time profiling throughthe built-in OpenCL functions.

The VP consists of multiple work-items3, which are orga-nized in work-groups. Each work-item is a SystemC-modeledaccelerator which includes the OpenCL kernel code, as wellas control and data signals. An important feature is the gatedclock input for each work-item: Firstly, it enables a low-powersystem design in early design stages. Secondly, this techniquemay lead to significant simulation time improvements, asSystemC is enabled to ommit the unused (e.g. early-finished)work-items. All work-items are controlled by a wrapper mod-ule, written in SystemC, which provides (1) the work-iteminterconnection, including the data access arbitration and thework-item synchronization (i.e. barrier handling), and (2) thecontrol handling from the host via the IPC, i.e. work-itemtriggering and event notification. Also, the wrapper includesa pointer to the shared memory segment for global data andconstants, as well as local memories, one for each work-group.This VP organization features modularity and configurability:The designer may use different system architectures by onlychoosing another wrapper version with different interconnec-tion scheme (e.g. bus, Network-on-Chip, etc.) and memorymodel (e.g. distributed memory, etc.), without having to changethe behavioural description of the work-items, and vice-versa.

Below, we provide an analysis on the layout of a typicalwrapper and the proposed IPC mechanism.

1) Wrapper layout: Although the layout of a work-itemwrapper strongly depends on the deployed inteconnectionand memory model, this section provides a typical wrapperarchitecture, which can be used as a paradigm for designinga wrapper library with a variety of different architecturalfeatures. The wrapper consists of two main modules, whichcontrol the VP work-items: (a) the scheduler and (b) thememory and interconnection model.

3In VP side, the work-items match to the available resources of the platform.

Available Work-Items (in SystemC VP)

Work Group wi

Work Item 1

... Invoked Work-Items (by Host)i

w

Work Item 2

Work Item N

Work Group

wi1iw

Work Group

wi 1iw

...

W work-groups

Scheduler[For each work-group]

Group wii

w

Segment 1Work Item 1

Work Item 2

Work Item N...

Group wi1i

w

...

Group wi1i

w...

W work-groups

Work Group wii

w

Work Item 1

Work Item 2

Work Item N

...

Group wi of Invoked Work-Itemsi

w

Previous Segment

Current Segment sj

Next Segment

TIME

...

N*(i+S*j)

+ 0

N*(i+S*j)

+ 1

N*(i+S*j) + N-1

...

...

Global ID: N*i + 0

Segment SWork Item 1

Work Item 2

Work Item N...

1js

1js

js

Global ID: N*i + 1

Global ID: N*i + N-1

Global ID: N*(i+S-1) + 0

Global ID: N*(i+S-1) + 1

Global ID: N*(i+S-1) + N-1

Available Resources

W x N available items

W x S x N invoked items

Global ID

Fig. 5. Work-item wrapper scheduler.

Memory & Interconnection Model

Control handlingLocal

Data

Inter-conn.

Interconnection

Global Data & Constants

Cache

To IPC

Local Data

Inter-conn.

Work Group wi

Work Item 1

...

iw

Work Item N

Work Group

wi1iw

Work Group

wi 1iw

...

W work-groups

...

Local Data

Interconn.

InterconnectionPorts for

Work-item 1

Ports for Work-item N

... Crossbar

Mem. Ports

Fig. 6. Work-item wrapper model for interconnection and memory.

i. Scheduler: The host may invoke more work-items thanthe available resources of the VP. In this case, the scheduleris responsible for the serialization of the invoked work-items,according to the available ones in the VP, as shown in Figure 5.The invoked work-items are separated into parallel groups, thenumber of which is equal to the number of VP work-groups(i.e. W ). In each group, the invoked work-items are organizedinto S segments, in each of which the invoked work-itemsshould not exceed the available ones. The scheduler properlyadjusts the global and local indices, so that one segment isrunning on the available work-items. When the execution isfinished, the work-items are re-triggered for the next segment.

ii. Memory and Interconnection: As Figure 6 shows,the wrapper uses separate local and global interconnection forlocal (one for each work-group) and global data access respec-tively, thus enabling data access parallelization. Each work-item has dedicated input/output signals for local and globalinterconnection. Every interconnection is a typical crossbarwhich consists of input/output ports, one pair for each work-item, as well as one pair for the memories. Each pair of portsconsists of control and data signals, allowing for transactionsin words of multiple bytes, defined by the designer at compiletime. The latter enables single-cycle transfers of vectors of 2,4, 8 or 16 values (of up to 32-bit each), which are supportedby OpenCL [12], thus enabling parallelism on data processing.

Each module of the local memory is attached to one localinterconnection, while a global/constant memory is attachedto the global interconnection. Upon memory access, the work-item source code defines the memory type (global/constantor local) and the address inside the memory. If multiplework-items access the same memory module, a round-robinarbitration is applied. We assume that single-port memoriesare utilized, supporting 32-bit accesses. However, significantbottlenecks may be induced, especially when reading globalor constant vectors of data. Hence, a cache module is used for

Host API

“TRIGGER”semaphore

“READY”semaphore

“ACK”semaphore

Invoke Kernel Wait READYAcknowledge

READY

OpenCL Host Side

Wrapper Side Control Handling

Polling Notification Ack. Waiting

Get Time Stamp

Time

Update TimeMemory Pointers

Shared Memory

memcpy()

IPC

Start VP proc.

Fig. 7. Inter-process communication mechanism.

the global data4, the size of which is determined at compiletime. The cache supports accesses in lengths equal to theword length of the interconnection, in order to retain theinterconnection performance and thus avoid bottlenecks. Thearea/power cost of such a cache depends on its size and wordlength, however the designer may fine-tune both parametersfor achieving optimized solutions.

2) Inter-Process Communication: The IPC mechanism ofthe proposed framework is based on a set of Unix semaphores,which are utilized for the control between the host and theVP, as shown in Figure 7. In particular, the set includesthree semaphores; one for the VP triggering (i.e. “Trigger”)and two for the host notification when processing ends (i.e.“Ready” and “Ack”). Apart from the semaphore-based control,the IPC mechanism incorporates an API for data exchange. Inparticular, the shared memory segment is manipulated by thehost through memcpy() calls. Also, the time variable is updatedby the wrapper in every (simulated) clock tick. The host readsthis variable when polling the current time-stamp.

Hence, (1) when the host invokes a kernel, the VP processis started by taking as input the number of work-items andwork-groups, as well as the input/output data size. Duringthe VP startup, the semaphores and the shared memory areattached to the process. Afterwards, (2) the host triggers thedata processing through the “Trigger” semaphore, which ispolled by the wrapper. This kind of waiting is non-blocking5

in order not to stall the simulated time. (3) During processing,the host waits until the result is ready, using the “Ready”semaphore (typically this is a blocking waiting). (4) Whenthe wrapper notifies the host that the processing has finished(through the “Ready semaphore”), (5) the VP process performsa blocking waiting through the “ACK” semaphore, which isused for verifying that the host has received the notification.

C. Prototyping Flow for OpenCL Applications

In order to automatically create the work-items prototype,the proposed framework is accompanied with an OpenCL-to-SystemC prototyping flow, presented in Figure 8. Aftera syntax check (typically using clang [14]), the OpenCLsource is converted into SystemC by using (a) a work-itemtemplate; (b) a C++ class for OpenCL vectors6 of differentdata types, supporting arithmetic/logic operations and vectorcomparisons according to the OpenCL specifications [12],while also enabling different degrees of parallelization invector processing; (c) mathematical functions for both scalarvariables and vectors; and (d) input/output functions.

As the syntax of OpenCL vector operations differs fromthe default C/C++ syntax, any vector-related operation is re-written according to the provided methods of the deployedC++ vector class. Figure 8 (“Vector Processing”) shows typicalconversion examples. This conversion is applied recursively:For example, V.odd is firstly converted to V.s13, then toVector(V(1),V(3)) and finally to Vector(V.array[1],V.array[3]).

4The constants are fetched only once and are saved inside the work-item.5In non-blocking waiting, the process is not blocked, but it performs active

waiting. In blocking waiting, the process is blocked.6Different from the built-in vector class provided by C++.

Syntax Check[clang]

OpenCL Kernel

OpenCL-to-SystemC Code Conversion

[proposed]

Work-Item Template

Vector Handling Math

I/O

VP Construction

[proposed]

Wrapper Library

Compi-lation

[gcc]

VP

Vector Processing [recursive]

Custom Vector Class

OpenCL Custom

V(i) V.array[i]

(V1(i), V2(j))

Literals

Concat. Vector(V1(i), V2(j))

V.s01Access Vector(V(0), V(1))

V.xyzw V.s0123

V.odd V.s13

V.even V.s02

Opera-tions

V1 + V2 V1 + V2 ß As is

V1.odd * V2.even

(V1(1)*V2(0), V1(3)*V2(2))

I/O Transactions[globals, constants & locals]

Input

A[pos]

Transactions Interface

value = read_T(Addr(A), pos)

Outputwrite_T(Addr(A), pos, value)

Detecting Globals, Constants and Locals

SystemC Library

Type T

Fig. 8. Proposed prototyping flow.

Design Space Exploration

Design Space Exploration in a single design stage

OpenCL Kernel

Kernel Compilation[HLS + Quartus]

BitstreamFPGA Board

Programming + ExecutionMetrics

Design Parameters Change

OpenCL Kernel

Prototyping with SystemC

[Figure 8]VP

Compilation+ Simulation

HLSAnnotated

VP

Parameters

Parameters

Metrics

Design Parameters ChangePrototype Refinement

Additional Architectural Details

(a)

(b)

Fig. 9. Typical design flows when using (a) the proposed prototypingframework; and (b) Altera SDK for OpenCL. The Altera-based flow requiresthe kernel compilation after every parameters change, in contrast to the flowutilizing the proposed framework.

Additionally, the OpenCL-to-SystemC conversion includes thedetection of the global constants and the global and localvariables7. Every access to that data is replaced by input/outputfunction calls for implementing memory accesses to/from thememories, as shown in Figure 8 (“I/O Transactions”).

When the SystemC source for the work-items is created,the next stage of the proposed flow involves the constructionof the whole VP, including the wrapper model. Finally aconventional C++ compiler is utilized, in combination withthe SystemC library, so that the VP executable is produced.

The main advantage of this flow is that it is applied onlyonce: The OpenCL code is not needed any more in systemdesign, as the created VP will be utilized in all the remaininghardware design stages, i.e. (i) functional verification, (ii)design parameters evaluation in terms of timing, resource uti-lization and power consumption, as well as (iii) final synthesis.This is also a major contribution of this work. To better explainthis advantage, Figures 9a and 9b show two typical designflows when using (a) the proposed prototyping frameworkand (b) Altera SDK for OpenCL respectively. Altera SDKfor OpenCL is chosen as state-of-the-art for mapping OpenCLkernels onto FPGAs.

The design flow using the proposed framework (Figure9a) starts with the prototyping procedure of Figure 8. Theproduced VP can be used in a typical design space exploration(DSE) and can be refined with more architectural details inlater design stages. In a single DSE, The VP is enrichedwith timing/area/power annotations which are derived usingHigh-Level Synthesis (HLS) [15]. The annotated VP is thencompiled and simulated. During simulation, the computationand communication behavior are combined for timing and

7Private variables are finally implemented as registers.

TABLE I. OPENCL-IMPLEMENTED ALGORITHMS FOR THEEXPERIMENTATION SETUP.

Work-ItemsAlgorithm Invoked Available Local InputPathfinder 256 256 256 2 × 128 matrixBFS 1024 1024 256 1024-node graphGaussian Elimination 64 × 64 64 × 64 1 16 × 16 matrixParticle Filter 256 256 1 256 video particlesaNearest Neighbor 42816 64 1 42764 recordsHistogram1024 384 384 96 10000 elementsMergeSort 3072 × 1024 256 × 1 256 × 1 10000 elementsBucketSort 1024 128 128 10000 elementsBack-Propagation 16 × 64 16 × 64 16 × 16 64-input ANNb

a In 10-frame 32 × 32 videob Neural network with 64 inputs, 1 hidden layer with 16 neurons and 1 output

power estimation, while different execution scenarios are takenby using different input data.

As compared to the above flow, the design procedure usingAltera SDK for OpenCL (Figure 9b) starts with the OpenCLkernels compilation, including HLS and RTL synthesis withQuartus. The result is a bitstream for programming an FPGAboard, where the system is evaluated. When using a typicalDSE, the whole procedure is repeated after every parameterschange. Also there is no support for higher abstraction levels.

V. EXPERIMENTAL RESULTS

The proposed prototyping framework is evaluated by usingRodinia benchmark suite [16]. Rodinia provides OpenCL-implemented algorithms, mainly focusing on GPU accelera-tion. However, the provided OpenCL kernels can be mappedonto FPGAs as well. For the scope of this work, we usedthe benchmarks of Table I, which also shows the number ofwork-items in total (including the invoked and the availablework-items in the VP) and locally (i.e. per work-group), aswell as the application input size. In applications with largenumber of invoked work-items, the OpenCL kernels havebeen partially serialized, in order to both avoid the excessivememory allocation and provide a more realistic model of thesystem-under-design.

The rest of this section (i) provides a quantitative compar-ison between Altera SDK for OpenCL (i.e. state-of-art) andthe proposed framework in terms of OpenCL compilation andapplications execution time; and (ii) analyzes the simulationtime when using x86 or OVP-based OpenCL hosts, while alsoevaluating the effect of separating the OVP simulator fromthe OpenCL work-item platform. All the experiments havebeen executed on an Intel Core-i5 Quad-Core CPU at 3.2 GHzrunning Fedora 23 with Linux kernel 4.4.

Altera SDK for OpenCL vs. Proposed Framework: Theselected OpenCL kernels have been mapped onto a CycloneV device, included in an Altera DE1SoC board, on which theapplications have been run in order to measure the algorithmexecution time. In the meanwhile, the OpenCL kernels havebeen prototyped in SystemC with the proposed frameworkand annotated in terms of timing and resource utilization, byusing Xilinx Vivado HLS8. Afterwards, the SystemC modelsare simulated by using the x86 CPU as OpenCL host.

The comparison results9 are depicted in Figure 10. Thedominant part of the Altera-based flow is compilation, whichis from 3× up to 18× slower than the proposed flow (includingprototyping, annotation and simulation). Although the VPsimulation depends on the input volume, the proposed method-ology enables the designer to perform a rapid evaluation by

8Altera does not provide a standalone HLS tool. However, despite theuse of different vendors, we intend to acquire typical execution time resultsonly. Similar HLS run-time results are expected with the use of any othercommercial HLS tool.

9The board execution time is multiplied by 500× to be visible to the chart.

Fig. 10. Comparison between the compilation/execution time with AlteraSDK for OpenCL and the prototyping/simulation time with the proposedprototyping framework.

Fig. 11. Simulation time comparison when using a x86 host and OVP-basedARM host. For the OVP scenarios, we evaluate the use of separate VPs, aswell as the use of a common OVP-based platform.

using a small amount of representative input data in earlydesign stages, for fast decision making, while larger input datavolumes can be utilized in later design stages. On the contrary,this feature is not provided by Altera SDK for OpenCL: In caseof a parameter modification, the designer has to wait morethan 40 minutes (independently from the input data) until theOpenCL kernels are (re-)implemented. Last but not least, thereare cases (e.g. Back-propagation) where the kernels do not fitinto the FPGA fabric; in that case, Altera compilation fails.

Simulation Time Analysis: The aim of this analysis isto study how the application execution time is affected whenusing different OpenCL hosts, namely a x86 host (i.e. theIntel Core-i5 CPU) and an ARM Cortex-A9 CPU model,provided by OVP. For the second case, two scenarios areinvestigated: (i) separate platforms for the software simulationand the OpenCL work-items (i.e. the proposed approach); and(ii) the use of a single TLM platform including the CPU model,memories and the OpenCL work-items (i.e. the state-of-artprototyping approach). In the single-platform scenario, usinga set of preliminary simulations, we have adjusted the timequantum of the OVP scheduler appropriately, so that achievingthe minimum possible simulation time overhead, according tothe concept of Figure 4. For the separate-platform scenario,such adjustments are not necessary, which is a first evidenceabout the efficiency of the proposed approach.

As Figure 11 depicts, the use of an OVP software simulatoras a separate platform is able to leverage the high simulationspeed provided by OVP without causing significant commu-nication overhead between the CPU and the OpenCL work-items, as it achieves similar simulation times as compared tothe use of a x86 host. On the contrary, the use of a single plat-form may cause significant simulation time overhead, rangingfrom 10% up to 5×. The first reason, as explained in Figure4, is that a single OVP-based platform performs quantum-based OVP scheduling, which may lead to significant timewaste. The second reason is that a single platform deploys aconstant number of work-items. On the contrary, in separateplatforms, only the necessary work-items are allocated. Thus ifthe host repeats a kernel with less invoked work-items, the VPsimulation will be faster, as less components will be simulated.

VI. CONCLUSIONS

This paper presents a rapid prototyping framework, whichautomatically derives a SystemC-based VP from OpenCLsources, thus combining the OpenCL portability with the ab-stracted modeling of Virtual Prototyping. The proposed frame-work supports different hardware architectures and memorymodels without the need for kernel modifications, while alsoenabling fast evaluation cycles, without long compilation pro-cedures. In particular, the design flow which accompanies theproposed framework achieves evaluation time improvementsup to 18×, as compared to Altera SDK for OpenCL. Theproposed framework also enables the use of any OpenCL host,which can be either a x86 CPU or a software simulator. Thehost communicates with the VP through an inter-process com-munication mechanism, which also allows for the separationof a software simulator from the VP, thus leading to significantsimulation time improvements reaching up to 5×.

REFERENCES

[1] OpenCL, by khronos group. https://www.khronos.org/opencl/.[2] (2013) Synopsys High-performance ASIC Prototyping Systems.

http://www.synopsys.com/Systems/FPGABasedPrototyping/Pages/HAPS.aspx.[3] J. Cong, M. Ghodrat, M. Gill, B. Grigorian, H. Huang, and G. Reinman,

“Composable accelerator-rich microprocessor enhanced for adaptivityand longevity,” in IEEE International Symposium on Low Power Elec-tronics and Design (ISLPED), 2013, Sept 2013, pp. 305–310.

[4] AMD OpenCL. http://developer.amd.com/tools-and-sdks/opencl-zone/.[5] NVIDIA OpenCL SDK. https://developer.nvidia.com/opencl.[6] K. Komatsu, K. Sato, Y. Arai, K. Koyama, H. Takizawa, and

H. Kobayashi, “Evaluating performance and portability of opencl pro-grams,” in 5th Intl. Workshop on Automatic Performance Tuning, 2010,pp. 7–22.

[7] Altera SDK for OpenCL. https://www.altera.com/products/design-software/embedded-software-developers/opencl/overview.html.

[8] Xilinx SDAccel. http://www.xilinx.com/products/design-tools/software-zone/sdaccel.html.

[9] “The Next Logical Step in C/C++, OpenCL Program-ming”, by Xcell Software Journal, Issue 1, 2015.http://www.xilinx.com/publications/archives/xcell-software/xcell-software1.pdf.

[10] Vivado Design Suite User Guide, UG902 (v2015.4), Nov. 24, 2015.http://www.xilinx.com/support/documentation/sw manuals/xilinx2015 4/ug902-vivado-high-level-synthesis.pdf.

[11] Vista virtual prototyping, by mentor graphics.https://www.mentor.com/esl/vista/virtual-prototyping/.

[12] The OpenCL specifications, version 1.0.https://www.khronos.org/registry/cl/specs/opencl-1.0.pdf.

[13] Open virtual platforms website. http://www.ovpworld.org.[14] clang: a C language family frontend for LLVM. http://clang.llvm.org/.[15] E. Sotiriou-Xanthopoulos, S. Xydis, K. Siozios, G. Economakos, and

D. Soudris, “Effective platform-level exploration for heterogeneousmulticores exploiting simulation-induced slacks,” in PARMA-DITAM’14. New York, NY, USA: ACM, 2014, pp. 13:13–13:16.

[16] Rodinia: A benchmark suite for heterogeneous computing, version 3.0.http://lava.cs.virginia.edu/Rodinia/.