1

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)".

Ryan Vogan
  • 43
  • 3
  • 1
    Why `vex::extents[1][0]` on a 1D arrray? Should it be just `vex::extents[0]`? – DarkZeros Nov 02 '16 at 09:52
  • Well I'm defining the shape using the vex::extents objects. So in this case I'm telling it that the matrix is n/2 rows by 2 columns. I followed the matrix transposition example from the docs. – Ryan Vogan Nov 02 '16 at 14:38
  • It's under the reshaping section [here](http://vexcl.readthedocs.io/en/latest/expressions.html#reshaping) – Ryan Vogan Nov 02 '16 at 14:39
  • I understand that the `dst` format has to be `[2][n/2]`, but the `src` is a 1D vector not a 2D vector that you want to transpose. I am not fully confident with extents format so I might be wrong.... In my opinion should be just `vex::extents[0]` stating that you want 1D direct filling. – DarkZeros Nov 02 '16 at 14:44

1 Answers1

1

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.

ddemidov
  • 1,731
  • 13
  • 15