• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Experimental extensions to the C API for eager execution of kernels.
2
3load("//tensorflow/core/platform:rules_cc.bzl", "cc_library")
4load(
5    "//tensorflow:tensorflow.bzl",
6    "tf_cc_test",
7    "tf_copts",
8    "tf_cuda_cc_test",
9    "tf_cuda_library",
10)
11
12# buildifier: disable=same-origin-load
13load("//tensorflow:tensorflow.bzl", "cc_header_only_library")
14
15# buildifier: disable=same-origin-load
16load("//tensorflow:tensorflow.bzl", "filegroup")
17
18# buildifier: disable=same-origin-load
19load("//tensorflow:tensorflow.bzl", "internal_tfrt_deps")
20load(
21    "//tensorflow/core/platform:build_config.bzl",
22    "tf_kernel_tests_linkstatic",
23)
24load(
25    "//tensorflow/core/platform:build_config_root.bzl",
26    "tf_cuda_tests_tags",
27)
28
29package(
30    licenses = ["notice"],
31)
32
33tf_cuda_library(
34    name = "c_api",
35    srcs = [
36        "c_api.cc",
37        "c_api_debug.cc",
38        "c_api_experimental.h",
39        "c_api_internal.h",
40        "c_api_unified_experimental.h",
41    ],
42    hdrs = ["c_api.h"],
43    copts = tf_copts(),
44    visibility = ["//visibility:public"],
45    deps = select({
46        "//tensorflow:android": [
47            "//tensorflow/core:portable_tensorflow_lib_lite",
48        ],
49        "//conditions:default": [
50            ":immediate_execution_context",
51            ":immediate_execution_operation",
52            ":immediate_execution_tensor_handle",
53            ":immediate_execution_distributed_manager",
54            ":tfe_context_internal",
55            ":tfe_cancellation_manager_internal",
56            ":tfe_executor_internal",
57            ":tfe_monitoring_internal",
58            ":tfe_op_attrs_internal",
59            ":tfe_op_internal",
60            ":tfe_tensor_debug_info_internal",
61            ":tfe_tensorhandle_internal",
62            "@com_google_absl//absl/algorithm:container",
63            "@com_google_absl//absl/types:span",
64            "@com_google_absl//absl/types:variant",
65            "//tensorflow/c:c_api",
66            "//tensorflow/c:c_api_internal",
67            "//tensorflow/c:tf_buffer",
68            "//tensorflow/c:tf_buffer_internal",
69            "//tensorflow/c:tf_status_internal",
70            "//tensorflow/c:tf_tensor_internal",
71            "//tensorflow/core:core_cpu",
72            "//tensorflow/core/common_runtime/eager:attr_builder",
73            "//tensorflow/core/common_runtime/eager:context",
74            "//tensorflow/core/common_runtime/eager:context_distributed_manager",
75            "//tensorflow/core/common_runtime/eager:core",
76            "//tensorflow/core/common_runtime/eager:custom_device",
77            "//tensorflow/core/common_runtime/eager:eager_executor",
78            "//tensorflow/core/common_runtime/eager:execute",
79            "//tensorflow/core/common_runtime/eager:tensor_handle",
80            "//tensorflow/core/common_runtime/eager:placement_utils",
81            "//tensorflow/core:core_cpu_internal",
82            "//tensorflow/core:framework",
83            "//tensorflow/core:framework_internal",
84            "//tensorflow/core:lib",
85            "//tensorflow/core:lib_internal",
86            "//tensorflow/core:protos_all_cc",
87            "//tensorflow/core/profiler/lib:traceme",
88        ],
89    }) + [
90        "@com_google_absl//absl/memory",
91        ":abstract_tensor_handle",
92        "//tensorflow/core/common_runtime/eager:eager_operation",
93        "//tensorflow/core/distributed_runtime/eager:remote_mgr",
94        "//tensorflow/core/distributed_runtime/eager:cluster_function_library_runtime",
95        "//tensorflow/core/distributed_runtime/eager:eager_client",
96        "//tensorflow/core/distributed_runtime/rpc/eager:grpc_eager_client",
97        "//tensorflow/core/distributed_runtime/rpc:grpc_channel",
98        "//tensorflow/core/distributed_runtime/rpc:grpc_server_lib",
99        "//tensorflow/core/distributed_runtime/rpc:grpc_worker_cache",
100        "//tensorflow/core/distributed_runtime/rpc:grpc_worker_service",
101        "//tensorflow/core/distributed_runtime/rpc:rpc_rendezvous_mgr",
102        "//tensorflow/core/distributed_runtime:remote_device",
103        "//tensorflow/core/distributed_runtime:server_lib",
104        "//tensorflow/core/distributed_runtime:worker_env",
105        "//tensorflow/core/distributed_runtime:worker_interface",
106        "//tensorflow/core:gpu_runtime",
107        "@com_google_absl//absl/strings:str_format",
108    ] + internal_tfrt_deps(),
109    alwayslink = 1,
110)
111
112filegroup(
113    name = "pywrap_required_hdrs",
114    srcs = [
115        "abstract_context.h",
116        "abstract_function.h",
117        "abstract_op_attrs.h",
118        "abstract_operation.h",
119        "abstract_tensor_handle.h",
120        "c_api.h",
121        "c_api_experimental.h",
122        "c_api_internal.h",
123        "c_api_unified_experimental.h",
124        "c_api_unified_experimental_internal.h",
125        "dlpack.h",
126        "gradients.h",
127        "gradients_internal.h",
128        "immediate_execution_context.h",
129        "immediate_execution_distributed_manager.h",
130        "immediate_execution_operation.h",
131        "immediate_execution_tensor_handle.h",
132        "tape.h",
133        "tfe_cancellation_manager_internal.h",
134        "tfe_context_internal.h",
135        "tfe_executor_internal.h",
136        "tfe_monitoring_internal.h",
137        "tfe_op_attrs_internal.h",
138        "tfe_tensor_debug_info_internal.h",
139        "tfe_tensorhandle_internal.h",
140    ],
141    visibility = [
142        "//tensorflow/core/function:__pkg__",
143        "//tensorflow/python:__subpackages__",
144    ],
145)
146
147cc_library(
148    name = "c_api_internal",
149    hdrs = [
150        "c_api_experimental.h",
151        "c_api_internal.h",
152    ],
153    visibility = ["//tensorflow:internal"],
154    deps = [
155        ":c_api",
156        ":tfe_cancellation_manager_internal",
157        ":tfe_executor_internal",
158        ":tfe_monitoring_internal",
159        ":tfe_op_attrs_internal",
160        ":tfe_tensor_debug_info_internal",
161        "//tensorflow/c:c_api_internal",
162    ],
163)
164
165cc_library(
166    name = "c_api_unified_internal",
167    hdrs = [
168        "c_api_unified_experimental_internal.h",
169    ],
170    visibility = [
171        "//tensorflow:internal",
172    ],
173    deps = [
174        ":abstract_context",
175        ":abstract_operation",
176        ":abstract_tensor_handle",
177        ":c_api",
178        ":c_api_experimental",
179        "//tensorflow/c:c_api_internal",
180        "//tensorflow/c:conversion_macros",
181        "//tensorflow/c:tf_status",
182        "//tensorflow/core:framework",
183        "//tensorflow/core/platform:casts",
184        "//tensorflow/core/platform:types",
185    ],
186)
187
188cc_library(
189    name = "tracing_utils",
190    srcs = ["tracing_utils.cc"],
191    hdrs = [
192        "tracing_utils.h",
193    ],
194    visibility = [
195        "//tensorflow:internal",
196    ],
197    deps = [
198        ":abstract_operation",
199        ":c_api_unified_internal",
200        "//tensorflow/c/experimental/gradients/tape:tape_operation",
201        "//tensorflow/core/lib/llvm_rtti",
202        "//tensorflow/core/platform:errors",
203    ],
204)
205
206cc_library(
207    name = "gradients_internal",
208    srcs = [
209        "gradients.cc",
210    ],
211    hdrs = [
212        "gradients.h",
213        "gradients_internal.h",
214    ],
215    visibility = [
216        "//tensorflow:internal",
217    ],
218    deps = [
219        ":abstract_context",
220        ":abstract_tensor_handle",
221        ":c_api_unified_internal",
222        ":tape",
223        "//tensorflow/core/common_runtime/eager:attr_builder",
224        "//tensorflow/core/lib/llvm_rtti",
225        "//tensorflow/core/platform:errors",
226        "@com_google_absl//absl/container:flat_hash_map",
227        "@com_google_absl//absl/strings",
228    ],
229)
230
231cc_library(
232    name = "unified_api_testutil",
233    testonly = 1,
234    srcs = [
235        "unified_api_testutil.cc",
236    ],
237    hdrs = [
238        "unified_api_testutil.h",
239    ],
240    visibility = [
241        "//tensorflow:internal",
242    ],
243    deps = [
244        ":abstract_context",
245        ":abstract_tensor_handle",
246        ":c_api_experimental",
247        ":c_api_test_util",
248        ":c_api_unified_internal",
249        "//tensorflow/c:tf_status",
250        "//tensorflow/c:tf_status_helper",
251        "//tensorflow/c:tf_tensor",
252        "//tensorflow/core:framework",
253        "//tensorflow/core/lib/llvm_rtti",
254        "//tensorflow/core/platform:errors",
255        "//tensorflow/core/platform:status",
256        "@com_google_absl//absl/container:flat_hash_set",
257    ],
258)
259
260tf_cuda_cc_test(
261    name = "gradients_test",
262    size = "small",
263    srcs = [
264        "gradients_test.cc",
265    ],
266    args = ["--heap_check="],
267    linkstatic = tf_kernel_tests_linkstatic(),
268    tags = tf_cuda_tests_tags() + ["nomac"],
269    deps = [
270        ":abstract_context",
271        ":abstract_tensor_handle",
272        ":c_api_experimental",
273        ":c_api_test_util",
274        ":c_api_unified_internal",
275        ":gradients_internal",
276        ":unified_api_testutil",
277        "//tensorflow/c:c_api",
278        "//tensorflow/c:c_test_util",
279        "//tensorflow/c:tf_status_helper",
280        "//tensorflow/c/experimental/gradients:array_grad",
281        "//tensorflow/c/experimental/gradients:math_grad",
282        "//tensorflow/c/experimental/gradients:not_differentiable",
283        "//tensorflow/c/experimental/gradients/tape:tape_context",
284        "//tensorflow/c/experimental/ops",
285        "//tensorflow/compiler/mlir/tensorflow/c:mlir_c_api_registration",
286        "//tensorflow/core:lib",
287        "//tensorflow/core:protos_all_cc",
288        "//tensorflow/core:test",
289        "//tensorflow/core:test_main",
290        "//tensorflow/core/lib/llvm_rtti",
291        "@com_google_absl//absl/container:flat_hash_set",
292        "@com_google_absl//absl/strings",
293        "@com_google_absl//absl/types:span",
294    ],
295)
296
297tf_cuda_cc_test(
298    name = "unified_api_test",
299    size = "small",
300    srcs = [
301        "unified_api_test.cc",
302    ],
303    args = ["--heap_check="],
304    linkstatic = tf_kernel_tests_linkstatic(),
305    tags = tf_cuda_tests_tags() + ["no_cuda_asan"],  # b/173654156
306    deps = [
307        ":c_api_experimental",
308        ":c_api_unified_internal",
309        ":unified_api_testutil",
310        "//tensorflow/c:tf_status_helper",
311        "//tensorflow/compiler/mlir/tensorflow/c:mlir_c_api_registration",
312        "//tensorflow/core:framework",
313        "//tensorflow/core:test",
314        "//tensorflow/core:test_main",
315        "//tensorflow/core/lib/llvm_rtti",
316        "//tensorflow/core/platform:errors",
317    ],
318)
319
320cc_library(
321    name = "gradient_checker",
322    testonly = 1,
323    srcs = [
324        "gradient_checker.cc",
325    ],
326    hdrs = [
327        "gradient_checker.h",
328    ],
329    visibility = [
330        "//tensorflow:internal",
331    ],
332    deps = [
333        ":abstract_tensor_handle",
334        ":unified_api_testutil",
335        "//tensorflow/c:tf_tensor_internal",
336        "//tensorflow/c/experimental/ops:math_ops",
337        "@com_google_absl//absl/types:span",
338    ],
339)
340
341tf_cuda_cc_test(
342    name = "gradient_checker_test",
343    size = "small",
344    srcs = [
345        "gradient_checker_test.cc",
346    ],
347    args = ["--heap_check="],
348    linkstatic = tf_kernel_tests_linkstatic(),
349    tags = tf_cuda_tests_tags() + [
350        "no_cuda_asan",  # b/175330074
351    ],
352    deps = [
353        ":abstract_tensor_handle",
354        ":c_api_experimental",
355        ":gradient_checker",
356        ":unified_api_testutil",
357        "//tensorflow/c:tf_status_helper",
358        "//tensorflow/c:tf_tensor_internal",
359        "//tensorflow/c/experimental/ops",
360        "//tensorflow/core:test",
361        "//tensorflow/core:test_main",
362        "//tensorflow/core/platform:tensor_float_32_utils",
363        "@com_google_absl//absl/types:span",
364    ],
365)
366
367cc_library(
368    name = "abstract_tensor_handle",
369    srcs = ["abstract_tensor_handle.cc"],
370    hdrs = ["abstract_tensor_handle.h"],
371    visibility = [
372        "//tensorflow:internal",
373    ],
374    deps = select({
375        "//tensorflow:android": [
376            "//tensorflow/core:portable_tensorflow_lib_lite",
377        ],
378        "//conditions:default": [
379            "//tensorflow/core:framework",
380            "//tensorflow/core:protos_all_cc",
381            "//tensorflow/core/platform:refcount",
382            "//tensorflow/core/platform:status",
383        ],
384    }),
385)
386
387cc_library(
388    name = "immediate_execution_tensor_handle",
389    srcs = ["immediate_execution_tensor_handle.cc"],
390    hdrs = ["immediate_execution_tensor_handle.h"],
391    visibility = [
392        "//tensorflow:internal",
393    ],
394    deps = [
395        ":abstract_tensor_handle",
396        "//tensorflow/c:tensor_interface",
397        "//tensorflow/core:framework",
398        "//tensorflow/core:lib",
399        "//tensorflow/core:protos_all_cc",
400    ],
401)
402
403cc_library(
404    name = "abstract_op_attrs",
405    hdrs = ["abstract_op_attrs.h"],
406    visibility = [
407        "//tensorflow:internal",
408    ],
409    deps = [
410        "//tensorflow/core:lib",
411        "//tensorflow/core:protos_all_cc",
412        "@com_google_absl//absl/container:inlined_vector",
413    ],
414)
415
416cc_library(
417    name = "abstract_operation",
418    hdrs = ["abstract_operation.h"],
419    visibility = [
420        "//tensorflow:internal",
421    ],
422    deps = [
423        ":abstract_tensor_handle",
424        "//tensorflow/c:tensor_interface",
425        "//tensorflow/core:framework",
426        "//tensorflow/core:lib",
427        "//tensorflow/core:protos_all_cc",
428        "@com_google_absl//absl/types:span",
429    ],
430)
431
432cc_library(
433    name = "immediate_execution_operation",
434    hdrs = ["immediate_execution_operation.h"],
435    visibility = [
436        "//tensorflow:internal",
437    ],
438    deps = [
439        ":abstract_operation",
440        ":abstract_tensor_handle",
441        ":immediate_execution_tensor_handle",
442        "//tensorflow/c:tensor_interface",
443        "//tensorflow/core:framework",
444        "//tensorflow/core:lib",
445        "//tensorflow/core:protos_all_cc",
446        "//tensorflow/core/util:managed_stack_trace",
447        "@com_google_absl//absl/types:optional",
448        "@com_google_absl//absl/types:span",
449    ],
450)
451
452cc_library(
453    name = "abstract_context",
454    hdrs = ["abstract_context.h"],
455    visibility = [
456        "//tensorflow:internal",
457    ],
458    deps = [
459        ":abstract_function",
460        ":abstract_operation",
461    ],
462)
463
464cc_library(
465    name = "abstract_function",
466    hdrs = ["abstract_function.h"],
467    visibility = [
468        "//tensorflow:internal",
469    ],
470    deps = [
471        "//tensorflow/core:protos_all_cc",
472        "//tensorflow/core/platform:intrusive_ptr",
473        "//tensorflow/core/platform:refcount",
474        "//tensorflow/core/platform:status",
475    ],
476)
477
478cc_library(
479    name = "immediate_execution_distributed_manager",
480    hdrs = ["immediate_execution_distributed_manager.h"],
481    visibility = [
482        "//tensorflow:internal",
483    ],
484    deps = [
485        "//tensorflow/core:framework",
486        "//tensorflow/core:lib",
487        "//tensorflow/core:protos_all_cc",
488    ],
489)
490
491cc_library(
492    name = "immediate_execution_context",
493    hdrs = ["immediate_execution_context.h"],
494    visibility = [
495        "//tensorflow:internal",
496    ],
497    deps = [
498        ":abstract_context",
499        ":immediate_execution_distributed_manager",
500        ":immediate_execution_operation",
501        ":immediate_execution_tensor_handle",
502        "//tensorflow/c:tensor_interface",
503        "//tensorflow/core:framework",
504        "//tensorflow/core:lib",
505        "//tensorflow/core:protos_all_cc",
506        "//tensorflow/core/platform",
507        "@com_google_absl//absl/types:optional",
508        "@com_google_absl//absl/types:span",
509    ],
510)
511
512cc_library(
513    name = "tfe_context_internal",
514    hdrs = ["tfe_context_internal.h"],
515    visibility = [
516        "//tensorflow:internal",
517    ],
518    deps = [
519        ":immediate_execution_context",
520        "//tensorflow/c:conversion_macros",
521    ],
522)
523
524cc_library(
525    name = "tfe_cancellation_manager_internal",
526    hdrs = ["tfe_cancellation_manager_internal.h"],
527    visibility = [
528        "//tensorflow:internal",
529    ],
530    deps = [
531        "//tensorflow/c:conversion_macros",
532        "//tensorflow/core:framework",
533    ],
534)
535
536cc_library(
537    name = "tfe_executor_internal",
538    hdrs = ["tfe_executor_internal.h"],
539    visibility = ["//visibility:private"],
540    deps = [
541        "//tensorflow/core/common_runtime/eager:eager_executor",
542    ],
543)
544
545cc_library(
546    name = "tfe_monitoring_internal",
547    hdrs = ["tfe_monitoring_internal.h"],
548    visibility = ["//visibility:private"],
549    deps = [
550        "//tensorflow/core:lib",
551        "@com_google_absl//absl/memory",
552    ],
553)
554
555cc_library(
556    name = "tfe_op_attrs_internal",
557    hdrs = ["tfe_op_attrs_internal.h"],
558    visibility = ["//visibility:private"],
559    deps = [
560        ":abstract_op_attrs",
561        "//tensorflow/c:conversion_macros",
562        "//tensorflow/c:tf_status",
563        "//tensorflow/core:protos_all_cc",
564    ],
565)
566
567cc_library(
568    name = "tfe_op_internal",
569    hdrs = ["tfe_op_internal.h"],
570    visibility = [
571        "//tensorflow:internal",
572    ],
573    deps = [
574        ":immediate_execution_operation",
575        "//tensorflow/c:conversion_macros",
576    ],
577)
578
579cc_library(
580    name = "tfe_tensor_debug_info_internal",
581    hdrs = ["tfe_tensor_debug_info_internal.h"],
582    visibility = ["//visibility:private"],
583    deps = [
584        "//tensorflow/core:lib",
585    ],
586)
587
588cc_library(
589    name = "tfe_tensorhandle_internal",
590    hdrs = ["tfe_tensorhandle_internal.h"],
591    visibility = [
592        "//tensorflow:internal",
593    ],
594    deps = [
595        ":immediate_execution_tensor_handle",
596        "//tensorflow/c:conversion_macros",
597    ],
598)
599
600cc_header_only_library(
601    name = "tfe_tensorhandle_internal_hdrs_only",
602    extra_deps = [
603        "@com_google_absl//absl/strings",
604    ],
605    visibility = [
606        "//tensorflow:internal",
607    ],
608    deps = [
609        ":tfe_tensorhandle_internal",
610    ],
611)
612
613cc_header_only_library(
614    name = "tfe_cancellationmanager_internal_hdrs_only",
615    extra_deps = [
616        "@com_google_absl//absl/strings",
617    ],
618    visibility = [
619        "//tensorflow:internal",
620    ],
621    deps = [
622        ":tfe_cancellation_manager_internal",
623    ],
624)
625
626tf_cuda_library(
627    name = "c_api_test_util",
628    testonly = 1,
629    srcs = ["c_api_test_util.cc"],
630    hdrs = ["c_api_test_util.h"],
631    visibility = [
632        "//learning/brain:__subpackages__",
633        "//tensorflow:__subpackages__",
634    ],
635    deps = [
636        ":c_api",
637        ":c_api_experimental",
638        "//tensorflow/c:c_test_util",
639        "//tensorflow/c:tf_datatype",
640        "//tensorflow/c:tf_tensor",
641        "//tensorflow/core:framework",
642        "//tensorflow/core:lib",
643        "//tensorflow/core:protos_all_cc",
644        "//tensorflow/core:test",
645    ],
646)
647
648tf_cuda_cc_test(
649    name = "c_api_test",
650    size = "small",
651    srcs = [
652        "c_api_debug_test.cc",
653        "c_api_test.cc",
654    ],
655    tags = [
656        "no_cuda_asan",  # TODO(b/181771536)
657        "guitar",
658        # "multi_gpu",  b/180748118
659    ],
660    deps = [
661        ":c_api",
662        ":c_api_experimental",
663        ":c_api_internal",
664        ":c_api_test_util",
665        ":tfe_op_internal",
666        ":tfe_tensorhandle_internal",
667        "@com_google_absl//absl/strings",
668        "//tensorflow/c:c_test_util",
669        "//tensorflow/core:lib",
670        "//tensorflow/core:lib_internal",
671        "//tensorflow/core:protos_all_cc",
672        "//tensorflow/core:test",
673        "//tensorflow/core:test_main",
674        "//tensorflow/core/common_runtime/eager:eager_operation",
675        "//tensorflow/core/common_runtime/eager:tensor_handle",
676        "//tensorflow/core/distributed_runtime/rpc:grpc_server_lib",
677        # copybara:uncomment_begin
678        # "//tensorflow/core/tfrt/eager:c_api_tfrt",
679        # "@tf_runtime//backends/cpu:tf_ops_alwayslink",
680        # copybara:uncomment_end
681    ],
682)
683
684tf_cuda_library(
685    name = "c_api_remote_test_util",
686    testonly = 1,
687    srcs = ["c_api_remote_test_util.cc"],
688    hdrs = ["c_api_remote_test_util.h"],
689    visibility = ["//visibility:private"],
690    deps = [
691        ":c_api",
692        ":c_api_internal",
693        ":c_api_test_util",
694        ":tfe_tensorhandle_internal",
695        "//tensorflow/core:framework",
696        "//tensorflow/core:lib",
697        "//tensorflow/core:protos_all_cc",
698        "//tensorflow/core:test",
699        "//tensorflow/core/common_runtime/eager:tensor_handle",
700        "//tensorflow/core/distributed_runtime/rpc:grpc_server_lib",
701        "@com_google_absl//absl/strings",
702    ],
703)
704
705tf_cuda_cc_test(
706    name = "c_api_remote_test",
707    size = "small",
708    srcs = [
709        "c_api_remote_test.cc",
710    ],
711    # TODO(b/136478427): Figure out how to correctly shut the server down
712    args = ["--heap_check="],
713    tags = [
714        "no_windows",
715    ],
716    deps = [
717        ":c_api",
718        ":c_api_experimental",
719        ":c_api_internal",
720        ":c_api_remote_test_util",
721        ":c_api_test_util",
722        ":tfe_tensorhandle_internal",
723        "//tensorflow/c:c_test_util",
724        "//tensorflow/core:framework",
725        "//tensorflow/core:graph",
726        "//tensorflow/core:lib",
727        "//tensorflow/core:protos_all_cc",
728        "//tensorflow/core:test",
729        "//tensorflow/core:test_main",
730        "//tensorflow/core/common_runtime:function_optimization_registry",
731        "//tensorflow/core/common_runtime/eager:eager_operation",
732        "//tensorflow/core/distributed_runtime/rpc:grpc_server_lib",
733        "@com_google_absl//absl/strings",
734    ],
735)
736
737tf_cuda_cc_test(
738    name = "c_api_remote_function_test",
739    size = "small",
740    srcs = [
741        "c_api_remote_function_test.cc",
742    ],
743    # TODO(b/136478427): Figure out how to correctly shut the server down
744    args = ["--heap_check="],
745    tags = [
746        "no_windows",
747    ],
748    deps = [
749        ":c_api_remote_test_util",
750        "//tensorflow/core:test",
751        "//tensorflow/core:test_main",
752    ],
753)
754
755tf_cuda_cc_test(
756    name = "c_api_distributed_test",
757    size = "small",
758    srcs = [
759        "c_api_distributed_test.cc",
760    ],
761    # TODO(b/136478427): Figure out how to correctly shut the server down
762    args = ["--heap_check="],
763    tags = [
764        "no_oss",  # TODO(b/200848572)
765        "no_windows",
766        "noasan",  # leaks gRPC server instances
767    ],
768    deps = [
769        ":c_api",
770        ":c_api_experimental",
771        ":c_api_internal",
772        ":c_api_test_util",
773        ":tfe_tensorhandle_internal",
774        "//tensorflow/c:c_test_util",
775        "//tensorflow/core:framework",
776        "//tensorflow/core:graph",
777        "//tensorflow/core:lib",
778        "//tensorflow/core:protos_all_cc",
779        "//tensorflow/core:test",
780        "//tensorflow/core:test_main",
781        "//tensorflow/core/common_runtime:function_optimization_registry",
782        "//tensorflow/core/common_runtime:optimization_registry",
783        "//tensorflow/core/common_runtime/eager:eager_operation",
784        "//tensorflow/core/distributed_runtime/rpc:grpc_server_lib",
785        "@com_google_absl//absl/strings",
786    ],
787)
788
789tf_cuda_cc_test(
790    name = "c_api_cluster_test",
791    size = "small",
792    srcs = [
793        "c_api_cluster_test.cc",
794    ],
795    # TODO(b/136478427): Figure out how to correctly shut the server down
796    args = ["--heap_check="],
797    tags = [
798        "no_windows",
799    ],
800    deps = [
801        ":c_api",
802        ":c_api_experimental",
803        ":c_api_internal",
804        ":c_api_test_util",
805        ":tfe_tensorhandle_internal",
806        "//tensorflow/c:c_test_util",
807        "//tensorflow/core:lib",
808        "//tensorflow/core:protos_all_cc",
809        "//tensorflow/core:test",
810        "//tensorflow/core:test_main",
811        "//tensorflow/core/common_runtime/eager:eager_operation",
812        "//tensorflow/core/distributed_runtime/rpc:grpc_server_lib",
813        "//tensorflow/core/platform:env",
814        "@com_google_absl//absl/strings",
815    ],
816)
817
818cc_library(
819    name = "graph_function",
820    srcs = ["graph_function.cc"],
821    hdrs = [
822        "graph_function.h",
823    ],
824    visibility = [
825        "//tensorflow:internal",
826    ],
827    deps = [
828        ":abstract_function",
829        "//tensorflow/core/lib/llvm_rtti",
830        "//tensorflow/core/platform:errors",
831    ],
832)
833
834tf_cuda_library(
835    name = "c_api_experimental",
836    srcs = [
837        "c_api_experimental.cc",
838        "c_api_unified_experimental.cc",
839        "c_api_unified_experimental_eager.cc",
840        "c_api_unified_experimental_graph.cc",
841        "c_api_unified_experimental_internal.h",
842    ],
843    hdrs = [
844        "c_api_experimental.h",
845        "c_api_unified_experimental.h",
846    ],
847    copts = tf_copts(),
848    visibility = ["//visibility:public"],
849    deps = select({
850        "//tensorflow:android": [
851            "//tensorflow/core:portable_tensorflow_lib_lite",
852        ],
853        "//conditions:default": [
854            ":c_api",
855            ":c_api_internal",
856            ":graph_function",
857            ":tfe_context_internal",
858            ":tfe_op_internal",
859            ":tfe_tensorhandle_internal",
860            ":abstract_operation",
861            ":abstract_context",
862            ":abstract_tensor_handle",
863            ":immediate_execution_tensor_handle",
864            ":immediate_execution_context",
865            "//tensorflow/core/lib/llvm_rtti",
866            "//tensorflow/c:c_api",
867            "//tensorflow/c:c_api_internal",
868            "//tensorflow/core:core_cpu",
869            "//tensorflow/core/common_runtime/eager:attr_builder",
870            "//tensorflow/core/common_runtime/eager:context",
871            "//tensorflow/core/common_runtime/eager:eager_executor",
872            "//tensorflow/core/common_runtime/eager:eager_operation",
873            "//tensorflow/core/common_runtime/eager:execute",
874            "//tensorflow/core/common_runtime/eager:kernel_and_device",
875            "//tensorflow/core/common_runtime/eager:tensor_handle",
876            "//tensorflow/core/common_runtime/eager:copy_to_device_node",
877            "//tensorflow/core:core_cpu_internal",
878            "//tensorflow/core:framework",
879            "//tensorflow/core:framework_internal",
880            "//tensorflow/core:lib",
881            "//tensorflow/core:lib_internal",
882            "//tensorflow/core:protos_all_cc",
883            "@com_google_absl//absl/types:variant",
884            "//tensorflow/c:conversion_macros",
885        ],
886    }) + select({
887        "//tensorflow:with_xla_support": [
888            "//tensorflow/compiler/tf2xla:xla_compiler",
889            "//tensorflow/compiler/jit",
890            "//tensorflow/compiler/jit:xla_device",
891        ],
892        "//conditions:default": [],
893    }) + [
894        "@com_google_absl//absl/memory",
895        "@com_google_absl//absl/strings",
896        "@com_google_absl//absl/container:flat_hash_map",
897        "//tensorflow/c:tf_status_helper",
898        "//tensorflow/core/distributed_runtime/coordination:coordination_service_agent",
899        "//tensorflow/core/distributed_runtime/eager:eager_client",
900        "//tensorflow/core/distributed_runtime/rpc/eager:grpc_eager_client",
901        "//tensorflow/core/distributed_runtime/rpc:grpc_channel",
902        "//tensorflow/core/distributed_runtime/rpc:grpc_server_lib",
903        "//tensorflow/core/distributed_runtime/rpc:grpc_worker_cache",
904        "//tensorflow/core/distributed_runtime/rpc:grpc_worker_service",
905        "//tensorflow/core/distributed_runtime/rpc:rpc_rendezvous_mgr",
906        "//tensorflow/core/distributed_runtime:remote_device",
907        "//tensorflow/core/distributed_runtime:server_lib",
908        "//tensorflow/core/distributed_runtime:worker_env",
909        "//tensorflow/core:gpu_runtime",
910    ],
911    alwayslink = 1,
912)
913
914tf_cuda_cc_test(
915    name = "c_api_experimental_test",
916    size = "small",
917    srcs = [
918        "c_api_experimental_test.cc",
919    ],
920    args = ["--heap_check="],
921    linkstatic = tf_kernel_tests_linkstatic(),
922    tags = tf_cuda_tests_tags() + ["nomac"],
923    deps = [
924        ":c_api",
925        ":c_api_experimental",
926        ":c_api_test_util",
927        "//tensorflow/c:c_test_util",
928        "//tensorflow/core:lib",
929        "//tensorflow/core:protos_all_cc",
930        "//tensorflow/core:test",
931        "//tensorflow/core:test_main",
932        "//tensorflow/core/platform:status",
933        "@com_google_absl//absl/strings",
934    ],
935)
936
937tf_cuda_cc_test(
938    name = "c_api_unified_experimental_test",
939    size = "small",
940    srcs = [
941        "c_api_unified_experimental_test.cc",
942    ],
943    args = ["--heap_check="],
944    linkstatic = tf_kernel_tests_linkstatic(),
945    tags = tf_cuda_tests_tags() + ["nomac"],
946    deps = [
947        ":c_api",
948        ":c_api_experimental",
949        ":c_api_test_util",
950        "//tensorflow/c:c_api",
951        "//tensorflow/c:c_test_util",
952        "//tensorflow/c:tf_status_helper",
953        "//tensorflow/compiler/mlir/tensorflow/c:mlir_c_api_registration",
954        "//tensorflow/core:lib",
955        "//tensorflow/core:protos_all_cc",
956        "//tensorflow/core:test",
957        "//tensorflow/core:test_main",
958        "@com_google_absl//absl/strings",
959    ],
960)
961
962cc_library(
963    name = "custom_device_testutil",
964    testonly = True,
965    srcs = ["custom_device_testutil.cc"],
966    hdrs = ["custom_device_testutil.h"],
967    visibility = ["//tensorflow:internal"],
968    deps = [
969        ":c_api",
970        ":c_api_experimental",
971        ":c_api_test_util",
972        "//tensorflow/c:c_api",
973        "//tensorflow/core:lib",
974        "//tensorflow/core:test",
975    ],
976)
977
978tf_cc_test(
979    name = "custom_device_test",
980    size = "small",
981    srcs = [
982        "custom_device_test.cc",
983    ],
984    deps = [
985        ":c_api",
986        ":c_api_experimental",
987        ":c_api_test_util",
988        ":custom_device_testutil",
989        "//tensorflow/c:c_api",
990        "//tensorflow/c:c_test_util",
991        "//tensorflow/core:lib",
992        "//tensorflow/core:protos_all_cc",
993        "//tensorflow/core:test",
994        "//tensorflow/core:test_main",
995        "@com_google_absl//absl/strings",
996    ],
997)
998
999cc_library(
1000    name = "tape",
1001    hdrs = ["tape.h"],
1002    visibility = ["//tensorflow:internal"],
1003    deps = [
1004        "//tensorflow/core:framework",
1005        "//tensorflow/core:lib",
1006    ],
1007)
1008
1009filegroup(
1010    name = "headers",
1011    srcs = [
1012        "c_api.h",
1013        "c_api_experimental.h",
1014        "dlpack.h",
1015    ],
1016    visibility = ["//tensorflow:__subpackages__"],
1017)
1018
1019cc_library(
1020    name = "dlpack",
1021    srcs = ["dlpack.cc"],
1022    hdrs = ["dlpack.h"],
1023    copts = [
1024        "-fexceptions",
1025        "-fno-strict-aliasing",
1026    ],
1027    features = ["-use_header_modules"],
1028    visibility = ["//tensorflow:__subpackages__"],
1029    deps = [
1030        ":c_api",
1031        ":c_api_experimental",
1032        ":tfe_tensorhandle_internal",
1033        "//tensorflow/c:tf_status_helper",
1034        "//tensorflow/c:tf_status_internal",
1035        "//tensorflow/core:framework",
1036        "//tensorflow/core:framework_internal",
1037        "//tensorflow/core:lib",
1038        "//tensorflow/core/common_runtime/eager:tensor_handle",
1039        "@dlpack",
1040    ],
1041    alwayslink = 1,
1042)
1043
1044# TODO(karllessard): only used by //tensorflow/core:mobile_srcs_only_runtime
1045# right now, remove this public rule when no longer needed (it should be
1046# replaced by TF Lite)
1047filegroup(
1048    name = "srcs",
1049    srcs = glob(
1050        [
1051            "*.cc",
1052            "*.h",
1053        ],
1054        exclude = [
1055            "c_api_experimental.cc",
1056            "c_api_unified_experimental.cc",
1057            "c_api_unified_experimental_eager.cc",
1058            "c_api_unified_experimental_graph.cc",
1059            "c_api_unified_experimental_internal.h",
1060            "graph_function.h",
1061            "graph_function.cc",
1062            "gradient_checker.cc",
1063            "gradient_checker.h",
1064            "gradients.cc",  # Uses RTTI.
1065            "tracing_utils.h",
1066            "tracing_utils.cc",
1067            "*test*",
1068            "*dlpack*",
1069        ],
1070    ),
1071    visibility = ["//visibility:public"],
1072)
1073