library.py 20.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#
# \file generator.py
#
# \brief Generates the CUTLASS Library's instances
#

import re

###################################################################################################

import enum

# The following block implements enum.auto() for Python 3.5 variants that don't include it such
# as the default 3.5.2 on Ubuntu 16.04.
15
#
16 17 18
# https://codereview.stackexchange.com/questions/177309/reimplementing-pythons-enum-auto-for-compatibility

try:
19 20 21 22 23 24 25 26 27 28
    from enum import auto as enum_auto
except ImportError:
    __cutlass_library_auto_enum = 0

    def enum_auto() -> int:
        global __cutlass_library_auto_enum
        i = __cutlass_library_auto_enum
        __cutlass_library_auto_enum += 1
        return i

29 30 31 32 33

###################################################################################################

#
class GeneratorTarget(enum.Enum):
34 35 36
    Library = enum_auto()


37
#
38
GeneratorTargetNames = {GeneratorTarget.Library: "library"}
39 40 41 42 43 44
#

###################################################################################################

#
class DataType(enum.Enum):
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
    b1 = enum_auto()
    u4 = enum_auto()
    u8 = enum_auto()
    u16 = enum_auto()
    u32 = enum_auto()
    u64 = enum_auto()
    s4 = enum_auto()
    s8 = enum_auto()
    s16 = enum_auto()
    s32 = enum_auto()
    s64 = enum_auto()
    f16 = enum_auto()
    bf16 = enum_auto()
    f32 = enum_auto()
    tf32 = enum_auto()
    f64 = enum_auto()
    cf16 = enum_auto()
    cbf16 = enum_auto()
    cf32 = enum_auto()
    ctf32 = enum_auto()
    cf64 = enum_auto()
    cs4 = enum_auto()
    cs8 = enum_auto()
    cs16 = enum_auto()
    cs32 = enum_auto()
    cs64 = enum_auto()
    cu4 = enum_auto()
    cu8 = enum_auto()
    cu16 = enum_auto()
    cu32 = enum_auto()
    cu64 = enum_auto()
    invalid = enum_auto()

78 79 80

#
ShortDataTypeNames = {
81 82 83 84 85 86
    DataType.s32: "i",
    DataType.f16: "h",
    DataType.f32: "s",
    DataType.f64: "d",
    DataType.cf32: "c",
    DataType.cf64: "z",
87 88 89 90
}

#
DataTypeNames = {
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
    DataType.b1: "b1",
    DataType.u4: "u4",
    DataType.u8: "u8",
    DataType.u16: "u16",
    DataType.u32: "u32",
    DataType.u64: "u64",
    DataType.s4: "s4",
    DataType.s8: "s8",
    DataType.s16: "s16",
    DataType.s32: "s32",
    DataType.s64: "s64",
    DataType.f16: "f16",
    DataType.bf16: "bf16",
    DataType.f32: "f32",
    DataType.tf32: "tf32",
    DataType.f64: "f64",
    DataType.cf16: "cf16",
    DataType.cbf16: "cbf16",
    DataType.cf32: "cf32",
    DataType.ctf32: "ctf32",
    DataType.cf64: "cf64",
    DataType.cu4: "cu4",
    DataType.cu8: "cu8",
    DataType.cu16: "cu16",
    DataType.cu32: "cu32",
    DataType.cu64: "cu64",
    DataType.cs4: "cs4",
    DataType.cs8: "cs8",
    DataType.cs16: "cs16",
    DataType.cs32: "cs32",
    DataType.cs64: "cs64",
122 123 124
}

DataTypeTag = {
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
    DataType.b1: "cutlass::uint1b_t",
    DataType.u4: "cutlass::uint4b_t",
    DataType.u8: "uint8_t",
    DataType.u16: "uint16_t",
    DataType.u32: "uint32_t",
    DataType.u64: "uint64_t",
    DataType.s4: "cutlass::int4b_t",
    DataType.s8: "int8_t",
    DataType.s16: "int16_t",
    DataType.s32: "int32_t",
    DataType.s64: "int64_t",
    DataType.f16: "cutlass::half_t",
    DataType.bf16: "cutlass::bfloat16_t",
    DataType.f32: "float",
    DataType.tf32: "cutlass::tfloat32_t",
    DataType.f64: "double",
    DataType.cf16: "cutlass::complex<cutlass::half_t>",
    DataType.cbf16: "cutlass::complex<cutlass::bfloat16_t>",
    DataType.cf32: "cutlass::complex<float>",
    DataType.ctf32: "cutlass::complex<cutlass::tfloat32_t>",
    DataType.cf64: "cutlass::complex<double>",
    DataType.cu4: "cutlass::complex<cutlass::uint4b_t>",
    DataType.cu8: "cutlass::complex<cutlass::uint8_t>",
    DataType.cu16: "cutlass::complex<cutlass::uint16_t>",
    DataType.cu32: "cutlass::complex<cutlass::uint32_t>",
    DataType.cu64: "cutlass::complex<cutlass::uint64_t>",
    DataType.cs4: "cutlass::complex<cutlass::int4b_t>",
    DataType.cs8: "cutlass::complex<cutlass::int8_t>",
    DataType.cs16: "cutlass::complex<cutlass::int16_t>",
    DataType.cs32: "cutlass::complex<cutlass::int32_t>",
    DataType.cs64: "cutlass::complex<cutlass::int64_t>",
156 157 158
}

DataTypeSize = {
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
    DataType.b1: 1,
    DataType.u4: 4,
    DataType.u8: 4,
    DataType.u16: 16,
    DataType.u32: 32,
    DataType.u64: 64,
    DataType.s4: 4,
    DataType.s8: 8,
    DataType.s16: 16,
    DataType.s32: 32,
    DataType.s64: 64,
    DataType.f16: 16,
    DataType.bf16: 16,
    DataType.f32: 32,
    DataType.tf32: 32,
    DataType.f64: 64,
    DataType.cf16: 32,
    DataType.cbf16: 32,
    DataType.cf32: 64,
    DataType.ctf32: 32,
    DataType.cf64: 128,
    DataType.cu4: 8,
    DataType.cu8: 16,
    DataType.cu16: 32,
    DataType.cu32: 64,
    DataType.cu64: 128,
    DataType.cs4: 8,
    DataType.cs8: 16,
    DataType.cs16: 32,
    DataType.cs32: 64,
    DataType.cs64: 128,
190 191 192 193 194 195
}

###################################################################################################

#
class ComplexTransform(enum.Enum):
196 197 198
    none = enum_auto()
    conj = enum_auto()

199 200 201

#
ComplexTransformTag = {
202 203
    ComplexTransform.none: "cutlass::ComplexTransform::kNone",
    ComplexTransform.conj: "cutlass::ComplexTransform::kConjugate",
204 205 206 207
}

#
RealComplexBijection = [
208 209 210
    (DataType.f16, DataType.cf16),
    (DataType.f32, DataType.cf32),
    (DataType.f64, DataType.cf64),
211 212 213 214
]

#
def is_complex(data_type):
215 216 217 218 219
    for r, c in RealComplexBijection:
        if data_type == c:
            return True
    return False

220 221 222

#
def get_complex_from_real(real_type):
223 224 225 226 227
    for r, c in RealComplexBijection:
        if real_type == r:
            return c
    return DataType.invalid

228 229 230

#
def get_real_from_complex(complex_type):
231 232 233 234 235
    for r, c in RealComplexBijection:
        if complex_type == c:
            return r
    return DataType.invalid

236 237 238

#
class ComplexMultiplyOp(enum.Enum):
239 240 241
    multiply_add = enum_auto()
    gaussian = enum_auto()

242 243 244 245 246

###################################################################################################

#
class MathOperation(enum.Enum):
247 248 249 250 251 252 253 254
    multiply_add = enum_auto()
    multiply_add_saturate = enum_auto()
    xor_popc = enum_auto()
    multiply_add_fast_bf16 = enum_auto()
    multiply_add_fast_f16 = enum_auto()
    multiply_add_complex = enum_auto()
    multiply_add_complex_gaussian = enum_auto()

255 256 257

#
MathOperationTag = {
258 259 260 261 262 263 264
    MathOperation.multiply_add: "cutlass::arch::OpMultiplyAdd",
    MathOperation.multiply_add_saturate: "cutlass::arch::OpMultiplyAddSaturate",
    MathOperation.xor_popc: "cutlass::arch::OpXorPopc",
    MathOperation.multiply_add_fast_bf16: "cutlass::arch::OpMultiplyAddFastBF16",
    MathOperation.multiply_add_fast_f16: "cutlass::arch::OpMultiplyAddFastF16",
    MathOperation.multiply_add_complex: "cutlass::arch::OpMultiplyAddComplex",
    MathOperation.multiply_add_complex_gaussian: "cutlass::arch::OpMultiplyAddGaussianComplex",
265 266 267 268 269 270
}

###################################################################################################

#
class LayoutType(enum.Enum):
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
    ColumnMajor = enum_auto()
    RowMajor = enum_auto()
    ColumnMajorInterleaved2 = enum_auto()
    RowMajorInterleaved2 = enum_auto()
    ColumnMajorInterleaved32 = enum_auto()
    RowMajorInterleaved32 = enum_auto()
    ColumnMajorInterleaved64 = enum_auto()
    RowMajorInterleaved64 = enum_auto()
    TensorNHWC = enum_auto()
    TensorNDHWC = enum_auto()
    TensorNCHW = enum_auto()
    TensorNGHWC = enum_auto()
    TensorNC4HW4 = enum_auto()
    TensorC4RSK4 = enum_auto()
    TensorNC8HW8 = enum_auto()
    TensorNC16HW16 = enum_auto()
    TensorNC32HW32 = enum_auto()
    TensorNC64HW64 = enum_auto()
    TensorC32RSK32 = enum_auto()
    TensorC64RSK64 = enum_auto()
    TensorK4RSC4 = enum_auto()
    TensorCK4RS4 = enum_auto()
    TensorCK8RS8 = enum_auto()
    TensorCK16RS16 = enum_auto()

296 297 298

#
LayoutTag = {
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
    LayoutType.ColumnMajor: "cutlass::layout::ColumnMajor",
    LayoutType.RowMajor: "cutlass::layout::RowMajor",
    LayoutType.ColumnMajorInterleaved2: "cutlass::layout::ColumnMajorInterleaved<2>",
    LayoutType.RowMajorInterleaved2: "cutlass::layout::RowMajorInterleaved<2>",
    LayoutType.ColumnMajorInterleaved32: "cutlass::layout::ColumnMajorInterleaved<32>",
    LayoutType.RowMajorInterleaved32: "cutlass::layout::RowMajorInterleaved<32>",
    LayoutType.ColumnMajorInterleaved64: "cutlass::layout::ColumnMajorInterleaved<64>",
    LayoutType.RowMajorInterleaved64: "cutlass::layout::RowMajorInterleaved<64>",
    LayoutType.TensorNHWC: "cutlass::layout::TensorNHWC",
    LayoutType.TensorNDHWC: "cutlass::layout::TensorNDHWC",
    LayoutType.TensorNCHW: "cutlass::layout::TensorNCHW",
    LayoutType.TensorNGHWC: "cutlass::layout::TensorNGHWC",
    LayoutType.TensorNC4HW4: "cutlass::layout::TensorNCxHWx<4>",
    LayoutType.TensorC4RSK4: "cutlass::layout::TensorCxRSKx<4>",
    LayoutType.TensorNC8HW8: "cutlass::layout::TensorNCxHWx<8>",
    LayoutType.TensorNC16HW16: "cutlass::layout::TensorNCxHWx<16>",
    LayoutType.TensorNC32HW32: "cutlass::layout::TensorNCxHWx<32>",
    LayoutType.TensorC32RSK32: "cutlass::layout::TensorCxRSKx<32>",
    LayoutType.TensorNC64HW64: "cutlass::layout::TensorNCxHWx<64>",
    LayoutType.TensorC64RSK64: "cutlass::layout::TensorCxRSKx<64>",
    LayoutType.TensorK4RSC4: "cutlass::layout::TensorKxRSCx<4>",
    LayoutType.TensorCK4RS4: "cutlass::layout::TensorCKxRSx<4>",
    LayoutType.TensorCK8RS8: "cutlass::layout::TensorCKxRSx<8>",
    LayoutType.TensorCK16RS16: "cutlass::layout::TensorCKxRSx<16>",
323 324 325 326
}

#
TransposedLayout = {
327 328 329 330 331 332 333 334 335
    LayoutType.ColumnMajor: LayoutType.RowMajor,
    LayoutType.RowMajor: LayoutType.ColumnMajor,
    LayoutType.ColumnMajorInterleaved2: LayoutType.RowMajorInterleaved2,
    LayoutType.RowMajorInterleaved2: LayoutType.ColumnMajorInterleaved2,
    LayoutType.ColumnMajorInterleaved32: LayoutType.RowMajorInterleaved32,
    LayoutType.RowMajorInterleaved32: LayoutType.ColumnMajorInterleaved32,
    LayoutType.ColumnMajorInterleaved64: LayoutType.RowMajorInterleaved64,
    LayoutType.RowMajorInterleaved64: LayoutType.ColumnMajorInterleaved64,
    LayoutType.TensorNHWC: LayoutType.TensorNHWC,
336 337 338 339
}

#
ShortLayoutTypeNames = {
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
    LayoutType.ColumnMajor: "n",
    LayoutType.ColumnMajorInterleaved32: "n2",
    LayoutType.ColumnMajorInterleaved32: "n32",
    LayoutType.ColumnMajorInterleaved64: "n64",
    LayoutType.RowMajor: "t",
    LayoutType.RowMajorInterleaved2: "t2",
    LayoutType.RowMajorInterleaved32: "t32",
    LayoutType.RowMajorInterleaved64: "t64",
    LayoutType.TensorNHWC: "nhwc",
    LayoutType.TensorNDHWC: "ndhwc",
    LayoutType.TensorNCHW: "nchw",
    LayoutType.TensorNGHWC: "nghwc",
    LayoutType.TensorNC4HW4: "nc4hw4",
    LayoutType.TensorC4RSK4: "c4rsk4",
    LayoutType.TensorNC8HW8: "nc8hw8",
    LayoutType.TensorNC16HW16: "nc16hw16",
    LayoutType.TensorNC32HW32: "nc32hw32",
    LayoutType.TensorNC64HW64: "nc64hw64",
    LayoutType.TensorC32RSK32: "c32rsk32",
    LayoutType.TensorC64RSK64: "c64rsk64",
    LayoutType.TensorK4RSC4: "k4rsc4",
    LayoutType.TensorCK4RS4: "ck4rs4",
    LayoutType.TensorCK8RS8: "ck8rs8",
    LayoutType.TensorCK16RS16: "ck16rs16",
364 365 366 367
}

#
ShortComplexLayoutNames = {
368 369 370 371
    (LayoutType.ColumnMajor, ComplexTransform.none): "n",
    (LayoutType.ColumnMajor, ComplexTransform.conj): "c",
    (LayoutType.RowMajor, ComplexTransform.none): "t",
    (LayoutType.RowMajor, ComplexTransform.conj): "h",
372 373 374 375 376
}

###################################################################################################
#
class OpcodeClass(enum.Enum):
377 378 379 380
    Simt = enum_auto()
    TensorOp = enum_auto()
    WmmaTensorOp = enum_auto()

381 382

OpcodeClassNames = {
383 384 385
    OpcodeClass.Simt: "simt",
    OpcodeClass.TensorOp: "tensorop",
    OpcodeClass.WmmaTensorOp: "wmma_tensorop",
386 387 388
}

OpcodeClassTag = {
389 390 391
    OpcodeClass.Simt: "cutlass::arch::OpClassSimt",
    OpcodeClass.TensorOp: "cutlass::arch::OpClassTensorOp",
    OpcodeClass.WmmaTensorOp: "cutlass::arch::OpClassWmmaTensorOp",
392 393 394 395 396 397
}

###################################################################################################

#
class OperationKind(enum.Enum):
398 399 400
    Gemm = enum_auto()
    Conv2d = enum_auto()

401 402

#
403
OperationKindNames = {OperationKind.Gemm: "gemm", OperationKind.Conv2d: "conv2d"}
404

405
#
406
class Target(enum.Enum):
407 408
    library = enum_auto()

409 410

ArchitectureNames = {
411 412 413 414 415 416
    50: "maxwell",
    60: "pascal",
    61: "pascal",
    70: "volta",
    75: "turing",
    80: "ampere",
417 418 419 420 421 422
}

###################################################################################################

#
def SubstituteTemplate(template, values):
423 424 425 426 427 428 429 430 431 432 433 434
    text = template
    changed = True
    while changed:
        changed = False
        for key, value in values.items():
            regex = "\\$\\{%s\\}" % key
            newtext = re.sub(regex, value, text)
            if newtext != text:
                changed = True
            text = newtext
    return text

435 436 437 438 439

###################################################################################################

#
class GemmKind(enum.Enum):
440 441 442 443 444 445 446 447
    Gemm = enum_auto()
    Sparse = enum_auto()
    Universal = enum_auto()
    PlanarComplex = enum_auto()
    PlanarComplexArray = enum_auto()
    SplitKParallel = enum_auto()
    GemvBatchedStrided = enum_auto()

448 449 450

#
GemmKindNames = {
451 452 453 454 455 456 457
    GemmKind.Gemm: "gemm",
    GemmKind.Sparse: "spgemm",
    GemmKind.Universal: "gemm",
    GemmKind.PlanarComplex: "gemm_planar_complex",
    GemmKind.PlanarComplexArray: "gemm_planar_complex_array",
    GemmKind.SplitKParallel: "gemm_split_k_parallel",
    GemmKind.GemvBatchedStrided: "gemv_batched_strided",
458 459 460 461
}

#
class EpilogueFunctor(enum.Enum):
462 463 464 465 466 467 468 469
    LinearCombination = enum_auto()
    LinearCombinationClamp = enum_auto()
    BiasAddLinearCombination = enum_auto()
    BiasAddLinearCombinationRelu = enum_auto()
    BiasAddLinearCombinationHSwish = enum_auto()
    BiasAddLinearCombinationClamp = enum_auto()
    BiasAddLinearCombinationReluClamp = enum_auto()
    BiasAddLinearCombinationHSwishClamp = enum_auto()
470 471 472 473


#
EpilogueFunctorTag = {
474 475 476 477 478 479 480 481
    EpilogueFunctor.LinearCombination: "cutlass::epilogue::thread::LinearCombination",
    EpilogueFunctor.LinearCombinationClamp: "cutlass::epilogue::thread::LinearCombinationClamp",
    EpilogueFunctor.BiasAddLinearCombination: "cutlass::epilogue::thread::BiasAddLinearCombination",
    EpilogueFunctor.BiasAddLinearCombinationRelu: "cutlass::epilogue::thread::BiasAddLinearCombinationRelu",
    EpilogueFunctor.BiasAddLinearCombinationHSwish: "cutlass::epilogue::thread::BiasAddLinearCombinationHSwish",
    EpilogueFunctor.BiasAddLinearCombinationClamp: "cutlass::epilogue::thread::BiasAddLinearCombinationClamp",
    EpilogueFunctor.BiasAddLinearCombinationReluClamp: "cutlass::epilogue::thread::BiasAddLinearCombinationReluClamp",
    EpilogueFunctor.BiasAddLinearCombinationHSwishClamp: "cutlass::epilogue::thread::BiasAddLinearCombinationHSwishClamp",
482 483 484 485
}

#
ShortEpilogueNames = {
486 487 488 489 490 491
    EpilogueFunctor.BiasAddLinearCombinationHSwishClamp: "hswish",
    EpilogueFunctor.BiasAddLinearCombinationReluClamp: "relu",
    EpilogueFunctor.BiasAddLinearCombinationClamp: "id",
    EpilogueFunctor.BiasAddLinearCombinationHSwish: "hswish",
    EpilogueFunctor.BiasAddLinearCombinationRelu: "relu",
    EpilogueFunctor.BiasAddLinearCombination: "id",
492 493 494 495 496
}


#
class SwizzlingFunctor(enum.Enum):
497 498 499 500 501 502 503 504 505 506 507 508
    Identity1 = enum_auto()
    Identity2 = enum_auto()
    Identity4 = enum_auto()
    Identity8 = enum_auto()
    ConvFpropNCxHWx = enum_auto()
    ConvFpropTrans = enum_auto()
    ConvDgradNCxHWx = enum_auto()
    ConvDgradTrans = enum_auto()
    DepthwiseConvolutionFprop = enum_auto()
    DepthwiseConvolutionDgrad = enum_auto()
    DepthwiseConvolutionWgrad = enum_auto()

509 510 511

#
SwizzlingFunctorTag = {
512 513 514 515 516 517 518 519 520 521 522
    SwizzlingFunctor.Identity1: "cutlass::gemm::threadblock::GemmIdentityThreadblockSwizzle<1>",
    SwizzlingFunctor.Identity2: "cutlass::gemm::threadblock::GemmIdentityThreadblockSwizzle<2>",
    SwizzlingFunctor.Identity4: "cutlass::gemm::threadblock::GemmIdentityThreadblockSwizzle<4>",
    SwizzlingFunctor.Identity8: "cutlass::gemm::threadblock::GemmIdentityThreadblockSwizzle<8>",
    SwizzlingFunctor.ConvFpropNCxHWx: "cutlass::conv::threadblock::ConvolutionFpropNCxHWxThreadblockSwizzle",
    SwizzlingFunctor.ConvFpropTrans: "cutlass::conv::threadblock::ConvolutionFpropTransThreadblockSwizzle",
    SwizzlingFunctor.ConvDgradNCxHWx: "cutlass::conv::threadblock::ConvolutionDgradNCxHWxThreadblockSwizzle",
    SwizzlingFunctor.ConvDgradTrans: "cutlass::conv::threadblock::ConvolutionDgradTransThreadblockSwizzle",
    SwizzlingFunctor.DepthwiseConvolutionFprop: "cutlass::conv::threadblock::DepthwiseConvolutionFpropThreadblockSwizzle",
    SwizzlingFunctor.DepthwiseConvolutionDgrad: "cutlass::conv::threadblock::DepthwiseConvolutionDgradThreadblockSwizzle",
    SwizzlingFunctor.DepthwiseConvolutionWgrad: "cutlass::conv::threadblock::DepthwiseConvolutionWgradThreadblockSwizzle",
523 524 525 526
}

###################################################################################################

527

528
class ConvType(enum.Enum):
529 530 531 532 533 534
    Convolution = enum_auto()
    BatchConvolution = enum_auto()
    Local = enum_auto()
    LocalShare = enum_auto()
    DepthwiseConvolution = enum_auto()

535 536

ConvTypeTag = {
537 538 539 540 541
    ConvType.Convolution: "cutlass::conv::ConvType::kConvolution",
    ConvType.BatchConvolution: "cutlass::conv::ConvType::kBatchConvolution",
    ConvType.Local: "cutlass::conv::ConvType::kLocal",
    ConvType.LocalShare: "cutlass::conv::ConvType::kLocalShare",
    ConvType.DepthwiseConvolution: "cutlass::conv::ConvType::kDepthwiseConvolution",
542 543 544 545
}

#
class ConvKind(enum.Enum):
546 547 548 549
    Fprop = enum_auto()
    Dgrad = enum_auto()
    Wgrad = enum_auto()

550 551 552

#
ConvKindTag = {
553 554 555
    ConvKind.Fprop: "cutlass::conv::Operator::kFprop",
    ConvKind.Dgrad: "cutlass::conv::Operator::kDgrad",
    ConvKind.Wgrad: "cutlass::conv::Operator::kWgrad",
556 557 558
}

ConvKindNames = {
559 560 561
    ConvKind.Fprop: "fprop",
    ConvKind.Dgrad: "dgrad",
    ConvKind.Wgrad: "wgrad",
562 563 564 565
}

#
class IteratorAlgorithm(enum.Enum):
566 567 568
    Analytic = enum_auto()
    Optimized = enum_auto()

569 570 571

#
IteratorAlgorithmTag = {
572 573
    IteratorAlgorithm.Analytic: "cutlass::conv::IteratorAlgorithm::kAnalytic",
    IteratorAlgorithm.Optimized: "cutlass::conv::IteratorAlgorithm::kOptimized",
574 575 576
}

IteratorAlgorithmNames = {
577 578
    IteratorAlgorithm.Analytic: "analytic",
    IteratorAlgorithm.Optimized: "optimized",
579 580 581 582
}

#
class StrideSupport(enum.Enum):
583 584 585
    Strided = enum_auto()
    Unity = enum_auto()

586 587 588

#
StrideSupportTag = {
589 590
    StrideSupport.Strided: "cutlass::conv::StrideSupport::kStrided",
    StrideSupport.Unity: "cutlass::conv::StrideSupport::kUnity",
591 592
}

593 594
StrideSupportNames = {StrideSupport.Strided: "", StrideSupport.Unity: "unity_stride"}

595

596
class SpecialOptimizeDesc(enum.Enum):
597 598 599 600
    NoneSpecialOpt = enum_auto()
    ConvFilterUnity = enum_auto()
    DeconvDoubleUpsampling = enum_auto()

601 602

SpecialOptimizeDescNames = {
603 604 605
    SpecialOptimizeDesc.NoneSpecialOpt: "none",
    SpecialOptimizeDesc.ConvFilterUnity: "conv_filter_unity",
    SpecialOptimizeDesc.DeconvDoubleUpsampling: "deconv_double_upsampling",
606 607 608
}

SpecialOptimizeDescTag = {
609 610 611
    SpecialOptimizeDesc.NoneSpecialOpt: "cutlass::conv::SpecialOptimizeDesc::NONE",
    SpecialOptimizeDesc.ConvFilterUnity: "cutlass::conv::SpecialOptimizeDesc::CONV_FILTER_UNITY",
    SpecialOptimizeDesc.DeconvDoubleUpsampling: "cutlass::conv::SpecialOptimizeDesc::DECONV_DOUBLE_UPSAMPLING",
612 613 614
}


615
class ImplicitGemmMode(enum.Enum):
616 617 618
    GemmNT = enum_auto()
    GemmTN = enum_auto()

619 620

ImplicitGemmModeNames = {
621 622
    ImplicitGemmMode.GemmNT: "gemm_nt",
    ImplicitGemmMode.GemmTN: "gemm_tn",
623 624 625
}

ImplicitGemmModeTag = {
626 627
    ImplicitGemmMode.GemmNT: "cutlass::conv::ImplicitGemmMode::GEMM_NT",
    ImplicitGemmMode.GemmTN: "cutlass::conv::ImplicitGemmMode::GEMM_TN",
628 629 630 631 632 633
}

###################################################################################################

#
class MathInstruction:
634 635 636 637 638 639 640 641 642 643 644 645 646 647 648
    def __init__(
        self,
        instruction_shape,
        element_a,
        element_b,
        element_accumulator,
        opcode_class,
        math_operation=MathOperation.multiply_add,
    ):
        self.instruction_shape = instruction_shape
        self.element_a = element_a
        self.element_b = element_b
        self.element_accumulator = element_accumulator
        self.opcode_class = opcode_class
        self.math_operation = math_operation
649 650 651 652


#
class TileDescription:
653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675
    def __init__(
        self,
        threadblock_shape,
        stages,
        warp_count,
        math_instruction,
        min_compute,
        max_compute,
    ):
        self.threadblock_shape = threadblock_shape
        self.stages = stages
        self.warp_count = warp_count
        self.math_instruction = math_instruction
        self.minimum_compute_capability = min_compute
        self.maximum_compute_capability = max_compute

    def procedural_name(self):
        return "%dx%d_%dx%d" % (
            self.threadblock_shape[0],
            self.threadblock_shape[1],
            self.threadblock_shape[2],
            self.stages,
        )
676 677 678 679


#
class TensorDescription:
680 681 682 683 684 685 686 687
    def __init__(
        self, element, layout, alignment=1, complex_transform=ComplexTransform.none
    ):
        self.element = element
        self.layout = layout
        self.alignment = alignment
        self.complex_transform = complex_transform

688 689

###################################################################################################
690

691

692
class GlobalCnt:
693
    cnt = 0