From ee71fd036c39a671be20bd21b57ea9274f5d7211 Mon Sep 17 00:00:00 2001 From: Alex Fikl <alexfikl@gmail.com> Date: Fri, 9 Feb 2018 13:38:49 -0600 Subject: [PATCH] fix the fortran examples as well --- examples/fortran/foo.floopy | 30 -- .../fortran/ipython-integration-demo.ipynb | 326 ++++++++---------- examples/fortran/matmul.floopy | 2 +- examples/fortran/tagging.floopy | 15 +- examples/fortran/volumeKernelSimple.floopy | 38 -- loopy/ipython_ext.py | 4 +- 6 files changed, 155 insertions(+), 260 deletions(-) delete mode 100644 examples/fortran/foo.floopy delete mode 100644 examples/fortran/volumeKernelSimple.floopy diff --git a/examples/fortran/foo.floopy b/examples/fortran/foo.floopy deleted file mode 100644 index 6b8741e11..000000000 --- a/examples/fortran/foo.floopy +++ /dev/null @@ -1,30 +0,0 @@ -subroutine fill(out, a, n) - implicit none - - real_type a, out(n) - integer n, i - - do i = 1, n - out(i) = a - end do - do i = 1, n - out(i) = out(i) * factor - end do -end - -!$loopy begin -! -! SOURCE = lp.c_preprocess(SOURCE, [ -! "factor 4.0", -! "real_type real*8", -! ]) -! fill, = lp.parse_fortran(SOURCE, FILENAME) -! fill = lp.split_iname(fill, "i", 128, -! outer_tag="g.0", inner_tag="l.0") -! fill = lp.split_iname(fill, "i_1", 128, -! outer_tag="g.0", inner_tag="l.0") -! RESULT = [fill] -! -!$loopy end - -! vim:filetype=floopy diff --git a/examples/fortran/ipython-integration-demo.ipynb b/examples/fortran/ipython-integration-demo.ipynb index c2b34f1d1..7a5c8257b 100644 --- a/examples/fortran/ipython-integration-demo.ipynb +++ b/examples/fortran/ipython-integration-demo.ipynb @@ -1,190 +1,142 @@ { - "metadata": { - "name": "", - "signature": "sha256:c9f8334aa7aa4a5ad1437fa5871aafa52bbc9131271d9e90e7be47d22725cc94" - }, - "nbformat": 3, - "nbformat_minor": 0, - "worksheets": [ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Loopy IPython Integration Demo" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "%load_ext loopy.ipython_ext" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Without transform code" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "%%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" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "print(fill)" + ] + }, { - "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": {} + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## With transform code" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "split_amount = 128" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "%%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" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "print(tr_fill)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] } - ] -} \ No newline at end of file + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.4" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/examples/fortran/matmul.floopy b/examples/fortran/matmul.floopy index 3352449d7..8ee05643b 100644 --- a/examples/fortran/matmul.floopy +++ b/examples/fortran/matmul.floopy @@ -1,6 +1,6 @@ subroutine dgemm(m,n,l,alpha,a,b,c) implicit none - real*8 temp, a(m,l),b(l,n),c(m,n), alpha + real*8 a(m,l),b(l,n),c(m,n), alpha integer m,n,k,i,j,l do j = 1,n diff --git a/examples/fortran/tagging.floopy b/examples/fortran/tagging.floopy index 40b487528..87aacba68 100644 --- a/examples/fortran/tagging.floopy +++ b/examples/fortran/tagging.floopy @@ -1,7 +1,7 @@ subroutine fill(out, a, n) implicit none - real*8 a, out(n) + real_type a, out(n) integer n, i !$loopy begin tagged: init @@ -9,17 +9,28 @@ subroutine fill(out, a, n) out(i) = a end do !$loopy end tagged: init + +!$loopy begin tagged: mult do i = 1, n - out(i) = out(i) * 2 + out(i) = out(i) * factor end do +!$loopy end tagged: mult end !$loopy begin +! +! SOURCE = lp.c_preprocess(SOURCE, [ +! "factor 4.0", +! "real_type real*8", +! ]) ! fill, = lp.parse_fortran(SOURCE, FILENAME) +! fill = lp.add_barrier(fill, "tag:init", "tag:mult", "gb1") ! fill = lp.split_iname(fill, "i", 128, ! outer_tag="g.0", inner_tag="l.0") ! fill = lp.split_iname(fill, "i_1", 128, ! outer_tag="g.0", inner_tag="l.0") ! RESULT = [fill] +! !$loopy end + ! vim:filetype=floopy diff --git a/examples/fortran/volumeKernelSimple.floopy b/examples/fortran/volumeKernelSimple.floopy deleted file mode 100644 index afc3321b8..000000000 --- a/examples/fortran/volumeKernelSimple.floopy +++ /dev/null @@ -1,38 +0,0 @@ -subroutine volumeKernel(elements, Nfields, Ngeo, Ndim, Dop, geo, Q, rhsQ ) - - implicit none - - integer elements, Nfields, Ngeo, Ndim - - real*4 Dop(Nq,Nq) - real*4 Q(Nq,Nq,Nq,Nfields,elements) - real*4 geo(Nq,Nq,Nq,Ngeo,elements) - real*4 rhsQ(Nq,Nq,Nq,Nfields,elements) - - integer e,i,j,k,d,n,cnt - - real*4 u,v,w,p, dFdr, dFds, dFdt, divF - real*4 F(Nq,Ndim) - - - do e=1,elements - do i=1,Nq - - F(i,1) = 5 - F(i,2) = 7 - - end do - - end do - -end subroutine volumeKernel - -!$loopy begin -! -! volumeKernel, = lp.parse_fortran(SOURCE, FILENAME) -! volumeKernel = lp.fix_parameters(volumeKernel, -! Nq=5, Ndim=3) -! volumeKernel = lp.tag_inames(volumeKernel, dict(i="l.0")) -! RESULT = [volumeKernel] -! -!$loopy end diff --git a/loopy/ipython_ext.py b/loopy/ipython_ext.py index 12fd03542..ec1b10f1f 100644 --- a/loopy/ipython_ext.py +++ b/loopy/ipython_ext.py @@ -9,7 +9,7 @@ import loopy as lp class LoopyMagics(Magics): @cell_magic def fortran_kernel(self, line, cell): - result = lp.parse_fortran(cell.encode()) + result = lp.parse_fortran(cell) for knl in result: self.shell.user_ns[knl.name] = knl @@ -17,7 +17,7 @@ class LoopyMagics(Magics): @cell_magic def transformed_fortran_kernel(self, line, cell): result = lp.parse_transformed_fortran( - cell.encode(), + cell, transform_code_context=self.shell.user_ns) for knl in result: -- GitLab