[Mesa-dev] [PATCH 1/2] nir: Add is_divergent_vector search helper
Jason Ekstrand
jason at jlekstrand.net
Tue May 7 14:36:57 UTC 2019
On Tue, May 7, 2019 at 9:28 AM Ilia Mirkin <imirkin at alum.mit.edu> wrote:
> Divergence is generally when multiple parallel "lanes" go in different
> directions -- a jump that some lanes take and others don't, which
> requires the GPU to execute some lanes first, and then the rest,
> separately.
>
> IMO better names might be is_scalar_swizzle or something.
>
I was going to make roughly the same comment but couldn't come up with a
good name suggestion. I like is_scalar_swizzle. :-D
> On Mon, May 6, 2019 at 11:00 PM Alyssa Rosenzweig <alyssa at rosenzweig.io>
> wrote:
> >
> > This allows algebraic optimizations to check if the argument accesses
> > multiple distinct components of a vector. So a swizzle like "xyz" will
> > return true, but "yyy" will return false, as will a scalar. This can be
> > useful for optimizations on vector processors, where a convergent
> > swizzle can be done in one clock (replicating as if a scalar) but a
> > divergent one must be scalarized. In these cases, it is useful to
> > optimize differently based on whether the swizzle diverges. (Use case is
> > the "csel" condition on Midgard).
> >
> > Signed-off-by: Alyssa Rosenzweig <alyssa at rosenzweig.io>
> > Cc: Jason Ekstrand <jason at jlekstrand.net>
> > ---
> > src/compiler/nir/nir_search_helpers.h | 16 ++++++++++++++++
> > 1 file changed, 16 insertions(+)
> >
> > diff --git a/src/compiler/nir/nir_search_helpers.h
> b/src/compiler/nir/nir_search_helpers.h
> > index 1624508993d..46d7c300643 100644
> > --- a/src/compiler/nir/nir_search_helpers.h
> > +++ b/src/compiler/nir/nir_search_helpers.h
> > @@ -143,6 +143,22 @@ is_not_const(nir_alu_instr *instr, unsigned src,
> UNUSED unsigned num_components,
> > return !nir_src_is_const(instr->src[src].src);
> > }
> >
> > +/* I.e. a vector that actually accesses multiple channels */
> > +
> > +static inline bool
> > +is_divergent_vector(nir_alu_instr *instr, UNUSED unsigned src, unsigned
> num_components,
> > + const uint8_t *swizzle)
> > +{
> > + unsigned first_component = swizzle[0];
> > +
> > + for (unsigned i = 1; i < num_components; ++i) {
> > + if (swizzle[i] != first_component)
> > + return true;
> > + }
>
> Can num_components be 1? If so, then this will return false, whereas
> you probably wanted it to return true.
>
Yes, it can. Good catch!
> > +
> > + return false;
> > +}
> > +
> > static inline bool
> > is_used_more_than_once(nir_alu_instr *instr)
> > {
> > --
> > 2.20.1
> >
> > _______________________________________________
> > mesa-dev mailing list
> > mesa-dev at lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/mesa-dev
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20190507/88e96821/attachment.html>
More information about the mesa-dev
mailing list