Grigori Fursin edited this page Aug 30, 2018 · 7 revisions

[ Home ]

CK is written in Python for productivity reasons since it is very fast and simple to prototype new ideas and develop new functionality while using dictionaries, JSON, and numerous third-party packages.

However, we also need to access CK from programs, libraries and tools written in other languages to be able to expose or even modify various features, optimization choices and decisions, run-time parameters and statistics to outside world in a unified CK way via JSON API (for example, to create interactive compilers as described in this paper.

Eventually, we have developed a small OpenME library as a light-weight event-based plugin framework, and xOpenME which is a striped version of OpenME without plugins. It is available at GitHub and can call CK from programs written in C,C++,Fortran,Java and PHP. Any help to improve it is very appreciated!

Table of Contents

Obtaining OpenME via CK

It is possible to install OpenME automatically via CK. The related CK packages are available in the ck-autotuning repository:

 $ ck pull repo:ck-autotuning
 $ ck find package:lib-openme
 $ ck find package:lib-rtl-xopenme

You can install them simply as follows

 $ ck install package:lib-rtl-xopenme

You can even install it for Android target via

 $ ck install package:lib-rtl-xopenme --target_os=android21-arm64
You may need to change android21-arm64 to the OS and arch of your mobile device (get a list of available options via ck list os:android*).

Using xOpenME in C,C++ and Fortran

Most of the benchmarks in the ctuning-programs repository are instrumented using xOpenME library, so you may see them here and use them as examples! Just search for openme.h or xopenme.h keywords.

Using OpenME in PHP

Accessing CK from PHP allows one to easily integrate CK modules with Microsoft IIS, Apache2, Mediawiki, Drupal and other systems. For example, our public CK live repository at is accessed like that!

You can find PHP openme interface files in the official CK distribution in the $CK_ROOT/ck/repo/module/web/php directory. There you will see two files:

  • openme.php - OpenME for PHP
  • ck_web.php - library to glew Internet Server and OpenME.
You will also see a directory server-side. You can simply put those files to any web directory of your Internet Server, update local environment to set $CK_ROOT and open this page ending with web.php in any browser.

Using OpenME to open up compilers

Note, that OpenME can be used as a standalone event-based plugin framework to access internal state of tools such as GCC and LLVM compilers via plugins.

We already successfully used such approach in the past to add plugin-based framework to mainline GCC and make it interactive (see article for more details). We have a similar prototype for Open64 and LLVM here.

We also used such approach to open up real applications for plugin-based autotuning (see article for more details)

We would like to extend this approach - any help is appreciated!

Using OpenME in Java and Android

We also provided a stripped Java version of OpenME interface to be able to use CK in Android-based mobile devices via CK web services.

It is also available in ck-autotuning repository:

 $ ck find package:lib-openme-java
 $ ck install package:lib-openme-java --target_os=android19-arm

We currently use Java version of OpenME interface for compiler/program crowd-tuning and bug detection using Android-based commodity mobile phones and tables using our universal Android app to crowdsource experiments (see the following articles 1, 2 and 3 for more details).

The sources of this app are now available at GitHub here.

We also have this silly Android app to automatically generate valid titles of possible research papers (reflecting our annoyance with the current publication model where amount of publications is often more important than the novelty, availability and reproducibility of the results). The source code is also available here and we mainly use to demonstrates how to use our Java-based OpenME interface to connect to CK JSON-based web service to generate and return such titles to your mobile device.

Here is an example of how to use OpenME in your Android Java apps:

 import org.ctuning.openme.openme;
 publishProgress("\n\nSending request to ...\n");

 JSONObject ii = new JSONObject();
 try {
  ii.put("remote_server_url", curl);
  ii.put("action", "generate");
  ii.put("module_uoa", "dissemination.publication");
  ii.put("data_uoa", "template-joke");
  ii.put("out", "json");
 } catch (JSONException e) {
   publishProgress("\nError with JSONObject ...\n\n");
   return null;

 JSONObject r = null;
 try {
  r = openme.remote_access(ii);
 } catch (JSONException e) {
    publishProgress("\nError calling OpenME interface (" + e.getMessage() + ") ...\n\n");
    return null;

 Integer rr = 0;
 if (!r.has("return")) {
  publishProgress("\nError obtaining key 'return' from OpenME output ...\n\n");
  return null;
 try {
  rr = (Integer) r.get("return");
 } catch (JSONException e) {
  publishProgress("\nError obtaining key 'return' from OpenME output (" + e.getMessage() + ") ...\n\n");
  return null;

 if ((rr > 0) && (rr != 16)) {
   String err = "";
   try {
     err = (String) r.get("error");
   } catch (JSONException e) {
     publishProgress("\nError obtaining key 'error' from OpenME output (" + e.getMessage() + ") ...\n\n");
     return null;
   publishProgress("\nProblem accessing " + err + "\n");
   return null;

 String title = "";
 try {
  title = (String) r.get("string");
 } catch (JSONException e) {
   publishProgress("\nError obtaining key 'string' from OpenME output (" + e.getMessage() + ") ...\n\n");
   return null;

 publishProgress("\nGenerated research topic or paper title:\n\n" + title + "\n");

We continue extending this technology, so any help (particularly for instrumenting LLVM and GCC) is appreciated!

Questions and comments

You are welcome to get in touch with the CK community if you have questions or comments!

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.