Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions include/tvm/relax/tir_pattern.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* 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.
*/

/*!
* \file tir_pattern.h
* \brief Data Structure of TIR Pattern used for matching.
*/

#ifndef TVM_RELAX_TIR_PATTERN_H_
#define TVM_RELAX_TIR_PATTERN_H_

#include <tvm/tir/function.h>

namespace tvm {
namespace relax {

using TIRPattern = tir::PrimFunc;

/*
* \brief The match result of a TIR pattern.
*/
class MatchResultNode : public Object {
public:
/*! The matched tir pattern*/
TIRPattern pattern;
/*! \brief The evaluated values of symbolic vars. */
Array<PrimExpr> symbol_values;
/*! \brief The matched buffers of input and output. */
Array<tir::Buffer> matched_buffers;
void VisitAttrs(AttrVisitor* v) {
v->Visit("pattern", &pattern);
v->Visit("symbol_values", &symbol_values);
v->Visit("matched_buffers", &matched_buffers);
}
static constexpr const char* _type_key = "relax.MatchResult";
TVM_DECLARE_FINAL_OBJECT_INFO(MatchResultNode, Object);
};

/*!
* \brief Managed reference to MatchResultNode.
*/
class MatchResult : public ObjectRef {
public:
/*!
* \brief Constructor
* \param pattern The matched tir pattern.
* \param symbol_values The evaluated values of symbolic vars.
* \param matched_buffers The matched buffers of input and output.
*/
TVM_DLL explicit MatchResult(TIRPattern pattern, Array<PrimExpr> symbol_values,
Array<tir::Buffer> matched_buffers);

TVM_DEFINE_OBJECT_REF_METHODS(MatchResult, ObjectRef, MatchResultNode)
};

using FCodegen = runtime::TypedPackedFunc<Array<ObjectRef>(Array<MatchResult> match_results)>;
} // namespace relax
} // namespace tvm
#endif // TVM_RELAX_TIR_PATTERN_H_
3 changes: 2 additions & 1 deletion python/tvm/contrib/cutlass/gemm_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,8 @@ def instantiate_gemm_template(attrs):
{
"bias_decl": "void* ptr_bias = (void*)(${bias_arg}->data);\n",
"ptr_c": "ptr_bias",
"c_stride": "${bias_arg}->ndim == 1 ? 0 : " + attrs["ldc"],
"c_stride": "(${bias_arg}->ndim == 1 || ${bias_arg}->shape[0] == 1) ? 0 : "
+ attrs["ldc"],
}
)
else:
Expand Down
20 changes: 20 additions & 0 deletions python/tvm/relax/backend_tir/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 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.
"""Relax backends, tir based"""

from . import contrib
from .pattern import get_tir_pattern
20 changes: 20 additions & 0 deletions python/tvm/relax/backend_tir/contrib/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 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.

"""External backend codegen modules for Relax, tir based."""

from .cutlass import cutlass_fcodegen
Loading