-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MSC] Reconstruct tensorrt module (#17344)
* reconstruct tensorrt * format fix
- Loading branch information
Showing
11 changed files
with
642 additions
and
283 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
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
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,58 @@ | ||
/* | ||
* 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 src/contrib/msc/core/transform/rewrite_utils.cc | ||
*/ | ||
#include "rewrite_utils.h" | ||
|
||
#include <set> | ||
#include <string> | ||
|
||
namespace tvm { | ||
namespace contrib { | ||
namespace msc { | ||
|
||
Var RewriteUtils::ReEmit(BlockBuilder builder, const String& name, const Expr& expr) { | ||
expr->span = SpanUtils::SetAttr(expr->span, msc_attr::kName, name); | ||
return builder->Emit(expr, name); | ||
} | ||
|
||
Var RewriteUtils::MakeCall(BlockBuilder builder, const String& name, Expr op, Array<Expr> args, | ||
Attrs attrs) { | ||
const auto& call = Call(op, args, attrs); | ||
return ReEmit(builder, name, call); | ||
} | ||
|
||
Expr RewriteUtils::MakeConstant(BlockBuilder builder, const String& name, double value, | ||
const DataType& dtype, size_t ndim) { | ||
const auto& data = support::FloatImmToNDArray(FloatImm(dtype, value)); | ||
Span span = SpanUtils::CreateWithAttr(msc_attr::kName, name); | ||
const auto& constant = Constant(data, NullOpt, span); | ||
if (ndim == 0) { | ||
return constant; | ||
} | ||
static const Op& reshape_op = Op::Get("relax.reshape"); | ||
Array<PrimExpr> exp_shape(ndim, Integer(1)); | ||
return MakeCall(builder, name + "_exp", reshape_op, {constant, ShapeExpr(exp_shape)}); | ||
} | ||
|
||
} // namespace msc | ||
} // namespace contrib | ||
} // namespace tvm |
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,72 @@ | ||
/* | ||
* 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 src/contrib/msc/core/transform/rewrite_utils.h | ||
* \brief Common utilities for rewrite. | ||
*/ | ||
#ifndef TVM_CONTRIB_MSC_CORE_TRANSFORM_REWRITE_UTILS_H_ | ||
#define TVM_CONTRIB_MSC_CORE_TRANSFORM_REWRITE_UTILS_H_ | ||
|
||
#include <tvm/ir/source_map.h> | ||
#include <tvm/relax/expr.h> | ||
|
||
#include <vector> | ||
|
||
#include "../../../../relax/transform/utils.h" | ||
#include "../../../../support/scalars.h" | ||
#include "../utils.h" | ||
|
||
namespace tvm { | ||
namespace contrib { | ||
namespace msc { | ||
|
||
using Expr = tvm::RelayExpr; | ||
using namespace tvm::relax; | ||
|
||
/*! | ||
* \brief Utils for Layout. | ||
*/ | ||
class RewriteUtils { | ||
public: | ||
/*! | ||
* \brief Emit call with span name. | ||
* \return The emitted var. | ||
*/ | ||
TVM_DLL static Var ReEmit(BlockBuilder builder, const String& name, const Expr& expr); | ||
|
||
/*! | ||
* \brief Make and emit a call binding with span. | ||
* \return The emitted var. | ||
*/ | ||
TVM_DLL static Var MakeCall(BlockBuilder builder, const String& name, Expr op, Array<Expr> args, | ||
Attrs attrs = Attrs()); | ||
|
||
/*! | ||
* \brief Make and emit a (shaped)constant with span. | ||
* \return The constant/reshape. | ||
*/ | ||
TVM_DLL static Expr MakeConstant(BlockBuilder builder, const String& name, double value, | ||
const DataType& dtype, size_t ndim = 0); | ||
}; | ||
|
||
} // namespace msc | ||
} // namespace contrib | ||
} // namespace tvm | ||
#endif // TVM_CONTRIB_MSC_CORE_TRANSFORM_REWRITE_UTILS_H_ |
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
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
Oops, something went wrong.