Hey Scott,
I think the problem here is that essentially you are nesting foreach loops,
which is not supported. The outer loop is using programCount and
programIndex and could essentially be rewritten as:
foreach (qbase = 0 ... qbase < N / nnodes )
{
int64 q = qbase;
...
}
Check out the Parallel Iteration Statements section in the docs.
It is also currently illegal to have nested foreach statements; this
> limitation will be removed in a future release of ispc.
>
Cheers,
Pete
On Wednesday, September 19, 2018 at 11:23:37 PM UTC-7, Scott Pakin wrote:
>
> I'm using ISPC to optimize some code written by a colleague. Here's a
> snippet of ISPC code that works correctly:
>
> extern uniform int64 N, nnodes;
> extern uniform float *uniform c;
>
> export void SWAP_helper (uniform int64 qubit1, uniform int64 qubit2) {
> for (uniform int64 qbase = 0; qbase < N/nnodes; qbase += programCount) {
> int64 q = qbase + programIndex;
> int64 x = q;
> int64 b1 = (x>>qubit1)&1ll;
> int64 b2 = (x>>qubit2)&1ll;
> cif (b1 != b2) {
> int64 y = (x^(1ll<<qubit1))^(1ll<<qubit2);
> cif (y > x) {
> float aux[2];
> aux[0] = c[2*x + 0];
> aux[1] = c[2*x + 1];
> c[2*x + 0] = c[2*y + 0];
> c[2*x + 1] = c[2*y + 1];
> c[2*y + 0] = aux[0];
> c[2*y + 1] = aux[1];
> }
> }
> }
> }
>
>
> I then put the swap operation in a foreach loop:
>
> extern uniform int64 N, nnodes;
> extern uniform float *uniform c;
>
> export void SWAP_helper (uniform int64 qubit1, uniform int64 qubit2) {
> for (uniform int64 qbase = 0; qbase < N/nnodes; qbase += programCount) {
> int64 q = qbase + programIndex;
> int64 x = q;
> int64 b1 = (x>>qubit1)&1ll;
> int64 b2 = (x>>qubit2)&1ll;
> cif (b1 != b2) {
> int64 y = (x^(1ll<<qubit1))^(1ll<<qubit2);
> cif (y > x) {
> float aux[2];
> foreach (i = 0 ... 2) {
> aux[i] = c[2*x + i];
> c[2*x + i] = c[2*y + i];
> c[2*y + i] = aux[i];
> }
> }
> }
> }
> }
>
>
> To my surprise, the program then failed its verification checks. Am I
> doing something stupid, or is there something about foreach I'm
> misunderstanding?
>
> Thanks,
> — Scott
>
>
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.