diff --git a/examples/fortran/ipython-integration-demo.ipynb b/examples/fortran/ipython-integration-demo.ipynb index 1b0a9df8d18da1947171eadf744cb3db2ea312da..8fe25780b3a3909b1b8b07b0df847348d27c103d 100644 --- a/examples/fortran/ipython-integration-demo.ipynb +++ b/examples/fortran/ipython-integration-demo.ipynb @@ -9,7 +9,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -25,9 +25,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/home/kaushikggg/pack/loopy_kc_env/src/loopy/loopy/frontend/fortran/translator.py:807: LoopyWarning: 'lang_version' was not passed to make_function(). To avoid this warning, pass lang_version=(2018, 2) in this invocation. (Or say 'from loopy.version import LOOPY_USE_LANGUAGE_VERSION_2018_2' in the global scope of the calling frame.)\n", + " seq_dependencies=seq_dependencies,\n" + ] + } + ], "source": [ "%%fortran_kernel\n", "\n", @@ -45,11 +54,37 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "---------------------------------------------------------------------------\n", + "KERNEL: fill\n", + "---------------------------------------------------------------------------\n", + "ARGUMENTS:\n", + "a: ValueArg, type: np:dtype('float64')\n", + "n: ValueArg, type: np:dtype('int32')\n", + "out: type: np:dtype('float64'), shape: (n), dim_tags: (N0:stride:1) aspace: global\n", + "---------------------------------------------------------------------------\n", + "DOMAINS:\n", + "[n] -> { [i] : 0 <= i < n }\n", + "---------------------------------------------------------------------------\n", + "INAME IMPLEMENTATION TAGS:\n", + "i: None\n", + "---------------------------------------------------------------------------\n", + "INSTRUCTIONS:\n", + "for i\n", + " \u001b[36mout[i]\u001b[0m = \u001b[35ma\u001b[0m {id=\u001b[32minsn0\u001b[0m}\n", + "end i\n", + "---------------------------------------------------------------------------\n" + ] + } + ], "source": [ - "print(fill)" + "print(prog)" ] }, { @@ -61,7 +96,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -70,7 +105,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -92,19 +127,53 @@ "! 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", + "! RESULT = tr_fill\n", "!\n", "!$loopy end" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "---------------------------------------------------------------------------\n", + "KERNEL: tr_fill\n", + "---------------------------------------------------------------------------\n", + "ARGUMENTS:\n", + "a: ValueArg, type: np:dtype('float64')\n", + "n: ValueArg, type: np:dtype('int32')\n", + "out: type: np:dtype('float64'), shape: (n), dim_tags: (N0:stride:1) aspace: global\n", + "---------------------------------------------------------------------------\n", + "DOMAINS:\n", + "[n] -> { [i_outer, i_inner] : i_inner >= 0 and -128i_outer <= i_inner <= 127 and i_inner < n - 128i_outer }\n", + "---------------------------------------------------------------------------\n", + "INAME IMPLEMENTATION TAGS:\n", + "i_inner: l.0\n", + "i_outer: g.0\n", + "---------------------------------------------------------------------------\n", + "INSTRUCTIONS:\n", + "for i_inner, i_outer\n", + " \u001b[36mout[i_inner + i_outer*128]\u001b[0m = \u001b[35ma\u001b[0m {id=\u001b[32minsn0\u001b[0m}\n", + "end i_inner, i_outer\n", + "---------------------------------------------------------------------------\n" + ] + } + ], "source": [ - "print(tr_fill)" + "print(prog)" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { diff --git a/loopy/ipython_ext.py b/loopy/ipython_ext.py index e44b183ed3a08726d66019f8900fc273d432d613..c0c74913b60fadb669d58cfd6153a4679947a595 100644 --- a/loopy/ipython_ext.py +++ b/loopy/ipython_ext.py @@ -9,10 +9,8 @@ import loopy as lp class LoopyMagics(Magics): @cell_magic def fortran_kernel(self, line, cell): - result = lp.parse_fortran(cell, return_list_of_knls=True) - - for knl in result: - self.shell.user_ns[knl.name] = knl + result = lp.parse_fortran(cell) + self.shell.user_ns['prog'] = result @cell_magic def transformed_fortran_kernel(self, line, cell): @@ -20,8 +18,7 @@ class LoopyMagics(Magics): cell, transform_code_context=self.shell.user_ns) - for knl in result: - self.shell.user_ns[knl.name] = knl + self.shell.user_ns['prog'] = result def load_ipython_extension(ip): diff --git a/loopy/program.py b/loopy/program.py index 5c79edec7515fc222cd1dd118a702b2f063905ae..76568cafa70da2b8ef5a67484fb053f146ea4114 100644 --- a/loopy/program.py +++ b/loopy/program.py @@ -311,10 +311,6 @@ class Program(ImmutableRecord): return self.copy(callables_table=callables_table) - def __iter__(self): - #FIXME: Document - return six.iterkeys(self.callables_table.resolved_functions) - def __getitem__(self, name): result = self.callables_table[name] if isinstance(result, CallableKernel):