niessner / Opt

Opt DSL
Other
256 stars 68 forks source link

Unknowns of different dimensions #82

Open JWHennessey opened 7 years ago

JWHennessey commented 7 years ago

Hi, still enjoying Opt but have some confusion how to add the next bit of complexity to my problem. Again what I have in mind might just be a feature request.

I have two unknown arrays of WxH, I also want to have a vector of K unknowns (e.g. spherical harmonics coefficients) but I get a compile time error when trying to use unknowns of varying dimensions.

local K,W,H = Dim("K",0),Dim("W",1), Dim("H",2)
local u_image1 = Unknown("u_image1", opt_float3,{W,H},0)
local u_image2 = Unknown("u_image2", opt_float3,{W,H},1)
local u_coeff = Unknown("u_coeff", opt_float,{K},2)

I've been trying to think how Opt's other tools could help e.g. multi-pass optimization or the graph data structure, but I can't get around having different dimensions. I also don't understand how you actually implement the mixed domain energies described in Section 7 Domains [Devito et. al 2016]

The best I've come up is use K WxH unknowns with a very high smoothness constraint to try and force them to be uniform but this is less than ideal.

Is there something else that Opt offers to help with this kind of problem? Thanks!

Mx7f commented 7 years ago

You could encode this using a graph, with edges between the image pixels and coefficients. This is an explicit encoding of WHK different edges; there isn't a natural implicit connectivity between two completely separate domains: what did the code that gave you a compile-time error look like?

In the current version of Opt, you may need to explicitly pack in the coefficients with the image as an extra row, and use a mask image to distinguish between the two for pixel-wise regularization; it won't be too far in the future when this extra step won't be necessary and we'll just launch separate kernels for separate dimensional kernels.

An alternative, which may end up being much faster depending on your energy function, is to do an alternating solve, where you swap between treating the images as unknowns and the coefficients as unknowns; but you still need explicit connectivity for the coefficient-as-unknowns half, so that is likely a net loss.

rongduo commented 7 years ago

Have you solved the problem how to use unknowns of different dimensions?