Построение задачи выпуска Tensorflow 2.0.0 на Windows с использованием Bazel на VS 2017 с селективной регистрацией - PullRequest
0 голосов
/ 03 апреля 2020

Я хочу уменьшить размер DLL Tensorflow и обнаружил, что Выборочная регистрация является потенциально жизнеспособным инструментом, который я могу использовать для достижения этой цели. Обратите внимание, что я могу собрать dll Tensorflow без выборочной регистрации.

Мой файл "ops_to_register.h":

// This file was autogenerated by print_selective_registration_header.py
#ifndef OPS_TO_REGISTER
#define OPS_TO_REGISTER

namespace {
  constexpr const char* skip(const char* x) {
    return (*x) ? (*x == ' ' ? skip(x + 1) : x) : x;
  }

  constexpr bool isequal(const char* x, const char* y) {
    return (*skip(x) && *skip(y))
               ? (*skip(x) == *skip(y) && isequal(skip(x) + 1, skip(y) + 1))
               : (!*skip(x) && !*skip(y));
  }

  template<int N>
  struct find_in {
    static constexpr bool f(const char* x, const char* const y[N]) {
      return isequal(x, y[0]) || find_in<N - 1>::f(x, y + 1);
    }
  };

  template<>
  struct find_in<0> {
    static constexpr bool f(const char* x, const char* const y[]) {
      return false;
    }
  };
}  // end namespace
constexpr const char* kNecessaryOpKernelClasses[] = {
"BinaryOp<GPUDevice, functor::add<float>>",
"BiasOp<GPUDevice, float>",
"ConcatV2Op<GPUDevice, float>",
"ConstantOp",
"_HostConstantOp",
"Conv2DOp<GPUDevice, float>",
"ExpandDimsOp<int32>",
"IdentityOp",
"ReductionOp<GPUDevice, float, int32, functor::MeanReducer<float>>",
"BinaryOp<CPUDevice, functor::mul<int32>>",
"BinaryOp<GPUDevice, functor::mul<float>>",
"NoOp",
"PlaceholderOp",
"ReluOp<GPUDevice, float>",
"ResizeBilinearOp<GPUDevice, float>",
"UnaryOp<GPUDevice, functor::rsqrt<float>>",
"ShapeOp<int32>",
"UnaryOp<GPUDevice, functor::sigmoid<float>>",
"SliceOp<CPUDevice, int32>",
"BinaryOp<GPUDevice, functor::squared_difference<float>>",
"IdentityOp",
"BinaryOp<GPUDevice, functor::sub<float>>",
"RecvOp",
"SendOp",
};
#define SHOULD_REGISTER_OP_KERNEL(clz) (find_in<sizeof(kNecessaryOpKernelClasses) / sizeof(*kNecessaryOpKernelClasses)>::f(clz, kNecessaryOpKernelClasses))

constexpr inline bool ShouldRegisterOp(const char op[]) {
  return false
     || isequal(op, "Add")
     || isequal(op, "BiasAdd")
     || isequal(op, "ConcatV2")
     || isequal(op, "Const")
     || isequal(op, "Conv2D")
     || isequal(op, "ExpandDims")
     || isequal(op, "Identity")
     || isequal(op, "Mean")
     || isequal(op, "Mul")
     || isequal(op, "NoOp")
     || isequal(op, "Placeholder")
     || isequal(op, "Relu")
     || isequal(op, "ResizeBilinear")
     || isequal(op, "Rsqrt")
     || isequal(op, "Shape")
     || isequal(op, "Sigmoid")
     || isequal(op, "Slice")
     || isequal(op, "SquaredDifference")
     || isequal(op, "StopGradient")
     || isequal(op, "Sub")
     || isequal(op, "_Recv")
     || isequal(op, "_Send")
  ;
}
#define SHOULD_REGISTER_OP(op) ShouldRegisterOp(op)

#define SHOULD_REGISTER_OP_GRADIENT false
#endif

Команда построения:

bazel build --config=opt --copt="-DSELECTIVE_REGISTRATION" --copt="-DSUPPORT_SELECTIVE_REGISTRATION" //tensorflow/tools/lib_package:libtensorflow

Ошибка:

tensorflow/core/grappler/optimizers/data/vectorization/reshape_vectorizer.cc(40): error C2039: 'StridedSlice': is not a member of 'tensorflow::ops'
bazel-out/x64_windows-opt/bin\tensorflow/cc/ops/math_ops.h(16): note: see declaration of 'tensorflow::ops'
tensorflow/core/grappler/optimizers/data/vectorization/reshape_vectorizer.cc(41): error C2039: 'StridedSlice': is not a member of 'tensorflow::ops'
bazel-out/x64_windows-opt/bin\tensorflow/cc/ops/math_ops.h(16): note: see declaration of 'tensorflow::ops'
tensorflow/core/grappler/optimizers/data/vectorization/reshape_vectorizer.cc(41): error C3083: 'StridedSlice': the symbol to the left of a '::' must be a type
tensorflow/core/grappler/optimizers/data/vectorization/reshape_vectorizer.cc(41): error C2039: 'Attrs': is not a member of 'tensorflow::ops'
bazel-out/x64_windows-opt/bin\tensorflow/cc/ops/math_ops.h(16): note: see declaration of 'tensorflow::ops'
tensorflow/core/grappler/optimizers/data/vectorization/reshape_vectorizer.cc(41): error C3861: 'Attrs': identifier not found
tensorflow/core/grappler/optimizers/data/vectorization/reshape_vectorizer.cc(40): error C3861: 'StridedSlice': identifier not found
tensorflow/core/grappler/optimizers/data/vectorization/reshape_vectorizer.cc(61): error C2039: 'Reshape': is not a member of 'tensorflow::ops'
bazel-out/x64_windows-opt/bin\tensorflow/cc/ops/math_ops.h(16): note: see declaration of 'tensorflow::ops'
tensorflow/core/grappler/optimizers/data/vectorization/reshape_vectorizer.cc(61): error C3861: 'Reshape': identifier not found
Target //tensorflow/tools/lib_package:libtensorflow failed to build
INFO: Elapsed time: 3827.498s, Critical Path: 2582.64s
INFO: 3956 processes: 3956 local.
FAILED: Build did NOT complete successfully

Я попытался включить соответствующие заголовочные файлы, но я просто получаю еще больше подобных ошибок. Кто-нибудь знает, как это решить?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...