diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4d4f7e52891a0cb8477672fbaf14b29c067de0f9..58fb78251d04afb0e7f613aae237799237a010b9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -117,6 +117,20 @@ Python 3.6 POCL Twice With Cache: # except: # - tags +Python 3.6 POCL Examples: + script: + - export PY_EXE=python3.6 + - export PYOPENCL_TEST=portable + - export EXTRA_INSTALL="numpy mako pyvisfile matplotlib jupyter nbconvert" + - ". ./build-py-project-and-run-examples.sh" + tags: + - python3.6 + - pocl + - large-node + - ispc + except: + - tags + CentOS binary: script: - (cd build-helpers; ./make-linux-build-docker.sh --nodate) diff --git a/build-py-project-and-run-examples.sh b/build-py-project-and-run-examples.sh new file mode 100644 index 0000000000000000000000000000000000000000..e51a86d2085364ca142f5bfde3380a9fade0de01 --- /dev/null +++ b/build-py-project-and-run-examples.sh @@ -0,0 +1,37 @@ +#! /bin/bash + +set -e + +curl -L -O -k https://gitlab.tiker.net/inducer/ci-support/raw/master/build-py-project.sh +source build-py-project.sh + +function run_examples() +{ + PATTERN=$1 + CMDLINE=$2 + for i in $(find examples -name "$PATTERN" -print ); do + echo "-----------------------------------------------------------------------" + echo "RUNNING $i" + echo "-----------------------------------------------------------------------" + dn=$(dirname "$i") + bn=$(basename "$i") + (cd $dn; echo $CMDLINE "$bn"; $CMDLINE "$bn") + done +} + +function run_py_examples() +{ + run_examples "*.py" ${PY_EXE} +} +function run_ipynb_examples() +{ + run_examples "*.ipynb" "${PY_EXE} -m nbconvert --execute" +} +function run_floopy_examples() +{ + run_examples "*.floopy" "${PY_EXE} -m loopy" +} + +run_py_examples +run_ipynb_examples +run_floopy_examples diff --git a/examples/fortran/foo.floopy b/examples/fortran/foo.floopy deleted file mode 100644 index 6b8741e1150a05226f3aa9de849db8abb1915002..0000000000000000000000000000000000000000 --- 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 c2b34f1d13f7b4971c0c2e88a0ae5013ed12ee23..7a5c8257bf80fdfcc3d3b978a7dca2d401c48271 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 3352449d7bfcc406e5349f36c5cb7ebb3e3613b6..8ee05643b926f722a3419378c52d254e43617708 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 40b487528cdd788f26fb4b600869e4bf81f090a8..87aacba68ae2fc6f3b7052325fcd2378e9880e47 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 afc3321b8fa18ff532b3c2898dbaea8f99e3700c..0000000000000000000000000000000000000000 --- 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/examples/python/find-centers.py b/examples/python/find-centers.py index c5e5e916156fd44b5a37cdb3cd41718916461a06..1822d3b7990d27f14d04e3b86a1d3c2d0b5c26ee 100644 --- a/examples/python/find-centers.py +++ b/examples/python/find-centers.py @@ -26,7 +26,7 @@ knl = lp.make_kernel( <> post_dist_sq = if(matches, dist_sq, HUGE) end - <> min_dist_sq, <> min_ictr = argmin(ictr, post_dist_sq) + <> min_dist_sq, <> min_ictr = argmin(ictr, ictr, post_dist_sq) tgt_to_qbx_center[itgt] = if(min_dist_sq < HUGE, min_ictr, -1) end diff --git a/examples/python/global_barrier_removal.py b/examples/python/global_barrier_removal.py index b71c561195647b7e35bc5538cfd1d601e270f3c2..7ab049cd1906f703b0efc39808ff68a63b91ff37 100644 --- a/examples/python/global_barrier_removal.py +++ b/examples/python/global_barrier_removal.py @@ -6,14 +6,17 @@ import pyopencl.array knl = lp.make_kernel( "{ [i,k]: 0<=i rowstart = rowstarts[i] - <> rowend = rowstarts[i] - <> length = rowend - rowstart - y[i] = sum(j, values[rowstart+j] * x[colindices[rowstart + j]]) + for i + <> rowstart = rowstarts[i] + <> rowend = rowstarts[i] + <> length = rowend - rowstart + y[i] = sum(j, values[rowstart+j] * x[colindices[rowstart + j]]) + end """) k = lp.add_and_infer_dtypes(k, { diff --git a/loopy/ipython_ext.py b/loopy/ipython_ext.py index 12fd0354267e86707cc91de0027319e3584a08f0..ec1b10f1f512e18079f44b94b298e876776cae35 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: