masahi commented on a change in pull request #9595: URL: https://github.com/apache/tvm/pull/9595#discussion_r759712433
########## File path: python/tvm/contrib/cutlass/gen_conv2d.py ########## @@ -0,0 +1,132 @@ +# 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 +"""Conv2d kernel generator and profiler for CUTLASS.""" +from .conv2d_operation import Conv2dOperation, EmitConv2dInstance +from .gen_gemm import CutlassGemmProfiler +from .library import ( + EpilogueFunctor, + SwizzlingFunctor, + TensorDescription, + LayoutType, + ConvKind, + StrideSupport, + IteratorAlgorithm, +) + + +def create_conv2d_operator( + tile_descriptions, + data_type, + alignment_constraints, + swizzling_functor=SwizzlingFunctor.Identity4, +): + """Exhaustively instantiate all kernels from a given configuration.""" + ret = [] + + kernel_emitter = EmitConv2dInstance() + + element_a, element_b, element_c, element_epilogue = data_type + iterator_algorithms = [IteratorAlgorithm.Optimized] + + layout = (LayoutType.TensorNHWC, LayoutType.TensorNHWC, LayoutType.TensorNHWC) + for tile 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) + + swizzling_functor_ = swizzling_functor + + for iterator_algorithm in iterator_algorithms: + op_entry = {} + + for epilogue, opdef in zip( + [ + EpilogueFunctor.LinearCombination, + EpilogueFunctor.LinearCombinationBias, + EpilogueFunctor.LinearCombinationRelu, + ], + ["opdef", "opdef_bias", "opdef_bias_relu"], + ): + op = Conv2dOperation( + ConvKind.Fprop, + iterator_algorithm, + tile.minimum_compute_capability, + tile, + A, + B, + C, + element_epilogue, + StrideSupport.Strided, + epilogue, + swizzling_functor_, + ) + + op_entry[opdef] = kernel_emitter.emit(op) + + if epilogue == EpilogueFunctor.LinearCombination: + op_entry["op"] = op + op_entry["name"] = op.procedural_name() + op_entry["runtime"] = 9999999 Review comment: This corresponds to the gemm generator counterpart in https://github.com/apache/tvm/blob/adf560ebed8465c22bf58f406d0a8d20663cdd1d/python/tvm/contrib/cutlass/gen_gemm.py#L109-L127 In addition to creating `opdef`, `opdef_bias` etc, we also need to set `op`, `name`, `runtime` etc. I tried to simplify that code and this is what I came up with. I'll rewrite this code to make it easier to understand (by pulling the non-activation case, `EpilogueFunctor.LinearCombination`, out of the loop). -- 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]
