SIMD array append idiom

33 views
Skip to first unread message

mcmc...@gmail.com

unread,
Aug 19, 2021, 4:08:05 PM8/19/21
to Intel SPMD Program Compiler Users
I have a case where I want to write something like this:

uniform int* uniform array = ...;
uniform int offset = 0;
foreach(x = ...) {
    if ( should_append(x) ) {
        array[offset++] = x;
    }
}

... but of course, that doesn't compile. 

Is there an idiom for doing this in ISPC?  It seems like it would be possible with some combination of broadcast()-like operations but I can't quite put my finger on it (and maybe it's simply just not practical).

I'm thinking of something like:

foreach(x = ...) {
    if ( should_append(x) ) {
        int varying_offset = some_incrementing_magic(offset);
        array[varying_offset] = x;
    }
}
... where each lane computes its own (unique) array offset based on the results of the gang.

Thanks in advance,
Mike

Dmitry Babokin

unread,
Aug 19, 2021, 4:15:36 PM8/19/21
to ispc-...@googlegroups.com
Mike,

I'm not sure that I understand your question correctly. Are you trying to pick some lanes of varying computations (i.e. based on should_append(x) selector) and serialize them in an array?


Dmitry.

PS It's preferred to post questions on https://github.com/ispc/ispc/discussions - it has wider reach and more chances to get answered.

--
You received this message because you are subscribed to the Google Groups "Intel SPMD Program Compiler Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ispc-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ispc-users/a5338031-900c-4605-90bd-7849a02c2bf0n%40googlegroups.com.

mcmc...@gmail.com

unread,
Aug 19, 2021, 4:27:25 PM8/19/21
to Intel SPMD Program Compiler Users
That looks like exactly what I am looking for.  I've scanned that document several times and somehow overlooked that section.   Thanks!
Reply all
Reply to author
Forward
0 new messages