-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1501 from risemeup1/support_round
support round
- Loading branch information
Showing
4 changed files
with
163 additions
and
1 deletion.
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,43 @@ | ||
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. | ||
// | ||
// Licensed 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 "paddle2onnx/mapper/tensor/fft_r2c.h" | ||
|
||
#include <cmath> | ||
#include <string> | ||
#include <vector> | ||
|
||
namespace paddle2onnx { | ||
REGISTER_PIR_MAPPER(fft_r2c, FftR2cMapper); | ||
|
||
int32_t FftR2cMapper::GetMinOpsetVersion(bool verbose) { | ||
return 17; | ||
} | ||
|
||
void FftR2cMapper::Opset17() { | ||
auto input_info =GetInput("x"); | ||
auto output_info = GetOutput("out"); | ||
output_info[0].dtype = P2ODataType::FP32; | ||
std::string one_str = helper_->Constant(GetOnnxDtype(P2ODataType::INT64), std::vector<int64_t>({-1})); | ||
std::string zero_str = helper_->Constant(GetOnnxDtype(P2ODataType::INT64), std::vector<int64_t>({0})); | ||
auto node1 = helper_->MakeNode("Unsqueeze", {input_info[0].name, one_str}); | ||
auto node2 = helper_->MakeNode("Unsqueeze", {node1->output(0), zero_str}); | ||
auto dft_node = helper_->MakeNode("DFT", {node2->output(0)}); | ||
AddAttribute(dft_node, "onesided", int64_t(onesided_)); | ||
AddAttribute(dft_node, "inverse", int64_t(0)); | ||
AddAttribute(dft_node, "axis", int64_t(2)); | ||
helper_->MakeNode("Squeeze", {dft_node->output(0), zero_str}, {output_info[0].name}); | ||
} | ||
|
||
} // namespace paddle2onnx |
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,48 @@ | ||
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. | ||
// | ||
// Licensed 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. | ||
|
||
#pragma once | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "paddle2onnx/mapper/mapper.h" | ||
|
||
namespace paddle2onnx { | ||
|
||
class FftR2cMapper : public Mapper { | ||
public: | ||
FftR2cMapper(const PaddlePirParser& p, | ||
OnnxHelper* helper, | ||
int64_t op_id, | ||
bool c) | ||
: Mapper(p, helper, op_id, c) { | ||
|
||
in_pir_mode = true; | ||
GetAttr("normalization", &normalization_); | ||
GetAttr("onesided", &onesided_); | ||
GetAttr("forward", &forward_); | ||
GetAttr("axes",&axes_); | ||
} | ||
|
||
int32_t GetMinOpsetVersion(bool verbose) override; | ||
void Opset17() override; | ||
|
||
private: | ||
std::string normalization_; | ||
bool onesided_; | ||
bool forward_; | ||
std::vector<int64_t> axes_; | ||
}; | ||
|
||
} // namespace paddle2onnx |
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 @@ | ||
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. | ||
# | ||
# Licensed 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. | ||
|
||
import paddle | ||
from onnxbase import APIOnnx | ||
from onnxbase import randtool | ||
from onnxbase import _test_only_pir | ||
|
||
|
||
class Net(paddle.nn.Layer): | ||
""" | ||
simple Net | ||
""" | ||
|
||
def __init__(self): | ||
super(Net, self).__init__() | ||
|
||
def forward(self, inputs): | ||
""" | ||
forward | ||
""" | ||
x = paddle.fft.rfft(inputs, axis=1) | ||
x = paddle.abs(x) | ||
return x | ||
|
||
|
||
@_test_only_pir | ||
def test_fftr2c_17(): | ||
""" | ||
api: paddle.fft.rfft | ||
op version: 17 | ||
""" | ||
op = Net() | ||
op.eval() | ||
# net, name, ver_list, delta=1e-6, rtol=1e-5 | ||
obj = APIOnnx(op, "fft_r2c", [17]) | ||
obj.set_input_data( | ||
"input_data", | ||
paddle.to_tensor(randtool("float", -1, 1, [3, 10, 10]).astype("float32")), | ||
) | ||
obj.run() |