-
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.
* Refactor use of weight transpose to common file between contrib codegens. * Make function areguments more explicit. * Update network hashes. Change-Id: Ib53bc7d2837b62908b92fd09062cbe9a8bb4ab30
- Loading branch information
Showing
9 changed files
with
123 additions
and
69 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
#include "constant_transforms.h" | ||
|
||
#include "../../transforms/pattern_utils.h" | ||
#include "../../transforms/simplify_expr.h" | ||
|
||
/*! | ||
* \file src/relay/backend/contrib/constant_transforms.cc | ||
* \brief Transforms applied to constant operations during codegen for BYOC backends. | ||
*/ | ||
|
||
namespace tvm { | ||
namespace relay { | ||
namespace contrib { | ||
|
||
Expr FoldConstantExpr(const Expr& expr, bool fold_qnn) { | ||
auto mod = IRModule::FromExpr(expr); | ||
mod = transform::FoldConstant(fold_qnn)(mod); | ||
auto entry_func = Downcast<Function>(mod->Lookup("main")); | ||
return expr.as<FunctionNode>() == nullptr ? entry_func->body : entry_func; | ||
} | ||
|
||
Constant TransposeWeights(const Constant& data, const std::string& source_layout, | ||
const std::string& target_layout) { | ||
Array<Integer> transpose_matrix; | ||
for (const char& c : target_layout) { | ||
int pos = source_layout.find(c); | ||
transpose_matrix.push_back(pos); | ||
} | ||
Expr transpose = MakeTranspose(data, transpose_matrix); | ||
transpose = InferType(FoldConstantExpr(transpose)); | ||
Constant transposed_data = Downcast<Constant>(transpose); | ||
return transposed_data; | ||
} | ||
|
||
} // namespace contrib | ||
} // namespace relay | ||
} // 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,52 @@ | ||
/* | ||
* 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/relay/backend/contrib/utils.h | ||
* \brief Transforms applied to constant operations during codegen for BYOC backends. | ||
*/ | ||
|
||
#include <tvm/relay/expr.h> | ||
|
||
namespace tvm { | ||
namespace relay { | ||
namespace contrib { | ||
|
||
/*! | ||
* \brief Apply constant folding on an expression. | ||
* | ||
* \param expr The expression to fold. | ||
* \param fold_qnn Whether to fold constants for QNN operations. | ||
* \returns The new folded expression. | ||
*/ | ||
Expr FoldConstantExpr(const Expr& expr, bool fold_qnn = true); | ||
|
||
/*! | ||
*\brief Transpose weights from `source_layout` to `target_layout` | ||
* | ||
* \param data The constant expression to transpose. | ||
* \param source_layout The current layout of the constant e.g. "OHWI". | ||
* \param target_layout The target layout of the constant e.g. "HWIO". | ||
*/ | ||
Constant TransposeWeights(const Constant& data, const std::string& source_layout, | ||
const std::string& target_layout); | ||
|
||
} // namespace contrib | ||
} // namespace relay | ||
} // 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
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