1load("@flatbuffers//:build_defs.bzl", "flatbuffer_cc_library") 2load( 3 "//tensorflow/core/platform:build_config_root.bzl", 4 "tf_gpu_tests_tags", 5) 6load("//tensorflow:tensorflow.bzl", "if_google", "workspace_root") 7 8package( 9 default_visibility = ["//visibility:public"], 10 licenses = ["notice"], 11) 12 13config_setting( 14 name = "opencl_delegate_no_gl", 15 values = {"copt": "-DCL_DELEGATE_NO_GL"}, 16) 17 18cc_library( 19 name = "api", 20 srcs = ["api.cc"], 21 hdrs = ["api.h"], 22 deps = select({ 23 ":opencl_delegate_no_gl": [], 24 "//conditions:default": [ 25 ":egl_sync", 26 ":gl_interop", 27 ], 28 }) + [ 29 ":cl_command_queue", 30 ":cl_errors", 31 ":cl_event", 32 ":environment", 33 ":inference_context", 34 ":opencl_wrapper", 35 ":tensor", 36 ":tensor_type_util", 37 "@com_google_absl//absl/memory", 38 "@com_google_absl//absl/types:span", 39 "//tensorflow/lite/delegates/gpu:api", 40 "//tensorflow/lite/delegates/gpu/cl/kernels:converter", 41 "//tensorflow/lite/delegates/gpu/common:data_type", 42 "//tensorflow/lite/delegates/gpu/common:model", 43 "//tensorflow/lite/delegates/gpu/common:precision", 44 "//tensorflow/lite/delegates/gpu/common:shape", 45 "//tensorflow/lite/delegates/gpu/common:status", 46 "//tensorflow/lite/delegates/gpu/common:tensor", 47 "//tensorflow/lite/delegates/gpu/common/task:tensor_desc", 48 ], 49) 50 51cc_library( 52 name = "buffer", 53 srcs = ["buffer.cc"], 54 hdrs = ["buffer.h"], 55 deps = [ 56 ":cl_command_queue", 57 ":cl_context", 58 ":gpu_object", 59 ":opencl_wrapper", 60 ":util", 61 "//tensorflow/lite/delegates/gpu/common:data_type", 62 "//tensorflow/lite/delegates/gpu/common:status", 63 "//tensorflow/lite/delegates/gpu/common/task:buffer_desc", 64 "@com_google_absl//absl/status", 65 "@com_google_absl//absl/strings", 66 "@com_google_absl//absl/types:span", 67 ], 68) 69 70cc_test( 71 name = "buffer_test", 72 srcs = ["buffer_test.cc"], 73 linkstatic = True, 74 tags = tf_gpu_tests_tags() + [ 75 "linux", 76 "local", 77 ], 78 deps = [ 79 ":buffer", 80 ":cl_test", 81 "//tensorflow/lite/delegates/gpu/common:status", 82 "@com_google_googletest//:gtest_main", 83 ], 84) 85 86cc_library( 87 name = "cl_test", 88 testonly = 1, 89 hdrs = ["cl_test.h"], 90 deps = [ 91 ":environment", 92 ":opencl_wrapper", 93 "@com_google_googletest//:gtest", 94 ], 95) 96 97cc_library( 98 name = "cl_arguments", 99 srcs = ["cl_arguments.cc"], 100 hdrs = ["cl_arguments.h"], 101 deps = [ 102 ":buffer", 103 ":cl_context", 104 ":gpu_object", 105 ":tensor", 106 "//tensorflow/lite/delegates/gpu/common:gpu_info", 107 "//tensorflow/lite/delegates/gpu/common:status", 108 "//tensorflow/lite/delegates/gpu/common:util", 109 "//tensorflow/lite/delegates/gpu/common/task:arguments", 110 "//tensorflow/lite/delegates/gpu/common/task:util", 111 "@com_google_absl//absl/strings", 112 ], 113) 114 115cc_test( 116 name = "cl_arguments_test", 117 srcs = ["cl_arguments_test.cc"], 118 linkstatic = True, 119 tags = tf_gpu_tests_tags() + [ 120 "linux", 121 "local", 122 ], 123 deps = [ 124 ":buffer", 125 ":cl_arguments", 126 ":gpu_object", 127 "//tensorflow/lite/delegates/gpu/common:gpu_info", 128 "@com_google_absl//absl/strings", 129 "@com_google_googletest//:gtest_main", 130 ], 131) 132 133cc_library( 134 name = "cl_command_queue", 135 srcs = ["cl_command_queue.cc"], 136 hdrs = ["cl_command_queue.h"], 137 deps = [ 138 ":cl_context", 139 ":cl_device", 140 ":cl_event", 141 ":cl_kernel", 142 ":opencl_wrapper", 143 ":util", 144 "//tensorflow/lite/delegates/gpu/common:status", 145 "//tensorflow/lite/delegates/gpu/common:types", 146 "//tensorflow/lite/delegates/gpu/common/task:profiling_info", 147 "@com_google_absl//absl/strings", 148 ], 149) 150 151cc_library( 152 name = "cl_context", 153 srcs = ["cl_context.cc"], 154 hdrs = ["cl_context.h"], 155 deps = [ 156 ":cl_device", 157 ":cl_image_format", 158 ":opencl_wrapper", 159 ":util", 160 "//tensorflow/lite/delegates/gpu/common:data_type", 161 "//tensorflow/lite/delegates/gpu/common:status", 162 "@com_google_absl//absl/strings", 163 ], 164) 165 166cc_library( 167 name = "cl_device", 168 srcs = ["cl_device.cc"], 169 hdrs = ["cl_device.h"], 170 deps = [ 171 ":opencl_wrapper", 172 ":util", 173 "//tensorflow/lite/delegates/gpu/common:gpu_info", 174 "//tensorflow/lite/delegates/gpu/common:status", 175 "//tensorflow/lite/delegates/gpu/common:types", 176 "//tensorflow/lite/experimental/acceleration/compatibility:android_info", 177 "@com_google_absl//absl/strings", 178 "@com_google_absl//absl/strings:str_format", 179 ], 180) 181 182cc_test( 183 name = "cl_device_test", 184 srcs = ["cl_device_test.cc"], 185 deps = [ 186 ":cl_device", 187 "@com_google_googletest//:gtest_main", 188 ], 189) 190 191cc_library( 192 name = "cl_errors", 193 hdrs = ["cl_errors.h"], 194 deps = [ 195 ":util", 196 "//tensorflow/lite/delegates/gpu/common:status", 197 ], 198) 199 200cc_library( 201 name = "cl_event", 202 srcs = ["cl_event.cc"], 203 hdrs = ["cl_event.h"], 204 deps = [ 205 ":opencl_wrapper", 206 ], 207) 208 209cc_library( 210 name = "cl_image_format", 211 srcs = ["cl_image_format.cc"], 212 hdrs = ["cl_image_format.h"], 213 deps = [ 214 ":opencl_wrapper", 215 "//tensorflow/lite/delegates/gpu/common:data_type", 216 ], 217) 218 219cc_library( 220 name = "cl_kernel", 221 srcs = ["cl_kernel.cc"], 222 hdrs = ["cl_kernel.h"], 223 deps = [ 224 ":cl_context", 225 ":cl_device", 226 ":cl_program", 227 ":opencl_wrapper", 228 ":util", 229 "//tensorflow/lite/delegates/gpu/common:kernel_info", 230 "//tensorflow/lite/delegates/gpu/common:status", 231 "@com_google_absl//absl/strings", 232 ], 233) 234 235cc_library( 236 name = "cl_memory", 237 srcs = ["cl_memory.cc"], 238 hdrs = ["cl_memory.h"], 239 deps = [ 240 ":opencl_wrapper", 241 "//tensorflow/lite/delegates/gpu/common:access_type", 242 "//tensorflow/lite/delegates/gpu/common:status", 243 ], 244) 245 246cc_library( 247 name = "cl_operation", 248 srcs = ["cl_operation.cc"], 249 hdrs = ["cl_operation.h"], 250 deps = [ 251 ":cl_arguments", 252 ":cl_command_queue", 253 ":cl_context", 254 ":cl_device", 255 ":cl_kernel", 256 ":program_cache", 257 ":tensor", 258 "//tensorflow/lite/delegates/gpu/common/task:gpu_operation", 259 ], 260) 261 262cc_library( 263 name = "cl_program", 264 srcs = ["cl_program.cc"], 265 hdrs = ["cl_program.h"], 266 deps = [ 267 ":cl_context", 268 ":cl_device", 269 ":opencl_wrapper", 270 ":util", 271 "//tensorflow/lite/delegates/gpu/common:status", 272 "//tensorflow/lite/delegates/gpu/common/task:compiler_options", 273 "@com_google_absl//absl/strings", 274 "@com_google_absl//absl/types:span", 275 ], 276) 277 278flatbuffer_cc_library( 279 name = "compiled_program_cache_cc_fbs", 280 srcs = ["compiled_program_cache.fbs"], 281 flatc_args = [ 282 "--scoped-enums", 283 ], 284) 285 286cc_library( 287 name = "egl_sync", 288 srcs = ["egl_sync.cc"], 289 hdrs = ["egl_sync.h"], 290 defines = [ 291 "EGL_EGLEXT_PROTOTYPES", 292 ], 293 deps = [ 294 "//tensorflow/lite/delegates/gpu/common:status", 295 "//tensorflow/lite/delegates/gpu/gl:gl_call", 296 ], 297) 298 299cc_library( 300 name = "environment", 301 srcs = ["environment.cc"], 302 hdrs = ["environment.h"], 303 deps = [ 304 ":cl_command_queue", 305 ":cl_context", 306 ":cl_device", 307 ":program_cache", 308 ":util", 309 "//tensorflow/lite/delegates/gpu/common:data_type", 310 "//tensorflow/lite/delegates/gpu/common:gpu_info", 311 "//tensorflow/lite/delegates/gpu/common:precision", 312 "//tensorflow/lite/delegates/gpu/common:shape", 313 "//tensorflow/lite/delegates/gpu/common:status", 314 "//tensorflow/lite/delegates/gpu/common:tensor", 315 "//tensorflow/lite/delegates/gpu/common/task:tensor_desc", 316 ], 317) 318 319cc_library( 320 name = "gl_interop", 321 srcs = ["gl_interop.cc"], 322 hdrs = ["gl_interop.h"], 323 deps = [ 324 ":cl_command_queue", 325 ":cl_context", 326 ":cl_device", 327 ":cl_errors", 328 ":cl_event", 329 ":cl_memory", 330 ":egl_sync", 331 ":environment", 332 ":opencl_wrapper", 333 "//tensorflow/lite/delegates/gpu:spi", 334 "//tensorflow/lite/delegates/gpu/common:access_type", 335 "//tensorflow/lite/delegates/gpu/common:status", 336 "//tensorflow/lite/delegates/gpu/gl:gl_call", 337 "//tensorflow/lite/delegates/gpu/gl:gl_sync", 338 "//tensorflow/lite/delegates/gpu/gl:portable", 339 "@com_google_absl//absl/strings", 340 ], 341) 342 343cc_library( 344 name = "gpu_api_delegate", 345 srcs = ["gpu_api_delegate.cc"], 346 hdrs = ["gpu_api_delegate.h"], 347 linkopts = select({ 348 "//tensorflow:android": [ 349 "-lEGL", 350 "-lGLESv3", 351 ], 352 "//conditions:default": [], 353 }), 354 deps = [ 355 ":api", 356 ":opencl_wrapper", 357 ":tensor_type_util", 358 "//tensorflow/lite:kernel_api", 359 "//tensorflow/lite/c:common", 360 "//tensorflow/lite/delegates/gpu:api", 361 "//tensorflow/lite/delegates/gpu:delegate", 362 "//tensorflow/lite/delegates/gpu/common:model", 363 "//tensorflow/lite/delegates/gpu/common:model_builder", 364 "//tensorflow/lite/delegates/gpu/common:model_transformer", 365 "//tensorflow/lite/delegates/gpu/common:status", 366 "//tensorflow/lite/delegates/gpu/common/transformations:model_transformations", 367 "@com_google_absl//absl/types:span", 368 ], 369) 370 371cc_library( 372 name = "gpu_object", 373 hdrs = ["gpu_object.h"], 374 deps = [ 375 ":opencl_wrapper", 376 "//tensorflow/lite/delegates/gpu/common:access_type", 377 "//tensorflow/lite/delegates/gpu/common:data_type", 378 "//tensorflow/lite/delegates/gpu/common:status", 379 "//tensorflow/lite/delegates/gpu/common/task:gpu_object_desc", 380 ], 381) 382 383cc_library( 384 name = "inference_context", 385 srcs = [ 386 "inference_context.cc", 387 ], 388 hdrs = [ 389 "inference_context.h", 390 ], 391 deps = [ 392 ":buffer", 393 ":cl_command_queue", 394 ":cl_device", 395 ":cl_operation", 396 ":environment", 397 ":gpu_object", 398 ":opencl_wrapper", 399 ":recordable_queue_builder", 400 ":serialization_cc_fbs", 401 ":tensor", 402 "//tensorflow/lite/delegates/gpu/common:data_type", 403 "//tensorflow/lite/delegates/gpu/common:gpu_model", 404 "//tensorflow/lite/delegates/gpu/common:gpu_model_cc_fbs", 405 "//tensorflow/lite/delegates/gpu/common:memory_management", 406 "//tensorflow/lite/delegates/gpu/common:model", 407 "//tensorflow/lite/delegates/gpu/common:model_hints", 408 "//tensorflow/lite/delegates/gpu/common:precision", 409 "//tensorflow/lite/delegates/gpu/common:shape", 410 "//tensorflow/lite/delegates/gpu/common:status", 411 "//tensorflow/lite/delegates/gpu/common:tensor", 412 "//tensorflow/lite/delegates/gpu/common:types", 413 "//tensorflow/lite/delegates/gpu/common:util", 414 "//tensorflow/lite/delegates/gpu/common/task:gpu_operation", 415 "//tensorflow/lite/delegates/gpu/common/task:serialization_base", 416 "//tensorflow/lite/delegates/gpu/common/task:tensor_desc", 417 "@com_google_absl//absl/container:flat_hash_map", 418 "@com_google_absl//absl/container:flat_hash_set", 419 ], 420) 421 422cc_library( 423 name = "opencl_wrapper", 424 srcs = ["opencl_wrapper.cc"], 425 hdrs = ["opencl_wrapper.h"], 426 linkopts = select({ 427 "//tensorflow:android": [ 428 "-ldl", # opencl_wrapper calls dlopen() 429 "-lm", 430 ], 431 "//conditions:default": ["-ldl"], # opencl_wrapper calls dlopen() 432 }), 433 deps = [ 434 "//tensorflow/lite/delegates/gpu/common:status", 435 "@com_google_absl//absl/strings", 436 "@opencl_headers", 437 "//tensorflow/lite/delegates/gpu/cl/" + if_google("google", "default") + ":qcom_wrapper", 438 ], 439) 440 441cc_library( 442 name = "program_cache", 443 srcs = ["program_cache.cc"], 444 hdrs = ["program_cache.h"], 445 deps = [ 446 ":cl_context", 447 ":cl_device", 448 ":cl_kernel", 449 ":cl_program", 450 ":compiled_program_cache_cc_fbs", 451 ":util", 452 "//tensorflow/lite/delegates/gpu/common:status", 453 "@com_google_absl//absl/container:flat_hash_map", 454 "@com_google_absl//absl/types:span", 455 "@farmhash_archive//:farmhash", 456 "@flatbuffers", 457 ], 458) 459 460cc_library( 461 name = "recordable_queue", 462 hdrs = ["recordable_queue.h"], 463 deps = [ 464 ":cl_command_queue", 465 ":cl_context", 466 ":cl_device", 467 ":cl_operation", 468 ":opencl_wrapper", 469 "//tensorflow/lite/delegates/gpu/common:status", 470 ], 471) 472 473cc_library( 474 name = "recordable_queue_builder", 475 hdrs = ["recordable_queue_builder.h"], 476 deps = [ 477 ":cl_context", 478 ":cl_device", 479 ":cl_operation", 480 ":recordable_queue", 481 "//tensorflow/lite/delegates/gpu/cl/" + if_google("google", "default") + ":recordable_queue", 482 ], 483) 484 485flatbuffer_cc_library( 486 name = "serialization_cc_fbs", 487 srcs = ["serialization.fbs"], 488 flatc_args = [ 489 "--scoped-enums", 490 "-I " + workspace_root, 491 ], 492 includes = [ 493 "//tensorflow/lite/delegates/gpu/common:gpu_model_cc_fbs_includes", 494 "//tensorflow/lite/delegates/gpu/common/task:serialization_base_cc_fbs_includes", 495 ], 496) 497 498cc_library( 499 name = "tensor", 500 srcs = ["tensor.cc"], 501 hdrs = ["tensor.h"], 502 deps = [ 503 ":buffer", 504 ":cl_command_queue", 505 ":cl_context", 506 ":cl_device", 507 ":cl_image_format", 508 ":cl_memory", 509 ":gpu_object", 510 ":util", 511 "//tensorflow/lite/delegates/gpu/common:data_type", 512 "//tensorflow/lite/delegates/gpu/common:shape", 513 "//tensorflow/lite/delegates/gpu/common:status", 514 "//tensorflow/lite/delegates/gpu/common:tensor", 515 "//tensorflow/lite/delegates/gpu/common:types", 516 "//tensorflow/lite/delegates/gpu/common/task:gpu_tensor", 517 "//tensorflow/lite/delegates/gpu/common/task:tensor_desc", 518 "@com_google_absl//absl/strings", 519 ], 520) 521 522cc_test( 523 name = "tensor_test", 524 srcs = ["tensor_test.cc"], 525 linkstatic = True, 526 tags = tf_gpu_tests_tags() + [ 527 "linux", 528 "local", 529 ], 530 deps = [ 531 ":cl_test", 532 ":tensor", 533 "//tensorflow/lite/delegates/gpu/common:data_type", 534 "//tensorflow/lite/delegates/gpu/common:shape", 535 "//tensorflow/lite/delegates/gpu/common:status", 536 "@com_google_googletest//:gtest_main", 537 ], 538) 539 540cc_library( 541 name = "tensor_type_util", 542 srcs = ["tensor_type_util.cc"], 543 hdrs = ["tensor_type_util.h"], 544 deps = [ 545 "//tensorflow/lite/delegates/gpu:api", 546 "//tensorflow/lite/delegates/gpu/common/task:tensor_desc", 547 ], 548) 549 550cc_library( 551 name = "util", 552 srcs = ["util.cc"], 553 hdrs = ["util.h"], 554 deps = [ 555 ":opencl_wrapper", 556 "//tensorflow/lite/delegates/gpu/common:data_type", 557 "//tensorflow/lite/delegates/gpu/common:status", 558 "//tensorflow/lite/delegates/gpu/common:tensor", 559 "//tensorflow/lite/delegates/gpu/common:util", 560 "@com_google_absl//absl/status", 561 "@com_google_absl//absl/strings", 562 "@com_google_absl//absl/types:span", 563 ], 564) 565