openclvexcl

VexCL Reshape Behaving Strangely


I have the following code snippet testing the VexCL reshape function:

std::vector<int> ints;
for (int i = 0; i < n; i++) ints.push_back(i);
vex::vector<int> vex_ints(ctx, ints);
vex_ints = vex::reshape(vex_ints, vex::extents[2][n/2], vex::extents[1][0]);
for(int i=0; i<n; i++) std::cout << vex_ints[i] << " "; std::cout << std::endl;

All it does is print the even integers that are less than n followed by the odd integers that are less than n. For example when n=10, it prints:

0 2 4 6 8 1 3 5 7 9 

But things behave strangely when n gets large. For example when n=10000, the first 50 printed integers are:

0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 128 132 136 140 144 148 152 156 160 164 168 172 176 180 184 188 192 196

Which starts to get it wrong after 62. There are other discrepancies further down the output, and some even numbers occur after odd numbers. Can anybody explain why this is happening? If it matters, the context I used was "GeForce GT 650M (Apple)".


Solution

  • The kernel that is generated from your expression uses vex_ints both for input and output. Since what vex::reshape does is basically a permutation, you can not do this in place. Please try to assign the result to a different vector and see if this fixes the problem for you.