Skip to content

Commit 2a8cd1c

Browse files
committed
Add generic CudaTensor types to cutorch
1 parent db83396 commit 2a8cd1c

26 files changed

+817
-488
lines changed

CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,18 @@ INSTALL(FILES
135135
THCDeviceTensorUtils.cuh
136136
THCDeviceTensorUtils-inl.cuh
137137
DESTINATION "${THC_INSTALL_INCLUDE_SUBDIR}/THC")
138+
139+
INSTALL(FILES
140+
generic/THCStorage.c
141+
generic/THCStorage.cu
142+
generic/THCStorage.h
143+
generic/THCTensor.c
144+
generic/THCTensor.cu
145+
generic/THCTensor.h
146+
generic/THCStorageCopy.c
147+
generic/THCStorageCopy.cu
148+
generic/THCStorageCopy.h
149+
generic/THCTensorCopy.c
150+
generic/THCTensorCopy.cu
151+
generic/THCTensorCopy.h
152+
DESTINATION "${THC_INSTALL_INCLUDE_SUBDIR}/THC/generic")

THCGenerateAllTypes.h

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#ifndef THC_GENERIC_FILE
2+
#error "You must define THC_GENERIC_FILE before including THGenerateAllTypes.h"
3+
#endif
4+
5+
#define THCTypeIdxByte 1
6+
#define THCTypeIdxChar 2
7+
#define THCTypeIdxShort 3
8+
#define THCTypeIdxInt 4
9+
#define THCTypeIdxLong 5
10+
#define THCTypeIdxFloat 6
11+
#define THCTypeIdxDouble 7
12+
#define THCTypeIdx_(T) TH_CONCAT_2(THCTypeIdx,T)
13+
14+
#define real unsigned char
15+
#define accreal long
16+
#define Real Byte
17+
#define CReal CudaByte
18+
#define THC_REAL_IS_BYTE
19+
#line 1 THC_GENERIC_FILE
20+
/*#line 1 "THByteStorage.h"*/
21+
#include THC_GENERIC_FILE
22+
#undef real
23+
#undef accreal
24+
#undef Real
25+
#undef CReal
26+
#undef THC_REAL_IS_BYTE
27+
28+
#define real char
29+
#define accreal long
30+
#define Real Char
31+
#define CReal CudaChar
32+
#define THC_REAL_IS_CHAR
33+
#line 1 THC_GENERIC_FILE
34+
#include THC_GENERIC_FILE
35+
#undef real
36+
#undef accreal
37+
#undef Real
38+
#undef CReal
39+
#undef THC_REAL_IS_CHAR
40+
41+
#define real short
42+
#define accreal long
43+
#define Real Short
44+
#define CReal CudaShort
45+
#define THC_REAL_IS_SHORT
46+
#line 1 THC_GENERIC_FILE
47+
#include THC_GENERIC_FILE
48+
#undef real
49+
#undef accreal
50+
#undef Real
51+
#undef CReal
52+
#undef THC_REAL_IS_SHORT
53+
54+
#define real int
55+
#define accreal long
56+
#define Real Int
57+
#define CReal CudaInt
58+
#define THC_REAL_IS_INT
59+
#line 1 THC_GENERIC_FILE
60+
#include THC_GENERIC_FILE
61+
#undef real
62+
#undef accreal
63+
#undef Real
64+
#undef CReal
65+
#undef THC_REAL_IS_INT
66+
67+
#define real long
68+
#define accreal long
69+
#define Real Long
70+
#define CReal CudaLong
71+
#define THC_REAL_IS_LONG
72+
#line 1 THC_GENERIC_FILE
73+
#include THC_GENERIC_FILE
74+
#undef real
75+
#undef accreal
76+
#undef Real
77+
#undef CReal
78+
#undef THC_REAL_IS_LONG
79+
80+
#define real float
81+
#define accreal double
82+
#define Real Float
83+
#define CReal Cuda
84+
#define THC_REAL_IS_FLOAT
85+
#line 1 THC_GENERIC_FILE
86+
#include THC_GENERIC_FILE
87+
#undef real
88+
#undef accreal
89+
#undef Real
90+
#undef CReal
91+
#undef THC_REAL_IS_FLOAT
92+
93+
#define real double
94+
#define accreal double
95+
#define Real Double
96+
#define CReal CudaDouble
97+
#define THC_REAL_IS_DOUBLE
98+
#line 1 THC_GENERIC_FILE
99+
#include THC_GENERIC_FILE
100+
#undef real
101+
#undef accreal
102+
#undef Real
103+
#undef CReal
104+
#undef THC_REAL_IS_DOUBLE
105+
106+
#undef THCTypeIdxByte
107+
#undef THCTypeIdxChar
108+
#undef THCTypeIdxShort
109+
#undef THCTypeIdxInt
110+
#undef THCTypeIdxLong
111+
#undef THCTypeIdxFloat
112+
#undef THCTypeIdxDouble
113+
114+
#undef THC_GENERIC_FILE

THCStorage.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "THCStorage.h"
2+
#include "THCGeneral.h"
3+
#include "THAtomic.h"
4+
5+
#include "generic/THCStorage.c"
6+
#include "THCGenerateAllTypes.h"

THCStorage.cu

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include "THCStorage.h"
2+
3+
#include <thrust/device_ptr.h>
4+
#include <thrust/fill.h>
5+
#if CUDA_VERSION >= 7000
6+
#include <thrust/system/cuda/execution_policy.h>
7+
#endif
8+
9+
#include "generic/THCStorage.cu"
10+
#include "THCGenerateAllTypes.h"

THCStorage.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef THC_STORAGE_INC
2+
#define THC_STORAGE_INC
3+
4+
#include "THStorage.h"
5+
#include "THCGeneral.h"
6+
7+
#define THCStorage TH_CONCAT_3(TH,CReal,Storage)
8+
#define THCStorage_(NAME) TH_CONCAT_4(TH,CReal,Storage_,NAME)
9+
10+
/* fast access methods */
11+
#define THC_STORAGE_GET(storage, idx) ((storage)->data[(idx)])
12+
#define THC_STORAGE_SET(storage, idx, value) ((storage)->data[(idx)] = (value))
13+
14+
#include "generic/THCStorage.h"
15+
#include "THCGenerateAllTypes.h"
16+
17+
#endif

THCStorageCopy.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include "THCStorageCopy.h"
2+
#include "THCGeneral.h"
3+
4+
#include "generic/THCStorageCopy.c"
5+
#include "THCGenerateAllTypes.h"

THCStorageCopy.cu

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include "THCStorageCopy.h"
2+
#include "THCGeneral.h"
3+
4+
#include "generic/THCStorageCopy.cu"
5+
#include "THCGenerateAllTypes.h"

THCStorageCopy.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef THC_STORAGE_COPY_INC
2+
#define THC_STORAGE_COPY_INC
3+
4+
#include "THCStorage.h"
5+
#include "THCGeneral.h"
6+
7+
#include "generic/THCStorageCopy.h"
8+
#include "THCGenerateAllTypes.h"
9+
10+
#endif

THCTensor.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "THCGeneral.h"
2+
#include "THCTensor.h"
3+
#include "THCTensorCopy.h"
4+
#include "THAtomic.h"
5+
6+
#include "generic/THCTensor.c"
7+
#include "THCGenerateAllTypes.h"

THCTensor.cu

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#include "THCTensor.h"
2+
3+
#include "generic/THCTensor.cu"
4+
#include "THCGenerateAllTypes.h"

0 commit comments

Comments
 (0)