Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Staggering not purged when index contains abs() of a value #1950

Closed
EdCaunt opened this issue Jun 23, 2022 · 0 comments · Fixed by #2120
Closed

Staggering not purged when index contains abs() of a value #1950

EdCaunt opened this issue Jun 23, 2022 · 0 comments · Fixed by #2120

Comments

@EdCaunt
Copy link
Contributor

EdCaunt commented Jun 23, 2022

If you try to use the absolute value of an index (for example when implementing a free-surface as in the acoustic examples) with a function that is staggered, the staggering is not correctly accounted for during compilation, resulting in a float being used as an index in the generated c code. This causes module compilation to fail.

MFE:

import devito as dv

grid = dv.Grid(shape=(11, 11), extent=(10., 10.))
x, y = grid.dimensions
f = dv.TimeFunction(name='f', grid=grid, space_order=2, staggered=x)

eq = dv.Eq(f.forward, f.dx)

lhs, rhs = eq.evaluate.args

funcs = dv.symbolics.retrieve_functions(rhs)
mapper = {}
for f in funcs:
    # Get the x index
    xind = f.indices[1]
    if (xind - x).as_coeff_Mul()[0] < 0:
        mapper.update({f: f.subs({xind: dv.symbolics.INT(abs(xind))})})

eq2 = dv.Eq(lhs, rhs.subs(mapper))

dv.Operator(eq2)(t_M=1)

Which returns:

/tmp/devito-jitcache-uid1000/1fe24909a093d8c69264ced7adcbb947db766fed.c: In function ‘Kernel’:
/tmp/devito-jitcache-uid1000/1fe24909a093d8c69264ced7adcbb947db766fed.c:47:41: error: array subscript is not an integer
   47 |         f[t1][x + 2][y + 2] = r0*(-f[t0][3.0F/2.0F + (int)(fabs(x - 1.0F/2.0F))][y + 2]) + r0*f[t0][x + 2][y + 2];
      |                                         ^
FAILED compiler invocation:gcc -O3 -g -fPIC -Wall -std=c99 -march=native -Wno-unused-result -Wno-unused-variable -Wno-unused-but-set-variable -ffast-math -shared -fopenmp /tmp/devito-jitcache-uid1000/1fe24909a093d8c69264ced7adcbb947db766fed.c -lm -o /tmp/devito-jitcache-uid1000/1fe24909a093d8c69264ced7adcbb947db766fed.so

to the stderr and:

Traceback (most recent call last):
  File "staggered_absolute_indices_mfe.py", line 23, in <module>
    dv.Operator(eq2)(t_M=1)
  File "/home/ed/devito/devito/operator/operator.py", line 653, in __call__
    return self.apply(**kwargs)
  File "/home/ed/devito/devito/operator/operator.py", line 724, in apply
    cfunction = self.cfunction
  File "/home/ed/devito/devito/operator/operator.py", line 606, in cfunction
    self._jit_compile()
  File "/home/ed/devito/devito/operator/operator.py", line 591, in _jit_compile
    recompiled, src_file = self._compiler.jit_compile(self._soname,
  File "/home/ed/devito/devito/arch/compiler.py", line 319, in jit_compile
    _, _, _, recompiled = compile_from_string(self, target, code, src_file,
  File "/home/ed/anaconda3/envs/devito/lib/python3.8/site-packages/codepy/jit.py", line 433, in compile_from_string
    toolchain.build_extension(ext_file, source_paths, debug=debug)
  File "/home/ed/anaconda3/envs/devito/lib/python3.8/site-packages/codepy/toolchain.py", line 210, in build_extension
    raise CompileError("module compilation failed")
codepy.CompileError: module compilation failed

to the stdout

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant