You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Broadcasting rules distinguish between host scalar and device scalars #49
I don't see a good reason why we don't support this.
I think we should also go a step ahead and make sure that we broadcast every cl.Array to be added (if legal) with all the leaf arrays of the array container. One way I could see this working is if every ArrayContext comes with a ARRAY_TYPE static, frozen attribute which gives us a hint to broadcast to all successive arrays.
I think every ArrayContext providing a type for a leaf array's type isn't too bad. And we can accordingly broadcast the operation with all the other leaf arrays in the array container.
I.e. I believe even the below operation could also work with the approach.
Arithmetic is a pretty important code path, eager+strong-scaling-wise. (Hence all that generated code.) I'm hesitant about doing something expensive there.
Finding the array context to go with a container (so that we can ask it what its array class is) seems kind of difficult. There currently isn't a great way to do so, and what little way there is would require recursion, i.e. it's quite expensive.
We could also do a global registry of array classes... 🤷 not that I'm a fan of that solution either.
That wouldn't fix your example though (unless you add an .array_context attribute). with_arithmetic already has _cls_has_array_context_attr (which, it occurs to me, could have a smarter default):
+1 for something like this on my side too. I was just playing with getting pytential working with force_device_scalars=True and it died pretty quicky because of expressions like
sym.Ones() * sym.mean(ambient_dim, dim, expr)
as it didn't know how to multiply a DOFArray (from Ones) with a device scalar (from mean).
Activity
inducer commentedon Jun 27, 2021
I agree that this is inconsistent, however there's an elephant of a practicality in the room: How do you propose we recognize scalars?
A shot-in-the-dark
.shape == ()?kaushikcfd commentedon Jun 27, 2021
I think every ArrayContext providing a type for a leaf array's type isn't too bad. And we can accordingly broadcast the operation with all the other leaf arrays in the array container.
I.e. I believe even the below operation could also work with the approach.
inducer commentedon Jun 27, 2021
Arithmetic is a pretty important code path, eager+strong-scaling-wise. (Hence all that generated code.) I'm hesitant about doing something expensive there.
Finding the array context to go with a container (so that we can ask it what its array class is) seems kind of difficult. There currently isn't a great way to do so, and what little way there is would require recursion, i.e. it's quite expensive.
We could also do a global registry of array classes... 🤷 not that I'm a fan of that solution either.
kaushikcfd commentedon Jun 27, 2021
How about we take this code path iff getting the array context is cheap like here:
arraycontext/test/test_arraycontext.py
Lines 506 to 508 in c006285
inducer commentedon Jun 27, 2021
That wouldn't fix your example though (unless you add an
.array_contextattribute).with_arithmeticalready has_cls_has_array_context_attr(which, it occurs to me, could have a smarter default):arraycontext/arraycontext/container/arithmetic.py
Line 136 in c006285
I guess I'm not super opposed to this, though certainly not delighted. Want to put together a PR so we can see what it might look like?
kaushikcfd commentedon Jun 27, 2021
Yup. Thanks for considering this.
alexfikl commentedon Jun 28, 2021
+1 for something like this on my side too. I was just playing with getting pytential working with
force_device_scalars=Trueand it died pretty quicky because of expressions likeas it didn't know how to multiply a
DOFArray(fromOnes) with a device scalar (frommean).kaushikcfd commentedon Jun 28, 2021
There's actually another issue hiding there:
I.e. PyOpenCL doesn't support broadcasting.
inducer commentedon Jun 28, 2021
Let's take the PyOpenCL discussion here: inducer/pyopencl#498
inducer commentedon Jun 28, 2021
See #51 for work by @kaushikcfd towards solving this.