Skip to content
Snippets Groups Projects
ipython-integration-demo.ipynb 4.96 KiB
Newer Older
  • Learn to ignore specific revisions
  • {
     "metadata": {
      "name": "",
    
      "signature": "sha256:c9f8334aa7aa4a5ad1437fa5871aafa52bbc9131271d9e90e7be47d22725cc94"
    
     },
     "nbformat": 3,
     "nbformat_minor": 0,
     "worksheets": [
      {
       "cells": [
        {
         "cell_type": "markdown",
         "metadata": {},
         "source": [
          "# Loopy IPython Integration Demo"
         ]
        },
        {
         "cell_type": "code",
         "collapsed": false,
         "input": [
          "%load_ext loopy.ipython_ext"
         ],
         "language": "python",
         "metadata": {},
         "outputs": [],
         "prompt_number": 1
        },
        {
         "cell_type": "markdown",
         "metadata": {},
         "source": [
          "## Without transform code"
         ]
        },
        {
         "cell_type": "code",
         "collapsed": false,
         "input": [
          "%%fortran_kernel\n",
          "\n",
          "subroutine fill(out, a, n)\n",
          "  implicit none\n",
          "\n",
          "  real*8 a, out(n)\n",
          "  integer n, i\n",
          "\n",
          "  do i = 1, n\n",
          "    out(i) = a\n",
          "  end do\n",
          "end"
         ],
         "language": "python",
         "metadata": {},
         "outputs": [],
    
         "prompt_number": 2
    
        },
        {
         "cell_type": "code",
         "collapsed": false,
         "input": [
          "print(fill)"
         ],
         "language": "python",
         "metadata": {},
         "outputs": [
          {
           "output_type": "stream",
           "stream": "stdout",
           "text": [
            "---------------------------------------------------------------------------\n",
            "KERNEL: fill\n",
            "---------------------------------------------------------------------------\n",
            "ARGUMENTS:\n",
            "a: ValueArg, type: float64\n",
            "n: ValueArg, type: int32\n",
            "out: GlobalArg, type: float64, shape: (n), dim_tags: (N0:stride:1)\n",
            "---------------------------------------------------------------------------\n",
            "DOMAINS:\n",
            "[n] -> { [i] : i >= 0 and i <= -1 + n }\n",
            "---------------------------------------------------------------------------\n",
            "INAME IMPLEMENTATION TAGS:\n",
            "i: None\n",
            "---------------------------------------------------------------------------\n",
            "INSTRUCTIONS:\n",
            "[i]                                  out[i] <- a   # insn0\n",
            "---------------------------------------------------------------------------\n"
           ]
          }
         ],
    
         "prompt_number": 3
    
        },
        {
         "cell_type": "markdown",
         "metadata": {},
         "source": [
          "## With transform code"
         ]
        },
        {
         "cell_type": "code",
         "collapsed": false,
         "input": [
          "split_amount = 128"
         ],
         "language": "python",
         "metadata": {},
         "outputs": [],
    
         "prompt_number": 4
    
        },
        {
         "cell_type": "code",
         "collapsed": false,
         "input": [
    
          "%%transformed_fortran_kernel\n",
    
          "\n",
          "subroutine tr_fill(out, a, n)\n",
          "  implicit none\n",
          "\n",
          "  real*8 a, out(n)\n",
          "  integer n, i\n",
          "\n",
          "  do i = 1, n\n",
          "    out(i) = a\n",
          "  end do\n",
          "end\n",
          "\n",
          "!$loopy begin\n",
          "!\n",
          "! tr_fill, = lp.parse_fortran(SOURCE)\n",
          "! tr_fill = lp.split_iname(tr_fill, \"i\", split_amount,\n",
          "!     outer_tag=\"g.0\", inner_tag=\"l.0\")\n",
          "! RESULT = [tr_fill]\n",
          "!\n",
          "!$loopy end"
         ],
         "language": "python",
         "metadata": {},
         "outputs": [],
    
         "prompt_number": 5
    
        },
        {
         "cell_type": "code",
         "collapsed": false,
         "input": [
          "print(tr_fill)"
         ],
         "language": "python",
         "metadata": {},
         "outputs": [
          {
           "output_type": "stream",
           "stream": "stdout",
           "text": [
            "---------------------------------------------------------------------------\n",
            "KERNEL: tr_fill\n",
            "---------------------------------------------------------------------------\n",
            "ARGUMENTS:\n",
            "a: ValueArg, type: float64\n",
            "n: ValueArg, type: int32\n",
            "out: GlobalArg, type: float64, shape: (n), dim_tags: (N0:stride:1)\n",
            "---------------------------------------------------------------------------\n",
            "DOMAINS:\n",
            "[n] -> { [i_outer, i_inner] : i_inner >= -128i_outer and i_inner <= -1 + n - 128i_outer and i_inner >= 0 and i_inner <= 127 }\n",
            "---------------------------------------------------------------------------\n",
            "INAME IMPLEMENTATION TAGS:\n",
            "i_inner: l.0\n",
            "i_outer: g.0\n",
            "---------------------------------------------------------------------------\n",
            "INSTRUCTIONS:\n",
            "[i_inner,i_outer]                    out[i_inner + i_outer*128] <- a   # insn0\n",
            "---------------------------------------------------------------------------\n"
           ]
          }
         ],
         "prompt_number": 6
        },
        {
         "cell_type": "code",
         "collapsed": false,
         "input": [],
         "language": "python",
         "metadata": {},
         "outputs": []
        }
       ],
       "metadata": {}
      }
     ]
    }