This repository has been archived by the owner on Nov 25, 2022. It is now read-only.
forked from apache/tvm
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CMSIS-NN][Perf] Converted Relay Conv2D into CMSIS-NN Depthwise (apac…
- Loading branch information
1 parent
cbf4396
commit bfa07c3
Showing
6 changed files
with
260 additions
and
15 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,46 @@ | ||
/* | ||
* 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 "convolutions.h" | ||
|
||
#include <string> | ||
|
||
#include "../../../qnn/utils.h" | ||
#include "tvm/ir/transform.h" | ||
#include "tvm/relay/attrs/nn.h" | ||
|
||
namespace tvm { | ||
namespace relay { | ||
namespace contrib { | ||
namespace cmsisnn { | ||
|
||
bool IsCMSISNNDepthwise(const Conv2DAttrs* conv2d_attrs, const Array<PrimExpr>& input_shape, | ||
const Array<PrimExpr>& kernel_shape) { | ||
std::string kernel_layout = conv2d_attrs->kernel_layout.c_str(); | ||
int kernel_pos_o = kernel_layout.find("O"); | ||
int kernel_pos_i = kernel_layout.find("I"); | ||
int kernel_dim_o_val = qnn::get_const_int(kernel_shape[kernel_pos_o]); | ||
int kernel_dim_i_val = qnn::get_const_int(kernel_shape[kernel_pos_i]); | ||
int64_t out_channels = conv2d_attrs->channels.as<IntImmNode>()->value; | ||
return (out_channels == kernel_dim_o_val * kernel_dim_i_val); | ||
} | ||
|
||
} // namespace cmsisnn | ||
} // 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,60 @@ | ||
/* | ||
* 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/cmsisnn/convolutions.h | ||
* \brief CMSIS-NN utility functions for Convolutions | ||
*/ | ||
|
||
#ifndef TVM_RELAY_BACKEND_CONTRIB_CMSISNN_CONVOLUTIONS_H_ | ||
#define TVM_RELAY_BACKEND_CONTRIB_CMSISNN_CONVOLUTIONS_H_ | ||
|
||
#include <tvm/relay/attrs/nn.h> | ||
#include <tvm/relay/attrs/transform.h> | ||
#include <tvm/relay/expr_functor.h> | ||
#include <tvm/relay/transform.h> | ||
#include <tvm/runtime/ndarray.h> | ||
|
||
#include "../../../op/make_op.h" | ||
#include "../../../qnn/utils.h" | ||
#include "../../../transforms/pattern_utils.h" | ||
|
||
namespace tvm { | ||
namespace relay { | ||
namespace contrib { | ||
namespace cmsisnn { | ||
/*! | ||
* \brief Checks if Relay Conv2D was originally CMSIS-NN compliant Depthwise Convolution | ||
* See: | ||
* https://github.com/apache/tvm/blob/6ed3ab3e33f8eafa4acaf53b7a671831de7587e9/python/tvm/relay/frontend/tflite.py#L2107 | ||
* | ||
* | ||
* \return true if a Conv2D is a Depthwise Convolution based on Conv2D's inputs' shapes and | ||
* attributes | ||
*/ | ||
|
||
bool IsCMSISNNDepthwise(const Conv2DAttrs* conv2d_attrs, const Array<PrimExpr>& input_shape, | ||
const Array<PrimExpr>& kernel_shape); | ||
|
||
} // namespace cmsisnn | ||
} // namespace contrib | ||
} // namespace relay | ||
} // namespace tvm | ||
|
||
#endif // TVM_RELAY_BACKEND_CONTRIB_CMSISNN_CONVOLUTIONS_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