{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'version': ['1', '2', '0605'], 'return': 0, 'version_str': '1.2.0605'}\n"
     ]
    }
   ],
   "source": [
    "# Initiate Collective Knowledge\n",
    "import ck.kernel as ck\n",
    "print ck.version({})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# Init pipeline\n",
    "ii={\"action\":\"pipeline\",\n",
    "    \n",
    "    \"module_uoa\":\"program\",\n",
    "    \n",
    "    \"program_uoa\":\"polyhedral-hog-opencl\",\n",
    "    \n",
    "    \"remove_compiler_vars\":[\"HOG1X1\",\"HOG2X2\",\"HOG4X4\"],\n",
    "    \"compiler_vars\":{\n",
    "      \"HOG2X2\":\"\"\n",
    "    },\n",
    "\n",
    "    \"speed\":\"yes\",\n",
    "\n",
    "    \"cpu_freq\":\"max\",\n",
    "    \"gpu_freq\":\"max\",\n",
    "\n",
    "    \"prepare\":\"yes\"\n",
    "   }\n",
    "r=ck.access(ii)\n",
    "if r['return']>0:\n",
    "   print (\"Error:\"+r['error'])\n",
    "   exit(1)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.025435958 0.013103292 0.0104835365\n"
     ]
    }
   ],
   "source": [
    "# Experiment output\n",
    "experiment_desc=r['experiment_desc']\n",
    "last_iteration_output=r['last_iteration_output']\n",
    "last_stat_analysis=r['last_stat_analysis']\n",
    "\n",
    "flat_stat=last_stat_analysis.get('dict_flat')\n",
    "\n",
    "cpu=flat_stat.get('##characteristics#run#dim_cpu#min',0)\n",
    "gpu_only=flat_stat.get('##characteristics#run#dim_gpu_only#min',0)\n",
    "gpu_with_mem=flat_stat.get('##characteristics#run#dim_gpu_with_mem#min',0)\n",
    "\n",
    "print cpu, gpu_with_mem, gpu_only"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# Save output to json\n",
    "rx=ck.save_json_to_file({'json_file':'tmp-output.json', 'dict':r})\n",
    "if rx['return']>0:\n",
    "   print (\"Error:\"+r['error'])\n",
    "   exit(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
