Increase vectorization by increasing the used type up to maxVectorWidth. Example: input array with return value = 4, means that the array became array . Parameters - IN maxVectorWidth: maximum vectorisation desired - IN/OUT dims[4]: dimensions of the array - IN/OUT istrides[4]: strides of the input array - IN/OUT indims: ndims of the input array. Updates when dim[0] becomes 1 - IN/
| 49 | // - All the parameters are updated accordingly |
| 50 | // |
| 51 | static inline unsigned vectorizeShape(const unsigned maxVectorWidth, |
| 52 | int dims[4], int istrides[4], int& indims, |
| 53 | dim_t& ioffset, int ostrides[4], |
| 54 | dim_t& ooffset) { |
| 55 | unsigned vectorWidth{1}; |
| 56 | if ((maxVectorWidth != 1) & (istrides[0] == 1) & (ostrides[0] == 1)) { |
| 57 | // - Only adjacent items can be vectorized into a base vector type |
| 58 | // - global is the OR of the values to be checked. When global is |
| 59 | // divisable by 2, than all source values are also |
| 60 | // - The buffers are always aligned at 128 Bytes, so the alignment is |
| 61 | // only dependable on the offsets |
| 62 | dim_t global{dims[0] | ioffset | ooffset}; |
| 63 | for (int i{1}; i < indims; ++i) { global |= istrides[i] | ostrides[i]; } |
| 64 | |
| 65 | // Determine the maximum vectorization possible |
| 66 | unsigned count{0}; |
| 67 | while (((global & 1) == 0) & (vectorWidth < maxVectorWidth)) { |
| 68 | ++count; |
| 69 | vectorWidth <<= 1; |
| 70 | global >>= 1; |
| 71 | } |
| 72 | if (count != 0) { |
| 73 | // update the dimensions, to correspond with the new vectorization |
| 74 | dims[0] >>= count; |
| 75 | ioffset >>= count; |
| 76 | ooffset >>= count; |
| 77 | for (int i{1}; i < indims; ++i) { |
| 78 | istrides[i] >>= count; |
| 79 | ostrides[i] >>= count; |
| 80 | } |
| 81 | if (dims[0] == 1) { |
| 82 | // Vectorization has absorbed the full dim0, so eliminate |
| 83 | // the 1st dimension |
| 84 | --indims; |
| 85 | for (int i{0}; i < indims; ++i) { |
| 86 | dims[i] = dims[i + 1]; |
| 87 | istrides[i] = istrides[i + 1]; |
| 88 | ostrides[i] = ostrides[i + 1]; |
| 89 | } |
| 90 | dims[indims] = 1; |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | return vectorWidth; |
| 95 | } |
| 96 | |
| 97 | template<typename T> |
| 98 | void memcopy(const cl::Buffer& b_out, const dim4& ostrides, |