Skip to content

Commit a9577b7

Browse files
committed
compiler: add top description to generated file
1 parent 9fa537f commit a9577b7

6 files changed

Lines changed: 47 additions & 19 deletions

File tree

devito/ir/cgen/printer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ def _print_ListInitializer(self, expr):
344344
return f"{{{', '.join(self._print(i) for i in expr.params)}}}"
345345

346346
def _print_IndexedPointer(self, expr):
347-
return f"{expr.base}{''.join(f'[{self._print(i)}]' for i in expr.index)}"
347+
return f"({expr.base}){''.join(f'[{self._print(i)}]' for i in expr.index)}"
348348

349349
def _print_IntDiv(self, expr):
350350
lhs = self._print(expr.lhs)

devito/ir/iet/visitors.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,17 @@ def visit_KernelLaunch(self, o):
671671
return c.Statement(f'{o.name}{templates}<<<{launch_config}>>>({arguments})')
672672

673673
# Operator-handle machinery
674+
def _operator_description(self, o):
675+
"""
676+
Generate cgen description from an iterable of symbols and expressions.
677+
"""
678+
if o.description:
679+
if isinstance(o.description, str):
680+
return [c.Comment(o.description), blankline]
681+
elif isinstance(o.description, Iterable):
682+
return [c.MultilineComment(o.description), blankline]
683+
else:
684+
return [c.Comment("Devito generated operator"), blankline]
674685

675686
def _operator_includes(self, o):
676687
"""
@@ -752,6 +763,9 @@ def visit_Operator(self, o, mode='all'):
752763
esigns.append(self._gen_signature(i, is_declaration=True))
753764
efuncs.extend([self._visit(i), blankline])
754765

766+
# Top description
767+
description = self._operator_description(o)
768+
755769
# Definitions
756770
headers = self._operator_headers(o)
757771

@@ -772,8 +786,8 @@ def visit_Operator(self, o, mode='all'):
772786
if globs:
773787
globs.append(blankline)
774788

775-
return c.Module(headers + includes + namespaces + typedecls + globs +
776-
esigns + [blankline, kernel] + efuncs)
789+
return c.Module(description + headers + includes + namespaces + typedecls
790+
+ globs + esigns + [blankline, kernel] + efuncs)
777791

778792

779793
class CInterface(CGen):

devito/operator/operator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,10 @@ def _soname(self):
768768
def _printer(self):
769769
return self._Target.Printer
770770

771+
@cached_property
772+
def description(self):
773+
return f"Devito generated code for Operator `{self.name}`"
774+
771775
@cached_property
772776
def headers(self):
773777
return OrderedSet(*self._printer._headers).union(self._headers)

examples/cfd/01_convection.ipynb

Lines changed: 10 additions & 7 deletions
Large diffs are not rendered by default.

examples/cfd/01_convection_revisited.ipynb

Lines changed: 10 additions & 7 deletions
Large diffs are not rendered by default.

examples/mpi/overview.ipynb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,9 @@
314314
{
315315
"data": {
316316
"text/plain": [
317-
"[stdout:0] #define _POSIX_C_SOURCE 200809L\n",
317+
"[stdout:0] /* Devito generated code for Operator `Kernel` */\n",
318+
"\n",
319+
"#define _POSIX_C_SOURCE 200809L\n",
318320
"#define START(S) struct timeval start_ ## S , end_ ## S ; gettimeofday(&start_ ## S , NULL);\n",
319321
"#define STOP(S,T) gettimeofday(&end_ ## S, NULL); T->S += (double)(end_ ## S .tv_sec-start_ ## S.tv_sec)+(double)(end_ ## S .tv_usec-start_ ## S .tv_usec)/1000000;\n",
320322
"\n",
@@ -407,7 +409,9 @@
407409
{
408410
"data": {
409411
"text/plain": [
410-
"[stdout:0] #define _POSIX_C_SOURCE 200809L\n",
412+
"[stdout:0] /* Devito generated code for Operator `Kernel` */\n",
413+
"\n",
414+
"#define _POSIX_C_SOURCE 200809L\n",
411415
"#define START(S) struct timeval start_ ## S , end_ ## S ; gettimeofday(&start_ ## S , NULL);\n",
412416
"#define STOP(S,T) gettimeofday(&end_ ## S, NULL); T->S += (double)(end_ ## S .tv_sec-start_ ## S.tv_sec)+(double)(end_ ## S .tv_usec-start_ ## S .tv_usec)/1000000;\n",
413417
"\n",

0 commit comments

Comments
 (0)