THCIndex.cuh 639 Bytes
Newer Older
rusty1s's avatar
rusty1s committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
template <typename a, int Dims>
struct IndexToOffset {
  static __device__ void compute(int i, const TensorInfo<a>& t1, int* t1Offset) {
    int curDimIndex;
    for (int d = Dims - 2; d >= 0; d--) {
      curDimIndex = i % t1.size[d];
      *t1Offset += curDimIndex * t1.stride[d];
      i /= t1.size[d];
    }
  }
};

template <typename a>
struct IndexToOffset<a, -1> {
  static __device__ void compute(int i, const TensorInfo<a>& t1, int* t1Offset) {
    int curDimIndex;
    for (int d = t1.dims - 2; d >= 0; d--) {
      curDimIndex = i % t1.size[d];
      *t1Offset += curDimIndex * t1.stride[d];
      i /= t1.size[d];
    }
  }
};