THCGraclus.cu 1.33 KB
Newer Older
rusty1s's avatar
rusty1s committed
1
2
3
4
5
6
7
8
#include "THCGraclus.h"

#include "common.cuh"
#include "THCDegree.cuh"
#include "THCColor.cuh"
#include "THCPropose.cuh"
#include "THCResponse.cuh"

rusty1s's avatar
rusty1s committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#define THC_TENSOR_GRACLUS(state, self, row, CODE) { \
  int nNodes = THCudaLongTensor_nElement(state, self); \
  THCudaLongTensor_fill(state, self, -1); \
\
  THCudaLongTensor *prop = THCudaLongTensor_newWithSize1d(state, nNodes); \
  THCudaLongTensor_fill(state, prop, -1); \
\
  THCudaLongTensor *degree = THCudaLongTensor_newWithSize1d(state, nNodes); \
  THCudaLongTensor_degree(state, degree, row); \
\
  THCudaLongTensor *cumDegree = THCudaLongTensor_newWithSize1d(state, nNodes); \
  THCudaLongTensor_cumDegree(state, cumDegree, row); \
\
  CODE \
\
  THCudaLongTensor_free(state, prop); \
  THCudaLongTensor_free(state, degree); \
  THCudaLongTensor_free(state, cumDegree); \
}

rusty1s's avatar
rusty1s committed
29
30
31
32
void THCTensor_graclus(THCState *state, THCudaLongTensor *self, THCudaLongTensor *row,
                       THCudaLongTensor *col) {
  THCAssertSameGPU(THCudaLongTensor_checkGPU(state, 3, self, row, col));

rusty1s's avatar
rusty1s committed
33
34
35
36
37
38
  THC_TENSOR_GRACLUS(state, self, row,
    while(!THCudaLongTensor_color(state, self)) {
      THCTensor_propose(state, self, prop, row, col, degree, cumDegree);
      THCTensor_response(state, self, prop, row, col, degree, cumDegree);
    }
  )
rusty1s's avatar
rusty1s committed
39
40
41
42
}

#include "generic/THCGraclus.cu"
#include "THC/THCGenerateAllTypes.h"