Comments (10)
There's actually another issue hiding there:
>>> a = cla.to_device(cq, np.ones(3))
>>> b = cla.to_device(cq, np.ones(()))
>>> a
cl.Array([1., 1., 1.])
>>> b
cl.Array(1.)
>>> a * b
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/shared/home/kgk2/pack/virtual_envs/emirge/pyopencl/pyopencl/array.py", line 1161, in __mul__
self._elwise_multiply(result, self, other))
File "/shared/home/kgk2/pack/virtual_envs/emirge/pyopencl/pyopencl/array.py", line 183, in kernel_runner
knl = kernel_getter(*args, **kwargs)
File "/shared/home/kgk2/pack/virtual_envs/emirge/pyopencl/pyopencl/array.py", line 897, in _elwise_multiply
assert out.shape == b.shape
I.e. PyOpenCL doesn't support broadcasting.
from arraycontext.
I agree that this is inconsistent, however there's an elephant of a practicality in the room: How do you propose we recognize scalars?
>>> import pyopencl as cl
>>> ctx = cl.create_some_context()
>>> queue = cl.CommandQueue(ctx)
>>> import pyopencl.array as clas
>>> import pyopencl.array as cla
>>> import numpy as np
>>> one = cla.to_device(queue, np.ones(()))
>>> np.isscalar(one)
False
>>> from numbers import Number
>>> isinstance(one, Number)
False
A shot-in-the-dark .shape == ()
?
from arraycontext.
How do you propose we recognize scalars?
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.
foo = Foo(DOFArray(actx, (actx.zeros(3, dtype=np.float64) + 41, )))
foo + cla.zeros(cq, (3,))
from arraycontext.
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.
from arraycontext.
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
from arraycontext.
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):
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?
from arraycontext.
Want to put together a PR so we can see what it might look like?
Yup. Thanks for considering this.
from arraycontext.
+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
).
from arraycontext.
Let's take the PyOpenCL discussion here: inducer/pyopencl#498
from arraycontext.
See #51 for work by @kaushikcfd towards solving this.
from arraycontext.
Related Issues (20)
- Handling temperature initial guesses
- Deprecate `is_array_container` HOT 7
- CI failing in mypy HOT 1
- `actx.compile` for pytato should allow things that are not array containers HOT 2
- Dealing with constants in `freeze`
- `arraycontext.container.to_numpy` semantics HOT 8
- Issues with `zeros` et al functions of array contexts HOT 4
- Make it so array containers do not know their array context? HOT 8
- Make a way to ensure we always use the actx's allocator
- Regression: "Out of host memory" on Nvidia ICD HOT 4
- Exposing `np.select`? HOT 1
- Function outlining errors in mirgecom
- Add optional `allow_single_version` Boolean arg to `actx.compile` HOT 12
- Precision: What actually do `freeze`/`thaw` mean?
- `(zeros|ones|full)_like` and `axes`/`tags` HOT 2
- `test_array_context_np_workalike` may be flaky
- Introduce a `-O0` mode to avoid full-blast code transformation for code that runs once
- Loopy a hard dependency? HOT 1
- eager arraycontext bug
- Renaming parts of partitioned DAGs HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arraycontext.