kernel.cu 1.19 KB
Newer Older
rusty1s's avatar
rusty1s committed
1
2
3
4
#include <THC.h>

#include "kernel.h"

rusty1s's avatar
rusty1s committed
5
6
7
#include "common.cuh"
#include "THCIndex.cuh"

rusty1s's avatar
bugfix  
rusty1s committed
8
#define cluster_(NAME) TH_CONCAT_4(cluster_, NAME, _kernel_, Real)
rusty1s's avatar
rusty1s committed
9
#define thc_(NAME) TH_CONCAT_4(thc_, NAME, _, Real)
rusty1s's avatar
rusty1s committed
10

rusty1s's avatar
rusty1s committed
11
#include "generic/common.cu"
rusty1s's avatar
rusty1s committed
12
#include "THCGenerateAllTypes.h"
rusty1s's avatar
rusty1s committed
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

template<typename Real, int Dims>
__global__ void gridKernel(int64_t *output, TensorInfo<Real> position, Real *size, int64_t *count, const int C, const int N) {
  KERNEL_LOOP(i, N) {
    int positionOffset = 0;
    IndexToOffset<Real, Dims>::compute(i, position, &positionOffset);

    int tmp = C; int64_t c = 0;
    for (int d = 0; d < position.size[position.dims - 1]; d++) {
      tmp = tmp / count[d];
      c += tmp * (int64_t) (position.data[positionOffset + d] / size[d]);
    }
    output[i] = c;
  }
}

#include "generic/kernel.cu"
#include "THCGenerateFloatType.h"
#include "generic/kernel.cu"
#include "THCGenerateDoubleType.h"
#include "generic/kernel.cu"
#include "THCGenerateByteType.h"
#include "generic/kernel.cu"
#include "THCGenerateCharType.h"
#include "generic/kernel.cu"
#include "THCGenerateShortType.h"
#include "generic/kernel.cu"
#include "THCGenerateIntType.h"
#include "generic/kernel.cu"
#include "THCGenerateLongType.h"