devitocodes / devito

DSL and compiler framework for automated finite-differences and stencil computation
http://www.devitoproject.org
MIT License
562 stars 228 forks source link

Arguments for apply() #250

Closed mloubout closed 7 years ago

mloubout commented 7 years ago

So there is a little "bug" in operator line 152.

        for argname in o_vals.keys():
            if not arguments[argname].shape == o_vals[argname].shape:
                raise InvalidArgument("Shapes must match")

The little problem with this is, any passed argument needs to have the exact same shape, including number of time steps. I kinda of defeat the purpose of generic dimensions if there sizes can't be changed.

AN example would be

u = TimeData(name='u', shape=(100, ), time_order=1, space_order=2, time_dim=100)
# Derive the stencil according to devito conventions
eqn = Eq(u.dt, u.dx)
stencil = solve(eqn, u.forward)[0]
op = Operator([Eq(u.forward, stencil)], subs={h: dx, s: dt})

# Execute the generated Devito stencil operator
op.apply()

the doing

u2 = TimeData(name='u', shape=(100, ), time_order=1, space_order=2, time_dim=200)
op.apply(u=u2)

produces

InvalidArgumentTraceback (most recent call last)<ipython-input-7-3e325d1513f1> in <module>()
      6 # stencil = solve(eqn, u2.forward)[0]
      7 # op = Operator([Eq(u2.forward, stencil)], subs={h: dx, s: dt})
----> 8 op.apply(u=u2)
/Users/mloubout/Dropbox/London/CodeGen/devito/devito/operator.pyc in apply(self, *args, **kwargs)
    478         """Apply the stencil kernel to a set of data objects"""
    479         # Build the arguments list to invoke the kernel function
--> 480         arguments, dim_sizes = self.arguments(*args, **kwargs)
    481 
    482         # Invoke kernel function with args
/Users/mloubout/Dropbox/London/CodeGen/devito/devito/operator.pyc in arguments(self, *args, **kwargs)
    152         for argname in o_vals.keys():
    153             if not arguments[argname].shape == o_vals[argname].shape:
--> 154                 raise InvalidArgument("Shapes must match")
    155 
    156             arguments[argname] = o_vals[argname]
InvalidArgument: Shapes must match
FabioLuporini commented 7 years ago

I wonder if this our usual caching @mlange05

mloubout commented 7 years ago

Well actually, thinking of it, it would be odd and error prone to pass arguments with differet sizes to apply as there is other objects ,m, src,rec that may not be compatible with this size leading to segfaults or errors.

FabioLuporini commented 7 years ago

Can this be closed @mlange05 ?

mloubout commented 7 years ago

This should be fixed by last week PRs

FabioLuporini commented 7 years ago

yes, but there's a new (smaller) issue now that is waiting for #273 ...

FabioLuporini commented 7 years ago

@mlange05 we can probably close this now?

mlange05 commented 7 years ago

Yes, I think the relevant parts have been addressed. Closing.