[mir] Remove stale serialization support (#6120)
authorСергей Баранников/AI Tools Lab /SRR/Engineer/삼성전자 <s.barannikov@samsung.com>
Fri, 2 Aug 2019 07:27:28 +0000 (10:27 +0300)
committerEfimov Alexander/AI Tools Lab/./Samsung Electronics <a.efimov@samsung.com>
Fri, 2 Aug 2019 07:27:28 +0000 (10:27 +0300)
It is stale and were never used.

Signed-off-by: Sergei Barannikov <s.barannikov@samsung.com>
compiler/mir/CMakeLists.txt
compiler/mir/include/mir/Serializer.h [deleted file]
compiler/mir/proto/CMakeLists.txt [deleted file]
compiler/mir/proto/mir.proto [deleted file]
compiler/mir/src/Deserializer.cpp [deleted file]
compiler/mir/src/Serializer.cpp [deleted file]
compiler/mir/unittests/CMakeLists.txt
compiler/mir/unittests/Serializer.cpp [deleted file]

index e7eaf51..9fa8ef0 100644 (file)
@@ -24,22 +24,12 @@ set(MIR_SOURCES
     src/TensorVariant.cpp
     src/Visitor.cpp)
 
-add_subdirectory(proto)
-
-if(TARGET mir_proto)
-    list(APPEND MIR_SOURCES src/Serializer.cpp src/Deserializer.cpp)
-endif()
-
 add_library(mir STATIC ${MIR_SOURCES})
 target_include_directories(mir PUBLIC include)
 target_link_libraries(mir PUBLIC adtidas)
 target_link_libraries(mir PRIVATE nncc_common)
 target_link_libraries(mir PUBLIC nncc_coverage)
 
-if(TARGET mir_proto)
-    target_link_libraries(mir PUBLIC mir_proto)
-endif()
-
 set_target_properties(mir PROPERTIES POSITION_INDEPENDENT_CODE ON)
 set_target_properties(mir PROPERTIES LINKER_LANGUAGE CXX)
 
diff --git a/compiler/mir/include/mir/Serializer.h b/compiler/mir/include/mir/Serializer.h
deleted file mode 100644 (file)
index d954616..0000000
+++ /dev/null
@@ -1,50 +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.
- */
-
-#ifndef _MIR_SERIALIZER_H_
-#define _MIR_SERIALIZER_H_
-
-#include <iostream>
-
-#include "mir.pb.h"
-
-#include "mir/Shape.h"
-#include "mir/Tensor.h"
-
-namespace mir
-{
-
-/**
- * @brief template class for serialization
- * @tparam T - a class, objects of which we serialize
- */
-template <class T> class Serializer
-{
-public:
-  /**
-   * @brief simple exception class for invalid options
-   */
-  void serializeToStream(const T &obj, std::ostream &stream);
-
-  /**
-   * @brief serialize object to a sequence of bytes, stored in a string
-   */
-  std::string getSerializedObject(const T &);
-};
-
-} // namespace mir
-
-#endif //_MIR_SERIALIZER_H_
diff --git a/compiler/mir/proto/CMakeLists.txt b/compiler/mir/proto/CMakeLists.txt
deleted file mode 100644 (file)
index c0dfd2b..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-nncc_find_package(Protobuf QUIET)
-
-if(NOT Protobuf_FOUND)
-    message(WARNING "Protobuf not found, MIR serialization will not available")
-    return()
-endif()
-
-Protobuf_Generate(MIR_PROTO ${CMAKE_CURRENT_BINARY_DIR}/generated
-                  ${CMAKE_CURRENT_SOURCE_DIR} mir.proto)
-
-add_library(mir_proto STATIC ${MIR_PROTO_SOURCES})
-target_include_directories(mir_proto PUBLIC ${MIR_PROTO_INCLUDE_DIRS})
-target_link_libraries(mir_proto PUBLIC libprotobuf)
-set_target_properties(mir_proto PROPERTIES POSITION_INDEPENDENT_CODE ON)
diff --git a/compiler/mir/proto/mir.proto b/compiler/mir/proto/mir.proto
deleted file mode 100644 (file)
index a185a73..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-// TODO: move to proto3
-syntax = "proto2";
-
-package mir.proto;
-
-enum DataType {
-    // Not a legal value for DataType.  Used to indicate a DataType field
-    // has not been set.
-    DT_INVALID = 0;
-
-    DT_FLOAT = 1;
-    DT_DOUBLE = 2;
-    DT_INT32 = 3;
-
-//
-//    Other data types that we may support but do not support yet:
-//
-//    DT_BOOL = 4;
-//
-//    DT_STRING = 5;
-//
-//    DT_INT8 = 6;
-//    DT_INT16 = 7;
-//    DT_INT64 = 8;
-//
-//    DT_UINT8 = 9;
-//    DT_UINT16 = 10;
-//    DT_UINT32 = 11;
-//    DT_UINT64 = 12;
-//
-//    DT_COMPLEX64 = 13;  // Single-precision complex
-//    DT_COMPLEX128 = 14;  // Double-precision complex
-//
-//    DT_QINT8 = 15;     // Quantized int8
-//    DT_QINT16 = 16;    // Quantized int16
-//
-//    DT_QUINT8 = 17;    // Quantized uint8
-//    DT_QUINT16 = 18;   // Quantized uint16
-//    DT_QINT32 = 19;    // Quantized int32
-//
-//    DT_HALF = 20;
-//
-}
-
-// Separate proto for Shape, because we might add fields in the future
-message TensorShapeProto {
-    // Tensor size across dimensions
-    // TODO: Consider adding names, as in TensorFlow
-    repeated int32 dims = 2;
-    // rank field is not needed as it is the size of dims
-};
-
-// Protocol buffer representing a tensor.
-message TensorProto {
-    // Tensor data type
-    optional DataType dtype = 1;
-
-    // Shape of the tensor
-    optional TensorShapeProto shape = 2;
-
-    // Tensor name
-    optional string name = 3;
-
-    // Raw tensor data stored as string of bytes
-    optional bytes tensor_content = 4;
-};
-
-
-
diff --git a/compiler/mir/src/Deserializer.cpp b/compiler/mir/src/Deserializer.cpp
deleted file mode 100644 (file)
index 749cd7e..0000000
+++ /dev/null
@@ -1,103 +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 "mir/Deserializer.h"
-#include "mir.pb.h"
-
-#include "mir/ShapeRange.h"
-
-namespace mir
-{
-
-//
-// Shape Deserialization
-//
-
-static Shape deserializeFromMessage(const proto::TensorShapeProto &object_as_message)
-{
-  int rank = object_as_message.dims_size();
-  Shape res(rank);
-  for (int i = 0; i < rank; ++i)
-    res.dim(i) = object_as_message.dims(i);
-
-  return res;
-}
-
-template <> Shape Deserializer<Shape>::deserializeFromStream(std::istream &stream)
-{
-  proto::TensorShapeProto object_as_message;
-
-  object_as_message.ParseFromIstream(&stream);
-
-  return deserializeFromMessage(object_as_message);
-}
-
-template <> Shape Deserializer<Shape>::deserializeFromString(const std::string &bytes)
-{
-  proto::TensorShapeProto object_as_message;
-
-  object_as_message.ParseFromString(bytes);
-
-  return deserializeFromMessage(object_as_message);
-}
-
-//
-// Tensor Deserialization
-//
-
-static TensorVariant deserializeFromMessage(const proto::TensorProto &object_as_message)
-{
-  DTYPE dtype;
-  switch (object_as_message.dtype())
-  {
-    case proto::DataType::DT_INT32:
-      dtype = DTYPE::INT32;
-      break;
-    case proto::DataType::DT_FLOAT:
-      dtype = DTYPE::FLOAT32;
-      break;
-    case proto::DataType::DT_DOUBLE:
-      dtype = DTYPE::FLOAT64;
-      break;
-    default:
-      throw std::logic_error("Deserializer<TensorVariant>: received unsupported data type");
-  }
-
-  const std::string &tensor_content = object_as_message.tensor_content();
-  Shape shape = deserializeFromMessage(object_as_message.shape());
-  return TensorVariant(dtype, shape, tensor_content.data());
-}
-
-template <> TensorVariant Deserializer<TensorVariant>::deserializeFromStream(std::istream &stream)
-{
-  proto::TensorProto object_as_message;
-
-  object_as_message.ParseFromIstream(&stream);
-
-  return deserializeFromMessage(object_as_message);
-}
-
-template <>
-TensorVariant Deserializer<TensorVariant>::deserializeFromString(const std::string &bytes)
-{
-  proto::TensorProto object_as_message;
-
-  object_as_message.ParseFromString(bytes);
-
-  return deserializeFromMessage(object_as_message);
-}
-
-} // namespace mir
diff --git a/compiler/mir/src/Serializer.cpp b/compiler/mir/src/Serializer.cpp
deleted file mode 100644 (file)
index b2b820a..0000000
+++ /dev/null
@@ -1,92 +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 "mir/Serializer.h"
-#include "mir.pb.h"
-
-#include "mir/ShapeRange.h"
-
-namespace mir
-{
-
-template <class T> void Serializer<T>::serializeToStream(const T &obj, std::ostream &stream)
-{
-  std::string serializedObject = getSerializedObject(obj);
-  stream.write(serializedObject.c_str(), serializedObject.size());
-}
-
-template <> std::string Serializer<Shape>::getSerializedObject(const Shape &shape)
-{
-  proto::TensorShapeProto shapeProto;
-
-  int32_t rank = shape.rank();
-  for (int32_t i = 0; i < rank; i++)
-  {
-    shapeProto.add_dims(shape.dim(i));
-  }
-
-  return shapeProto.SerializeAsString();
-}
-
-static void setShapeToTensorProto(proto::TensorProto &tensor_proto, const Shape &shape)
-{
-  Serializer<Shape> shape_serializer;
-  tensor_proto.mutable_shape()->ParseFromString(shape_serializer.getSerializedObject(shape));
-}
-
-template <typename T, proto::DataType dtype>
-static proto::TensorProto serializeTensorContent(const Tensor<T> &tensor)
-{
-  proto::TensorProto tp;
-  setShapeToTensorProto(tp, tensor.getShape());
-
-  tp.set_dtype(dtype);
-
-  size_t data_size = tensor.getShape().numElements();
-  auto tensor_data = new T[data_size];
-  size_t i = 0;
-  ShapeRange shapeRange(tensor.getShape());
-  for (auto &idx : shapeRange)
-  {
-    tensor_data[i] = tensor.at(idx);
-    i++;
-  }
-
-  size_t raw_data_size = data_size * sizeof(T);
-  std::string raw_data(reinterpret_cast<char *>(tensor_data), raw_data_size);
-  delete[] tensor_data;
-  tp.set_tensor_content(raw_data);
-
-  return tp;
-}
-
-template <> std::string Serializer<Tensor<int>>::getSerializedObject(const Tensor<int> &tensor)
-{
-  return serializeTensorContent<int, proto::DT_INT32>(tensor).SerializeAsString();
-}
-
-template <> std::string Serializer<Tensor<float>>::getSerializedObject(const Tensor<float> &tensor)
-{
-  return serializeTensorContent<float, proto::DT_FLOAT>(tensor).SerializeAsString();
-}
-
-template <>
-std::string Serializer<Tensor<double>>::getSerializedObject(const Tensor<double> &tensor)
-{
-  return serializeTensorContent<double, proto::DT_DOUBLE>(tensor).SerializeAsString();
-}
-
-} // namespace mir
index 7151a5d..98f5fe6 100644 (file)
@@ -7,10 +7,6 @@ set(MIR_TEST_SOURCES
     NodeReplacer.cpp
     Graph.cpp)
 
-if(TARGET mir_proto)
-    list(APPEND MIR_TEST_SOURCES Serializer.cpp Deserializer.cpp)
-endif()
-
 if(NOT ENABLE_TEST)
     return()
 endif(NOT ENABLE_TEST)
diff --git a/compiler/mir/unittests/Serializer.cpp b/compiler/mir/unittests/Serializer.cpp
deleted file mode 100644 (file)
index e11028b..0000000
+++ /dev/null
@@ -1,246 +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 <gtest/gtest.h>
-#include <cmath>
-
-#include "mir/Serializer.h"
-#include "mir/ShapeRange.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 <typename T>
-static void checkTensorContent(const Tensor<T> &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<int> &tensor, const proto::TensorProto &proto_tensor)
-{
-  ASSERT_EQ(proto_tensor.dtype(), proto::DataType::DT_INT32);
-  checkTensorContent<int>(tensor, proto_tensor);
-}
-
-static void checkFloatTensor(const Tensor<float> &tensor, const proto::TensorProto &proto_tensor)
-{
-  ASSERT_EQ(proto_tensor.dtype(), proto::DataType::DT_FLOAT);
-  checkTensorContent<float>(tensor, proto_tensor);
-}
-
-static void checkDoubleTensor(const Tensor<double> &tensor, const proto::TensorProto &proto_tensor)
-{
-  ASSERT_EQ(proto_tensor.dtype(), proto::DataType::DT_DOUBLE);
-  checkTensorContent<double>(tensor, proto_tensor);
-}
-
-TEST(Serializer, ShapeSerializationTest)
-{
-  Serializer<Shape> serializer;
-
-  Shape shape_0{};
-  std::string serializedShape_0 = serializer.getSerializedObject(shape_0);
-  proto::TensorShapeProto proto_shape_0;
-  proto_shape_0.ParseFromString(serializedShape_0);
-  checkShape(shape_0, proto_shape_0);
-
-  Shape shape_1{1};
-  std::string serializedShape_1 = serializer.getSerializedObject(shape_1);
-  proto::TensorShapeProto proto_shape_1;
-  proto_shape_1.ParseFromString(serializedShape_1);
-  checkShape(shape_1, proto_shape_1);
-
-  Shape shape_2{5};
-  std::string serializedShape_2 = serializer.getSerializedObject(shape_2);
-  proto::TensorShapeProto proto_shape_2;
-  proto_shape_2.ParseFromString(serializedShape_2);
-  checkShape(shape_2, proto_shape_2);
-
-  Shape shape_3{2, 4};
-  std::string serializedShape_3 = serializer.getSerializedObject(shape_3);
-  proto::TensorShapeProto proto_shape_3;
-  proto_shape_3.ParseFromString(serializedShape_3);
-  checkShape(shape_3, proto_shape_3);
-
-  Shape shape_4{1, 1, 1, 1};
-  std::string serializedShape_4 = serializer.getSerializedObject(shape_4);
-  proto::TensorShapeProto proto_shape_4;
-  proto_shape_4.ParseFromString(serializedShape_4);
-  checkShape(shape_4, proto_shape_4);
-
-  Shape shape_5{1, 2, 3, 4, 5};
-  std::string serializedShape_5 = serializer.getSerializedObject(shape_5);
-  proto::TensorShapeProto proto_shape_5;
-  proto_shape_5.ParseFromString(serializedShape_5);
-  checkShape(shape_5, proto_shape_5);
-}
-
-TEST(Serializer, IntTensorSerializationTest)
-{
-  Serializer<Tensor<int>> serializer;
-  int tmp = 0;
-
-  Shape shape_1{3};
-  TensorVariant tv_1(DTYPE::INT32, shape_1);
-  Tensor<int> tensor_1(tv_1);
-  for (auto &idx : ShapeRange(shape_1))
-  {
-    tensor_1.at(idx) = tmp++;
-  }
-  std::string serializedTensor_1 = serializer.getSerializedObject(tensor_1);
-  proto::TensorProto proto_tensor_1;
-  proto_tensor_1.ParseFromString(serializedTensor_1);
-  checkShape(shape_1, proto_tensor_1.shape());
-  checkIntTensor(tensor_1, proto_tensor_1);
-
-  Shape shape_2{3, 4, 5};
-  TensorVariant tv_2(DTYPE::INT32, shape_2);
-  Tensor<int> tensor_2(tv_2);
-  for (auto &idx : ShapeRange(tensor_2.getShape()))
-  {
-    tensor_2.at(idx) = tmp--;
-  }
-  std::string serializedTensor_2 = serializer.getSerializedObject(tensor_2);
-  proto::TensorProto proto_tensor_2;
-  proto_tensor_2.ParseFromString(serializedTensor_2);
-  checkShape(shape_2, proto_tensor_2.shape());
-  checkIntTensor(tensor_2, proto_tensor_2);
-
-  Shape shape_3{1, 1, 1, 1, 1};
-  TensorVariant tv_3(DTYPE::INT32, shape_3);
-  Tensor<int> tensor_3(tv_3);
-  for (auto &idx : ShapeRange(tensor_3.getShape()))
-  {
-    tensor_3.at(idx) = tmp++;
-  }
-  std::string serializedTensor_3 = serializer.getSerializedObject(tensor_3);
-  proto::TensorProto proto_tensor_3;
-  proto_tensor_3.ParseFromString(serializedTensor_3);
-  checkShape(shape_3, proto_tensor_3.shape());
-  checkIntTensor(tensor_3, proto_tensor_3);
-}
-
-TEST(Serializer, FloatTensorSerializationTest)
-{
-  Serializer<Tensor<float>> serializer;
-  float tmp = 1.0f;
-
-  Shape shape_1{3};
-  TensorVariant tv_1(DTYPE::FLOAT32, shape_1);
-  Tensor<float> tensor_1(tv_1);
-  for (auto &idx : ShapeRange(tensor_1.getShape()))
-  {
-    tensor_1.at(idx) = tmp;
-    tmp += 10.3f;
-  }
-  std::string serializedTensor_1 = serializer.getSerializedObject(tensor_1);
-  proto::TensorProto proto_tensor_1;
-  proto_tensor_1.ParseFromString(serializedTensor_1);
-  checkShape(shape_1, proto_tensor_1.shape());
-  checkFloatTensor(tensor_1, proto_tensor_1);
-
-  Shape shape_2{3, 4, 5};
-  TensorVariant tv_2(DTYPE::FLOAT32, shape_2);
-  Tensor<float> tensor_2(tv_2);
-  for (auto &idx : ShapeRange(tensor_2.getShape()))
-  {
-    tensor_2.at(idx) = tmp;
-    tmp *= -1.21f;
-  }
-  std::string serializedTensor_2 = serializer.getSerializedObject(tensor_2);
-  proto::TensorProto proto_tensor_2;
-  proto_tensor_2.ParseFromString(serializedTensor_2);
-  checkShape(shape_2, proto_tensor_2.shape());
-  checkFloatTensor(tensor_2, proto_tensor_2);
-
-  Shape shape_3{1, 1, 1, 1, 1};
-  TensorVariant tv_3(DTYPE::FLOAT32, shape_3);
-  Tensor<float> tensor_3(tv_3);
-  for (auto &idx : ShapeRange(tensor_3.getShape()))
-  {
-    tmp -= 6.66f;
-    tensor_3.at(idx) = tmp;
-  }
-  std::string serializedTensor_3 = serializer.getSerializedObject(tensor_3);
-  proto::TensorProto proto_tensor_3;
-  proto_tensor_3.ParseFromString(serializedTensor_3);
-  checkShape(shape_3, proto_tensor_3.shape());
-  checkFloatTensor(tensor_3, proto_tensor_3);
-}
-
-TEST(Serializer, DoubleTensorSerializationTest)
-{
-  Serializer<Tensor<double>> serializer;
-  double tmp = 1.0f;
-
-  Shape shape_1{3};
-  TensorVariant tv_1(DTYPE::FLOAT64, shape_1);
-  Tensor<double> tensor_1(tv_1);
-  for (auto &idx : ShapeRange(tensor_1.getShape()))
-  {
-    tensor_1.at(idx) = tmp;
-    tmp += 10.3f;
-  }
-  std::string serializedTensor_1 = serializer.getSerializedObject(tensor_1);
-  proto::TensorProto proto_tensor_1;
-  proto_tensor_1.ParseFromString(serializedTensor_1);
-  checkShape(shape_1, proto_tensor_1.shape());
-  checkDoubleTensor(tensor_1, proto_tensor_1);
-
-  Shape shape_2{3, 4, 5};
-  TensorVariant tv_2(DTYPE::FLOAT64, shape_2);
-  Tensor<double> tensor_2(tv_2);
-  for (auto &idx : ShapeRange(tensor_2.getShape()))
-  {
-    tensor_2.at(idx) = tmp;
-    tmp *= -1.21f;
-  }
-  std::string serializedTensor_2 = serializer.getSerializedObject(tensor_2);
-  proto::TensorProto proto_tensor_2;
-  proto_tensor_2.ParseFromString(serializedTensor_2);
-  checkShape(shape_2, proto_tensor_2.shape());
-  checkDoubleTensor(tensor_2, proto_tensor_2);
-
-  Shape shape_3{1, 1, 1, 1, 1};
-  TensorVariant tv_3(DTYPE::FLOAT64, shape_3);
-  Tensor<double> tensor_3(tv_3);
-  for (auto &idx : ShapeRange(tensor_3.getShape()))
-  {
-    tmp -= 6.66f;
-    tensor_3.at(idx) = tmp;
-  }
-  std::string serializedTensor_3 = serializer.getSerializedObject(tensor_3);
-  proto::TensorProto proto_tensor_3;
-  proto_tensor_3.ParseFromString(serializedTensor_3);
-  checkShape(shape_3, proto_tensor_3.shape());
-  checkDoubleTensor(tensor_3, proto_tensor_3);
-}