美文网首页
在tensorflow里使用bazel调用外部的库

在tensorflow里使用bazel调用外部的库

作者: yxd886 | 来源:发表于2021-01-25 20:51 被阅读0次

    以调用机器上存在的openmpi的库为例。

    1. 首先在tensorflow 根目录下的WORKSPACE里定义好自己要引用的外部库:
      使用new_local_respository命令
    new_local_repository(
    name = "openmpi",
    path = "/usr/local/openmpi",
    build_file_content = """
    cc_library(
    name = "openmpi-lib",
    srcs = ["lib/libmpi.so","lib/libmpi_mpifh.so"],
    hdrs = glob(["include/*.h"]),
    includes = ["include"],
    visibility = ["//visibility:public"],
    )
    """
    )
    
    

    然后在要使用的.cc对应的BUILD文件中的cc_library里添加好刚刚定义的依赖:

    cc_library(
        name = "my_instruction_fusion",
        srcs = ["my_instruction_fusion.cc"],
        hdrs = ["my_instruction_fusion.h"],
        deps = [
            ":gpu_fusible",
            ":instruction_fusion",
            ":multi_output_fusion",
            "//tensorflow/compiler/xla/service:all_reduce_combiner",
            ":ir_emission_utils",
            "//tensorflow/compiler/xla:shape_util",
            "//tensorflow/compiler/xla:xla_data_proto_cc",
            "//tensorflow/compiler/xla/service:fusion_node_indexing_evaluation",
            "//tensorflow/compiler/xla/service:hlo",
            "//tensorflow/compiler/xla/service:hlo_query",
            "//tensorflow/compiler/xla/service:pattern_matcher",
            "//tensorflow/compiler/xla/service/llvm_ir:fused_ir_emitter",
            "@com_google_absl//absl/container:flat_hash_map",
            "@com_google_absl//absl/container:flat_hash_set",
            "//tensorflow/compiler/xla:debug_options_flags",
            "//tensorflow/compiler/xla:statusor",
            "//tensorflow/compiler/xla/service:hlo_pass",
            "//tensorflow/compiler/xla/service:hlo_reachability",
            "//tensorflow/core:lib",
            "@com_google_absl//absl/algorithm:container",
            "@com_google_absl//absl/strings",
            "@openmpi//:openmpi-lib",
            
        ],
    )
    

    相关文章

      网友评论

          本文标题:在tensorflow里使用bazel调用外部的库

          本文链接:https://www.haomeiwen.com/subject/bwgizktx.html