cutensor.pxd 7.63 KB
Newer Older
root's avatar
root committed
1
2
3
4
5
6
7
8
9
10
11
12
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
from libc.stdint cimport int32_t, uint32_t, int64_t, uint64_t, intptr_t


###############################################################################
# Enum
###############################################################################

cpdef enum:
    # cutensorAlgo_t (values > 0 correspond to certain algorithms of GETT)
    ALGO_DEFAULT_PATIENT = -6  # NOQA, Uses the more accurate but also more time-consuming performance model
    ALGO_GETT = -4             # NOQA, Choose the GETT algorithm
    ALGO_TGETT = -3            # NOQA, Transpose (A or B) + GETT
    ALGO_TTGT = -2             # NOQA, Transpose-Transpose-GEMM-Transpose (requires additional memory)
    ALGO_DEFAULT = -1          # NOQA, Lets the internal heuristic choose

    # cutensorWorksizePreference_t
    WORKSPACE_MIN = 1          # NOQA, At least one algorithm will be available
    WORKSPACE_RECOMMENDED = 2  # NOQA, The most suitable algorithm will be available
    WORKSPACE_MAX = 3          # NOQA, All algorithms will be available

    # cutensorOperator_t (Unary)
    OP_IDENTITY = 1  # NOQA, Identity operator (i.e., elements are not changed)
    OP_SQRT = 2      # NOQA, Square root
    OP_RELU = 8      # NOQA, Rectified linear unit
    OP_CONJ = 9      # NOQA, Complex conjugate
    OP_RCP = 10      # NOQA, Reciprocal
    OP_SIGMOID = 11  # NOQA, y=1/(1+exp(-x))
    OP_TANH = 12     # NOQA, y=tanh(x)
    OP_EXP = 22      # NOQA, Exponentiation.
    OP_LOG = 23      # NOQA, Log (base e).
    OP_ABS = 24      # NOQA, Absolute value.
    OP_NEG = 25      # NOQA, Negation.
    OP_SIN = 26      # NOQA, Sine.
    OP_COS = 27      # NOQA, Cosine.
    OP_TAN = 28      # NOQA, Tangent.
    OP_SINH = 29     # NOQA, Hyperbolic sine.
    OP_COSH = 30     # NOQA, Hyperbolic cosine.
    OP_ASIN = 31     # NOQA, Inverse sine.
    OP_ACOS = 32     # NOQA, Inverse cosine.
    OP_ATAN = 33     # NOQA, Inverse tangent.
    OP_ASINH = 34    # NOQA, Inverse hyperbolic sine.
    OP_ACOSH = 35    # NOQA, Inverse hyperbolic cosine.
    OP_ATANH = 36    # NOQA, Inverse hyperbolic tangent.
    OP_CEIL = 37     # NOQA, Ceiling.
    OP_FLOOR = 38    # NOQA, Floor.

    # cutensorOperator_t (Binary)
    OP_ADD = 3  # NOQA, Addition of two elements
    OP_MUL = 5  # NOQA, Multiplication of two elements
    OP_MAX = 6  # NOQA, Maximum of two elements
    OP_MIN = 7  # NOQA, Minimum of two elements

    # cutensorStatus_t
    STATUS_SUCCESS = 0
    STATUS_NOT_INITIALIZED = 1
    STATUS_ALLOC_FAILED = 3
    STATUS_INVALID_VALUE = 7
    STATUS_ARCH_MISMATCH = 8  # NOQA, Indicates that the device is either not ready, or the target architecture is not supported.
    STATUS_MAPPING_ERROR = 11
    STATUS_EXECUTION_FAILED = 13
    STATUS_INTERNAL_ERROR = 14
    STATUS_NOT_SUPPORTED = 15
    STATUS_LICENSE_ERROR = 16
    STATUS_CUBLAS_ERROR = 17
    STATUS_CUDA_ERROR = 18
    STATUS_INSUFFICIENT_WORKSPACE = 19
    STATUS_INSUFFICIENT_DRIVER = 20  # NOQA, Indicates that the driver version is insufficient.
    STATUS_IO_ERROR = 21

    # cutensorComputeType_t
    # (*) compute types added in versoin 1.2
    COMPUTE_16F = 1     # NOQA, half
    COMPUTE_16BF = 1024  # NOQA, bfloat
    COMPUTE_TF32 = 4096  # NOQA, tensor-float-32
    COMPUTE_32F = 4     # NOQA, float
    COMPUTE_64F = 16    # NOQA, double
    COMPUTE_8U = 64    # NOQA, uint8
    COMPUTE_8I = 256   # NOQA, int8
    COMPUTE_32U = 128   # NOQA, uint32
    COMPUTE_32I = 512   # NOQA, int32
    # (*) compute types below will be deprecated in the furture release.
    R_MIN_16F = 1    # NOQA, real as a half
    C_MIN_16F = 2    # NOQA, complex as a half
    R_MIN_32F = 4    # NOQA, real as a float
    C_MIN_32F = 8    # NOQA, complex as a float
    R_MIN_64F = 16   # NOQA, real as a double
    C_MIN_64F = 32   # NOQA, complex as a double
    R_MIN_8U = 64   # NOQA, real as a uint8
    R_MIN_32U = 128  # NOQA, real as a uint32
    R_MIN_8I = 256  # NOQA, real as a int8
    R_MIN_32I = 512  # NOQA, real as a int32
    R_MIN_16BF = 1024  # NOQA, real as a bfloat16
    R_MIN_TF32 = 2048  # NOQA, real as a tensorfloat32
    C_MIN_TF32 = 4096  # NOQA, complex as a tensorfloat32


cpdef size_t get_version()


cdef class Handle:

    cdef void* _ptr


cdef class TensorDescriptor:

    cdef void* _ptr


cdef class ContractionDescriptor:

    cdef void* _ptr


cdef class ContractionFind:

    cdef void* _ptr


cdef class ContractionPlan:

    cdef void* _ptr


cpdef init(Handle handle)

cpdef initTensorDescriptor(
    Handle handle,
    TensorDescriptor desc,
    uint32_t numModes,
    intptr_t extent,
    intptr_t stride,
    int dataType,
    int unaryOp)

cpdef elementwiseTrinary(
    Handle handle,
    intptr_t alpha,
    intptr_t A,
    TensorDescriptor descA,
    intptr_t modeA,
    intptr_t beta,
    intptr_t B,
    TensorDescriptor descB,
    intptr_t modeB,
    intptr_t gamma,
    intptr_t C,
    TensorDescriptor descC,
    intptr_t modeC,
    intptr_t D,
    TensorDescriptor descD,
    intptr_t modeD,
    int opAB,
    int opABC,
    int typeScalar)

cpdef elementwiseBinary(
    Handle handle,
    intptr_t alpha,
    intptr_t A,
    TensorDescriptor descA,
    intptr_t modeA,
    intptr_t gamma,
    intptr_t C,
    TensorDescriptor descC,
    intptr_t modeC,
    intptr_t D,
    TensorDescriptor descD,
    intptr_t modeD,
    int opAC,
    int typeScalar)

cpdef permutation(
    Handle handle,
    intptr_t alpha,
    intptr_t A,
    TensorDescriptor descA,
    intptr_t modeA,
    intptr_t B,
    TensorDescriptor descB,
    intptr_t modeB,
    int typeScalar)

cpdef initContractionDescriptor(
    Handle handle,
    ContractionDescriptor desc,
    TensorDescriptor descA,
    intptr_t modeA,
    uint32_t alignmentRequirementA,
    TensorDescriptor descB,
    intptr_t modeB,
    uint32_t alignmentRequirementB,
    TensorDescriptor descC,
    intptr_t modeC,
    uint32_t alignmentRequirementC,
    TensorDescriptor descD,
    intptr_t modeD,
    uint32_t alignmentRequirementD,
    int computeType)

cpdef initContractionFind(
    Handle handle,
    ContractionFind find,
    int algo)

cpdef initContractionPlan(
    Handle handle,
    ContractionPlan plan,
    ContractionDescriptor desc,
    ContractionFind find,
    uint64_t workspaceSize)

cpdef contraction(
    Handle handle,
    ContractionPlan plan,
    intptr_t alpha,
    intptr_t A,
    intptr_t B,
    intptr_t beta,
    intptr_t C,
    intptr_t D,
    intptr_t workspace,
    uint64_t workspaceSize)

cpdef uint64_t contractionGetWorkspaceSize(
    Handle handle,
    ContractionDescriptor desc,
    ContractionFind find,
    int pref)

cpdef uint64_t contractionGetWorkspace(
    Handle handle,
    ContractionDescriptor desc,
    ContractionFind find,
    int pref)

cpdef int32_t contractionMaxAlgos()

cpdef reduction(
    Handle handle,
    intptr_t alpha,
    intptr_t A,
    TensorDescriptor descA,
    intptr_t modeA,
    intptr_t beta,
    intptr_t C,
    TensorDescriptor descC,
    intptr_t modeC,
    intptr_t D,
    TensorDescriptor descD,
    intptr_t modeD,
    int opReduce,
    int minTypeCompute,
    intptr_t workspace,
    uint64_t workspaceSize)

cpdef uint64_t reductionGetWorkspaceSize(
    Handle handle,
    intptr_t A,
    TensorDescriptor descA,
    intptr_t modeA,
    intptr_t C,
    TensorDescriptor descC,
    intptr_t modeC,
    intptr_t D,
    TensorDescriptor descD,
    intptr_t modeD,
    int opReduce,
    int typeCompute)

cpdef uint64_t reductionGetWorkspace(
    Handle handle,
    intptr_t A,
    TensorDescriptor descA,
    intptr_t modeA,
    intptr_t C,
    TensorDescriptor descC,
    intptr_t modeC,
    intptr_t D,
    TensorDescriptor descD,
    intptr_t modeD,
    int opReduce,
    int typeCompute)

cpdef uint32_t getAlignmentRequirement(
    Handle handle,
    intptr_t ptr,
    TensorDescriptor desc)