Skip to content

Commit

Permalink
Reference implementation of DFT and IDFT operations (openvinotoolkit#…
Browse files Browse the repository at this point in the history
…4938)

* Started to write the header file for (I)DFT reference implementation.

* Continued to write the header file for (I)DFT reference implementation.

* Renamed the header file for the reference implementation of (I)DFT.

* Started to write an implementation file for the reference implementation of (I)DFT.

* Continued to write an implementation file for the reference implementation of (I)DFT.

* Continued to write an implementation file for the reference implementation of (I)DFT.

* Small fix.

* Written copying data from input and copying data to output.

* Code style fixes.

* Small fix.

* Some fixes.

* Some fixes.

* Small fix.

* Written naive version of (I)DFT calculation.

* Some fixes.

* Some fixes.

* Some fixes.

* Some fixes.

* Some fixes.

* Small fixes.

* Written the draft of the reference implementation of (I)DFT.

* Small fix.

* Small fix.

* Code style fixes.

* Added evaluation of (I)DFT to evaluation_map.cpp.

* Small fixes.

* Some fixes.

* Written test for evaluation of 1D DFT.

* Fixed ngraph/test/CMakeLists.txt.

* Disabled DFT evaluation test in CPU, because (I)DFT has not implemented yet in CPU.

* Added debug prints to evaluation test of DFT.

* Added debug prints into evaluate_map.cpp for DFT evaluation.

* Added some debug prints into FFT calculation.

* Added more debug prints.

* Added more debug prints.

* Added more debug prints.

* Added more debug prints.

* Added more debug prints.

* Small fix.

* Added more debug prints.

* Added more debug prints.

* Small change.

* Some fixes.

* Small fix.

* Some changes.

* Added more tests.

* Added test for IDFT 1D calculation.

* Some fixes.

* Added more debug prints.

* Small fix.

* Small fix.

* Some fixes.

* Some fix.

* Small fix.

* Added tests for 2D case of IDFT.

* Some fixes.

* Written tests for 3D case of DFT.

* Some fixes.

* Small fix.

* Added test for 3D case of IDFT.

* Some fixes.

* Deleted debug prints from tests for IDFT.

* Deleted debug prints from tests for DFT.

* Deleted debug prints from the reference implementation of (I)DFT.

* Code style fixes.

* Deleted debug prints from evaluates_map.cpp.

* Written the header file for the base class of DFT and IDFT operations.

* Written an implementation of the base class of DFT and IDFT.

* Now nGraph IDFT operation class is a derived class of FFTBase.

* Now the nGraph operation DFT is a derived class of FFTBase.

* Added assert for axes in (I)DFT reference.

* Small refactoring.

* Deleted commented code.

* Small refactoring.

* Small fix.

* Initialization of calculations of the reference implementation of (I)DFT was moved in the separate function.

* Small fix.

* Code style fix.

* Small fix.

* Now evaluate() of (I)DFT uses canonicalize_axes() from the reference implementation.

* Code style fix.

* Deleted commented code.

* Added tests for i32 axes of DFT.

* Added test for i32 axes of 2D DFT.

* Added i32 axes case to test for 3D DFT.

* Added test for i32 axes in tests for IDFT.

* Written signal_size case test for 1D DFT.

* Small fix.

* Written test for signal_size case for 2D DFT.

* Added test for bfloat16 input data of 1D DFT.

* Small fix.

* Small fix.

* Small fix.

* Some fixes.

* Some fix.

* Added bfloat16 input tests for 2D DFT.

* Some fixes.

* Written tests for bfloat16 input of 3D DFT.

* Some fixes.

* Some fixes.

* Added tests for bfloat16 input of 1D IDFT.

* Some fixes.

* Added tests for bfloat16 input of 2D IDFT.

* Added test for bfloat16 input of 3D IDFT.

* Small fix.

* Some fixes.

* Added tests for float16 input of 1D DFT.

* Small fix.

* Written tests for float16 input of 2D and 3D DFT.

* Small fix.

* Some fixes.

* Some fixes.

* Written tests for float16 inputs of 1D, 2D, 3D IDFT.

* Some fixes.

* Some fixes.

* Some fixes.

* Some fixes.

* Deleted redundant include.

* Some fixes.

* Added tests of 1D and 2D DFT for the case when some axes lengths are powers of 2.

* Added tests for 3D DFT and 1D, 2D, 3D IDFT in the case when lengths of some axes are powers of 2.

* Small fix.

* Added some comments.

* Added some comments.
  • Loading branch information
vgavrilo authored Apr 14, 2021
1 parent 1c4428e commit f2366f7
Show file tree
Hide file tree
Showing 14 changed files with 3,816 additions and 417 deletions.
8 changes: 2 additions & 6 deletions ngraph/core/include/ngraph/op/dft.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "ngraph/attribute_adapter.hpp"
#include "ngraph/op/op.hpp"
#include "ngraph/op/util/attr_types.hpp"
#include "ngraph/op/util/fft_base.hpp"

namespace ngraph
{
Expand All @@ -29,7 +30,7 @@ namespace ngraph
namespace v7
{
/// \brief An operation DFT that computes the discrete Fourier transformation.
class NGRAPH_API DFT : public Op
class NGRAPH_API DFT : public util::FFTBase
{
public:
NGRAPH_RTTI_DECLARATION;
Expand All @@ -52,13 +53,8 @@ namespace ngraph

bool visit_attributes(AttributeVisitor& visitor) override;

void validate_and_infer_types() override;

std::shared_ptr<Node>
clone_with_new_inputs(const OutputVector& new_args) const override;

protected:
void validate();
};
}
}
Expand Down
8 changes: 2 additions & 6 deletions ngraph/core/include/ngraph/op/idft.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "ngraph/attribute_adapter.hpp"
#include "ngraph/op/op.hpp"
#include "ngraph/op/util/attr_types.hpp"
#include "ngraph/op/util/fft_base.hpp"

namespace ngraph
{
Expand All @@ -17,7 +18,7 @@ namespace ngraph
namespace v7
{
/// \brief An operation IDFT that computes the inverse discrete Fourier transformation.
class NGRAPH_API IDFT : public Op
class NGRAPH_API IDFT : public util::FFTBase
{
public:
NGRAPH_RTTI_DECLARATION;
Expand All @@ -40,13 +41,8 @@ namespace ngraph

bool visit_attributes(AttributeVisitor& visitor) override;

void validate_and_infer_types() override;

std::shared_ptr<Node>
clone_with_new_inputs(const OutputVector& new_args) const override;

protected:
void validate();
};
}
}
Expand Down
46 changes: 46 additions & 0 deletions ngraph/core/include/ngraph/op/util/fft_base.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (C) 2018-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//

#pragma once

#include "ngraph/op/op.hpp"
#include "ngraph/op/util/attr_types.hpp"

namespace ngraph
{
namespace op
{
namespace util
{
/// \brief Base class for operations DFT and DFT.
class NGRAPH_API FFTBase : public Op
{
public:
NGRAPH_RTTI_DECLARATION;
FFTBase() = default;

void validate_and_infer_types() override;
bool visit_attributes(AttributeVisitor& visitor) override;

protected:
/// \brief Constructs an FFT operation. FFT is performed for full size axes.
///
/// \param data Input data
/// \param axes Axes to perform FFT
FFTBase(const Output<Node>& data, const Output<Node>& axes);

/// \brief Constructs a FFT operation.
///
/// \param data Input data
/// \param axes Axes to perform FFT
/// \param signal_size Signal sizes for 'axes'
FFTBase(const Output<Node>& data,
const Output<Node>& axes,
const Output<Node>& signal_size);

void validate();
};
}
}
}
62 changes: 62 additions & 0 deletions ngraph/core/reference/include/ngraph/runtime/reference/fft.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//*****************************************************************************
// Copyright 2017-2021 Intel Corporation
//
// 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 <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstddef>
#include <functional>
#include <map>
#include <ngraph/runtime/host_tensor.hpp>
#include <vector>
#include "ngraph/node.hpp"
#include "ngraph/op/util/op_types.hpp"
#include "ngraph/ops.hpp"
#include "ngraph/shape_util.hpp"

namespace ngraph
{
namespace runtime
{
namespace reference
{
enum class FFTKind
{
Forward,
Inverse
};

void fft(const float* input_data,
const Shape& input_data_shape,
const int64_t* axes_data,
const Shape& axes_data_shape,
float* fft_result,
const Shape& output_shape,
FFTKind fft_kind);

void fft_postprocessing(const HostTensorVector& outputs,
const ngraph::element::Type output_type,
const std::vector<float>& fft_result);

std::vector<int64_t> canonicalize_axes(const int64_t* axes_data,
const Shape& axes_data_shape,
int64_t complex_data_rank);
}
}
}
Loading

0 comments on commit f2366f7

Please sign in to comment.