forked from apache/tvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
162 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# 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=import-outside-toplevel, invalid-name | ||
"""Instantiate a C++ source for profiling CUTLASS kernels.""" | ||
from .gemm_profiler import GemmProfilerEmitter | ||
|
||
|
||
class Conv2dProfilerEmitter: | ||
def __init__(self): | ||
self.gemm_profiler_emitter = GemmProfilerEmitter() | ||
|
||
def emit(self, op_name, op_def, dtype_a, dtype_b, dtype_c, ld): | ||
return self.gemm_profiler_emitter(op_name, op_def, dtype_a, dtype_b, dtype_c, ld) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# 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 .conv2d_profiler import Conv2dProfilerEmitter | ||
from .library import ( | ||
EpilogueFunctor, | ||
SwizzlingFunctor, | ||
TensorDescription, | ||
DataTypeTag, | ||
LayoutType, | ||
MathInstruction, | ||
DataType, | ||
OpcodeClass, | ||
MathOperation, | ||
TileDescription, | ||
ConvKind, | ||
IteratorAlgorithm, | ||
StrideSupport, | ||
) | ||
|
||
|
||
def create_conv2d_operator( | ||
layout, | ||
tile_descriptions, | ||
data_type, | ||
alignment_constraints, | ||
swizzling_functor=SwizzlingFunctor.Identity4, | ||
): | ||
"""Exhaustively instantiate all kernels from a given configuration.""" | ||
ret = [] | ||
|
||
profiler_emitter = Conv2dProfilerEmitter() | ||
kernel_emitter = EmitConv2dInstance() | ||
|
||
element_a, element_b, element_c, element_epilogue = data_type | ||
iterator_algorithms = [IteratorAlgorithm.Analytic, IteratorAlgorithm.Optimized] | ||
|
||
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) | ||
|
||
op = op_entry["opdef"] | ||
op_entry["op"] = op | ||
op_entry["name"] = op.procedural_name() | ||
op_entry["src"] = profiler_emitter.emit( | ||
op.procedural_name(), | ||
op, | ||
DataTypeTag[element_a], | ||
DataTypeTag[element_b], | ||
DataTypeTag[element_c], | ||
op.leading_dim(), | ||
) | ||
op_entry["runtime"] = 9999999 | ||
|
||
ret.append(op_entry) | ||
|
||
return ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters