File: library_defaults.py

package info (click to toggle)
nvidia-cutlass 3.4.1%2Bds-2
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid, trixie
  • size: 48,488 kB
  • sloc: cpp: 206,571; ansic: 69,215; python: 25,487; sh: 16; makefile: 15
file content (566 lines) | stat: -rw-r--r-- 26,509 bytes parent folder | download
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
#################################################################################################
#
# Copyright (c) 2023 - 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#################################################################################################

"""
Classes containing valid operations for a given compute capability and data types.
"""

from itertools import combinations_with_replacement
import logging

from cuda import __version__
import cutlass_library
from cutlass_library.library import ConvKind, IteratorAlgorithm, StrideSupport, GroupMode

import cutlass
from cutlass.utils.check import valid_stage_count
from cutlass.utils.datatypes import td_from_profiler_td, td_from_profiler_op


_generator_ccs = [50, 60, 61, 70, 75, 80, 90]

# Strip any additional information from the CUDA version
_cuda_version = __version__.split("rc")[0]


class KernelsForDataType:
    """
    Container class for keeping track of kernels that correspond to a particular combination
    of data types for operands A, B, and accumulator
    """

    def __init__(self, datatype_comb: tuple, layout_comb: tuple):
        self.datatype_comb = datatype_comb
        self.layout_comb = layout_comb
        self.math_operations = set()

        # Dictionary mapping from alignment (int) to a list of kernels that fit the alignment
        # constraint for the data type combination
        self.kernels_by_alignment = {}

    def add(self, operation):
        """
        Add an operation to the list of supported kernels
        """
        alignment_key = f"{operation.A.alignment} {operation.B.alignment} {operation.C.alignment}"
        if alignment_key not in self.kernels_by_alignment:
            self.kernels_by_alignment[alignment_key] = []
        self.kernels_by_alignment[alignment_key].append(operation)
        self.math_operations.add(operation.tile_description.math_instruction.math_operation)

    def alignments(self, operand: str):
        """
        Returns an unsorted list of alignments supported by this data type combination

        :param operand: identifier of operand in question (e.g., A, B, C)
        :type operand: str

        :return: unsorted list of alignments supported by this data type combination
        :rtype: list
        """
        operand_idx = self._operand_idx(operand)
        return [int(key.split(" ")[operand_idx]) for key in self.kernels_by_alignment.keys()]

    @property
    def all_operations(self):
        """
        Returns a list of all operations supported by this data type combination

        :return: list of all operations supported by this data type combination
        :rtype: list
        """
        ops = []
        for _, alignment_ops in self.kernels_by_alignment.items():
            ops.extend(alignment_ops)
        return ops

    def default_operation(self, math_operation: cutlass.MathOperation):
        key = sorted(list(self.kernels_by_alignment.keys()))[0]
        kernels = self.kernels_by_alignment[key]
        if math_operation is not None:
            kernels = [x for x in kernels if x.tile_description.math_instruction.math_operation == math_operation]
        return kernels[0]

    def operations(self, alignment_A: int, alignment_B: int, alignment_C: int, math_operation: cutlass.MathOperation):
        """
        Returns operations satisfying the alignment constraints

        :param alignment_A: alignment constraint of operations to return
        :type alignment_A: int
        :param alignment_B: alignment constraint of operations to return
        :type alignment_B: int
        :param alignment_C: alignment constraint of operations to return
        :type alignment_C: int
        :param math_operation: math operation to consider
        :type math_operation: cutlass.MathOperation

        :return: list of operations
        :rtype: list
        """
        key = f"{alignment_A} {alignment_B} {alignment_C}"

        if key not in self.kernels_by_alignment:
            og_key = key
            # Reconcile A, B, and C alignments by trying to align to the minimum
            min_alignment = min(alignment_A, alignment_B, alignment_C)
            key = f"{min_alignment} {min_alignment} {min_alignment}"
            if key not in self.kernels_by_alignment:
                # Finally, go through all available alignment combinations and find
                # one for which all values are less than those passed in.
                key = None
                alignments = sorted([(int(x) for x in k.split(" ")) for k in self.kernels_by_alignment.keys()], reverse=True)
                for align_A, align_B, align_C in alignments:
                    if align_A <= alignment_A and align_B <= alignment_B and align_C <= alignment_C:
                        key = f"{align_A} {align_B} {align_C}"
                        break

                if key is None:
                    raise Exception(
                        f"No operations of alignment {og_key} found for data type and layout "
                        f"combination {self.datatype_comb} {self.layout_comb}. Compatible alignments "
                        f"are {self.kernels_by_alignment.keys()}"
                    )

        ops = self.kernels_by_alignment[key]
        if math_operation is not None:
            ops = [op for op in ops if op.tile_description.math_instruction.math_operation == math_operation]
        return ops

    def _operand_idx(self, key: str) -> int:
        operand_list = ["A", "B", "C"]
        if key not in operand_list:
            raise Exception(f"Unexpected operand {operand}")

        return operand_list.index(key)

    def find_alignment(self, shape: tuple, layout: cutlass.LayoutType, operand=str) -> int:
        """
        Returns the most preferable alignment for a given shape and layout

        :param shape: extent of each dimension of the tensor
        :type shape: tuple
        :param layout: layout of the tensor
        :type layout: cutlass.LayoutType
        :param operand: descriptor of the operand in question
        :type operand: str

        :return: maximum alignment supported by the data type combination and tensor size
        :rtype: int
        """
        operand_idx = self._operand_idx(operand)

        # Determine the leading dimension of the shape
        if layout == cutlass.LayoutType.ColumnMajor:
            ld = shape[-2]
        elif layout == cutlass.LayoutType.RowMajor:
            ld = shape[-1]
        elif layout == cutlass.LayoutType.TensorNHWC:
            ld = shape[-1]
        else:
            raise Exception(f"Unexpected or unsupported layout {layout}")

        for alignments in sorted(list(self.kernels_by_alignment.keys()), reverse=True):
            alignment = int(alignments.split(" ")[operand_idx])
            if ld % alignment == 0:
                return alignment

        # Default to alignment of 1 if no others match
        return 1

    def sort(self):
        """
        Sorts each list of kernels in `kernels_by_alignment` in descending order of threadblock shape
        """
        key = lambda op: (
            op.tile_description.threadblock_shape[0]
            * op.tile_description.threadblock_shape[1]
            * op.tile_description.threadblock_shape[2]
        )
        for alignment in self.kernels_by_alignment.keys():
            self.kernels_by_alignment[alignment].sort(key=key, reverse=True)

    def supports_math_operation(self, math_operation: cutlass.MathOperation) -> bool:
        """
        Returns whether `math_operation` is supported by at least one operation.

        :param math_operation: math operation to consider
        :type math_operation: cutlass.MathOperation

        :return: whether math_operation is supported by at least one operation
        :rtype: bool
        """
        return math_operation is None or math_operation in self.math_operations


class ArchOptions:
    """
    Structure for keeping track of kernels available on a given compute capability

    :param target_cc: compute capability of the device on which kernels will be run
    :type target_cc: int
    :param kernel_cc: compute capability of the kernels to generate
    :type kernel_cc: int
    :param operation_kind: type of operation to register
    :type operation_kind: cutlass_library.OperationKind
    :param gemm_kinds: types of GEMM operations that can be included
    :type gemm_kinds: list
    :param allowed_math_operations: types of primitive math operations allowed
    :type allowed_math_operations: list
    """

    def __init__(
        self,
        target_cc: int,
        kernel_cc: int,
        operation_kind: cutlass_library.OperationKind,
        gemm_kinds: list,
        allowed_math_operations: list = [
            cutlass_library.MathOperation.multiply_add,
            cutlass_library.MathOperation.multiply_add_saturate,
            cutlass_library.MathOperation.multiply_add_mixed_input_upcast,
            cutlass_library.MathOperation.multiply_add_fast_f32
        ]
    ):
        self.cc = kernel_cc

        # Dictionary with following structure:
        #  Key: OpcodeClass
        #  Value: Dictionary with the following structure:
        #     Key: tuple of ((DataType, DataType, DataType), (LayoutType, LayoutType, LayoutType),
        #          representing ((element_a, element_b, element_accumulator), (layout_a, layout_b))
        #     Value: KernelsForDataType
        self.operations_by_opclass = {}
        self.op_class = None
        self.allowed_math_operations = allowed_math_operations

        # Identify the method within CUTLASS generator script that generates kernel
        # descriptions for the target CC
        generate_function_name = "GenerateSM" + str(kernel_cc)
        if not hasattr(cutlass_library.generator, generate_function_name):
            cutlass.logger.warning(f"No generator found for architecture {kernel_cc}")
            return
        generate_function = getattr(cutlass_library.generator, generate_function_name)

        # Initialize a default manifest and populate it with valid kernel descriptions
        # for the target CC
        args = [
            "--kernels=all",
            f"--log-level={logging.getLevelName(cutlass.logger.level)}"
        ]
        manifest_args = cutlass_library.generator.define_parser().parse_args(args)
        manifest = cutlass_library.manifest.Manifest(manifest_args)
        generate_function(manifest, _cuda_version)

        if operation_kind not in manifest.operations:
            # No kernels generated for this architecture, this could be because the CUDA
            # toolkit is insufficient to support operations in this CC
            cutlass.logger.warning(f"No operations of type {operation_kind} found for CC {kernel_cc}")
            return

        # Only one CC should be returned, given the setup above of calling only the generation scripts
        # for a given CC
        if len(manifest.operations[operation_kind].keys()) != 1 or kernel_cc not in manifest.operations[operation_kind]:
            raise Exception(f"Error finding kernels for SM{kernel_cc}. Check that your CUDA toolkit version "
                             "is sufficient for the architecture in question.")

        # Iterate through the available operations for this operation kind and
        # find available opclasses and data types
        for name, op_list in manifest.operations[operation_kind][kernel_cc].items():
            for op in op_list:
                if operation_kind == cutlass_library.OperationKind.Gemm:
                    if op.gemm_kind not in gemm_kinds:
                        continue

                mi = op.tile_description.math_instruction
                if mi.math_operation not in self.allowed_math_operations:
                    continue

                # Prune operations that don't fit in shared memory
                td = td_from_profiler_op(op)
                if not valid_stage_count(target_cc, kernel_cc, td, verbose=False)[0]:
                    continue

                if mi.opcode_class not in self.operations_by_opclass:
                    self.operations_by_opclass[mi.opcode_class] = {}

                datatype_comb = (mi.element_a, mi.element_b, mi.element_accumulator)
                layout_comb = (op.A.layout, op.B.layout)

                # Register TF32 kernels as F32 to enable F32 -> TF32 conversion + TF32 Tensor Core operations
                if datatype_comb == (cutlass_library.DataType.tf32, cutlass_library.DataType.tf32, cutlass_library.DataType.f32):
                    # TF32 kernels only supported on SM80 and beyond
                    if self.cc < 80:
                        continue
                    elif self.cc == 90:
                        if (op.A.element != cutlass_library.DataType.f32
                            or op.B.element != cutlass_library.DataType.f32
                            or op.C.element != cutlass_library.DataType.f32):
                            continue

                    datatype_comb = (cutlass_library.DataType.f32, cutlass_library.DataType.f32, cutlass_library.DataType.f32)

                opclass_dict = self.operations_by_opclass[mi.opcode_class]
                key = (datatype_comb, layout_comb)
                if key not in opclass_dict:
                    opclass_dict[key] = KernelsForDataType(datatype_comb, layout_comb)
                opclass_dict[key].add(op)

        # Set the default opclass to TensorOp, if available. Otherwise default to SIMT
        if cutlass_library.OpcodeClass.TensorOp in self.operations_by_opclass:
            self.op_class = cutlass_library.OpcodeClass.TensorOp
        else:
            self.op_class = cutlass_library.OpcodeClass.Simt

        # The profiler's generator may generate only a limited set of combinations of operands for SIMT kernels.
        # Here, we generate additional versions via a generic TileDescription.
        if cutlass_library.OpcodeClass.Simt not in self.operations_by_opclass:
            self.operations_by_opclass[cutlass_library.OpcodeClass.Simt] = {}

        if operation_kind == cutlass_library.OperationKind.Gemm:
            types = [
                (cutlass_library.DataType.s8, cutlass_library.DataType.s8, cutlass_library.DataType.s8),
                (cutlass_library.DataType.s8, cutlass_library.DataType.s8, cutlass_library.DataType.s32),
                (cutlass_library.DataType.f16, cutlass_library.DataType.f16, cutlass_library.DataType.f16),
                (cutlass_library.DataType.f16, cutlass_library.DataType.f16, cutlass_library.DataType.f32),
                (cutlass_library.DataType.f32, cutlass_library.DataType.f32, cutlass_library.DataType.f32),
                (cutlass_library.DataType.f64, cutlass_library.DataType.f64, cutlass_library.DataType.f64),
            ]

            # Add FP8 A/B/C
            fp8_types = [cutlass_library.DataType.e4m3, cutlass_library.DataType.e5m2]
            for type_comb in combinations_with_replacement(fp8_types, 3):
                types.append(type_comb)

            # Add FP8 A/B with FP32 C
            for type_comb in combinations_with_replacement(fp8_types, 2):
                types.append(type_comb + (cutlass.DataType.f32,))

            layouts = [
                (cutlass_library.LayoutType.RowMajor, cutlass_library.LayoutType.RowMajor),
                (cutlass_library.LayoutType.RowMajor, cutlass_library.LayoutType.ColumnMajor),
                (cutlass_library.LayoutType.ColumnMajor, cutlass_library.LayoutType.RowMajor),
                (cutlass_library.LayoutType.ColumnMajor, cutlass_library.LayoutType.ColumnMajor),
            ]
        elif operation_kind == cutlass_library.OperationKind.Conv2d:
            types = [
                (cutlass_library.DataType.f16, cutlass_library.DataType.f16, cutlass_library.DataType.f16),
                (cutlass_library.DataType.f16, cutlass_library.DataType.f16, cutlass_library.DataType.f32),
                (cutlass_library.DataType.f32, cutlass_library.DataType.f32, cutlass_library.DataType.f32),
                (cutlass_library.DataType.f64, cutlass_library.DataType.f64, cutlass_library.DataType.f64),
            ]

            layouts = [
                (cutlass_library.LayoutType.TensorNHWC, cutlass_library.LayoutType.TensorNHWC),
            ]
        else:
            raise NotImplementedError(f"Operation kind {operation_kind} is currently unsupported.")

        alignment = 1
        epilogue_functor = cutlass_library.EpilogueFunctor.LinearCombination
        swizzling_functor = cutlass_library.SwizzlingFunctor.Identity8
        for type_comb in types:
            for layout_comb in layouts:
                comb = (type_comb, layout_comb)
                if comb in self.operations_by_opclass[cutlass_library.OpcodeClass.Simt]:
                    continue

                A = cutlass_library.TensorDescription(type_comb[0], layout_comb[0], alignment)
                B = cutlass_library.TensorDescription(type_comb[1], layout_comb[1], alignment)
                C = cutlass_library.TensorDescription(type_comb[2], cutlass_library.LayoutType.ColumnMajor, alignment)
                math_inst = cutlass_library.MathInstruction(
                    [1, 1, 1],
                    type_comb[0],
                    type_comb[1],
                    type_comb[2],
                    cutlass_library.OpcodeClass.Simt,
                    cutlass_library.MathOperation.multiply_add
                )

                td = cutlass_library.TileDescription(
                    [128, 128, 8], 2, [4, 2, 1], math_inst, 50, 1024)

                # Prune operations that don't fit in shared memory
                if not valid_stage_count(target_cc, kernel_cc, td_from_profiler_td(td), verbose=False)[0]:
                    continue

                new_kernels = KernelsForDataType(type_comb, layout_comb)

                if operation_kind == cutlass_library.OperationKind.Gemm:
                    new_operation = cutlass_library.manifest.GemmOperation(
                        cutlass_library.GemmKind.Universal, td.minimum_compute_capability,
                        td, A, B, C, type_comb[2], epilogue_functor, swizzling_functor)
                    new_kernels.add(new_operation)
                elif operation_kind == cutlass_library.OperationKind.Conv2d:
                    for conv_kind in [ConvKind.Fprop, ConvKind.Dgrad, ConvKind.Wgrad]:
                        new_operation = cutlass_library.manifest.Conv2dOperation(
                            conv_kind, IteratorAlgorithm.Analytic, td.minimum_compute_capability, td,
                            A, B, C, type_comb[2], StrideSupport.Strided, epilogue_functor, swizzling_functor,
                            group_mode=GroupMode.SingleGroup
                        )
                        new_kernels.add(new_operation)

                self.operations_by_opclass[cutlass_library.OpcodeClass.Simt][comb] = new_kernels

        # Sort all operations
        for oc in self.operations_by_opclass.keys():
            for comb in self.operations_by_opclass[oc].keys():
                self.operations_by_opclass[oc][comb].sort()

    def opclass_supports_combination(
        self, op_class: cutlass_library.OpcodeClass, datatype_comb: tuple, layout_comb: tuple, math_operation: cutlass_library.MathOperation
    ) -> bool:
        """
        Returns whether the provided operation class supports the provided data type and layout combination

        :param op_class: operation class to consider
        :type op_class: cutlass_library.OpcodeClass
        :param datatype_comb: tuple of data types for (element_A, element_B, element_accumulator)
        :type datatype_comb: tuple[cutlass_library.DataType]
        :param layout_comb: tuple of data types for (layout_A, layout_B)
        :type layout_comb: tuple[cutlass_library.LayoutType]
        :param math_operation: math operation to consider or None if any can be considered
        :type math_operation: cutlass.MathOperation

        :return: set of operation classes that support the provided data type and layout combination
        :rtype: set
        """
        if op_class not in self.operations_by_opclass:
            raise Exception(f"Unexpected or unsupported operation class {op_class}")

        if operations := self.operations_by_opclass[op_class].get((datatype_comb, layout_comb)):
            if math_operation is not None:
                return operations.supports_math_operation(math_operation)
            else:
                return True

        return False


    def supporting_opclasses(
        self,
        element_a: cutlass_library.DataType,
        element_b: cutlass_library.DataType,
        element_accumulator: cutlass_library.DataType,
        layout_a: cutlass_library.LayoutType,
        layout_b: cutlass_library.LayoutType,
        math_operation: cutlass_library.MathOperation,
    ) -> set:
        """
        Returns a set of operation classes that support the provided data type combination

        :param element_a: data type of operand A
        :type element_a: cutlass_library.DataType
        :param element_b: data type of operand B
        :type element_b: cutlass_library.DataType
        :param element_accumulator: data type of accumulator
        :type element_accumulator: cutlass_library.DataType
        :param layout_a: layout of operand A
        :type layout_a: cutlass_library.LayoutType
        :param layout_b: layout of operand B
        :type layout_b: cutlass_library.LayoutType
        :param math_operation: math operation to consider
        :type math_operation: cutlass.MathOperation

        :return: set of operation classes that support the provided data type combination
        :rtype: set
        """
        supporting_op_classes = set()
        datatype_comb = (element_a, element_b, element_accumulator)
        layout_comb = (layout_a, layout_b)

        for op_class in self.operations_by_opclass.keys():
            if self.opclass_supports_combination(op_class, datatype_comb, layout_comb, math_operation):
                supporting_op_classes.add(op_class)
        return supporting_op_classes

    def operations(
        self,
        op_class: cutlass_library.OpcodeClass,
        element_a: cutlass_library.DataType,
        element_b: cutlass_library.DataType,
        element_accumulator: cutlass_library.DataType,
        layout_a: cutlass_library.LayoutType,
        layout_b: cutlass_library.LayoutType,
        math_operation: cutlass_library.MathOperation,
    ) -> KernelsForDataType:
        """
        Returns whether the provided operation class supports the provided data type combination

        :param op_class: operation class to consider
        :type op_class: cutlass_library.OpcodeClass
        :param element_a: data type of operand A
        :type element_a: cutlass_library.DataType
        :param element_b: data type of operand B
        :type element_b: cutlass_library.DataType
        :param element_accumulator: data type of accumulator
        :type element_accumulator: cutlass_library.DataType
        :param layout_a: layout of operand A
        :type layout_a: cutlass_library.LayoutType
        :param layout_b: layout of operand B
        :type layout_b: cutlass_library.LayoutType
        :param math_operation: math operation to consider
        :type math_operation: cutlass.MathOperation

        :return: container of kernels by alignment supported by the provided combination of parameters
        :rtype: KernelsForDataType
        """
        datatype_comb = (element_a, element_b, element_accumulator)
        layout_comb = (layout_a, layout_b)
        if not self.opclass_supports_combination(op_class, datatype_comb, layout_comb, math_operation):
            raise Exception(
                f"Data type layout combination {datatype_comb}, {layout_comb} "
                f"is not supported by opcode class {op_class} on CC {self.cc}."
            )
        return self.operations_by_opclass[op_class][(datatype_comb, layout_comb)]


class OptionRegistry:
    """
    Container of all architecture-specific options

    :param target_cc: compute capability of the device on which operations will be run
    :type target_cc: int
    """

    def __init__(self, target_cc: int):
        self.registry = {}

        gemm_kinds = [cutlass_library.GemmKind.Universal, cutlass_library.GemmKind.Universal3x]
        operation_kinds = [cutlass_library.OperationKind.Gemm, cutlass_library.OperationKind.Conv2d]
        # Construct options for each CC
        for kernel_cc in _generator_ccs:
            self.registry[kernel_cc] = {}
            for opkind in operation_kinds:
                self.registry[kernel_cc][opkind] = ArchOptions(target_cc, kernel_cc, opkind, gemm_kinds)

    def options_for_cc(self, cc: int, op_kind=cutlass_library.OperationKind.Gemm) -> ArchOptions:
        return self.registry.get(cc, None)[op_kind]