我想使用bazel交叉编译TensorFlow的C ++代码并获得arm可执行版本,在Arm架构机器上运行它。
关注维基https://github.com/bazelbuild/bazel/wiki/Building-with-a-custom-toolchain,我修改了一些代码,然后将代码推送到mygithub:bazel_toolchain。
然后我将bazel_toolchain目录放在TensorFlow github存储库的克隆文件tensorflow / bazel_toolchain中
现在树是/ root / tensorflow_master / tensorflow / bazel_toochain
我添加hello.cc代码如下:
hello.cc代码:
#include "tensorflow/cc/client/client_session.h"
#include "tensorflow/cc/ops/standard_ops.h"
#include "tensorflow/core/framework/tensor.h"
int main() {
using namespace tensorflow;
using namespace tensorflow::ops;
Scope root = Scope::NewRootScope();
// Matrix A = [3 2; -1 0]
auto A = Const(root, { {3.f, 2.f}, {-1.f, 0.f} });
// Vector b = [3 5]
auto b = Const(root, { {3.f, 5.f} });
// v = Ab^T
auto v = MatMul(root.WithOpName("v"), A, b, MatMul::TransposeB(true));
std::vector<Tensor> outputs;
ClientSession session(root);
// Run and fetch v
TF_CHECK_OK(session.Run({v}, &outputs));
// Expect outputs[0] == [19; -3]
LOG(INFO) << outputs[0].matrix<float>();
return 0;
}
构建文件如下:
filegroup(
name = "srcs",
srcs = glob(["**"]),
visibility = ["//tensorflow/bazel_toolchain:__pkg__"],
)
cc_binary(
name = "hello",
srcs = ["hello.cc"],
deps = [
"//tensorflow/cc:cc_ops",
"//tensorflow/cc:client_session",
"//tensorflow/core:tensorflow",
],
)
当我在/ root / tensorflow_master /目录下执行命令时,
bazel build --crosstool_top=//tensorflow/bazel_toolchain/tools/arm_compiler:toolchain --cpu=armeabi-v7a
//tensorflow/bazel_toolchain:hello
它注意到了
tensorflow-master/tensorflow/bazel_toolchain/tools/arm_compiler/BUILD:46:1: no such package '@org_linaro_components_toolchain_gcc_5_3_1//': The repository could not be resolved and referenced by '//tensorflow/bazel_toolchain/tools/arm_compiler:linaro_linux_linker_files'.
错误:分析目标&#39; // tensorflow / bazel_toolchain:你好&#39;失败;建立中止
我该怎么办?非常感谢!
答案 0 :(得分:0)
The build file you shared is not correct, there is )
after srcs
that effectively closes cc_binary
, so deps
are not an attribute on cc_binary
but a declaration of a variable in the BUILD file (I think). Move deps
into cc_binary.
The error message is however unrelated to above. Can you share the command line you use to build hello-world? Do you use --crosstool_top to use your custom crosstool? Can you edit your question to add content of your WORKSPACE file?