From 2001e0863f1816fea0a5880b0ea7c31d9b566511 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=91=D0=B0=D1=80?= =?utf8?q?=D0=B0=D0=BD=D0=BD=D0=B8=D0=BA=D0=BE=D0=B2/AI=20Tools=20Lab=20/S?= =?utf8?q?RR/Engineer/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Mon, 5 Aug 2019 14:09:54 +0300 Subject: [PATCH] [mir] Remove Deserializer unittest (#6178) This is a leftover after removing serialization support. Signed-off-by: Sergei Barannikov --- compiler/mir/unittests/Deserializer.cpp | 303 -------------------------------- 1 file changed, 303 deletions(-) delete mode 100644 compiler/mir/unittests/Deserializer.cpp diff --git a/compiler/mir/unittests/Deserializer.cpp b/compiler/mir/unittests/Deserializer.cpp deleted file mode 100644 index 5b23f90..0000000 --- a/compiler/mir/unittests/Deserializer.cpp +++ /dev/null @@ -1,303 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. 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 - -#include "mir/Deserializer.h" -#include "mir/ShapeRange.h" -#include "mir/Tensor.h" - -using namespace mir; - -const double EPS = 0.0000001; - -static void checkShape(const Shape &shape, const proto::TensorShapeProto &proto_shape) -{ - ASSERT_EQ(shape.rank(), proto_shape.dims_size()); - for (int i = 0; i < shape.rank(); i++) - { - ASSERT_EQ(shape.dim(i), proto_shape.dims(i)); - } -} - -template -static void checkTensorContent(const Tensor &tensor, const proto::TensorProto &proto_tensor) -{ - ShapeRange range(tensor.getShape()); - auto data = (T *)proto_tensor.tensor_content().c_str(); - int i = 0; - for (auto &idx : range) - { - ASSERT_EQ(tensor.at(idx), data[i++]); - } -} - -static void checkIntTensor(const Tensor &tensor, const proto::TensorProto &proto_tensor) -{ - ASSERT_EQ(proto_tensor.dtype(), proto::DataType::DT_INT32); - checkTensorContent(tensor, proto_tensor); -} - -static void checkFloatTensor(const Tensor &tensor, const proto::TensorProto &proto_tensor) -{ - ASSERT_EQ(proto_tensor.dtype(), proto::DataType::DT_FLOAT); - checkTensorContent(tensor, proto_tensor); -} - -static void checkDoubleTensor(const Tensor &tensor, const proto::TensorProto &proto_tensor) -{ - ASSERT_EQ(proto_tensor.dtype(), proto::DataType::DT_DOUBLE); - checkTensorContent(tensor, proto_tensor); -} - -TEST(Deserializer, ShapeDeserializationTest) -{ - Deserializer deserializer; - - proto::TensorShapeProto proto_shape; - std::string serializedShape; - Shape shape; - proto_shape.SerializeToString(&serializedShape); - shape = deserializer.deserializeFromString(serializedShape); - checkShape(shape, proto_shape); - - proto_shape.add_dims(5); - proto_shape.SerializeToString(&serializedShape); - shape = deserializer.deserializeFromString(serializedShape); - checkShape(shape, proto_shape); - - proto_shape.add_dims(2); - proto_shape.add_dims(4); - proto_shape.SerializeToString(&serializedShape); - shape = deserializer.deserializeFromString(serializedShape); - checkShape(shape, proto_shape); - - proto_shape.clear_dims(); - proto_shape.add_dims(1); - proto_shape.add_dims(1); - proto_shape.add_dims(1); - proto_shape.add_dims(1); - proto_shape.SerializeToString(&serializedShape); - shape = deserializer.deserializeFromString(serializedShape); - checkShape(shape, proto_shape); -} - -TEST(Deserializer, IntTensorDeserializationTest) -{ - Deserializer deserializer; - int tmp = 0; - - std::vector values; - proto::TensorProto proto_tensor; - proto_tensor.set_dtype(proto::DataType::DT_INT32); - proto::TensorShapeProto *proto_shapePtr = proto_tensor.mutable_shape(); - std::string serializedTensor; - - Shape shape_1{3}; - for (auto &idx : ShapeRange(shape_1)) - { - (void)idx; - values.push_back(tmp++); - } - proto_tensor.set_tensor_content( - std::string((char *)values.data(), sizeof(int) * shape_1.numElements())); - for (int32_t i = 0; i < shape_1.rank(); i++) - { - proto_shapePtr->add_dims(shape_1.dim(i)); - } - proto_tensor.SerializeToString(&serializedTensor); - TensorVariant tensor_1 = deserializer.deserializeFromString(serializedTensor); - checkShape(shape_1, proto_tensor.shape()); - checkIntTensor(Tensor(tensor_1), proto_tensor); - - Shape shape_2{3, 4, 5}; - values.clear(); - proto_shapePtr->clear_dims(); - for (auto &idx : ShapeRange(shape_2)) - { - (void)idx; - values.push_back(tmp--); - } - proto_tensor.set_tensor_content( - std::string((char *)values.data(), sizeof(int) * shape_2.numElements())); - for (int32_t i = 0; i < shape_2.rank(); i++) - { - proto_shapePtr->add_dims(shape_2.dim(i)); - } - proto_tensor.SerializeToString(&serializedTensor); - TensorVariant tensor_2 = deserializer.deserializeFromString(serializedTensor); - checkShape(shape_2, proto_tensor.shape()); - checkIntTensor(Tensor(tensor_2), proto_tensor); - - Shape shape_3{1, 1, 1, 1, 1}; - values.clear(); - proto_shapePtr->clear_dims(); - for (auto &idx : ShapeRange(shape_3)) - { - (void)idx; - values.push_back(tmp++); - } - proto_tensor.set_tensor_content( - std::string((char *)values.data(), sizeof(int) * shape_3.numElements())); - for (int32_t i = 0; i < shape_3.rank(); i++) - { - proto_shapePtr->add_dims(shape_3.dim(i)); - } - proto_tensor.SerializeToString(&serializedTensor); - TensorVariant tensor_3 = deserializer.deserializeFromString(serializedTensor); - checkShape(shape_3, proto_tensor.shape()); - checkIntTensor(Tensor(tensor_3), proto_tensor); -} - -TEST(Deserializer, FloatTensorDeserializationTest) -{ - Deserializer deserializer; - float tmp = 1.0f; - - std::vector values; - proto::TensorProto proto_tensor; - proto_tensor.set_dtype(proto::DataType::DT_FLOAT); - proto::TensorShapeProto *proto_shapePtr = proto_tensor.mutable_shape(); - std::string serializedTensor; - - Shape shape_1{3}; - for (auto &idx : ShapeRange(shape_1)) - { - (void)idx; - values.push_back(tmp); - tmp += 7.3f; - } - proto_tensor.set_tensor_content( - std::string((char *)values.data(), sizeof(float) * shape_1.numElements())); - for (int32_t i = 0; i < shape_1.rank(); i++) - { - proto_shapePtr->add_dims(shape_1.dim(i)); - } - proto_tensor.SerializeToString(&serializedTensor); - TensorVariant tensor_1 = deserializer.deserializeFromString(serializedTensor); - checkShape(shape_1, proto_tensor.shape()); - checkFloatTensor(Tensor(tensor_1), proto_tensor); - - Shape shape_2{3, 4, 5}; - values.clear(); - proto_shapePtr->clear_dims(); - for (auto &idx : ShapeRange(shape_2)) - { - (void)idx; - values.push_back(tmp); - tmp *= -1.32f; - } - proto_tensor.set_tensor_content( - std::string((char *)values.data(), sizeof(float) * shape_2.numElements())); - for (int32_t i = 0; i < shape_2.rank(); i++) - { - proto_shapePtr->add_dims(shape_2.dim(i)); - } - proto_tensor.SerializeToString(&serializedTensor); - TensorVariant tensor_2 = deserializer.deserializeFromString(serializedTensor); - checkShape(shape_2, proto_tensor.shape()); - checkFloatTensor(Tensor(tensor_2), proto_tensor); - - Shape shape_3{1, 1, 1, 1, 1}; - values.clear(); - proto_shapePtr->clear_dims(); - for (auto &idx : ShapeRange(shape_3)) - { - (void)idx; - tmp /= 2; - values.push_back(tmp); - } - proto_tensor.set_tensor_content( - std::string((char *)values.data(), sizeof(float) * shape_3.numElements())); - for (int32_t i = 0; i < shape_3.rank(); i++) - { - proto_shapePtr->add_dims(shape_3.dim(i)); - } - proto_tensor.SerializeToString(&serializedTensor); - TensorVariant tensor_3 = deserializer.deserializeFromString(serializedTensor); - checkShape(shape_3, proto_tensor.shape()); - checkFloatTensor(Tensor(tensor_3), proto_tensor); -} - -TEST(Deserializer, DoubleTensorDeserializationTest) -{ - Deserializer deserializer; - double tmp = 1.0f; - - std::vector values; - proto::TensorProto proto_tensor; - proto_tensor.set_dtype(proto::DataType::DT_DOUBLE); - proto::TensorShapeProto *proto_shapePtr = proto_tensor.mutable_shape(); - std::string serializedTensor; - - Shape shape_1{3}; - for (auto &idx : ShapeRange(shape_1)) - { - (void)idx; - values.push_back(tmp); - tmp += 7.3f; - } - proto_tensor.set_tensor_content( - std::string((char *)values.data(), sizeof(double) * shape_1.numElements())); - for (int32_t i = 0; i < shape_1.rank(); i++) - { - proto_shapePtr->add_dims(shape_1.dim(i)); - } - proto_tensor.SerializeToString(&serializedTensor); - TensorVariant tensor_1 = deserializer.deserializeFromString(serializedTensor); - checkShape(shape_1, proto_tensor.shape()); - checkDoubleTensor(Tensor(tensor_1), proto_tensor); - - Shape shape_2{3, 4, 5}; - values.clear(); - proto_shapePtr->clear_dims(); - for (auto &idx : ShapeRange(shape_2)) - { - (void)idx; - values.push_back(tmp); - tmp *= -1.32f; - } - proto_tensor.set_tensor_content( - std::string((char *)values.data(), sizeof(double) * shape_2.numElements())); - for (int32_t i = 0; i < shape_2.rank(); i++) - { - proto_shapePtr->add_dims(shape_2.dim(i)); - } - proto_tensor.SerializeToString(&serializedTensor); - TensorVariant tensor_2 = deserializer.deserializeFromString(serializedTensor); - checkShape(shape_2, proto_tensor.shape()); - checkDoubleTensor(Tensor(tensor_2), proto_tensor); - - Shape shape_3{1, 1, 1, 1, 1}; - values.clear(); - proto_shapePtr->clear_dims(); - for (auto &idx : ShapeRange(shape_3)) - { - (void)idx; - tmp /= 2; - values.push_back(tmp); - } - proto_tensor.set_tensor_content( - std::string((char *)values.data(), sizeof(double) * shape_3.numElements())); - for (int32_t i = 0; i < shape_3.rank(); i++) - { - proto_shapePtr->add_dims(shape_3.dim(i)); - } - proto_tensor.SerializeToString(&serializedTensor); - TensorVariant tensor_3 = deserializer.deserializeFromString(serializedTensor); - checkShape(shape_3, proto_tensor.shape()); - checkDoubleTensor(Tensor(tensor_3), proto_tensor); -} -- 2.7.4