<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>A Runtime Controller for OpenCL Applications on ∗ Heterogeneous System Architectures</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Politecnico di Milano DEIB</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Politecnico di Milano DEIB</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Simone Libutti DEIB</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Politecnico di Milano simone.libutti@polimi.it</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Antonio Miele DEIB</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Politecnico di Milano antonio.miele@polimi.it</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Marco D. Santambrogio DEIB</institution>
          ,
          <addr-line>Politecnico di Milano</addr-line>
        </aff>
      </contrib-group>
      <abstract>
        <p>Heterogeneous architectures nowadays are becoming very attractive in the embedded and mobile markets thanks to the possibility to exploit the best computational resource to optimize the performance per Watt figure of merit. Unfortunately, deciding the right resource to use and its operating frequency is a difficult problem that depends on the actual conditions in which the system is operating. This work aims at proposing a runtime controller, integrated in Linux Operating System (OS), for optimizing the power efficiency of a running application deciding the system configuration. Our experimental results over a set of applications from the Polybench suite on the Odroid XU3 board show that our controller is able to obtain a power efficiency of more than 90% of the one achievable via offline profiling.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>1. INTRODUCTION</title>
      <p>
        Heterogeneous System Architectures (HSAs) [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ] are
becoming nowadays an attractive solution for achieving an
optimal trade-off between performance and power/energy
consumption thanks to the availability of different kind of
resources, such as Central Processing Units (CPUs), possibly
integrating heterogeneous cores, Graphic Processing Units
(GPUs), Digital Signal Processors (DSPs) and other kinds
of HW accelerators. Examples are the Samsung Exynos 5
Octa [
        <xref ref-type="bibr" rid="ref15">15</xref>
        ], hosting an ARM big.LITTLE asymmetric
octacore CPU and an ARM Mali GPU, and the Xilinx Zynq [
        <xref ref-type="bibr" rid="ref17">17</xref>
        ],
integrating an ARM dual-core CPU and a reconfigurable
Field Programmable Gate Array (FPGA) unit.
      </p>
      <p>However this increase in heterogeneity comes at the cost of
new issues in programmability and runtime management of
these resources to achieve the pursued performance/power
consumption trade-off. In particular, various kind of
processing units imply different type of programming languages
and models thus introducing new implementation and
integration challenges. Nevertheless, this abundance of
resources has to be properly managed in the execution of the
workload, since each type of processing unit offers a different
level of performance/power efficiency to each single
application and part of it.</p>
      <p>
        In 2009, Khronos Group, including Apple, ARM, Samsung
and many other industrial partners, has defined OpenCL [
        <xref ref-type="bibr" rid="ref10">10</xref>
        ],
a cross-platform programming model designed around the
Single Instruction Multiple Thread (SIMT) computational
∗EWiLi’16, October 6th, 2016, Pittsburgh, USA. Copyright
retained by the authors.
paradigm, to exploit data parallelism on heterogeneous
accelerators. OpenCL, that has been implemented as an
extension of C/C++ languages, enables the programmability
and the usage of a large variety of processing units with
a single programming model. However, even if enabling
functional portability between different processing units, the
OpenCL API still requires the programmer to explicitly
select and tune the resources to be used for the execution of
the application. This still constitutes a limitation since each
application may have different optimal operating points on
different platforms, and, also on the same platform, the
optimal configuration may also vary on the basis of performance
requirements expressed by the user or on the overall
working conditions of the board (e.g., low-battery mode). Thus,
there is a quest in self-adaptation of OpenCL applications to
identify in each working scenario the optimal working point.
      </p>
      <p>In this paper, we present a runtime controller integrated
within OpenCL applications running on Linux enabling the
monitoring of system status and the automated adaptation
of the application itself 1. We also propose a novel policy
integrated within this controller allowing the application to
self-tuning by acting on the mapping and the Dynamic
Voltage and Frequency Scaling (DVFS) of the processing units
to optimize the performance/power consumption trade-off.
Experimental results presented in the paper show the
efficiency of the controller to quickly converge to the optimal
solution with less than 10% of error.</p>
      <p>The rest of the paper is organized as follows. Section 2
briefly discussed the related work. Then Section 3 introduces
the working scenario and states the addressed optimization
problem. The implementation of the proposed integrated
runtime controller and the decision policy are provided in
the Sections 4 and 5, respectively. Then, an experimental
evaluation of the approach is provided in the subsequent
Section 6, and, finally, Section 7 concludes the paper.
2.</p>
    </sec>
    <sec id="sec-2">
      <title>RELATED WORK</title>
      <p>
        Many OpenCL runtime supports have been defined by
vendors for their designed processing units; examples are
Intel for last generations of Pentium, Xeon and HD
Graphics units, NVidia and ARM for GPU devices, and Xilinx
for FPGAs. Moreover, other open source runtime supports,
such as [
        <xref ref-type="bibr" rid="ref3 ref8 ref9">3, 9, 8</xref>
        ], have been designed to overcome the
unavailability of commercial solutions especially for some type of
1The source code is publicly available at https://bitbucket.
org/necst/opencl-cgroups-library-release
      </p>
      <sec id="sec-2-1">
        <title>Cortex-A15 Core Cortex-A15 Core</title>
      </sec>
      <sec id="sec-2-2">
        <title>Cortex-A15 Core Cortex-A15 Core</title>
        <p>
          CPUs. Finally, OpenCL ICD loaders (e.g., [
          <xref ref-type="bibr" rid="ref16">16</xref>
          ]) have been
also implemented to dynamically discover and use at the
same time in the same application various runtime supports
in computing systems containing devices from different
vendors. When considering the mobile and embedded scenario,
the main limitation of these OpenCL solutions is the lack of
an advanced support to the widely-used ARM big.LITTLE
device. In fact, ARM does not provide any runtime for the
CPUs [
          <xref ref-type="bibr" rid="ref1">1</xref>
          ], while open source solutions handle such a
multicore as a single device and spawn threads indistinctly on all
the cores. Thus, the presence of two highly-different clusters
that could be used separately is neglected.
        </p>
        <p>
          Approaches for tuning and optimizing OpenCL
applications on HSAs have been recently investigated by a number
of works, such as [
          <xref ref-type="bibr" rid="ref11 ref13 ref14">13, 14, 11</xref>
          ]. Their main idea is to perform
a design space exploration to identify the best solution by
acting on the workgroup tuning and task mapping [
          <xref ref-type="bibr" rid="ref13">13</xref>
          ], or
workload partitioning among CPU and GPU [
          <xref ref-type="bibr" rid="ref14">14</xref>
          ], or by
using Domain Specific Languages and source-to-source
compilation of the customized OpenCL [
          <xref ref-type="bibr" rid="ref11">11</xref>
          ]. Since all these works
are based on design-time activities, they require a specific
design optimization for each considered architectural
platform and, nevertheless, do not feature runtime controllers
able to adapt to changes in the working conditions.
        </p>
        <p>
          Further works (e.g., [
          <xref ref-type="bibr" rid="ref12 ref2">2, 12</xref>
          ]) have proposed runtime
controllers to perform dynamic resource management; their goal
is to optimize the trade-off between performance and
power/energy consumption by adapting to the currently running
workload and related execution requirements specified by
the user. Unfortunately, none of such frameworks support
OpenCL applications.
        </p>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>PROBLEM DEFINITION</title>
      <p>This section presents the working scenario considered in
this paper, consisting of the target platform and the class of
executed applications. Finally, we formulate the
optimization problem addressed in the runtime controller we propose.
3.1</p>
    </sec>
    <sec id="sec-4">
      <title>Target Architecture and Applications</title>
      <p>
        In this work we consider an HSA as the Samsung Exynos
5422 [
        <xref ref-type="bibr" rid="ref15">15</xref>
        ]. As depicted in Figure 1, this chip features an
ARM A15 quad-core cluster (called big) and an ARM A7
one (called LITTLE ). The big cluster, suited for high
performance, can run at frequencies in the ranges from 200 to
2000 MHz, while the LITTLE one, suited for low power, at
frequencies in the 200-1300 MHz range. Moreover, the
architecture contains an ARM MALI GPU which frequency can
be configured in the 177-600 MHz range. DVFS can be used
to change the frequency at runtime with a per-cluster
granularity. Finally, the chip is provided with power monitoring
sensors. Both sensors and actuators are accessible though
standard interfaces provided by the loaded Linux OS. As
a final note, the solution is valid for any alternative HSAs
with a similar architecture running Linux OS.
      </p>
      <p>
        Regarding the target applications, a set of computational
kernels that is of great interest in the context of
embedded and mobile systems is the family of polyhedral
applications. Polyhedral applications comprise algorithms for video
processing, filters and algebraic transformations which are
at the basis of control, infotainment and augmented reality
software. These applications are characterized by a
computational intensive kernel continuously executed in a loop
on incoming data, such as the frames in a video to be
processed. In this work we considered the OpenCL
implementation of Polybench [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ] benchmark suite as a representative
set of polyhedral applications.
3.2
      </p>
    </sec>
    <sec id="sec-5">
      <title>Problem Formulation</title>
      <p>The addressed problem is to identify for a single given
application running in our system which is the best operating
point in terms of Performance per Watt. In particular, we
want to identify at runtime, without previous profiling
information, which is the best processing unit to use and the
related frequency level.</p>
      <p>In a more formal way, let us consider the controlled
application A running on the target architecture containing three
different processing units P = {BIG, LIT T LE, GP U }; each
unit is characterized by a set of possible frequencies (in
MHz):
fBIG = {200, 300, . . . , 1900, 2000}
fLIT T LE = {200, 300, . . . , 1200, 1300}
fGP U = {177, 266, 350, 420, 480, 543, 600}
The running application will be characterized for each
processing unit and supported frequency level, by two direct
metrics the throughput, T hr, and the overall power
consumption W , and a derived metric called the power efficiency
EF F , defined as following:</p>
      <p>EF Fp,f = T hrp,f , p ∈ P, f ∈ fp</p>
      <p>Wp,f
The goal tackled in this work is to find pˆ ∈ P and fˆ ∈ fpˆ
such that:</p>
      <p>EF Fpˆ,fˆ ≥ EF Fp,f , ∀p ∈ P ∧ ∀f ∈ fp</p>
      <p>In order to solve this optimization problem we need to
address a set of technical issues related to the monitoring
and controllability of the running application on the target
system; specifically, we need i) the support for OpenCL for
all the processors with the possibility to constrain and move
the execution at runtime; ii) to measure the throughput of
one iteration of the application and its power consumption;
iii) a smart algorithm to explore the power efficiency curves
and rapidly identify the best operating point.</p>
    </sec>
    <sec id="sec-6">
      <title>CONTROLLER IMPLEMENTATION</title>
      <p>The self-adaptive approach proposed in this paper has
been implemented in a specific controller C++ class directly
instantiated within the application source code. Figure 2
depicts the overall structure of the controller and its
integration within the system. Moreover, in order to enable the
actuation of the mapping on all OpenCL devices, the
application has to be implemented according to a specific
template. Listing 1 shows the defined application template and
how the controller is instantiated and used. All the details
of the controller in Figure 2 are discussed in the following
paragraphs.</p>
      <p>
        OpenCL runtime. To enable the support for all the
devices available in the Exynos chip, we have installed both
ARM OpenCL Mali SDK [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ] and Portable OpenCL library [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ],
and we have enabled the concurrent discovery of both the
platforms with the OpenCL ICD Loader provided by [
        <xref ref-type="bibr" rid="ref16">16</xref>
        ].
      </p>
      <p>OpenCL template. The defined application structure is
shown in Listing 1; it slightly enhances the standard OpenCL
template. In particular, the latter one requires the
programmer to select and configure the desired platform and device
to be used to execute the kernel. We extend this template
to allow the defined controller to dynamically select at each
iteration of the application which device to use.</p>
      <p>To enable this capability, in the OpenCL initialization
step, all platforms and devices are discovered and set up,
as shown in the piece of code reporting the cl_init()
function (Lines 8-19). In particular, the function iterates on
all platforms and sets up all devices2 and related OpenCL
objects, such as the context, the memory objects and the
program objects; all these objects are stored in arrays.</p>
      <p>Then, a specific variable, curr_device, is used to specify
the index of the current device to be used in the execution
of the kernel. Thus, the run_kernel() function uses the
execution context specified in such a variable to run the
kernel (Lines 21-38).</p>
      <p>
        Cgroups actuation. In order to enable cluster-level
mapping on the big.LITTLE CPU, we have exploited OS
facilities for task mapping to force the usage of a subset
of the cores. Linux OS provides two different mechanisms:
sched_set_affinity() and cgroups. sched_set_affinity()
cannot be used in OpenCL applications, since it needs to
know thread IDs; indeed, threads are generated within the
OpenCL runtime and their IDs are not visible externally.
Instead, cgroups offers the possibility to assign a set of cores,
and, more in general, further resources such as CPU quota
and memory amount, by specifying only the application
PID; all the threads spawned by that PID are then
managed automatically. Therefore, as in [
        <xref ref-type="bibr" rid="ref12">12</xref>
        ] we have integrated
cgroups in the proposed controller.
2For the sake of space, in the listing at Line 14 it is assumed
to have a single device per platform.
      </p>
      <p>Listing 1: Application template
1 //OpenCL o b j e c t s
2 c l p l a t f o r m i d p l a t f o r m i d s [MAX PLATFORMS ] ;
3 c l d e v i c e i d d e v i c e i d s [ MAX DEVICES ] ;
4 . . .
5 c l u i n t num platforms ;
6 c l u i n t num devices ;
7
8 void c l i n i t ( ) {
9 int i ;
10 // s e t u p OpenCL environment f o r a l l d e v i c e s
11 c l G e t P l a t f o r m I D s ( 0 , NULL, &amp;num platforms ) ;
12 c l G e t P l a t f o r m I D s ( num platforms , p l a t f o r m i d s ,</p>
      <p>NULL) ;
13 for ( i =0; i &lt;num platforms ; i ++){
14 c l G e t D e v i c e I D s ( p l a t f o r m i d s [ i ] ,</p>
      <p>CL DEVICE TYPE ALL , 1 , &amp;d e v i c e i d s [ i ] ,
&amp;num devices ) ;
// s e t u p o t h e r OpenCL o b j e c t s f o r d e v i c e [ i ]
// i . e . cont ex t , queues , memory , programs
. . .
15
16
17
18 }
19 }
20
21 void r u n k e r n e l ( int c u r r D e v i c e ) {
22 // l o a d a p p l i c a t i o n data
23 . . .
24 // s e t u p t h e workgroup s i z e s
25 l o c a l W o r k S i z e [ 0 ] = . . .
26 g l o b a l W o r k S i z e [ 0 ] = . . .
27 // w r i t e memory o b j e c t s
28 c l E n q u e u e W r i t e B u f f e r ( cmdQueue [ c u r r D e v i c e ] ,</p>
      <p>mem obj [ c u r r D e v i c e ] , CL TRUE, . . . ) ;
. . .
// Set t h e arguments o f t h e k e r n e l
c l S e t K e r n e l A r g ( c l K e r n e l [ c u r r D e v i c e ] , 0 ,
s i z e o f ( cl mem ) , ( void ∗)&amp;mem obj [
c u r r D e v i c e ] ) ;
. . .
// e x e c u t e k e r n e l
clEnqueueNDRangeKernel ( cmqQueue [ c u r r D e v i c e ] ,
c l K e r n e l [ c u r r D e v i c e ] , 2 , NULL,
globalWorkSize , l o c a l W o r k S i z e , 0 , NULL,</p>
      <p>NULL) ;
c l F i n i s h ( cmdQueue [ c u r r D e v i c e ] ) ;
// read memory o b j e c t s
clEnqueueReadBuffer ( cmdQueue [ c u r r D e v i c e ] ,</p>
      <p>mem obj2 [ c u r r D e v i c e ] , CL TRUE, . . . ) ;</p>
      <p>
        Performance monitor. Instruction per Cycle (IPC) or
other classical low-level metrics computed by the OS do not
represent a useful information to the final user to perceive
the actual progress of an application. As an example, IPC
is not able to show if the video application in execution is
providing a minimum Quality of Service (QoS) in terms of
frame/s. Therefore, to enable run-time performance
monitoring, we have integrated in the controller the Heartbeat
mechanism [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ], a state-of-the-art solution to acquire
high15
]
s
[
e
m
10
i
T
n
o
i
tu5
c
e
x
E
0
      </p>
      <p>Target
BIG
LGIPTUTLE
2000
1000
Frequency [MHz]
1500</p>
      <p>2000
(a) Power consumption
500</p>
      <p>1000
Frequency [MHz]</p>
      <p>1500
(b) Throughput
0000tt//[(])rrfsaecea1*noPmWW....000010102864 500 SYFrReq21uK0e0n0Ecyff[iMciHenz]1c5y00 TaLBGrIIgPTGeUTt2L0E00 100tt//[()frr]saecea1*onPmWW...075050 500 MFrVeqT1u0e0En0cfyfic[MieHnzc]y1500
(a) LITTLE cluster is the most efficient. (b) big cluster is the most efficient.
level information from the application.</p>
      <p>The basic idea of the Heartbeat mechanism is to measure
the throughput of periodic application by i) measuring the
duration of the execution of each single loop and ii)
computing the ratio between the amount of processed data and such
a duration. Therefore, the controller initialized all necessary
data structures (timers and accumulators) during the
initialization (Line 47). Then, at the end of the loop (Line 52), the
invoked send_heartbeat() function collects the new
timestamp and the size of the processed data (directly specified by
the programmer) and based on such information computes
the current throughput.</p>
      <p>Power monitor. The considered Exynos chip integrated
various sensors to monitor the status of the hardware
platform, such as power consumption and temperature of the
various clusters. Such sensors are exposed to the
programmer through the virtual file systems of Linux OS.</p>
      <p>In order to trace the power consumption of the big and
LITTLE clusters and of the GPU, we have implemented
an external monitor acting as a separate process daemon
and periodically (i.e. every 50ms) collecting power values
from the interface provided by the sys virtual file system of
Linux OS. The external monitor can be triggered via a
message over a named pipe (a Linux interprocess communication
mechanism) and instructed to collect power information
aggregating them over a period of time. Another message on
the same pipe can stop the acquisition returning the average
power consumption over the considered period.</p>
      <p>Controller. The controller has been implemented in a
single class encapsulating all the discussed mechanism and
the decision policy. It exposes the following methods:
• init(), invoked at Line 47, sets up the environment
by initializing the data structures of the Heartbeat,
cgroups and of the decision policy; moreover the
function connects to the external power monitor by means
of the named pipe.
• get_curr_config(), invoked at Line 50, analyzes all
collected metrics (power and throughput) and executes
the decision policy to identify on which device to run
the application kernel during the current loop
iteration; moreover, it actuates on the cgroup library.
• send_heartbeat(), invoked at Line 52, processes
current Heartbeat at the end of the main loop to compute
the throughput.
• destroy(), invoked at Line 55, deallocates all data</p>
      <p>structures.
5.</p>
    </sec>
    <sec id="sec-7">
      <title>CONTROLLER POLICY</title>
      <p>This section describes the controller policy that allows to
solve the problem tackled in this paper, defined in Section 3.
We will first discuss a preliminary profiling phase carried
out on the target applications in order to understand which
control strategy should to be adopted, and, then, we will
describe the policy itself.
5.1</p>
    </sec>
    <sec id="sec-8">
      <title>Preliminary Analysis</title>
      <p>In a preliminary phase, we carried out an experimental
evaluation of the behavior of such applications on the
considered heterogeneous platform. We measured the execution
time, power consumption and power efficiency of each
considered application on each processing unit (big, LITTLE
and GPU) at each available frequency level.</p>
      <p>During this analysis, we noticed that the power profile is
almost the same for all the considered applications
presenting a quadratic relation with respect to the frequency, as
shown for GEMM application in Figure 3(a). In the same
way the execution time of the applications follows the same
trend for all the benchmarks where an increase in the
frequency level turns into an improvement of the execution
time up until a certain value, as shown in Figure 3(b) for
the GEMM application.</p>
      <p>Combining these two curves we found how the power
efficiency of the benchmarks varies (Figure 4). Also in this case,</p>
      <p>Listing 2: Selection of next configuration
1 C o n f i g u r a t i o n C o n t r o l l e r : : g e t C o n f i g u r a t i o n ( ) {
2 for ( auto d : d e v i c e s L i s t ) {
3 i f ( ! d−&gt;hasConverged ( ) )
4 return d−&gt;g e t N e x t C o n f i g u r a t i o n ( ) ;
5 }
6
7
s t d : : v e c t o r &lt;s t d : : p a i r &lt;f l o a t , int&gt;&gt;</p>
      <p>b e s t E f f i c i e n c y ;
for ( int i =0; i &lt;d e v i c e s L i s t . s i z e ( ) ; i ++){
f l o a t xMax , yMax ;
xMax = d e v i c e s L i s t [ i ]−&gt;maxEstimation ;
yMax = d e v i c e s L i s t [ i ]−&gt;</p>
      <p>getEstimationAtFrequency (xMax) ;
b e s t E f f i c i e n c y . push back ( s t d : : p a i r &lt;f l o a t ,
int &gt;(yMax , i ) ) ;
}
s t d : : s o r t ( b e s t E f f i c i e n c y . b e g i n ( ) ,</p>
      <p>b e s t E f f i c i e n c y . end ( ) ) ;
s t d : : p a i r &lt;f l o a t , int&gt; b e s t D e v i c e =</p>
      <p>b e s t E f f i c i e n c y [ b e s t E f f i c i e n c y . s i z e ( ) −1];
return d e v i c e s L i s t [ b e s t D e v i c e . second]−&gt;</p>
      <p>g e t N e x t C o n f i g u r a t i o n ( ) ;</p>
      <p>Listing 3: Code of the get curr config() API
1 unsigned int OpenCl Contr oll er : : g e t c u r r c o n f i g
( ) {
2 this−&gt;c u r r e n t C o n f i g u r a t i o n = g e t C o n f i g u r a t i o n
( ) ;
// Set f r e q u e n c y using e i t h e r cpufreq −s e t f o r</p>
      <p>CPU or using f i l e s y s t e m f o r GPU
// For CPU d e v i c e s a l s o c a l l s t h e proper</p>
      <p>cgroups f u n c t i o n s
this−&gt;c u r r e n t C o n f i g u r a t i o n . d−&gt;
s e t C o n f i g u r a t i o n ( this−&gt;
c u r r e n t C o n f i g u r a t i o n . f r e q u e n c y ) ;
// Return t h e d e v i c e i d t o use in t h e</p>
      <p>a p p l i c a t i o n
return this−&gt;c u r r e n t C o n f i g u r a t i o n . d e v i c e −&gt;
o p e n C l d e v i c e I d ;
the trend of the curves is similar for all the benchmarks. An
interesting aspect is that, depending on the actual values of
the execution time and power consumption, three different
situations can be found where either the big, the LITTLE,
or the GPU outperforms the other units (as shown in
Figure 4). Finally, all these curves present a maximum which is
located around the middle of the frequency range for all
architectures. The goal of the policy is then to find at runtime
this maximum without any previous profiling information.
5.2</p>
    </sec>
    <sec id="sec-9">
      <title>Policy Definition</title>
      <p>The controller policy is triggered each time the user code
requests a configuration to use (i.e. at the beginning of each
iteration of the application loop).</p>
      <p>Considering the structure of the power efficiency curves,
if we fix a device, we can use a ternary search algorithm to
solve our optimization problem. This algorithm can be used
to find a maximum of a mathematical continuous function
F (with a single maximum point), and, actually, the curves
characterizing the computational efficiency of the considered
applications (refer to Figure 4) present such a shape.</p>
      <p>The algorithm needs to find three initial points a, b, c | a &lt;
b &lt; c ∧ F (b) ≥ F (a) ∧ F (b) ≥ F (c); to do this we execute
the first three iterations of the application loop on a given
device at its minimum, maximum and middle frequencies.</p>
      <p>Then, at each iteration we acquire a new estimation of
the power efficiency of the application at the last operating
frequency for a given device. The new a, b, c points will
be chosen by sorting the estimation and picking the two
frequencies next to the current maximum efficiency found.
At this point one operating frequency is chosen in the ranges
(a, b) or (b, c), priority is given to the first interval; if no
frequency exists in those two ranges, it means that the three
points a, b, c are contiguous to each others, and b is the actual
maximum we are looking for.</p>
      <p>The ternary search algorithm has been implemented in
a function called getNextConfiguration() that is used to
pick for a given device the frequency to use. This function
is then used in the getConfiguration() routine (Listing 2)
that decides which device to use to execute the application
kernel alongside its frequency. In the getConfiguration()
function, the controller checks for all the available devices
(devicesList) whether there exists an estimation for the
best efficiency. If such estimation does not exist the
controller uses the ternary search on the device to find the
maximum as explained before (Line 2). When all the estimations
are available, the algorithm selects the device with the best
power efficiency (Lines 9-14) and asks that device for the
next configuration (Line 16).</p>
      <p>The whole configuration decision process is invoked when
the application code calls the get_curr_config() (Line 50
in Listing 1). The code of this function, which bridges the
application code with the controller policy is represented in
Listing 3. The API calls the get_curr_config() function
and then invokes the function to set the desired
configuration: only the frequency for the GPU, both frequency and
cgroups configuration for the CPU. Finally, it returns to the
user the device id to use when invoking the OpenCL kernel,
as explained in the application template section.</p>
    </sec>
    <sec id="sec-10">
      <title>6. EXPERIMENTAL RESULTS</title>
      <p>
        This section illustrates the results of our controller.
Experiments have been conducted on an Odroid XU3 board [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ]
hosting an Exynos 5420 chip. We used a set of 7 applications
from the Polyhedral benchmark suite [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ], namely 3DCONV,
3MM, ATAX, BICG, GEMM, MVT, SYR2K. All these
applications have been extended with the inclusion of the
controller proposed in this work.
      </p>
      <p>In order to test the performance of our controller, we
modified each application to execute the computational kernel for
a fixed number of 50 iterations to see if the controller was
able to converge to the most power efficient solution
possible. The best configuration for power efficiency has been
identified with an offline profiling phase which performed an
exhaustive exploration of all the possible configurations.</p>
      <p>Figure 5 illustrates the comparison among the profiled
power efficiency and the one found at runtime by our
controller. Note that the power measures are subject to a
little variability due to different working condition (i.e.
background system processes, out of our control). As the
figure shows, the runtime power efficiency adheres for all the
benchmarks to the best power efficiency found during the
profiling phase. In particular, for the first five benchmarks
(from 3DCONV to GEMM) we have that the GPU has the
best power efficiency and the controller is able to converge
and use the same device at runtime. In the last two
benchmarks we have that MVT has the best efficiency on the BIG</p>
      <p>SYR2K</p>
      <p>BICG</p>
      <p>Polybench
processors while SYR2K3 is optimal on the LITTLE ones;
nonetheless the controller found also in these situations a
solution near to the optimum. More in details the controller
reaches a power efficiency which is at least 90% of the best
value found in profiling. The reason behind the 10% error
is due to runtime measurements variability. This causes the
policy to converge to a frequency that is near to the optimal
one; e.g. GEMM converges to 350 instead of 480 MHz.</p>
      <p>In all these experiments the time needed to execute our
policy is included in the execution time of the kernel
iteration and concurs in defining the power efficiency of the
application. Since all the controller functionalities are invoked
also when the policy has converged, we can state that the
overhead introduced by our solution is negligible.</p>
      <p>Concerning the convergence time we have that the
controller converges by testing less than 20 different
configurations; this represents about 50% of the overall design space
(that is composed of 38 configurations) as shows in Table 1.
At the opposite, the offline profiling strategy has always to
explore all the 38 configurations. Furthermore, we have to
keep in mind that the offline profiling requires that the
working conditions are exactly the same at the moment the
application is in execution. At the opposite, runtime adaptation
allows to converge also when the working conditions change.</p>
    </sec>
    <sec id="sec-11">
      <title>7. CONCLUSIONS AND FUTURE WORK</title>
      <p>This paper has presented a novel runtime controller
integrated within OpenCL applications able to enable its
automated adaptation. The controller features a novel policy
allowing the application to adapt by acting on the mapping
and the DVFS of the processing units to optimize the
per3
All the SYR2K power efficiency values have been multiplied
by 100 for sake of clarity.
formance/power consumption trade-off. Experimental
results have demonstrated the efficiency of the controller to
quickly converge to the optimal solution with less than 10%
of error. Future work deals with the adoption of further
actuation knobs for resource usage, such as quota assignment
and finer-grained mapping, the improvement of the proposed
policy and controller to support the concurrent execution of
several applications.</p>
    </sec>
    <sec id="sec-12">
      <title>Acknowledgments</title>
      <p>This work has been partially funded by the EU FP7 SAVE
project (#610996-SAVE).</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          <source>[1] ARM. Exynos 5 Octa</source>
          . https://developer.arm.com/ products/software/mali-sdks/mali-opencl-sdk.
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>C.</given-names>
            <surname>Bolchini</surname>
          </string-name>
          ,
          <string-name>
            <given-names>G. C.</given-names>
            <surname>Durelli</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Miele</surname>
          </string-name>
          , G. Pallotta, and
          <string-name>
            <given-names>M. D.</given-names>
            <surname>Santambrogio</surname>
          </string-name>
          .
          <article-title>An orchestrated approach to efficiently manage resources in heterogeneous system architectures</article-title>
          .
          <source>In Intl. Conf. on Computer Design</source>
          , pages
          <fpage>200</fpage>
          -
          <lpage>207</lpage>
          ,
          <year>2015</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>R.</given-names>
            <surname>Brochard</surname>
          </string-name>
          and
          <string-name>
            <given-names>N.</given-names>
            <surname>Nikolaev</surname>
          </string-name>
          . FreeOCL. https://forge.imag.fr/projects/ocl-icd.
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>S.</given-names>
            <surname>Grauer-Gray</surname>
          </string-name>
          ,
          <string-name>
            <given-names>L.</given-names>
            <surname>Xu</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R.</given-names>
            <surname>Searles</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Ayalasomayajula</surname>
          </string-name>
          , and
          <string-name>
            <given-names>J.</given-names>
            <surname>Cavazos</surname>
          </string-name>
          .
          <article-title>Auto-tuning a high-level language targeted to GPU codes</article-title>
          .
          <source>In Proc. of Innovative Parallel Computing</source>
          , pages
          <fpage>1</fpage>
          -
          <lpage>10</lpage>
          ,
          <year>2012</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          <article-title>[5] Hardkernel co</article-title>
          .
          <source>Odroid XU3</source>
          . http://www.hardkernel.com/ main/products/prdt info.php?g code=
          <fpage>G140448267127</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>H.</given-names>
            <surname>Hoffmann</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Eastep</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M. D.</given-names>
            <surname>Santambrogio</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J. E.</given-names>
            <surname>Miller</surname>
          </string-name>
          ,
          <article-title>and</article-title>
          <string-name>
            <given-names>A.</given-names>
            <surname>Agarwal</surname>
          </string-name>
          .
          <article-title>Application heartbeats for software performance and health</article-title>
          .
          <source>ACM Sigplan Notices</source>
          ,
          <volume>45</volume>
          (
          <issue>5</issue>
          ):
          <fpage>347</fpage>
          -
          <lpage>348</lpage>
          ,
          <year>2010</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>HSA</given-names>
            <surname>Foundation</surname>
          </string-name>
          . http://www.hsafoundation.com/,
          <year>2015</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <given-names>P.</given-names>
            <surname>Ja</surname>
          </string-name>
          <article-title>¨a¨skela¨inen,</article-title>
          <string-name>
            <surname>C. S. de La Lama</surname>
            ,
            <given-names>E.</given-names>
          </string-name>
          <string-name>
            <surname>Schnetter</surname>
            ,
            <given-names>K.</given-names>
          </string-name>
          <string-name>
            <surname>Raiskila</surname>
            ,
            <given-names>J.</given-names>
          </string-name>
          <string-name>
            <surname>Takala</surname>
            , and
            <given-names>H.</given-names>
          </string-name>
          <string-name>
            <surname>Berg</surname>
          </string-name>
          .
          <article-title>pocl: A Performance-Portable OpenCL Implementation</article-title>
          .
          <source>International Journal of Parallel Programming</source>
          ,
          <volume>43</volume>
          (
          <issue>5</issue>
          ):
          <fpage>752</fpage>
          -
          <lpage>785</lpage>
          ,
          <year>2015</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [9]
          <string-name>
            <given-names>G.</given-names>
            <surname>Jo</surname>
          </string-name>
          ,
          <string-name>
            <given-names>W. J.</given-names>
            <surname>Jeon</surname>
          </string-name>
          ,
          <string-name>
            <given-names>W.</given-names>
            <surname>Jung</surname>
          </string-name>
          , G. Taft, and
          <string-name>
            <given-names>J.</given-names>
            <surname>Lee</surname>
          </string-name>
          .
          <article-title>OpenCL Framework for ARM Processors with NEON Support</article-title>
          .
          <source>In Proc. of Workshop on Programming Models for SIMD/Vector Processing</source>
          ,
          <year>2014</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          [10] Khronos Group. OpenCL. https://www.khronos.org/opencl/,
          <year>2016</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          [11]
          <string-name>
            <given-names>T.</given-names>
            <surname>Lepley</surname>
          </string-name>
          ,
          <string-name>
            <given-names>P.</given-names>
            <surname>Paulin</surname>
          </string-name>
          , and
          <string-name>
            <given-names>E.</given-names>
            <surname>Flamand</surname>
          </string-name>
          .
          <article-title>A novel compilation approach for image processing graphs on a many-core platform with explicitly managed memory</article-title>
          .
          <source>In Proc. Conf. on Compilers, Architecture and Synthesis for Embedded Systems (CASES)</source>
          , pages
          <fpage>1</fpage>
          -
          <lpage>10</lpage>
          ,
          <year>2013</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          [12]
          <string-name>
            <given-names>S.</given-names>
            <surname>Libutti</surname>
          </string-name>
          , G. Massari, and
          <string-name>
            <given-names>W.</given-names>
            <surname>Fornaciari</surname>
          </string-name>
          .
          <article-title>Co-scheduling tasks on multi-core heterogeneous systems: An energy-aware perspective</article-title>
          .
          <source>IET Computers Digital Techniques</source>
          ,
          <volume>10</volume>
          (
          <issue>2</issue>
          ):
          <fpage>77</fpage>
          -
          <lpage>84</lpage>
          ,
          <year>2016</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref13">
        <mixed-citation>
          [13]
          <string-name>
            <given-names>E.</given-names>
            <surname>Paone</surname>
          </string-name>
          ,
          <string-name>
            <given-names>F.</given-names>
            <surname>Robino</surname>
          </string-name>
          ,
          <string-name>
            <given-names>G.</given-names>
            <surname>Palermo</surname>
          </string-name>
          ,
          <string-name>
            <given-names>V.</given-names>
            <surname>Zaccaria</surname>
          </string-name>
          ,
          <string-name>
            <surname>I. Sander</surname>
          </string-name>
          , and
          <string-name>
            <given-names>C.</given-names>
            <surname>Silvano</surname>
          </string-name>
          .
          <article-title>Customization of OpenCL Applications for Efficient Task Mapping Under Heterogeneous Platform Constraints</article-title>
          .
          <source>In Proc. Conf. on Design, Automation &amp; Test in Europe (DATE)</source>
          , pages
          <fpage>736</fpage>
          -
          <lpage>741</lpage>
          ,
          <year>2015</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref14">
        <mixed-citation>
          [14]
          <string-name>
            <given-names>A.</given-names>
            <surname>Prakash</surname>
          </string-name>
          ,
          <string-name>
            <given-names>S.</given-names>
            <surname>Wang</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A. E.</given-names>
            <surname>Irimiea</surname>
          </string-name>
          , and
          <string-name>
            <given-names>T.</given-names>
            <surname>Mitra</surname>
          </string-name>
          .
          <article-title>Energy-efficient execution of data-parallel applications on heterogeneous mobile platforms</article-title>
          .
          <source>In Proc. Int. Conf. on Computer Design (ICCD)</source>
          , pages
          <fpage>208</fpage>
          -
          <lpage>215</lpage>
          ,
          <year>2015</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref15">
        <mixed-citation>
          [15]
          <string-name>
            <surname>Samsung</surname>
          </string-name>
          . Exynos 5 Octa. http://www.samsung.com/global/business/semiconductor/ product/application/detail?productId=
          <volume>7978</volume>
          &amp;iaId=
          <fpage>2341</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref16">
        <mixed-citation>
          [16]
          <string-name>
            <given-names>B.</given-names>
            <surname>Videau</surname>
          </string-name>
          and
          <string-name>
            <given-names>V.</given-names>
            <surname>Danjean. OpenCL ICD</surname>
          </string-name>
          <article-title>Loader</article-title>
          . https://forge.imag.fr/projects/ocl-icd.
        </mixed-citation>
      </ref>
      <ref id="ref17">
        <mixed-citation>
          [17]
          <string-name>
            <surname>Xilinx</surname>
          </string-name>
          . Zynq-700
          <source>All Programmable SoC</source>
          . http://www. xilinx.com/products/silicon-devices/soc/zynq-7000.html.
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>