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

Lifted or Undeclared variable scheduled in wrong set of loops #2525

Open
georgebisbas opened this issue Jan 28, 2025 · 0 comments
Open

Lifted or Undeclared variable scheduled in wrong set of loops #2525

georgebisbas opened this issue Jan 28, 2025 · 0 comments
Assignees
Labels
bug-C bug in the generated code compiler

Comments

@georgebisbas
Copy link
Contributor

Undeclared var, possibly due to wrong scheduling
(Initial thread from @felipeguedessilva,
here: https://devitocodes.slack.com/archives/C7JMLMSG0/p1736908013546609)

mfe.py

from devito import Grid, TimeFunction, Function, Eq, Operator

# Setup Configuration
grid = Grid(shape=(30, 30))

# Symbolic Dimensions
x, y = grid.dimensions
t = grid.stepping_dim

# Reduced MFE Lame Parameters
VS = Function(name="VS", grid=grid, space_order=2)

# Symbolic Fields Construction
v = TimeFunction(name='v', grid=grid, space_order=2)

# Reduced MFE Higdon Condition - Velocity
eqs = []

beta = (1 + (1/VS))
dz = (1 / beta)

eqv1 = Eq(v.forward, v[t, x, y+1])

eqv2 = Eq(v.forward,
          (v[t+1, x-1, y] +
           v[t+1, x, y-1] +
           (dz)*v[t+1, x, y]))

eqs.append(eqv1)
eqs.append(eqv2)

# Operator Definition
op = Operator(eqs)

op(dt=0.1, time=10)

To reproduce:
DEVITO_LOGGING=DEBUG python mfe.py

Error:

Operator `Kernel` generated in 0.18 s
  * lowering.Clusters: 0.09 s (52.3 %)
     * specializing.Clusters: 0.05 s (29.1 %)
  * lowering.IET: 0.07 s (40.7 %)
     * specializing.IET: 0.04 s (23.3 %)
Flops reduction after symbolic optimization: [6 --> 6]
gcc -march=native -O3 -g -fPIC -Wall -std=c99 -Wno-unused-result -Wno-unused-variable -Wno-unused-but-set-variable -ffast-math -shared -fopenmp /tmp/devito-jitcache-uid1000/5cc44d7ce38ff1f3bbc1699a3fca1f2c9d9896be.c -lm -o /tmp/devito-jitcache-uid1000/5cc44d7ce38ff1f3bbc1699a3fca1f2c9d9896be.so
/tmp/devito-jitcache-uid1000/5cc44d7ce38ff1f3bbc1699a3fca1f2c9d9896be.c: In function ‘Kernel’:
/tmp/devito-jitcache-uid1000/5cc44d7ce38ff1f3bbc1699a3fca1f2c9d9896be.c:53:31: error: ‘r0’ undeclared (first use in this function); did you mean ‘t0’?
   53 |         v[t1][x + 2][y + 2] = r0*v[t1][x + 2][y + 2] + v[t1][x + 1][y + 2] + v[t1][x + 2][y + 1];
      |                               ^~
      |                               t0
/tmp/devito-jitcache-uid1000/5cc44d7ce38ff1f3bbc1699a3fca1f2c9d9896be.c:53:31: note: each undeclared identifier is reported only once for each function it appears in
FAILED compiler invocation: gcc -march=native -O3 -g -fPIC -Wall -std=c99 -Wno-unused-result -Wno-unused-variable -Wno-unused-but-set-variable -ffast-math -shared -fopenmp /tmp/devito-jitcache-uid1000/5cc44d7ce38ff1f3bbc1699a3fca1f2c9d9896be.c -lm -o /tmp/devito-jitcache-uid1000/5cc44d7ce38ff1f3bbc1699a3fca1f2c9d9896be.so
Traceback (most recent call last):
  File "/home/gb4018/workspace/devitocodes/devito/examples/minimal.py", line 35, in <module>
    op(dt=0.1, time=10)
  File "/home/gb4018/workspace/devitocodes/devito/devito/operator/operator.py", line 833, in __call__
    return self.apply(**kwargs)
  File "/home/gb4018/workspace/devitocodes/devito/devito/operator/operator.py", line 899, in apply
    cfunction = self.cfunction
  File "/home/gb4018/workspace/devitocodes/devito/devito/operator/operator.py", line 786, in cfunction
    self._jit_compile()
  File "/home/gb4018/workspace/devitocodes/devito/devito/operator/operator.py", line 772, in _jit_compile
    recompiled, src_file = self._compiler.jit_compile(self._soname, str(self))
  File "/home/gb4018/workspace/devitocodes/devito/devito/arch/compiler.py", line 379, in jit_compile
    _, _, _, recompiled = compile_from_string(self, target, code, src_file,
  File "/home/gb4018/environments/python310-venv/lib/python3.10/site-packages/codepy/jit.py", line 439, in compile_from_string
    toolchain.build_extension(ext_file, source_paths, debug=debug)
  File "/home/gb4018/environments/python310-venv/lib/python3.10/site-packages/codepy/toolchain.py", line 211, in build_extension
    raise CompileError("module compilation failed")
codepy.CompileError: module compilation failed
@georgebisbas georgebisbas added bug-C bug in the generated code compiler labels Jan 28, 2025
@georgebisbas georgebisbas self-assigned this Jan 28, 2025
georgebisbas added a commit that referenced this issue Feb 4, 2025

Verified

This commit was signed with the committer’s verified signature.
georgebisbas George Bisbas
georgebisbas added a commit that referenced this issue Feb 6, 2025

Verified

This commit was signed with the committer’s verified signature.
georgebisbas George Bisbas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-C bug in the generated code compiler
Projects
None yet
Development

No branches or pull requests

1 participant