From 07fc3b991417e5621d88feab1e0a1a70c67b9ec8 Mon Sep 17 00:00:00 2001 From: zhengzhouheng Date: Tue, 6 Apr 2021 18:22:37 +0800 Subject: [PATCH] add the clip, dropout, batchnorm op --- include/tim/vx/ops/batchnorm.h | 45 ++++++++++++++++++++++++++++++++ include/tim/vx/ops/clip.h | 47 ++++++++++++++++++++++++++++++++++ include/tim/vx/ops/dropout.h | 47 ++++++++++++++++++++++++++++++++++ src/tim/vx/ops/README.md | 6 ++--- src/tim/vx/ops/batchnorm.cc | 43 +++++++++++++++++++++++++++++++ src/tim/vx/ops/clip.cc | 45 ++++++++++++++++++++++++++++++++ src/tim/vx/ops/dropout.cc | 43 +++++++++++++++++++++++++++++++ 7 files changed, 273 insertions(+), 3 deletions(-) create mode 100755 include/tim/vx/ops/batchnorm.h create mode 100755 include/tim/vx/ops/clip.h create mode 100755 include/tim/vx/ops/dropout.h create mode 100755 src/tim/vx/ops/batchnorm.cc create mode 100755 src/tim/vx/ops/clip.cc create mode 100755 src/tim/vx/ops/dropout.cc diff --git a/include/tim/vx/ops/batchnorm.h b/include/tim/vx/ops/batchnorm.h new file mode 100755 index 0000000..9cb63c3 --- /dev/null +++ b/include/tim/vx/ops/batchnorm.h @@ -0,0 +1,45 @@ +/**************************************************************************** +* +* Copyright (c) 2020 Vivante Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +* DEALINGS IN THE SOFTWARE. +* +*****************************************************************************/ +#ifndef OVXLIBXX_OPERATIONS_BATCHNORM_H_ +#define OVXLIBXX_OPERATIONS_BATCHNORM_H_ +#include "tim/vx/operation.h" + +namespace tim { +namespace vx { +namespace ops { + + +class BatchNorm : public Operation { + public: + BatchNorm(Graph* graph, float eps); + + protected: + float eps_; +}; + +} // namespace ops +} // namespace vx +} // namespace tim + +#endif /* OVXLIBXX_OPERATIONS_BATCHNORM_H_ */ diff --git a/include/tim/vx/ops/clip.h b/include/tim/vx/ops/clip.h new file mode 100755 index 0000000..9e98bdc --- /dev/null +++ b/include/tim/vx/ops/clip.h @@ -0,0 +1,47 @@ +/**************************************************************************** +* +* Copyright (c) 2020 Vivante Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +* DEALINGS IN THE SOFTWARE. +* +*****************************************************************************/ +#ifndef OVXLIBXX_OPERATIONS_CLIP_H_ +#define OVXLIBXX_OPERATIONS_CLIP_H_ +#include "tim/vx/operation.h" + + +namespace tim { +namespace vx { +namespace ops { + + +class Clip : public Operation { + public: + Clip(Graph* graph, float min, float max); + protected: + float min_; + float max_; +}; + +} // namespace ops +} // namespace vx +} // namespace tim + + +#endif /* OVXLIBXX_OPERATIONS_CLIP_H_ */ diff --git a/include/tim/vx/ops/dropout.h b/include/tim/vx/ops/dropout.h new file mode 100755 index 0000000..9e84ef1 --- /dev/null +++ b/include/tim/vx/ops/dropout.h @@ -0,0 +1,47 @@ +/**************************************************************************** +* +* Copyright (c) 2020 Vivante Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +* DEALINGS IN THE SOFTWARE. +* +*****************************************************************************/ +#ifndef OVXLIBXX_OPERATIONS_DROPOUT_H_ +#define OVXLIBXX_OPERATIONS_DROPOUT_H_ +#include "tim/vx/operation.h" + + +namespace tim { +namespace vx { +namespace ops { + + +class Dropout : public Operation { + public: + Dropout(Graph* graph, float ratio); + + protected: + float ratio_; +}; + +} // namespace ops +} // namespace vx +} // namespace tim + + +#endif /* OVXLIBXX_OPERATIONS_DROPOUT_H_ */ diff --git a/src/tim/vx/ops/README.md b/src/tim/vx/ops/README.md index 9ad5078..89ca76c 100644 --- a/src/tim/vx/ops/README.md +++ b/src/tim/vx/ops/README.md @@ -15,7 +15,7 @@ Concat|CONCAT|Mapped Split|SPLIT|Mapped ||NOOP|Unmapped ||ROI_POOL|Unmapped -||BATCH_NORM|Unmapped +BatchNorm|BATCH_NORM|Mapped ||PROPOSAL|Unmapped DeConv2d|DECONVOLUTION|Mapped Reshape|RESHAPE|Mapped @@ -42,7 +42,7 @@ Sqrt|SQRT|Mapped Rsqrt|RSQRT|Mapped SoftRelu|SOFTRELU|Unmapped Div|DIVIDE|Mapped -||DROPOUT|Unmapped +Dropout|DROPOUT|Mapped ||SHUFFLECHANNEL|Unmapped Resize|RESIZE|Mapped Reverse|REVERSE|Mapped @@ -94,7 +94,7 @@ Exp|EXP|Mapped ||EMBEDDING_LOOKUP|Unmapped ||LSH_PROJECTION|Unmapped ||RNN|Unmapped -||CLIP|Unmapped +Clip|CLIP|Mapped ||POST_PROCESS|Unmapped ||PRE_PROCESS_GRAY|Unmapped ||UNSTACK|Unmapped diff --git a/src/tim/vx/ops/batchnorm.cc b/src/tim/vx/ops/batchnorm.cc new file mode 100755 index 0000000..21a5c41 --- /dev/null +++ b/src/tim/vx/ops/batchnorm.cc @@ -0,0 +1,43 @@ +/**************************************************************************** +* +* Copyright (c) 2020 Vivante Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +* DEALINGS IN THE SOFTWARE. +* +*****************************************************************************/ +#include "tim/vx/ops/batchnorm.h" + +#include "vsi_nn_pub.h" + +#include "operation_private.h" + +namespace tim { +namespace vx { +namespace ops { + + +BatchNorm::BatchNorm(Graph* graph, float eps) + : Operation(graph, VSI_NN_OP_BATCH_NORM), + eps_(eps) { + this->impl()->node()->nn_param.batch_norm.eps = eps_; +} + +} // namespace ops +} // namespace vx +} // namespace tim diff --git a/src/tim/vx/ops/clip.cc b/src/tim/vx/ops/clip.cc new file mode 100755 index 0000000..b76d448 --- /dev/null +++ b/src/tim/vx/ops/clip.cc @@ -0,0 +1,45 @@ +/**************************************************************************** +* +* Copyright (c) 2020 Vivante Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +* DEALINGS IN THE SOFTWARE. +* +*****************************************************************************/ +#include "tim/vx/ops/clip.h" + +#include "vsi_nn_pub.h" + +#include "operation_private.h" + +namespace tim { +namespace vx { +namespace ops { + + +Clip::Clip(Graph* graph, float min, float max) + : Operation(graph, VSI_NN_OP_CLIP), + min_(min), + max_(max) { + this->impl()->node()->nn_param.clip.min = min_; + this->impl()->node()->nn_param.clip.max = max_; +} + +} // namespace ops +} // namespace vx +} // namespace tim diff --git a/src/tim/vx/ops/dropout.cc b/src/tim/vx/ops/dropout.cc new file mode 100755 index 0000000..598cfbe --- /dev/null +++ b/src/tim/vx/ops/dropout.cc @@ -0,0 +1,43 @@ +/**************************************************************************** +* +* Copyright (c) 2020 Vivante Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +* DEALINGS IN THE SOFTWARE. +* +*****************************************************************************/ +#include "tim/vx/ops/dropout.h" + +#include "vsi_nn_pub.h" + +#include "operation_private.h" + +namespace tim { +namespace vx { +namespace ops { + + +Dropout::Dropout(Graph* graph, float ratio) + : Operation(graph, VSI_NN_OP_DROPOUT), + ratio_(ratio) { + this->impl()->node()->nn_param.dropout.ratio = ratio_; +} + +} // namespace ops +} // namespace vx +} // namespace tim