<!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>Automatic Pruning of Autotuning Parameter Space for OpenCL Applications</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Ahmet Erdem</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Gianluca Palermo</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Cristina Silvano</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Department of Electronics</institution>
          ,
          <addr-line>Information and Bioengineering Politecnico di Milano</addr-line>
        </aff>
      </contrib-group>
      <pub-date>
        <year>2016</year>
      </pub-date>
      <abstract>
        <p>OpenCL standard reaches more wider audience due to increasing the number of devices supporting it. This situation puts developers who want performance on large range of platforms in a di cult position. To solve this problem, autotuning frameworks are deployed. But the problem of design exploration space is seriously large because of OpenCL parameters. In this work, we introduce an approach which uses constraint programming to prune the design space before employing intelligent or exhaustive techniques to explore.</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>Introduction</title>
      <p>The recent advances in computer architecture made heterogeneous computer
systems available to not only data centers and supercomputers but also to
commercial personal computers. Especially, with the advent of AMD APUs and Intel
CPUs which include integrated GPUs, the heterogeneity of modern machines has
increased. Furthermore, enabling discrete GPUs for general purpose computing
has added another type of computation device to the system. While each
system has provided di erent granularity of parallelism which needs to be properly
exploited, the communication between various computation units must also be
handled according to the needs of application as well.</p>
      <p>
        Open Computing Language (OpenCL) which is maintained by Khronos
consortium [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] is an open standard for developing parallel applications on
heterogeneous systems by abstracting the underlying compute machine. OpenCL adopts
data parallel approach by describing the parallel computations as a group of
work-items, called work-groups. This hierarchical parallelism has been realized
by launching kernel functions with a number of work-groups including a set of
work-items. Kernel function describes how each work-item de nes the operations
that is to be carried out on a single data. Therefore the collection of work-items
under all work-groups together expresses the data parallelism for an application.
Although OpenCL de nes the execution of the application that is portable
between the devices conforming the OpenCL standard, it does not guarantee the
performance to be optimal. Especially, moving applications to di erent types of
architectures like from CPU to GPU may result signi cant loss of performance,
this is the reason why OpenCL is not considered performance portable. On
heterogeneous performance portability represents a challenging research issue.
      </p>
      <p>One naive solution to performance portability is to develop separate
kernel functions for each device the application is supposed to run. This solution
makes development of application dramatically complicated when the system
is heterogeneous, because of explicit management of multiple command queues
and contexts in the presence of multiple vendors on the system.</p>
      <p>
        Performance portability problem of OpenCL applications has been approached
either by tuning of signi cant parameters described as in [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ] or by introducing
Domain-speci c languages to annotate kernel and OpenCL code generation [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ].
      </p>
      <p>
        From another perspective, it is not always possible to access these parameters
to tune if they are not being exposed by developers. The work of [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ] tackles this
problem by coalescing work-groups using compiler transforms while preserving
the correctness of application.
      </p>
      <p>
        In this work, we introduce an automation of extraction of OpenCL platform
parameters and usage of the information that is gathered to aid the tuning
process described in [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ].
2
      </p>
    </sec>
    <sec id="sec-2">
      <title>Proposed Methodology</title>
      <p>The procedure of autotuning of an OpenCL application in order to get optimum
performance without concerns of underlying architecture of the platform requires
a set of parameters that de ne characteristics of the machine. In the case of
OpenCL, these platform speci c parameters are stated by the OpenCL standard
itself. Furthermore, it is possible to gather them using the querying framework
which is provided by the OpenCL standard. With these information gathered,
it is possible to determine the size of the exploration space and then using
intelligent methods for searching optimum design space.</p>
      <p>Outside of platform parameters, there might be also application speci c
parameters that can be tightly related to platforms capabilities. An example of
this situation is well-known tiled version of the matrix multiplication. Size of
the tiles are considered as an application parameters and due to nature of the
algorithm there is a sharing of information between work-items on the elements
of the same tile. Due to OpenCL architecture design, this kind of communication
requires local memory to be used. Therefore tile size is directly related to local
memory usage which is a limited resource of the platforms.</p>
      <p>There are some problems regarding with this approach; design space is larger
for even simple applications, for instance, Nvidia Fermi architecture allows up
to 1024 work-items for rst and second dimensions and 64 work-item for the
third dimension, resulting a 226 di erent con gurations already. Most of the
con gurations are not feasible in the sense that the kernel may not even launch
or may fail during execution, due to illogical con gurations parameters. Moreover
these failed attempts of kernel launches do not provide any information about
the sample that has been taken from design space. Hence e ort and time are
wasted on these ill-advised con gurations.</p>
      <p>
        In order to address this issue, the work in [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ] presented a design space
exploration ow that includes constraint programming to prune the design space
and eliminate infeasible solutions. This helps reduction of space while only
using samples which makes sense within the scope of OpenCL standard. Fig. 1
demonstrates this idea simply.
      </p>
      <p>
        Our work aims to improve the pruning phase by automating the extraction
of platform speci cations, to nd constraints that are valid for all platforms,
so that application programmer only needs to insert constraints related to
application itself. For constraint programming, we used MiniZinc [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ] constraint
modelling language as it is used in [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ]. Using OpenCL querying framework, for
each OpenCL compliant device available on the machine we generated MiniZinc
data les which include the following information about the device:
{ maximum work-group size for each three dimensions.
{ maximum number of total work-group a kernel launch may contain.
{ number of compute units on the device.
{ local memory size of the device.
      </p>
      <p>
        In addition to these, a set of constraints that can be deduced from standard
[
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] has been used to generate platform constraint model, thus together with
application constraints provided by programmer can prune the design space
e ectively. The generated platform constraints are as follows:
{ total number of work-groups launched must be less than or equal to
maximum work-group size.
      </p>
      <p>workgroupx
workgroupy
workgroupz &lt;= max total wg
(1)
{ each global work-item dimensions must be multiple of corresponding
workgroup dimension size.
{ total number of work-groups should be equal or greater than number of
compute units. Otherwise there will be idle compute units.</p>
      <p>globalx=workgroupx + globaly=workgroupy+
globalz=workgroupz &gt;= num compute units
globalx%workgroupx == 0
globaly%workgroupy == 0
globalz%workgroupz == 0
(2)
(3)
3</p>
    </sec>
    <sec id="sec-3">
      <title>Use Case Example</title>
      <p>In order to test our approach, we used a machine with Intel i7-2630QM which is a
quad-core CPU at 2.0Ghz and Nvidia GeForce GT 550M which is a mobile GPU
with 96 CUDA cores. For testing purposes, tiled version of matrix multiplication
is used and tile size is given as a application parameter and it is been set the
interval of [1 : 256]. Furthermore, we have taken into account that application
global work size and set it to 4096x4096 matrix for this experiment.</p>
      <p>
        Given this setting, the design space for CPU is 234 and for GPU it is 247. But
after the pruning of infeasible con gurations, there are only 367 con gurations
left for CPU and 421 con gurations for GPU. Considering the result of
pruning for the use case given, it is even possible to search exhaustively all possible
con gurations left to nd the optimal one. However the given example is too
elementary to deduce this conclusion for broader range of applications. Hence, the
next step is to introduce tools to at least one of the industry-proven benchmarks
like OpenDwarfs [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ], Rodinia [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ] and shoc [
        <xref ref-type="bibr" rid="ref8">8</xref>
        ]. Moreover, testing with more
diverse and recent hardware platforms is necessary to prove generality of the work.
Additionally, besides platform speci c and application speci c parameters, there
is a possibility of adding compiler-supported parameters like coalescing factor
that has been explored in [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ].
      </p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <given-names>G.</given-names>
            <surname>Agosta</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Barenghi</surname>
          </string-name>
          , G. Pelosi, and
          <string-name>
            <given-names>M.</given-names>
            <surname>Scandale</surname>
          </string-name>
          .
          <article-title>Towards transparently tackling functionality and performance issues across di erent opencl platforms</article-title>
          .
          <source>In In proceedings of the Second International Symposium on Computing and Networking Across Practical Development and Theoretical Research (CANDAR</source>
          <year>2014</year>
          ), Dec.
          <year>2014</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <given-names>N.</given-names>
            <surname>Chaimov</surname>
          </string-name>
          ,
          <string-name>
            <given-names>B.</given-names>
            <surname>Norris</surname>
          </string-name>
          ,
          <article-title>and</article-title>
          <string-name>
            <given-names>A.</given-names>
            <surname>Malony</surname>
          </string-name>
          .
          <article-title>Toward multi-target autotuning for accelerators</article-title>
          .
          <source>In Parallel and Distributed Systems (ICPADS)</source>
          ,
          <year>2014</year>
          , pages
          <fpage>534</fpage>
          {
          <fpage>541</fpage>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <given-names>Khronos</given-names>
            <surname>Group</surname>
          </string-name>
          .
          <article-title>The open standard for parallel programming of heterogeneous systems</article-title>
          .
          <source>[Online; Accessed: Nov</source>
          .
          <year>2015</year>
          ].
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4. MiniZinc.
          <article-title>Medium-level constraint modelling language minizinc</article-title>
          .
          <source>[Online; Accessed: Dec</source>
          .
          <year>2015</year>
          ].
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5. OpenDwarfs. Opendwarfs. [Online; Accessed: Jan.
          <year>2016</year>
          ].
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <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 e cient task mapping under heterogeneous platform constraints</article-title>
          .
          <source>In Proceedings of the 2015 Design, Automation &amp; Test in Europe Conference &amp; Exhibition</source>
          , pages
          <volume>736</volume>
          {
          <fpage>741</fpage>
          . EDA Consortium,
          <year>2015</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <string-name>
            <surname>Rodinia</surname>
          </string-name>
          .
          <article-title>Rodinia:accelerating compute-intensive applications with accelerators</article-title>
          .
          <source>[Online; Accessed: Jan</source>
          .
          <year>2016</year>
          ].
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          8.
          <string-name>
            <surname>Shoc</surname>
          </string-name>
          .
          <article-title>Scalable heterogeneous computing (shoc)</article-title>
          .
          <source>[Online; Accessed: Jan</source>
          .
          <year>2016</year>
          ].
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>