Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch rknpu #528

Merged
merged 6 commits into from
Nov 9, 2020
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
34 changes: 34 additions & 0 deletions source/tnn/device/rknpu/convert/math/rknpu_abs_layer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Tencent is pleased to support the open source community by making TNN available.
//
// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
//
// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
// in compliance with the License. You may obtain a copy of the License at
//
// https://opensource.org/licenses/BSD-3-Clause
//
// 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 "rknpu_unary_operator.h"
#include "tnn/device/rknpu/convert/rknpu_base_layer.h"
#include "tnn/device/rknpu/convert/rknpu_utils.h"

namespace TNN_NS {

class RknpuAbsLayer : public RknpuUnaryLayer {
public:
RknpuAbsLayer(LayerType ignore) : RknpuUnaryLayer(LAYER_ABS) {}
~RknpuAbsLayer() {}

protected:
Status Convert() {
return RknpuUnaryLayer::UnaryConvert(rk::nn::OperatorType::ABS);
}
};

REGISTER_RKNPU_LAYER(Abs, LAYER_ABS);

} // namespace TNN_NS
34 changes: 34 additions & 0 deletions source/tnn/device/rknpu/convert/math/rknpu_sub_layer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Tencent is pleased to support the open source community by making TNN available.
//
// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
//
// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
// in compliance with the License. You may obtain a copy of the License at
//
// https://opensource.org/licenses/BSD-3-Clause
//
// 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 "rknpu_binary_layer.h"
#include "tnn/device/rknpu/convert/rknpu_base_layer.h"
#include "tnn/device/rknpu/convert/rknpu_utils.h"

namespace TNN_NS {

class RknpuSubLayer : public RknpuBinaryLayer {
public:
RknpuSubLayer(LayerType ignore) : RknpuBinaryLayer(LAYER_SUB) {}
~RknpuSubLayer() {}

protected:
Status Convert() {
return RknpuBinaryLayer::BinaryConvert(rk::nn::OperatorType::SUBTRACT);
}
};

REGISTER_RKNPU_LAYER(Sub, LAYER_SUB);

} // namespace TNN_NS
47 changes: 47 additions & 0 deletions source/tnn/device/rknpu/convert/rknpu_normalize_layer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Tencent is pleased to support the open source community by making TNN available.
//
// Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
//
// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
// in compliance with the License. You may obtain a copy of the License at
//
// https://opensource.org/licenses/BSD-3-Clause
//
// 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 <tnn/utils/data_type_utils.h>

#include "rknpu_base_layer.h"
#include "rknpu_utils.h"

namespace TNN_NS {

DECLARE_RKNPU_LAYER(Normalize, LAYER_NORMALIZE)

Status RknpuNormalizeLayer::Convert() {
auto param = dynamic_cast<NormalizeLayerParam *>(param_);

if (param->axis != 1 || param->across_spatial != 0 || param->p != 2) {
return Status(TNNERR_PARAM_ERR, "Error: NormalizeLayer dont support these param!");
}

Status ret = TNN_OK;
std::vector<std::shared_ptr<rk::nn::Tensor>> inputs;

// input
inputs.push_back(input_ops_[0]);

// output
ADD_OUTPUT_OP();

graph_->AddOperator(rk::nn::OperatorType::L2_NORMALIZE, inputs, output_ops_, NULL);

return ret;
}

REGISTER_RKNPU_LAYER(Normalize, LAYER_NORMALIZE)

} // namespace TNN_NS
1 change: 1 addition & 0 deletions source/tnn/device/rknpu/convert/rknpu_reduce_mean_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Status RknpuReduceMeanLayer::Convert() {
for (const auto val : axes) {
attr.axis.push_back(static_cast<uint32_t>(val));
}
attr.axis_num = attr.axis.size();
attr.keep_dim = param->keep_dims;
graph_->AddOperator(rk::nn::OperatorType::REDUCE, inputs, output_ops_, (void *)&attr);

Expand Down
5 changes: 5 additions & 0 deletions source/tnn/device/rknpu/rknpu_network.cc
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,11 @@ Status RknpuNetwork::DeInit() {
if (blob_manager_)
delete blob_manager_;

if (context_ != nullptr) {
delete context_;
context_ = nullptr;
}

return TNN_OK;
}

Expand Down