masahi commented on a change in pull request #9261: URL: https://github.com/apache/tvm/pull/9261#discussion_r737956332
########## File path: python/tvm/contrib/cutlass/gen_gemm.py ########## @@ -0,0 +1,335 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# pylint: disable=invalid-name +"""Kernel generator and profiler for CUTLASS.""" +import os +import re +import tempfile +import subprocess +from .gemm_operation import GemmOperation, EmitGemmInstance +from .gemm_profiler import GemmProfilerEmitter +from .library import ( + EpilogueFunctor, + SwizzlingFunctor, + TensorDescription, + DataTypeTag, + LayoutType, + MathInstruction, + DataType, + OpcodeClass, + MathOperation, + TileDescription, +) + + +def create_gemm_operator( + layouts, + tile_descriptions, + data_type, + alignment_constraints, + epilogue_functor=EpilogueFunctor.LinearCombination, + swizzling_functor=SwizzlingFunctor.Identity8, +): + """Exhaustively instantiate all kernels from a given configuration.""" + ret = [] + kernel_emitter = EmitGemmInstance() + profiler_emitter = GemmProfilerEmitter() + + element_a, element_b, element_c, element_epilogue = data_type + + for layout in layouts: + for tile_description in tile_descriptions: + for alignment in alignment_constraints: + alignment_c = min(8, alignment) + + A = TensorDescription(element_a, layout[0], alignment) + B = TensorDescription(element_b, layout[1], alignment) + C = TensorDescription(element_c, layout[2], alignment_c) + + op_entry = {} + op = GemmOperation( + tile_description.minimum_compute_capability, + tile_description, + A, + B, + C, + element_epilogue, + epilogue_functor, + swizzling_functor, + ) + op_bias = GemmOperation( + tile_description.minimum_compute_capability, + tile_description, + A, + B, + C, + element_epilogue, + EpilogueFunctor.LinearCombinationBias, + swizzling_functor, + ) + op_bias_relu = GemmOperation( + tile_description.minimum_compute_capability, + tile_description, + A, + B, + C, + element_epilogue, + EpilogueFunctor.LinearCombinationRelu, + swizzling_functor, + ) + op_bias_gelu = GemmOperation( + tile_description.minimum_compute_capability, + tile_description, + A, + B, + C, + element_epilogue, + EpilogueFunctor.LinearCombinationGelu, + swizzling_functor, + ) + + kernel_emitter = EmitGemmInstance() + op_entry["op"] = op + op_entry["name"] = op.procedural_name() + op_entry["opdef"] = kernel_emitter.emit(op) + op_entry["opdef_bias"] = kernel_emitter.emit(op_bias, no_beta_scaling=True) + op_entry["opdef_bias_relu"] = kernel_emitter.emit( + op_bias_relu, no_beta_scaling=True + ) + op_entry["opdef_bias_gelu"] = kernel_emitter.emit(op_bias_gelu) + op_entry["src"] = profiler_emitter.emit( + op.procedural_name(), + op_entry["opdef"], + DataTypeTag[element_a], + DataTypeTag[element_b], + DataTypeTag[element_c], + op.leading_dim(), + ) + op_entry["runtime"] = 9999999 + ret.append(op_entry) + return ret + + +def generate_tensor_op_common(math_instructions, alignment_constraints, get_tile_descriptions): + """Common kernel generator to be used by archtecture specific generators.""" + ops = [] + layouts = [ + (LayoutType.RowMajor, LayoutType.ColumnMajor, LayoutType.RowMajor), + ] + for math_inst in math_instructions: + tile_descriptions = get_tile_descriptions(math_inst) + data_type = [ + math_inst.element_a, + math_inst.element_b, + math_inst.element_accumulator, + math_inst.element_accumulator, + ] + + out = create_gemm_operator(layouts, tile_descriptions, data_type, alignment_constraints) Review comment: Yes, I have a test that exercises hetero output dtype, and it works https://github.com/apache/tvm/blob/ff66ef49ecb9d1946511b545fd4d92359f60a813/tests/python/contrib/test_cutlass.py#L102 Although we currently don't generate such op, I'm not ruling out such use cases (e.g. if we want to make our so-called "ToMixedPrecision" pass truly support mixed precision). Cutlass may support the 3rd kernel, but we don't have a good reason to support it, as discussed in the thread above. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
