THCGrid.cu 639 Bytes
Newer Older
rusty1s's avatar
rusty1s committed
1
2
#include "THCGrid.h"

rusty1s's avatar
rusty1s committed
3
#include "common.cuh"
rusty1s's avatar
rusty1s committed
4
5
6
#include "THCNumerics.cuh"

template<typename T>
rusty1s's avatar
rusty1s committed
7
__global__ void gridKernel(int64_t *self, TensorInfo<T> posInfo, T *size,
rusty1s's avatar
rusty1s committed
8
                           int64_t *count, ptrdiff_t nNodes) {
rusty1s's avatar
rusty1s committed
9
  KERNEL_LOOP(i, nNodes) {
rusty1s's avatar
rusty1s committed
10
    T *pos = posInfo.data + i * posInfo.stride[0];
rusty1s's avatar
rusty1s committed
11
    int64_t coef = 1, value = 0;
rusty1s's avatar
rusty1s committed
12
13
    for (ptrdiff_t d = 0; d < posInfo.dims * posInfo.stride[1]; d += posInfo.stride[1]) {
      value += coef * THCNumerics<T>::floor(THCNumerics<T>::div(pos[d], size[d]));
rusty1s's avatar
rusty1s committed
14
15
      coef *= count[d];
    }
rusty1s's avatar
rusty1s committed
16
    self[i] = value;
rusty1s's avatar
rusty1s committed
17
18
19
  }
}

rusty1s's avatar
rusty1s committed
20
21
#include "generic/THCGrid.cu"
#include "THC/THCGenerateAllTypes.h"