From 0d17866453f898e314c174563d9a6805a854bbe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=8D=E6=80=BF=E6=B6=9B?= Date: Fri, 19 Nov 2021 11:20:40 +0000 Subject: [PATCH 01/10] update tf_adapter/python/npu_bridge/npu_cpu/npu_cpu_ops.py. --- tf_adapter/python/npu_bridge/npu_cpu/npu_cpu_ops.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tf_adapter/python/npu_bridge/npu_cpu/npu_cpu_ops.py b/tf_adapter/python/npu_bridge/npu_cpu/npu_cpu_ops.py index 73b76b4fe..bdae0023d 100644 --- a/tf_adapter/python/npu_bridge/npu_cpu/npu_cpu_ops.py +++ b/tf_adapter/python/npu_bridge/npu_cpu/npu_cpu_ops.py @@ -235,4 +235,16 @@ def resize_and_clip_polys(polys_data, polys_offset, polys_size, h_scale, w_scale w_scale=w_scale, img_h=img_h, img_w=img_w) + return result + +## 提供NonZeroWithValueShape功能 +# @param value double, float, float16, int8, unit8, int16, unit16, int32, unit32, int64, unit64, bool 类型 +# @param index int32 类型 +# @param count int32 类型 +# @return out_value,out_index double, float, float16, int8, unit8, int16, unit16, int32, unit32, int64, unit64, bool,int32,int32 类型 +def non_zero_with_value_shape(value, index, count): + result = gen_npu_cpu_ops.non_zero_with_value_shape( + value=value, + index=index, + count=count) return result \ No newline at end of file -- Gitee From beca874301bb1406b8efb69a04a8afbc51a847f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=8D=E6=80=BF=E6=B6=9B?= Date: Fri, 19 Nov 2021 11:23:58 +0000 Subject: [PATCH 02/10] update tf_adapter/kernels/npu_cpu_ops.cc. --- tf_adapter/kernels/npu_cpu_ops.cc | 69 +++++++++++++------------------ 1 file changed, 28 insertions(+), 41 deletions(-) diff --git a/tf_adapter/kernels/npu_cpu_ops.cc b/tf_adapter/kernels/npu_cpu_ops.cc index 7e4891543..49a6aeeff 100644 --- a/tf_adapter/kernels/npu_cpu_ops.cc +++ b/tf_adapter/kernels/npu_cpu_ops.cc @@ -23,56 +23,49 @@ #include "tf_adapter/util/cache_interface.h" namespace tensorflow { -class EmbeddingRankIdOpKernel : public OpKernel { - public: +class EmbeddingRankIdOpKernel : public OpKernel { public: explicit EmbeddingRankIdOpKernel(OpKernelConstruction *context) : OpKernel(context) {} ~EmbeddingRankIdOpKernel() {} void Compute(OpKernelContext *context) override { ADP_LOG(INFO) << "EmbeddingRankIdOp Compute."; } }; -class EmbeddingLocalIndexOpKernel : public OpKernel { - public: +class EmbeddingLocalIndexOpKernel : public OpKernel { public: explicit EmbeddingLocalIndexOpKernel(OpKernelConstruction *context) : OpKernel(context) {} ~EmbeddingLocalIndexOpKernel() {} void Compute(OpKernelContext *context) override { ADP_LOG(INFO) << "EmbeddingLocalIndexOp Compute."; } }; -class LruCacheOp : public ResourceOpKernel { - public: +class LruCacheOp : public ResourceOpKernel { public: explicit LruCacheOp(OpKernelConstruction* context) : ResourceOpKernel(context) {} ~LruCacheOp() override {} void Compute(OpKernelContext* context) override { ADP_LOG(INFO) << "LruCacheOp Compute"; } - private: +private: Status CreateResource(CacheInterface** resource) override EXCLUSIVE_LOCKS_REQUIRED(mu_) { return Status::OK(); } }; -class CacheAddOp : public OpKernel { - public: +class CacheAddOp : public OpKernel { public: explicit CacheAddOp(OpKernelConstruction *context) : OpKernel(context) {} ~CacheAddOp() override {} void Compute(OpKernelContext *context) override { ADP_LOG(INFO) << "CacheAddOp Compute"; } }; -class CacheRemoteIndexToLocalOp : public OpKernel { - public: +class CacheRemoteIndexToLocalOp : public OpKernel { public: explicit CacheRemoteIndexToLocalOp(OpKernelConstruction *context) : OpKernel(context) {} ~CacheRemoteIndexToLocalOp() override {} void Compute(OpKernelContext *context) override { ADP_LOG(INFO) << "CacheRemoteIndexToLocalOp Compute"; } }; -class CacheAllIndexToLocalOp : public OpKernel { - public: +class CacheAllIndexToLocalOp : public OpKernel { public: explicit CacheAllIndexToLocalOp(OpKernelConstruction *context) : OpKernel(context) {} ~CacheAllIndexToLocalOp() override {} void Compute(OpKernelContext *context) override { ADP_LOG(INFO) << "CacheAllIndexToLocalOp Compute"; } }; template -class DeformableOffsetsOp : public OpKernel { - public: +class DeformableOffsetsOp : public OpKernel { public: explicit DeformableOffsetsOp(OpKernelConstruction *context) : OpKernel(context) {} ~DeformableOffsetsOp() override {} void Compute(OpKernelContext *context) override { @@ -83,8 +76,7 @@ class DeformableOffsetsOp : public OpKernel { }; template -class DeformableOffsetsGradOp : public OpKernel { - public: +class DeformableOffsetsGradOp : public OpKernel { public: explicit DeformableOffsetsGradOp(OpKernelConstruction *context) : OpKernel(context) {} ~DeformableOffsetsGradOp() override {} void Compute(OpKernelContext *context) override { @@ -94,8 +86,7 @@ class DeformableOffsetsGradOp : public OpKernel { bool IsExpensive() override { return false; } }; -class RandomChoiceWithMaskOp : public OpKernel { - public: +class RandomChoiceWithMaskOp : public OpKernel { public: explicit RandomChoiceWithMaskOp(OpKernelConstruction *context) : OpKernel(context) {} ~RandomChoiceWithMaskOp() override {} void Compute(OpKernelContext *context) override { @@ -104,8 +95,7 @@ class RandomChoiceWithMaskOp : public OpKernel { }; template -class DenseImageWarpOp : public OpKernel { - public: +class DenseImageWarpOp : public OpKernel { public: explicit DenseImageWarpOp(OpKernelConstruction *context) : OpKernel(context) {} ~DenseImageWarpOp() override {} void Compute(OpKernelContext *context) override {} @@ -113,77 +103,73 @@ class DenseImageWarpOp : public OpKernel { }; template -class DenseImageWarpGradOp : public OpKernel { - public: +class DenseImageWarpGradOp : public OpKernel { public: explicit DenseImageWarpGradOp(OpKernelConstruction *context) : OpKernel(context) {} ~DenseImageWarpGradOp() override {} void Compute(OpKernelContext *context) override {} bool IsExpensive() override { return false; } }; -class BatchEnqueueOp : public OpKernel { - public: +class BatchEnqueueOp : public OpKernel { public: explicit BatchEnqueueOp(OpKernelConstruction *context) : OpKernel(context) {} ~BatchEnqueueOp() override {} void Compute(OpKernelContext *context) override { ADP_LOG(INFO) << "BatchEnqueueOp Compute"; } }; -class OCRRecognitionPreHandleOp : public OpKernel { - public: +class OCRRecognitionPreHandleOp : public OpKernel { public: explicit OCRRecognitionPreHandleOp(OpKernelConstruction *context) : OpKernel(context) {} ~OCRRecognitionPreHandleOp() override {} void Compute(OpKernelContext *context) override { ADP_LOG(INFO) << "OCRRecognitionPreHandleOp Compute"; } }; -class OCRDetectionPreHandleOp : public OpKernel { - public: +class OCRDetectionPreHandleOp : public OpKernel { public: explicit OCRDetectionPreHandleOp(OpKernelConstruction *context) : OpKernel(context) {} ~OCRDetectionPreHandleOp() override {} void Compute(OpKernelContext *context) override { ADP_LOG(INFO) << "OCRDetectionPreHandleOp Compute"; } }; -class OCRIdentifyPreHandleOp : public OpKernel { - public: +class OCRIdentifyPreHandleOp : public OpKernel { public: explicit OCRIdentifyPreHandleOp(OpKernelConstruction *context) : OpKernel(context) {} ~OCRIdentifyPreHandleOp() override {} void Compute(OpKernelContext *context) override { ADP_LOG(INFO) << "OCRIdentifyPreHandleOp Compute"; } }; -class BatchDilatePolysOp : public OpKernel { - public : +class BatchDilatePolysOp : public OpKernel { public : explicit BatchDilatePolysOp(OpKernelConstruction *context):OpKernel(context){} ~BatchDilatePolysOp() override{} void Compute(OpKernelContext *context) override{ADP_LOG(INFO)<<"BatchDilatePolysOp Compute";} }; -class OCRFindContoursOp : public OpKernel { - public : +class OCRFindContoursOp : public OpKernel { public : explicit OCRFindContoursOp(OpKernelConstruction *context):OpKernel(context){} ~OCRFindContoursOp() override{} void Compute(OpKernelContext *context) override{ADP_LOG(INFO)<<"OCRFindContoursOp Compute";} }; -class OCRDetectionPostHandleOp : public OpKernel { - public: +class OCRDetectionPostHandleOp : public OpKernel { public: explicit OCRDetectionPostHandleOp(OpKernelConstruction *context) : OpKernel(context) {} ~OCRDetectionPostHandleOp() override {} void Compute(OpKernelContext *context) override { ADP_LOG(INFO) << "OCRDetectionPostHandleOp Compute"; } }; -class ResizeAndClipPolysOp : public OpKernel { - public: +class ResizeAndClipPolysOp : public OpKernel { public: explicit ResizeAndClipPolysOp(OpKernelConstruction *context) : OpKernel(context) {} ~ResizeAndClipPolysOp() override {} void Compute(OpKernelContext *context) override { ADP_LOG(INFO) << "ResizeAndClipPolysOp Compute"; } }; -class DequeueOp : public OpKernel { - public: +class DequeueOp : public OpKernel { public: explicit DequeueOp(OpKernelConstruction *context) : OpKernel(context) {} ~DequeueOp() override {} void Compute(OpKernelContext *context) override { ADP_LOG(INFO) << "DequeueOp Compute"; } }; +class NonZeroWithValueShapeOp : public OpKernel { public: + explicit NonZeroWithValueShapeOp(OpKernelConstruction *context) : OpKernel(context) {} + ~NonZeroWithValueShapeOp() override {} + void Compute(OpKernelContext *context) override { ADP_LOG(INFO) << "NonZeroWithValueShapeOp Compute"; } +}; + REGISTER_KERNEL_BUILDER(Name("EmbeddingRankId").Device(DEVICE_CPU), EmbeddingRankIdOpKernel); REGISTER_KERNEL_BUILDER(Name("EmbeddingLocalIndex").Device(DEVICE_CPU), EmbeddingLocalIndexOpKernel); REGISTER_KERNEL_BUILDER(Name("LruCache").Device(DEVICE_CPU), LruCacheOp); @@ -200,6 +186,7 @@ REGISTER_KERNEL_BUILDER(Name("OCRFindContours").Device(DEVICE_CPU), OCRFindConto REGISTER_KERNEL_BUILDER(Name("OCRDetectionPostHandle").Device(DEVICE_CPU), OCRDetectionPostHandleOp); REGISTER_KERNEL_BUILDER(Name("ResizeAndClipPolys").Device(DEVICE_CPU), ResizeAndClipPolysOp); REGISTER_KERNEL_BUILDER(Name("Dequeue").Device(DEVICE_CPU), DequeueOp); +REGISTER_KERNEL_BUILDER(Name("NonZeroWithValueShape").Device(DEVICE_CPU), NonZeroWithValueShapeOp); #define REGISTER_KERNEL(type) \ REGISTER_KERNEL_BUILDER(Name("DeformableOffsets") \ -- Gitee From 373d4f1f328acdc5a0becc49f3fed129a81da101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=8D=E6=80=BF=E6=B6=9B?= Date: Fri, 19 Nov 2021 11:25:48 +0000 Subject: [PATCH 03/10] update tf_adapter/ops/npu_cpu_ops.cc. --- tf_adapter/ops/npu_cpu_ops.cc | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/tf_adapter/ops/npu_cpu_ops.cc b/tf_adapter/ops/npu_cpu_ops.cc index f0f151582..fb9ce37b6 100644 --- a/tf_adapter/ops/npu_cpu_ops.cc +++ b/tf_adapter/ops/npu_cpu_ops.cc @@ -44,7 +44,7 @@ REGISTER_OP("EmbeddingRankId") Output rank_id: Tensors with the same shape as index.dim(0)*3. )doc"); -//regist embedding local index op +// regist embedding local index op REGISTER_OP("EmbeddingLocalIndex") .Input("addr_table: uint64") .Input("index: T") @@ -74,7 +74,7 @@ REGISTER_OP("EmbeddingLocalIndex") recover_idx: The sorted local_idx element corresponds to the position of the original input index. )doc"); -//regist lru cahe op +// regist lru cahe op REGISTER_OP("LruCache") .Output("cache: resource") .Attr("cache_size: int") @@ -84,7 +84,7 @@ REGISTER_OP("LruCache") .Attr("dtype: {uint32, uint64, int32, int64}") .SetIsStateful() .SetShapeFn(shape_inference::ScalarShape); -//regist cache add op +// regist cache add op REGISTER_OP("CacheAdd") .Input("cache: resource") .Input("ids: T") @@ -100,7 +100,7 @@ REGISTER_OP("CacheAdd") c->set_output(3, c->Vector(c->UnknownDim())); return Status::OK(); }); -//regist cache remote index to local op +// regist cache remote index to local op REGISTER_OP("CacheRemoteIndexToLocal") .Input("cache: resource") .Input("ids: T") @@ -110,7 +110,7 @@ REGISTER_OP("CacheRemoteIndexToLocal") c->set_output(0, c->Vector(c->Rank(c->input(1)))); return Status::OK(); }); -//regist cache all index to local op +// regist cache all index to local op REGISTER_OP("CacheAllIndexToLocal") .Input("cache: resource") .Output("local_idx: dtype") @@ -120,7 +120,7 @@ REGISTER_OP("CacheAllIndexToLocal") return Status::OK(); }); -//regist deformable offsets op +// regist deformable offsets op REGISTER_OP("DeformableOffsets") .Input("x: T") .Input("offsets: T") @@ -173,7 +173,7 @@ REGISTER_OP("DeformableOffsets") c->set_output(0, c->MakeShape(out_dims)); return Status::OK(); }); -//regist deformable offsets grad op +// regist deformable offsets grad op REGISTER_OP("DeformableOffsetsGrad") .Input("grad: T") .Input("x: T") @@ -195,7 +195,7 @@ REGISTER_OP("DeformableOffsetsGrad") c->set_output(1, input_offsets_shape); return Status::OK(); }); -//regist Random Choice With Mask op +// regist Random Choice With Mask op REGISTER_OP("RandomChoiceWithMask") .Input("x: bool") .Output("y: int32") @@ -219,7 +219,7 @@ REGISTER_OP("RandomChoiceWithMask") } return Status::OK(); }); -//regist dense image warp op +// regist dense image warp op REGISTER_OP("DenseImageWarp") .Input("image: T") .Input("flow: S") @@ -231,7 +231,7 @@ REGISTER_OP("DenseImageWarp") c->set_output(0, input_image_shape); return Status::OK(); }); -//regist dense image warp grad op +// regist dense image warp grad op REGISTER_OP("DenseImageWarpGrad") .Input("grad: T") .Input("image: T") @@ -515,4 +515,18 @@ REGISTER_OP("OCRDetectionPostHandle") c->set_output(3, c->Scalar()); return Status::OK(); }); + + REGISTER_OP("NonZeroWithValueShape") + .Input("value: T") + .Input("index: int32") + .Input("count: int32") + .Output("out_value: T") + .Output("out_index: int32") + .Attr("T: {double, float, float16, int8, uint8, int16, uint16, int32, uint32, int64, uint64, bool}") + + .SetShapeFn([](shape_inference::InferenceContext *c) { + c->set_output(0, c->Vector(c->UnknownDim())); + c->set_output(1, c->Vector(c->UnknownDim())); + return Status::OK(); + }); } // namespace tensorflow -- Gitee From 1ca6cf37f97b8752522b0d667e94c802a1f3b108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=8D=E6=80=BF=E6=B6=9B?= Date: Fri, 19 Nov 2021 11:28:12 +0000 Subject: [PATCH 04/10] add tf_adapter/tests/ut/kernels/testcase/non_zero_with_value_shape_ops_test.cc. --- .../non_zero_with_value_shape_ops_test.cc | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 tf_adapter/tests/ut/kernels/testcase/non_zero_with_value_shape_ops_test.cc diff --git a/tf_adapter/tests/ut/kernels/testcase/non_zero_with_value_shape_ops_test.cc b/tf_adapter/tests/ut/kernels/testcase/non_zero_with_value_shape_ops_test.cc new file mode 100644 index 000000000..6739b7849 --- /dev/null +++ b/tf_adapter/tests/ut/kernels/testcase/non_zero_with_value_shape_ops_test.cc @@ -0,0 +1,63 @@ +#include +#include "tf_adapter/kernels/npu_cpu_ops.cc" +#include "gtest/gtest.h" +#include "tensorflow/core/framework/attr_value.pb.h" +#include "tensorflow/core/framework/attr_value_util.h" +#include "tensorflow/core/framework/fake_input.h" +#include "tensorflow/core/framework/node_def.pb.h" +#include "tensorflow/core/framework/node_def_builder.h" +#include "tensorflow/core/framework/op_kernel.h" +#include "tensorflow/core/framework/shape_inference.h" +#include "tensorflow/core/platform/test.h" + +namespace tensorflow { +namespace { + +PartialTensorShape TShape(std::initializer_list dims) { + return PartialTensorShape(dims); +} + +FakeInputFunctor FakeInputStub(DataType dt) { + return [dt](const OpDef& op_def, int in_index, const NodeDef& node_def, + NodeDefBuilder* builder) { + char c = 'a' + (in_index % 26); + string in_node = string(&c, 1); + builder->Input(in_node, 0, dt); + return Status::OK(); + }; +} + + +TEST(NonZeroWithValueOpsTest, TestNonZeroWithValueShape) { + DataTypeSlice input_types({DT_INT32, DT_INT32, DT_INT32}); + MemoryTypeSlice input_memory_types; + DataTypeSlice output_types({DT_INT32, DT_INT32}); + MemoryTypeSlice output_memory_types; + DeviceBase *device = new DeviceBase(Env::Default()); + NodeDef *node_def = new NodeDef(); + OpDef *op_def = new OpDef(); + OpKernelConstruction *context = new OpKernelConstruction(DEVICE_CPU, device, nullptr, node_def, op_def, nullptr, + input_types, input_memory_types, output_types, output_memory_types, + 1, nullptr); + NonZeroWithValueShapeOp cache(context); + delete device; + delete node_def; + delete op_def; + delete context; +} + +TEST(NonZeroWithValueOpsTest, TestNonZeroWithValueShapeInfer) { + const OpRegistrationData* reg; + TF_CHECK_OK(OpRegistry::Global()->LookUp("NonZeroWithValueShape", ®)); + OpDef op_def = reg->op_def; + NodeDef def; + TF_CHECK_OK(NodeDefBuilder("dummy", &op_def) + .Input(FakeInputStub(DT_INT32)) + .Input(FakeInputStub(DT_INT32)) + .Input(FakeInputStub(DT_INT32)) + .Finalize(&def)); + shape_inference::InferenceContext c(0, &def, op_def, {TShape({})}, {}, {}, {}); + TF_CHECK_OK(reg->shape_inference_fn(&c)); +} +} // namespace +} // namespace tensorflow \ No newline at end of file -- Gitee From e868f163be2a5b241e0e0055003f3242ecf77aaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=8D=E6=80=BF=E6=B6=9B?= Date: Fri, 19 Nov 2021 11:29:13 +0000 Subject: [PATCH 05/10] add tf_adapter/tests/st/kernels/testcase/non_zero_with_value_shape_ops_test.cc. --- .../non_zero_with_value_shape_ops_test.cc | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 tf_adapter/tests/st/kernels/testcase/non_zero_with_value_shape_ops_test.cc diff --git a/tf_adapter/tests/st/kernels/testcase/non_zero_with_value_shape_ops_test.cc b/tf_adapter/tests/st/kernels/testcase/non_zero_with_value_shape_ops_test.cc new file mode 100644 index 000000000..24239045f --- /dev/null +++ b/tf_adapter/tests/st/kernels/testcase/non_zero_with_value_shape_ops_test.cc @@ -0,0 +1,63 @@ +#include +#include "tf_adapter/kernels/npu_cpu_ops.cc" +#include "gtest/gtest.h" +#include "tensorflow/core/framework/attr_value.pb.h" +#include "tensorflow/core/framework/attr_value_util.h" +#include "tensorflow/core/framework/fake_input.h" +#include "tensorflow/core/framework/node_def.pb.h" +#include "tensorflow/core/framework/node_def_builder.h" +#include "tensorflow/core/framework/op_kernel.h" +#include "tensorflow/core/framework/shape_inference.h" +#include "tensorflow/core/platform/test.h" + +namespace tensorflow { +namespace { + +PartialTensorShape TShape(std::initializer_list dims) { + return PartialTensorShape(dims); +} + +FakeInputFunctor FakeInputStub(DataType dt) { + return [dt](const OpDef& op_def, int in_index, const NodeDef& node_def, + NodeDefBuilder* builder) { + char c = 'a' + (in_index % 26); + string in_node = string(&c, 1); + builder->Input(in_node, 0, dt); + return Status::OK(); + }; +} + + +TEST(NonZeroWithValueOpsTest, TestNonZeroWithValueShape) { + DataTypeSlice input_types({DT_INT32, DT_INT32, DT_INT32}); + MemoryTypeSlice input_memory_types; + DataTypeSlice output_types({DT_INT32, DT_INT32}); + MemoryTypeSlice output_memory_types; + DeviceBase *device = new DeviceBase(Env::Default()); + NodeDef *node_def = new NodeDef(); + OpDef *op_def = new OpDef(); + OpKernelConstruction *context = new OpKernelConstruction(DEVICE_CPU, device, nullptr, node_def, op_def, nullptr, + input_types, input_memory_types, output_types, output_memory_types, + 1, nullptr); + NonZeroWithValueShapeOp cache(context); + delete device; + delete node_def; + delete op_def; + delete context; +} + +TEST(NonZeroWithValueOpsTest, TestNonZeroWithValueShapeInfer) { + const OpRegistrationData* reg; + TF_CHECK_OK(OpRegistry::Global()->LookUp("NonZeroWithValueShape", ®)); + OpDef op_def = reg->op_def; + NodeDef def; + TF_CHECK_OK(NodeDefBuilder("dummy", &op_def) + .Input(FakeInputStub(DT_INT32)) + .Input(FakeInputStub(DT_INT32)) + .Input(FakeInputStub(DT_INT32)) + .Finalize(&def)); + shape_inference::InferenceContext c(0, &def, op_def,{TShape({})}, {}, {}, {}); + TF_CHECK_OK(reg->shape_inference_fn(&c)); +} +} // namespace +} // namespace tensorflow \ No newline at end of file -- Gitee From 80b4c6294de2e02ed7f9d7f1316bde8047c5c2e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=8D=E6=80=BF=E6=B6=9B?= Date: Fri, 19 Nov 2021 11:29:40 +0000 Subject: [PATCH 06/10] update tf_adapter/tests/st/CMakeLists.txt. --- tf_adapter/tests/st/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/tf_adapter/tests/st/CMakeLists.txt b/tf_adapter/tests/st/CMakeLists.txt index 302442238..40b45c3b7 100644 --- a/tf_adapter/tests/st/CMakeLists.txt +++ b/tf_adapter/tests/st/CMakeLists.txt @@ -27,6 +27,7 @@ file(GLOB_RECURSE ST_SOURCES "optimizers/testcase/get_attr_optimize_pass_test.cc" "kernels/testcase/ocr_ops_test.cc" "kernels/testcase/non_zero_with_value_ops_test.cc" + "kernels/testcase/non_zero_with_value_shape_ops_test.cc" "kernels/testcase/geop_npu_test.cc" "util/testcase/*.cc" "kernels/testcase/layer_norm_ops_test.cc" -- Gitee From 629b015e31b3b6b5dc04e7036401a44ca0ae00c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=8D=E6=80=BF=E6=B6=9B?= Date: Mon, 29 Nov 2021 02:03:19 +0000 Subject: [PATCH 07/10] update tf_adapter/kernels/npu_cpu_ops.cc. --- tf_adapter/kernels/npu_cpu_ops.cc | 65 ++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 22 deletions(-) diff --git a/tf_adapter/kernels/npu_cpu_ops.cc b/tf_adapter/kernels/npu_cpu_ops.cc index 49a6aeeff..3b5e0e54f 100644 --- a/tf_adapter/kernels/npu_cpu_ops.cc +++ b/tf_adapter/kernels/npu_cpu_ops.cc @@ -23,49 +23,56 @@ #include "tf_adapter/util/cache_interface.h" namespace tensorflow { -class EmbeddingRankIdOpKernel : public OpKernel { public: +class EmbeddingRankIdOpKernel : public OpKernel { + public: explicit EmbeddingRankIdOpKernel(OpKernelConstruction *context) : OpKernel(context) {} ~EmbeddingRankIdOpKernel() {} void Compute(OpKernelContext *context) override { ADP_LOG(INFO) << "EmbeddingRankIdOp Compute."; } }; -class EmbeddingLocalIndexOpKernel : public OpKernel { public: +class EmbeddingLocalIndexOpKernel : public OpKernel { + public: explicit EmbeddingLocalIndexOpKernel(OpKernelConstruction *context) : OpKernel(context) {} ~EmbeddingLocalIndexOpKernel() {} void Compute(OpKernelContext *context) override { ADP_LOG(INFO) << "EmbeddingLocalIndexOp Compute."; } }; -class LruCacheOp : public ResourceOpKernel { public: +class LruCacheOp : public ResourceOpKernel { + public: explicit LruCacheOp(OpKernelConstruction* context) : ResourceOpKernel(context) {} ~LruCacheOp() override {} void Compute(OpKernelContext* context) override { ADP_LOG(INFO) << "LruCacheOp Compute"; } -private: + private: Status CreateResource(CacheInterface** resource) override EXCLUSIVE_LOCKS_REQUIRED(mu_) { return Status::OK(); } }; -class CacheAddOp : public OpKernel { public: +class CacheAddOp : public OpKernel { + public: explicit CacheAddOp(OpKernelConstruction *context) : OpKernel(context) {} ~CacheAddOp() override {} void Compute(OpKernelContext *context) override { ADP_LOG(INFO) << "CacheAddOp Compute"; } }; -class CacheRemoteIndexToLocalOp : public OpKernel { public: +class CacheRemoteIndexToLocalOp : public OpKernel { + public: explicit CacheRemoteIndexToLocalOp(OpKernelConstruction *context) : OpKernel(context) {} ~CacheRemoteIndexToLocalOp() override {} void Compute(OpKernelContext *context) override { ADP_LOG(INFO) << "CacheRemoteIndexToLocalOp Compute"; } }; -class CacheAllIndexToLocalOp : public OpKernel { public: +class CacheAllIndexToLocalOp : public OpKernel { + public: explicit CacheAllIndexToLocalOp(OpKernelConstruction *context) : OpKernel(context) {} ~CacheAllIndexToLocalOp() override {} void Compute(OpKernelContext *context) override { ADP_LOG(INFO) << "CacheAllIndexToLocalOp Compute"; } }; template -class DeformableOffsetsOp : public OpKernel { public: +class DeformableOffsetsOp : public OpKernel { + public: explicit DeformableOffsetsOp(OpKernelConstruction *context) : OpKernel(context) {} ~DeformableOffsetsOp() override {} void Compute(OpKernelContext *context) override { @@ -76,7 +83,8 @@ class DeformableOffsetsOp : public OpKernel { public: }; template -class DeformableOffsetsGradOp : public OpKernel { public: +class DeformableOffsetsGradOp : public OpKernel { + public: explicit DeformableOffsetsGradOp(OpKernelConstruction *context) : OpKernel(context) {} ~DeformableOffsetsGradOp() override {} void Compute(OpKernelContext *context) override { @@ -86,7 +94,8 @@ class DeformableOffsetsGradOp : public OpKernel { public: bool IsExpensive() override { return false; } }; -class RandomChoiceWithMaskOp : public OpKernel { public: +class RandomChoiceWithMaskOp : public OpKernel { + public: explicit RandomChoiceWithMaskOp(OpKernelConstruction *context) : OpKernel(context) {} ~RandomChoiceWithMaskOp() override {} void Compute(OpKernelContext *context) override { @@ -95,7 +104,8 @@ class RandomChoiceWithMaskOp : public OpKernel { public: }; template -class DenseImageWarpOp : public OpKernel { public: +class DenseImageWarpOp : public OpKernel { + public: explicit DenseImageWarpOp(OpKernelConstruction *context) : OpKernel(context) {} ~DenseImageWarpOp() override {} void Compute(OpKernelContext *context) override {} @@ -103,68 +113,79 @@ class DenseImageWarpOp : public OpKernel { public: }; template -class DenseImageWarpGradOp : public OpKernel { public: +class DenseImageWarpGradOp : public OpKernel { + public: explicit DenseImageWarpGradOp(OpKernelConstruction *context) : OpKernel(context) {} ~DenseImageWarpGradOp() override {} void Compute(OpKernelContext *context) override {} bool IsExpensive() override { return false; } }; -class BatchEnqueueOp : public OpKernel { public: +class BatchEnqueueOp : public OpKernel { + public: explicit BatchEnqueueOp(OpKernelConstruction *context) : OpKernel(context) {} ~BatchEnqueueOp() override {} void Compute(OpKernelContext *context) override { ADP_LOG(INFO) << "BatchEnqueueOp Compute"; } }; -class OCRRecognitionPreHandleOp : public OpKernel { public: +class OCRRecognitionPreHandleOp : public OpKernel { + public: explicit OCRRecognitionPreHandleOp(OpKernelConstruction *context) : OpKernel(context) {} ~OCRRecognitionPreHandleOp() override {} void Compute(OpKernelContext *context) override { ADP_LOG(INFO) << "OCRRecognitionPreHandleOp Compute"; } }; -class OCRDetectionPreHandleOp : public OpKernel { public: +class OCRDetectionPreHandleOp : public OpKernel { + public: explicit OCRDetectionPreHandleOp(OpKernelConstruction *context) : OpKernel(context) {} ~OCRDetectionPreHandleOp() override {} void Compute(OpKernelContext *context) override { ADP_LOG(INFO) << "OCRDetectionPreHandleOp Compute"; } }; -class OCRIdentifyPreHandleOp : public OpKernel { public: +class OCRIdentifyPreHandleOp : public OpKernel { + public: explicit OCRIdentifyPreHandleOp(OpKernelConstruction *context) : OpKernel(context) {} ~OCRIdentifyPreHandleOp() override {} void Compute(OpKernelContext *context) override { ADP_LOG(INFO) << "OCRIdentifyPreHandleOp Compute"; } }; -class BatchDilatePolysOp : public OpKernel { public : +class BatchDilatePolysOp : public OpKernel { + public : explicit BatchDilatePolysOp(OpKernelConstruction *context):OpKernel(context){} ~BatchDilatePolysOp() override{} void Compute(OpKernelContext *context) override{ADP_LOG(INFO)<<"BatchDilatePolysOp Compute";} }; -class OCRFindContoursOp : public OpKernel { public : +class OCRFindContoursOp : public OpKernel { + public : explicit OCRFindContoursOp(OpKernelConstruction *context):OpKernel(context){} ~OCRFindContoursOp() override{} void Compute(OpKernelContext *context) override{ADP_LOG(INFO)<<"OCRFindContoursOp Compute";} }; -class OCRDetectionPostHandleOp : public OpKernel { public: +class OCRDetectionPostHandleOp : public OpKernel { + public: explicit OCRDetectionPostHandleOp(OpKernelConstruction *context) : OpKernel(context) {} ~OCRDetectionPostHandleOp() override {} void Compute(OpKernelContext *context) override { ADP_LOG(INFO) << "OCRDetectionPostHandleOp Compute"; } }; -class ResizeAndClipPolysOp : public OpKernel { public: +class ResizeAndClipPolysOp : public OpKernel { + public: explicit ResizeAndClipPolysOp(OpKernelConstruction *context) : OpKernel(context) {} ~ResizeAndClipPolysOp() override {} void Compute(OpKernelContext *context) override { ADP_LOG(INFO) << "ResizeAndClipPolysOp Compute"; } }; -class DequeueOp : public OpKernel { public: +class DequeueOp : public OpKernel { + public: explicit DequeueOp(OpKernelConstruction *context) : OpKernel(context) {} ~DequeueOp() override {} void Compute(OpKernelContext *context) override { ADP_LOG(INFO) << "DequeueOp Compute"; } }; -class NonZeroWithValueShapeOp : public OpKernel { public: +class NonZeroWithValueShapeOp : public OpKernel { + public: explicit NonZeroWithValueShapeOp(OpKernelConstruction *context) : OpKernel(context) {} ~NonZeroWithValueShapeOp() override {} void Compute(OpKernelContext *context) override { ADP_LOG(INFO) << "NonZeroWithValueShapeOp Compute"; } -- Gitee From 3b6a0f0c38c53f4599572d6348fa08596a8f18a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=8D=E6=80=BF=E6=B6=9B?= Date: Fri, 10 Dec 2021 02:45:19 +0000 Subject: [PATCH 08/10] update non_zero_with_value_shape_ops_test.cc. --- .../ut/kernels/testcase/non_zero_with_value_shape_ops_test.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/tf_adapter/tests/ut/kernels/testcase/non_zero_with_value_shape_ops_test.cc b/tf_adapter/tests/ut/kernels/testcase/non_zero_with_value_shape_ops_test.cc index 6739b7849..03a21b11e 100644 --- a/tf_adapter/tests/ut/kernels/testcase/non_zero_with_value_shape_ops_test.cc +++ b/tf_adapter/tests/ut/kernels/testcase/non_zero_with_value_shape_ops_test.cc @@ -27,7 +27,6 @@ FakeInputFunctor FakeInputStub(DataType dt) { }; } - TEST(NonZeroWithValueOpsTest, TestNonZeroWithValueShape) { DataTypeSlice input_types({DT_INT32, DT_INT32, DT_INT32}); MemoryTypeSlice input_memory_types; -- Gitee From d1d4e7512a75a301ebc2be3604ef389c392094df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=8D=E6=80=BF=E6=B6=9B?= Date: Fri, 10 Dec 2021 02:50:44 +0000 Subject: [PATCH 09/10] update tf_adapter/tests/st/CMakeLists.txt. --- tf_adapter/tests/st/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tf_adapter/tests/st/CMakeLists.txt b/tf_adapter/tests/st/CMakeLists.txt index 40b45c3b7..832b73f12 100644 --- a/tf_adapter/tests/st/CMakeLists.txt +++ b/tf_adapter/tests/st/CMakeLists.txt @@ -27,7 +27,7 @@ file(GLOB_RECURSE ST_SOURCES "optimizers/testcase/get_attr_optimize_pass_test.cc" "kernels/testcase/ocr_ops_test.cc" "kernels/testcase/non_zero_with_value_ops_test.cc" - "kernels/testcase/non_zero_with_value_shape_ops_test.cc" + "kernels/testcase/geop_npu_test.cc" "util/testcase/*.cc" "kernels/testcase/layer_norm_ops_test.cc" -- Gitee From 92eabd2db0b255ba8913588e720470fcff6f8c0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=8D=E6=80=BF=E6=B6=9B?= Date: Fri, 10 Dec 2021 02:51:11 +0000 Subject: [PATCH 10/10] update tf_adapter/tests/st/CMakeLists.txt. --- tf_adapter/tests/st/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tf_adapter/tests/st/CMakeLists.txt b/tf_adapter/tests/st/CMakeLists.txt index 832b73f12..40b45c3b7 100644 --- a/tf_adapter/tests/st/CMakeLists.txt +++ b/tf_adapter/tests/st/CMakeLists.txt @@ -27,7 +27,7 @@ file(GLOB_RECURSE ST_SOURCES "optimizers/testcase/get_attr_optimize_pass_test.cc" "kernels/testcase/ocr_ops_test.cc" "kernels/testcase/non_zero_with_value_ops_test.cc" - + "kernels/testcase/non_zero_with_value_shape_ops_test.cc" "kernels/testcase/geop_npu_test.cc" "util/testcase/*.cc" "kernels/testcase/layer_norm_ops_test.cc" -- Gitee