1 # Description: 2 # C API for TensorFlow, for use by client language bindings. 3 4 licenses(["notice"]) # Apache 2.0 5 6 load( 7 "//tensorflow:tensorflow.bzl", 8 "tf_cc_test", 9 "tf_copts", 10 "tf_cuda_library", 11 "tf_custom_op_library", 12 "tf_kernel_library", 13 ) 14 load("//tensorflow:tensorflow.bzl", "tf_cuda_cc_test") 15 16 # ----------------------------------------------------------------------------- 17 # Public targets 18 19 filegroup( 20 name = "headers", 21 srcs = [ 22 "c_api.h", 23 "c_api_experimental.h", 24 ], 25 visibility = ["//tensorflow:__subpackages__"], 26 ) 27 28 filegroup( 29 name = "srcs", 30 srcs = glob( 31 [ 32 "*.cc", 33 "*.h", 34 ], 35 exclude = [ 36 "c_api_experimental.cc", 37 "c_api_experimental.h", 38 "python_api.cc", 39 "python_api.h", 40 "*test*", 41 ], 42 ) + [ 43 "//tensorflow/cc:srcs", 44 "//tensorflow/core/distributed_runtime:server_lib.h", 45 ], 46 visibility = ["//visibility:public"], 47 ) 48 49 tf_cuda_library( 50 name = "c_api_internal", 51 hdrs = [ 52 "c_api.h", 53 "c_api_internal.h", 54 ], 55 visibility = [ 56 "//tensorflow:internal", 57 "//tensorflow/c:__subpackages__", 58 ], 59 deps = select({ 60 "//tensorflow:android": [ 61 "//tensorflow/core:android_tensorflow_lib_lite", 62 ], 63 "//conditions:default": [ 64 "//tensorflow/core:core_cpu", 65 "//tensorflow/core:framework", 66 "//tensorflow/core:lib", 67 "//tensorflow/core:lib_platform", 68 "//tensorflow/core:op_gen_lib", 69 "//tensorflow/core/distributed_runtime:server_lib", 70 ], 71 }), 72 ) 73 74 tf_cuda_library( 75 name = "c_api", 76 hdrs = [ 77 "c_api.h", 78 ], 79 copts = tf_copts(), 80 visibility = ["//visibility:public"], 81 deps = [ 82 ":c_api_no_xla", 83 ":c_api_internal", 84 ] + select({ 85 "//tensorflow:with_xla_support": [ 86 "//tensorflow/compiler/tf2xla:xla_compiler", 87 "//tensorflow/compiler/jit", 88 ], 89 "//conditions:default": [], 90 }), 91 ) 92 93 tf_cuda_library( 94 name = "c_api_no_xla", 95 srcs = [ 96 "c_api.cc", 97 "c_api_function.cc", 98 ], 99 hdrs = ["c_api.h"], 100 copts = tf_copts(), 101 visibility = ["//tensorflow/c:__subpackages__"], 102 deps = [":c_api_internal"] + select({ 103 "//tensorflow:android": [ 104 "//tensorflow/core:android_tensorflow_lib_lite", 105 ], 106 "//conditions:default": [ 107 "//tensorflow/cc/saved_model:loader_lite", 108 "//tensorflow/cc:gradients", 109 "//tensorflow/cc:ops", 110 "//tensorflow/cc:grad_ops", 111 "//tensorflow/cc:scope_internal", 112 "//tensorflow/cc:while_loop", 113 "//tensorflow/core:core_cpu", 114 "//tensorflow/core:core_cpu_internal", 115 "//tensorflow/core:framework", 116 "//tensorflow/core:op_gen_lib", 117 "//tensorflow/core:protos_all_cc", 118 "//tensorflow/core:lib", 119 "//tensorflow/core:lib_internal", 120 "//tensorflow/core/distributed_runtime:server_lib", 121 "//tensorflow/core/kernels:logging_ops", 122 ], 123 }), 124 ) 125 126 tf_cuda_library( 127 name = "c_api_experimental", 128 srcs = [ 129 "c_api_experimental.cc", 130 ], 131 hdrs = [ 132 "c_api_experimental.h", 133 ], 134 copts = tf_copts(), 135 visibility = ["//visibility:public"], 136 deps = [ 137 ":c_api", 138 ":c_api_internal", 139 "//tensorflow/c/eager:c_api", 140 "//tensorflow/c/eager:c_api_internal", 141 "//tensorflow/compiler/jit:flags", 142 "//tensorflow/core:core_cpu", 143 "//tensorflow/core:framework", 144 "//tensorflow/core:lib", 145 "//tensorflow/core:lib_platform", 146 "//tensorflow/core:protos_all_cc", 147 "//tensorflow/core/common_runtime/eager:attr_builder", 148 "@com_google_absl//absl/strings", 149 ], 150 ) 151 152 cc_library( 153 name = "c_api_headers", 154 hdrs = [ 155 "c_api.h", 156 ], 157 copts = tf_copts(), 158 visibility = ["//tensorflow:__subpackages__"], 159 ) 160 161 exports_files( 162 [ 163 "version_script.lds", 164 "exported_symbols.lds", 165 ], 166 visibility = ["//visibility:public"], 167 ) 168 169 tf_cuda_library( 170 name = "tf_status_helper", 171 srcs = ["tf_status_helper.cc"], 172 hdrs = ["tf_status_helper.h"], 173 visibility = ["//visibility:public"], 174 deps = [ 175 ":c_api_internal", 176 ":c_api_no_xla", 177 "//tensorflow/core:lib", 178 ], 179 ) 180 181 tf_cuda_library( 182 name = "checkpoint_reader", 183 srcs = ["checkpoint_reader.cc"], 184 hdrs = ["checkpoint_reader.h"], 185 visibility = ["//visibility:public"], 186 deps = [ 187 ":tf_status_helper", 188 "//tensorflow/core:framework", 189 "//tensorflow/core:lib", 190 "//tensorflow/core/util/tensor_bundle", 191 ], 192 ) 193 194 tf_cuda_library( 195 name = "env", 196 srcs = [ 197 "env.cc", 198 ], 199 hdrs = [ 200 "env.h", 201 ], 202 copts = tf_copts(), 203 visibility = ["//visibility:public"], 204 deps = select({ 205 "//tensorflow:android": [ 206 ":c_api", 207 ":tf_status_helper", 208 "//tensorflow/core:android_tensorflow_lib_lite", 209 "//tensorflow/core:lib", 210 ], 211 "//conditions:default": [ 212 ":c_api", 213 ":tf_status_helper", 214 "//tensorflow/core:framework", 215 "//tensorflow/core:lib", 216 ], 217 }) + [":c_api_internal"], 218 ) 219 220 tf_cuda_library( 221 name = "kernels", 222 srcs = [ 223 "kernels.cc", 224 ], 225 hdrs = [ 226 "kernels.h", 227 ], 228 copts = tf_copts(), 229 visibility = ["//visibility:public"], 230 deps = select({ 231 "//tensorflow:android": [ 232 ":c_api_no_xla", 233 ":c_api_internal", 234 ":tf_status_helper", 235 "//tensorflow/core:android_tensorflow_lib_lite", 236 ], 237 "//conditions:default": [ 238 ":c_api_no_xla", 239 ":c_api_internal", 240 ":tf_status_helper", 241 "//tensorflow/core:framework", 242 ], 243 }), 244 ) 245 246 # ----------------------------------------------------------------------------- 247 # Tests 248 249 tf_cuda_library( 250 name = "c_test_util", 251 testonly = 1, 252 srcs = ["c_test_util.cc"], 253 hdrs = ["c_test_util.h"], 254 visibility = [ 255 "//learning/brain:__subpackages__", 256 "//tensorflow:__subpackages__", 257 ], 258 deps = [ 259 ":c_api", 260 ":c_api_experimental", 261 "//tensorflow/core:lib", 262 "//tensorflow/core:protos_all_cc", 263 "//tensorflow/core:session_options", 264 "//tensorflow/core:test", 265 ], 266 ) 267 268 tf_cc_test( 269 name = "c_test", 270 srcs = ["c_test.c"], 271 extra_copts = ["-std=c11"], 272 deps = [ 273 ":c_api", 274 ":c_api_experimental", 275 ":env", 276 ":kernels", 277 ], 278 ) 279 280 tf_cuda_cc_test( 281 name = "c_api_test", 282 size = "small", 283 srcs = ["c_api_test.cc"], 284 data = [ 285 ":test_op1.so", 286 "//tensorflow/cc/saved_model:saved_model_half_plus_two", 287 ], 288 kernels = [":test_op_kernel"], 289 linkopts = select({ 290 "//tensorflow:macos": ["-headerpad_max_install_names"], 291 "//conditions:default": [], 292 }), 293 tags = [ 294 "no_oss", # http://b/119522529 295 "noasan", 296 ], 297 # We must ensure that the dependencies can be dynamically linked since 298 # the shared library must be able to use core:framework. 299 # linkstatic = tf_kernel_tests_linkstatic(), 300 deps = [ 301 ":c_api", 302 ":c_test_util", 303 "//tensorflow/cc:cc_ops", 304 "//tensorflow/cc:grad_ops", 305 "//tensorflow/cc/saved_model:signature_constants", 306 "//tensorflow/cc/saved_model:tag_constants", 307 "//tensorflow/compiler/jit", 308 "//tensorflow/core:array_ops_op_lib", 309 "//tensorflow/core:bitwise_ops_op_lib", 310 "//tensorflow/core:control_flow_ops_op_lib", 311 "//tensorflow/core:core_cpu_internal", 312 "//tensorflow/core:direct_session", 313 "//tensorflow/core:framework", 314 "//tensorflow/core:framework_internal", 315 "//tensorflow/core:functional_ops_op_lib", 316 "//tensorflow/core:lib", 317 "//tensorflow/core:math_ops_op_lib", 318 "//tensorflow/core:nn_ops_op_lib", 319 "//tensorflow/core:no_op_op_lib", 320 "//tensorflow/core:proto_text", 321 "//tensorflow/core:protos_all_cc", 322 "//tensorflow/core:sendrecv_ops_op_lib", 323 "//tensorflow/core:spectral_ops_op_lib", 324 "//tensorflow/core:state_ops_op_lib", 325 "//tensorflow/core:test", 326 "//tensorflow/core:test_main", 327 "//tensorflow/core/kernels:array", 328 "//tensorflow/core/kernels:control_flow_ops", 329 "//tensorflow/core/kernels:math", 330 ], 331 ) 332 333 tf_cc_test( 334 name = "c_api_experimental_test", 335 size = "medium", 336 srcs = ["c_api_experimental_test.cc"], 337 data = ["testdata/tf_record"], 338 linkopts = select({ 339 "//tensorflow:macos": ["-headerpad_max_install_names"], 340 "//conditions:default": [], 341 }), 342 # We must ensure that the dependencies can be dynamically linked since 343 # the shared library must be able to use core:framework. 344 # linkstatic = tf_kernel_tests_linkstatic(), 345 deps = [ 346 ":c_api", 347 ":c_api_experimental", 348 ":c_api_internal", 349 ":c_test_util", 350 "//tensorflow/c/eager:c_api", 351 "//tensorflow/c/eager:c_api_test_util", 352 "//tensorflow/core:lib", 353 "//tensorflow/core:protos_all_cc", 354 "//tensorflow/core:test", 355 "//tensorflow/core:test_main", 356 ], 357 ) 358 359 tf_cc_test( 360 name = "c_api_function_test", 361 size = "small", 362 srcs = ["c_api_function_test.cc"], 363 deps = [ 364 ":c_api", 365 ":c_api_internal", 366 ":c_test_util", 367 "//tensorflow/core:lib", 368 "//tensorflow/core:lib_internal", 369 "//tensorflow/core:protos_all_cc", 370 "//tensorflow/core:test", 371 "//tensorflow/core:test_main", 372 ], 373 ) 374 375 tf_cc_test( 376 name = "while_loop_test", 377 size = "small", 378 srcs = ["while_loop_test.cc"], 379 deps = [ 380 ":c_api", 381 ":c_test_util", 382 "//tensorflow/core:lib", 383 "//tensorflow/core:test", 384 "//tensorflow/core:test_main", 385 ], 386 ) 387 388 tf_custom_op_library( 389 name = "test_op1.so", 390 srcs = ["test_op1.cc"], 391 ) 392 393 tf_kernel_library( 394 name = "test_op_kernel", 395 srcs = ["test_op.cc"], 396 deps = [ 397 "//tensorflow/core:framework", 398 "//tensorflow/core:lib", 399 ], 400 alwayslink = 1, 401 ) 402 403 tf_cuda_cc_test( 404 name = "env_test", 405 size = "small", 406 srcs = ["env_test.cc"], 407 linkopts = select({ 408 "//tensorflow:macos": ["-headerpad_max_install_names"], 409 "//conditions:default": [], 410 }), 411 tags = ["noasan"], 412 # We must ensure that the dependencies can be dynamically linked since 413 # the shared library must be able to use core:framework. 414 # linkstatic = tf_kernel_tests_linkstatic(), 415 deps = [ 416 ":c_api", 417 ":env", 418 "//tensorflow/core:lib", 419 "//tensorflow/core:test", 420 "//tensorflow/core:test_main", 421 ], 422 ) 423 424 tf_cuda_cc_test( 425 name = "kernels_test", 426 size = "small", 427 srcs = ["kernels_test.cc"], 428 linkopts = select({ 429 "//tensorflow:macos": ["-headerpad_max_install_names"], 430 "//conditions:default": [], 431 }), 432 tags = ["noasan"], 433 # We must ensure that the dependencies can be dynamically linked since 434 # the shared library must be able to use core:framework. 435 # linkstatic = tf_kernel_tests_linkstatic(), 436 deps = [ 437 ":c_api", 438 ":kernels", 439 "//tensorflow/core:framework", 440 "//tensorflow/core:lib", 441 "//tensorflow/core:proto_text", 442 "//tensorflow/core:protos_all_cc", 443 "//tensorflow/core:test", 444 "//tensorflow/core:test_main", 445 ], 446 ) 447 448 # ----------------------------------------------------------------------------- 449 # Python API target 450 451 tf_cuda_library( 452 name = "python_api", 453 srcs = ["python_api.cc"], 454 hdrs = ["python_api.h"], 455 visibility = ["//tensorflow/python:__pkg__"], 456 deps = [ 457 ":c_api", 458 ":c_api_internal", 459 # TODO(b/74620627): remove when _USE_C_SHAPES is removed 460 "//tensorflow/python:cpp_shape_inference_proto_cc", 461 ], 462 ) 463