Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

Quantized16bit, unidirectional and bidirectional LSTMs #149

Open
wants to merge 3 commits into
base: A11_V1.3_dev
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ shared_library("intel_nnhal") {
"ngraph_creator/operations/src/Argmin.cpp",
"ngraph_creator/operations/src/AveragePool2D.cpp",
"ngraph_creator/operations/src/BatchToSpace.cpp",
"ngraph_creator/operations/src/BidirectionalSequenceLSTM.cpp",
"ngraph_creator/operations/src/BidirectionalSequenceRNN.cpp",
"ngraph_creator/operations/src/Cast.cpp",
"ngraph_creator/operations/src/ChannelShuffle.cpp",
Expand Down Expand Up @@ -122,6 +123,7 @@ shared_library("intel_nnhal") {
"ngraph_creator/operations/src/Pow.cpp",
"ngraph_creator/operations/src/PRelu.cpp",
"ngraph_creator/operations/src/Quantize.cpp",
"ngraph_creator/operations/src/Quantized16BitLSTM.cpp",
"ngraph_creator/operations/src/ReduceAll.cpp",
"ngraph_creator/operations/src/ReduceAny.cpp",
"ngraph_creator/operations/src/ReduceMax.cpp",
Expand Down Expand Up @@ -152,6 +154,7 @@ shared_library("intel_nnhal") {
"ngraph_creator/operations/src/TopkV2.cpp",
"ngraph_creator/operations/src/TransposeConv2D.cpp",
"ngraph_creator/operations/src/Transpose.cpp",
"ngraph_creator/operations/src/UnidirectionalSequenceLSTM.cpp",
"ngraph_creator/operations/src/UnidirectionalSequenceRNN.cpp",
"service.cpp",
"Driver.cpp",
Expand Down
3 changes: 3 additions & 0 deletions ngraph_creator/Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ cc_library_static {
"operations/src/Argmin.cpp",
"operations/src/AveragePool2D.cpp",
"operations/src/BatchToSpace.cpp",
"operations/src/BidirectionalSequenceLSTM.cpp",
"operations/src/BidirectionalSequenceRNN.cpp",
"operations/src/Cast.cpp",
"operations/src/ChannelShuffle.cpp",
Expand Down Expand Up @@ -60,6 +61,7 @@ cc_library_static {
"operations/src/Pow.cpp",
"operations/src/PRelu.cpp",
"operations/src/Quantize.cpp",
"operations/src/Quantized16BitLSTM.cpp",
"operations/src/ReduceAll.cpp",
"operations/src/ReduceAny.cpp",
"operations/src/ReduceMax.cpp",
Expand Down Expand Up @@ -90,6 +92,7 @@ cc_library_static {
"operations/src/TopkV2.cpp",
"operations/src/TransposeConv2D.cpp",
"operations/src/Transpose.cpp",
"operations/src/UnidirectionalSequenceLSTM.cpp",
"operations/src/UnidirectionalSequenceRNN.cpp"
],

Expand Down
3 changes: 3 additions & 0 deletions ngraph_creator/include/OperationsFactory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <Argmin.hpp>
#include <AveragePool2D.hpp>
#include <BatchToSpace.hpp>
#include <BidirectionalSequenceLSTM.hpp>
#include <BidirectionalSequenceRNN.hpp>
#include <Cast.hpp>
#include <ChannelShuffle.hpp>
Expand Down Expand Up @@ -50,6 +51,7 @@
#include <PadV2.hpp>
#include <Pow.hpp>
#include <Quantize.hpp>
#include <Quantized16BitLSTM.hpp>
#include <RNN.hpp>
#include <ROIAlign.hpp>
#include <ROIPooling.hpp>
Expand Down Expand Up @@ -80,6 +82,7 @@
#include <TopkV2.hpp>
#include <Transpose.hpp>
#include <TransposeConv2D.hpp>
#include <UnidirectionalSequenceLSTM.hpp>
#include <UnidirectionalSequenceRNN.hpp>

namespace android {
Expand Down
40 changes: 40 additions & 0 deletions ngraph_creator/operations/include/BidirectionalSequenceLSTM.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#pragma once

#include <OperationsBase.hpp>

namespace android {
namespace hardware {
namespace neuralnetworks {
namespace nnhal {

class BidirectionalSequenceLSTM : public OperationsBase {
public:
BidirectionalSequenceLSTM(int operationIndex);
bool validate() override;
std::shared_ptr<ngraph::Node> createNode() override;
void connectOperationToGraph() override;

std::shared_ptr<ngraph::Node> add(const ngraph::Output<ngraph::Node>& lhs,
const ngraph::Output<ngraph::Node>& rhs);
std::shared_ptr<ngraph::Node> sub(const ngraph::Output<ngraph::Node>& lhs,
const ngraph::Output<ngraph::Node>& rhs);
std::shared_ptr<ngraph::Node> mul(const ngraph::Output<ngraph::Node>& lhs,
const ngraph::Output<ngraph::Node>& rhs);
std::shared_ptr<ngraph::Node> matMul(const ngraph::Output<ngraph::Node>& lhs,
const ngraph::Output<ngraph::Node>& rhs,
bool transpose_lhs, bool transpose_rhs);
std::shared_ptr<ngraph::Node> clip(const ngraph::Output<ngraph::Node>& data,
float m_clip) const;
std::shared_ptr<ngraph::Node> applyActivation(const std::shared_ptr<ngraph::Node>& arg,
int activationFn) const;
std::shared_ptr<ngraph::Node> LayerNorm(const ngraph::Output<ngraph::Node>& input,
const std::shared_ptr<ngraph::Node>& normalizedweights,
const std::shared_ptr<ngraph::Node>& bias);

bool isValidInputTensor(uint32_t inputIndex);
};

} // namespace nnhal
} // namespace neuralnetworks
} // namespace hardware
} // namespace android
35 changes: 35 additions & 0 deletions ngraph_creator/operations/include/Quantized16BitLSTM.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once

#include <OperationsBase.hpp>

namespace android {
namespace hardware {
namespace neuralnetworks {
namespace nnhal {

class Quantized16BitLSTM : public OperationsBase {
public:
Quantized16BitLSTM(int operationIndex);
bool validate() override;
std::shared_ptr<ngraph::Node> createNode() override;
void connectOperationToGraph() override;

std::shared_ptr<ngraph::Node> applyActivation(const std::shared_ptr<ngraph::Node>& arg,
int activationFn) const;
std::shared_ptr<ngraph::Node> add(const ngraph::Output<ngraph::Node>& lhs,
const ngraph::Output<ngraph::Node>& rhs);
std::shared_ptr<ngraph::Node> sub(const ngraph::Output<ngraph::Node>& lhs,
const ngraph::Output<ngraph::Node>& rhs);
std::shared_ptr<ngraph::Node> mul(const ngraph::Output<ngraph::Node>& lhs,
const ngraph::Output<ngraph::Node>& rhs);
std::shared_ptr<ngraph::Node> matMul(const ngraph::Output<ngraph::Node>& lhs,
const ngraph::Output<ngraph::Node>& rhs,
bool transpose_lhs, bool transpose_rhs);
std::shared_ptr<ngraph::Node> clip(const ngraph::Output<ngraph::Node>& data,
float m_clip) const;
};

} // namespace nnhal
} // namespace neuralnetworks
} // namespace hardware
} // namespace android
39 changes: 39 additions & 0 deletions ngraph_creator/operations/include/UnidirectionalSequenceLSTM.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#pragma once

#include <OperationsBase.hpp>

namespace android {
namespace hardware {
namespace neuralnetworks {
namespace nnhal {

class UnidirectionalSequenceLSTM : public OperationsBase {
public:
UnidirectionalSequenceLSTM(int operationIndex);
bool validate() override;
std::shared_ptr<ngraph::Node> createNode() override;

std::shared_ptr<ngraph::Node> add(const ngraph::Output<ngraph::Node>& lhs,
const ngraph::Output<ngraph::Node>& rhs);
std::shared_ptr<ngraph::Node> sub(const ngraph::Output<ngraph::Node>& lhs,
const ngraph::Output<ngraph::Node>& rhs);
std::shared_ptr<ngraph::Node> mul(const ngraph::Output<ngraph::Node>& lhs,
const ngraph::Output<ngraph::Node>& rhs);
std::shared_ptr<ngraph::Node> matMul(const ngraph::Output<ngraph::Node>& lhs,
const ngraph::Output<ngraph::Node>& rhs,
bool transpose_lhs, bool transpose_rhs);
std::shared_ptr<ngraph::Node> clip(const ngraph::Output<ngraph::Node>& data,
float m_clip) const;
std::shared_ptr<ngraph::Node> applyActivation(const std::shared_ptr<ngraph::Node>& arg,
int activationFn) const;
std::shared_ptr<ngraph::Node> LayerNorm(const ngraph::Output<ngraph::Node>& input,
const std::shared_ptr<ngraph::Node>& normalizedweights,
const std::shared_ptr<ngraph::Node>& bias);

bool isValidInputTensor(uint32_t inputIndex);
};

} // namespace nnhal
} // namespace neuralnetworks
} // namespace hardware
} // namespace android
Loading