| # Copyright 2023 The Chromium Authors | |
| # Use of this source code is governed by a BSD-style license that can be | |
| # found in the LICENSE file. | |
| import("//build/buildflag_header.gni") | |
| import("//mojo/public/tools/fuzzers/mojolpm.gni") | |
| import("//services/on_device_model/on_device_model.gni") | |
| import("//services/webnn/features.gni") | |
| import("//third_party/protobuf/proto_library.gni") | |
| import("//third_party/tflite/features.gni") | |
| buildflag_header("buildflags") { | |
| header = "buildflags.h" | |
| flags = [ | |
| "WEBNN_USE_TFLITE=$webnn_use_tflite", | |
| "WEBNN_USE_LITERT=$webnn_use_litert", | |
| "WEBNN_USE_CHROME_ML_API=$webnn_use_chrome_ml_api", | |
| "WEBNN_ENABLE_TFLITE_PROFILER=$webnn_enable_tflite_profiler", | |
| "WEBNN_INSTALL_RUNTIME_IN_CHROME_INSTALLER=$webnn_install_runtime_in_chrome_installer", | |
| ] | |
| } | |
| source_set("webnn_switches") { | |
| sources = [ | |
| "webnn_switches.cc", | |
| "webnn_switches.h", | |
| ] | |
| deps = [ | |
| ":buildflags", | |
| "//base", | |
| ] | |
| } | |
| component("webnn_service") { | |
| defines = [ "IS_WEBNN_SERVICE_IMPL" ] | |
| sources = [ | |
| "error.h", | |
| "scoped_gpu_sequence.cc", | |
| "scoped_gpu_sequence.h", | |
| "sequence_deleter.cc", | |
| "sequence_deleter.h", | |
| "webnn_constant_operand.cc", | |
| "webnn_constant_operand.h", | |
| "webnn_context_impl.cc", | |
| "webnn_context_impl.h", | |
| "webnn_context_provider_impl.cc", | |
| "webnn_context_provider_impl.h", | |
| "webnn_graph_builder_impl.cc", | |
| "webnn_graph_builder_impl.h", | |
| "webnn_graph_impl.cc", | |
| "webnn_graph_impl.h", | |
| "webnn_object_impl.h", | |
| "webnn_pending_constant_operand.cc", | |
| "webnn_pending_constant_operand.h", | |
| "webnn_tensor_impl.cc", | |
| "webnn_tensor_impl.h", | |
| "webnn_utils.cc", | |
| "webnn_utils.h", | |
| ] | |
| deps = [ | |
| ":buildflags", | |
| ":webnn_switches", | |
| "//base", | |
| "//gpu/command_buffer/service", | |
| "//gpu/command_buffer/service:gles2", | |
| "//gpu/config", | |
| "//mojo/public/cpp/bindings", | |
| "//services/viz/privileged/mojom/gl", | |
| "//services/webnn/public/mojom", | |
| "//third_party/tflite:buildflags", | |
| ] | |
| if (is_win) { | |
| sources += [ | |
| "dml/adapter.cc", | |
| "dml/adapter.h", | |
| "dml/command_queue.cc", | |
| "dml/command_queue.h", | |
| "dml/command_recorder.cc", | |
| "dml/command_recorder.h", | |
| "dml/context_impl_dml.cc", | |
| "dml/context_impl_dml.h", | |
| "dml/context_provider_dml.cc", | |
| "dml/context_provider_dml.h", | |
| "dml/error.h", | |
| "dml/graph_builder_dml.cc", | |
| "dml/graph_builder_dml.h", | |
| "dml/graph_impl_dml.cc", | |
| "dml/graph_impl_dml.h", | |
| "dml/platform_functions.cc", | |
| "dml/platform_functions.h", | |
| "dml/tensor_desc.cc", | |
| "dml/tensor_desc.h", | |
| "dml/tensor_impl_dml.cc", | |
| "dml/tensor_impl_dml.h", | |
| "dml/utils.cc", | |
| "dml/utils.h", | |
| ] | |
| deps += [ | |
| "//third_party/fp16", | |
| "//third_party/microsoft_dxheaders:dxguids", | |
| "//ui/gl", | |
| "//ui/gl/init", | |
| ] | |
| libs = [ "dxgi.lib" ] | |
| } | |
| if (is_apple) { | |
| sources += [ | |
| "coreml/buffer_content_coreml.h", | |
| "coreml/buffer_content_coreml.mm", | |
| "coreml/context_impl_coreml.h", | |
| "coreml/context_impl_coreml.mm", | |
| "coreml/graph_builder_coreml.cc", | |
| "coreml/graph_builder_coreml.h", | |
| "coreml/graph_impl_coreml.h", | |
| "coreml/graph_impl_coreml.mm", | |
| "coreml/tensor_impl_coreml.h", | |
| "coreml/tensor_impl_coreml.mm", | |
| "coreml/utils_coreml.h", | |
| "coreml/utils_coreml.mm", | |
| ] | |
| frameworks = [ | |
| "CoreFoundation.framework", | |
| "CoreML.framework", | |
| "CoreVideo.framework", | |
| "Foundation.framework", | |
| "IOSurface.framework", | |
| ] | |
| deps += [ | |
| "//third_party/coremltools:modelformat_proto", | |
| "//third_party/fp16", | |
| ] | |
| } | |
| if (webnn_use_tflite || webnn_use_litert) { | |
| sources += [ | |
| "tflite/buffer_content_tflite.cc", | |
| "tflite/buffer_content_tflite.h", | |
| "tflite/context_impl_tflite.cc", | |
| "tflite/context_impl_tflite.h", | |
| "tflite/graph_builder_tflite.cc", | |
| "tflite/graph_builder_tflite.h", | |
| "tflite/graph_impl_tflite.cc", | |
| "tflite/graph_impl_tflite.h", | |
| "tflite/op_resolver.cc", | |
| "tflite/op_resolver.h", | |
| "tflite/tensor_impl_tflite.cc", | |
| "tflite/tensor_impl_tflite.h", | |
| ] | |
| if (webnn_use_litert) { | |
| sources += [ | |
| "tflite/context_impl_litert.cc", | |
| "tflite/context_impl_litert.h", | |
| "tflite/graph_impl_litert.cc", | |
| "tflite/graph_impl_litert.h", | |
| ] | |
| } | |
| deps += [ | |
| "//third_party/flatbuffers", | |
| "//third_party/fp16", | |
| "//third_party/tflite", | |
| "//third_party/tflite:tflite_builtin_op_resolver", | |
| "//third_party/tflite:tflite_public_headers", | |
| ] | |
| if (webnn_use_litert) { | |
| deps += [ "//third_party/litert" ] | |
| } | |
| if (build_tflite_with_xnnpack) { | |
| deps += [ "//third_party/xnnpack" ] | |
| } | |
| if (enable_ml_internal) { | |
| deps += [ "//services/on_device_model/ml" ] | |
| } | |
| } | |
| if (is_win) { | |
| sources += [ | |
| "ort/context_impl_ort.cc", | |
| "ort/context_impl_ort.h", | |
| "ort/context_provider_ort.cc", | |
| "ort/context_provider_ort.h", | |
| "ort/device_allocator.cc", | |
| "ort/device_allocator.h", | |
| "ort/environment.cc", | |
| "ort/environment.h", | |
| "ort/external_weights_manager.cc", | |
| "ort/external_weights_manager.h", | |
| "ort/graph_builder_ort.cc", | |
| "ort/graph_builder_ort.h", | |
| "ort/graph_impl_ort.cc", | |
| "ort/graph_impl_ort.h", | |
| "ort/logging.cc", | |
| "ort/logging.h", | |
| "ort/model_editor.cc", | |
| "ort/model_editor.h", | |
| "ort/ort_data_type.cc", | |
| "ort/ort_data_type.h", | |
| "ort/ort_session_options.cc", | |
| "ort/ort_session_options.h", | |
| "ort/ort_status.cc", | |
| "ort/ort_status.h", | |
| "ort/platform_functions_ort.cc", | |
| "ort/platform_functions_ort.h", | |
| "ort/scoped_ort_types.h", | |
| "ort/tensor_impl_ort.cc", | |
| "ort/tensor_impl_ort.h", | |
| ] | |
| deps += [ | |
| "//services/webnn/public/cpp:win", | |
| "//third_party/windows_app_sdk_headers", | |
| ] | |
| libs += [ "runtimeobject.lib" ] | |
| # TODO(crbug.com/40031409): Fix code that adds exit-time destructors and | |
| # enable the diagnostic by removing this line. | |
| configs += [ "//build/config/compiler:no_exit_time_destructors" ] | |
| } | |
| if (is_apple || webnn_use_tflite || webnn_use_litert) { | |
| sources += [ | |
| "queueable_resource_state.h", | |
| "queueable_resource_state_base.cc", | |
| "queueable_resource_state_base.h", | |
| "resource_task.cc", | |
| "resource_task.h", | |
| ] | |
| } | |
| } | |
| source_set("webnn_test_support") { | |
| testonly = true | |
| sources = [ | |
| "webnn_test_environment.cc", | |
| "webnn_test_environment.h", | |
| ] | |
| deps = [ | |
| ":webnn_service", | |
| "//base", | |
| "//base/test:test_support", | |
| "//gpu/command_buffer/service", | |
| "//gpu/config", | |
| "//mojo/public/cpp/bindings", | |
| "//services/viz/privileged/mojom/gl", | |
| "//services/webnn/host", | |
| "//services/webnn/public/mojom", | |
| ] | |
| if (is_win) { | |
| deps += [ | |
| "//services/webnn/host", | |
| "//ui/gfx/mojom", | |
| ] | |
| } | |
| } | |
| source_set("tests") { | |
| testonly = true | |
| sources = [ | |
| "webnn_context_provider_impl_unittest.cc", | |
| "webnn_graph_builder_impl_unittest.cc", | |
| "webnn_graph_impl_unittest.cc", | |
| "webnn_test_utils.cc", | |
| "webnn_test_utils.h", | |
| ] | |
| if (webnn_use_tflite || webnn_use_litert || is_mac) { | |
| sources += [ | |
| "webnn_graph_impl_backend_test.cc", | |
| "webnn_tensor_impl_backend_test.cc", | |
| ] | |
| } | |
| if (is_win) { | |
| sources += [ | |
| "ort/model_editor_test.cc", | |
| "ort/platform_functions_ort_test.cc", | |
| "ort/test_base_ort.cc", | |
| "ort/test_base_ort.h", | |
| ] | |
| } | |
| deps = [ | |
| ":buildflags", | |
| ":webnn_service", | |
| ":webnn_test_support", | |
| "//base", | |
| "//base/test:test_support", | |
| "//mojo/public/cpp/bindings", | |
| "//mojo/public/cpp/test_support:test_utils", | |
| "//services/webnn/public/mojom", | |
| "//testing/gtest", | |
| "//third_party/fp16", | |
| ] | |
| if (is_win) { | |
| deps += [ | |
| "//ui/gl", | |
| "//ui/gl/init", | |
| ] | |
| } | |
| } | |
| mojolpm_fuzzer_test("webnn_graph_mojolpm_fuzzer") { | |
| sources = [ "webnn_graph_mojolpm_fuzzer.cc" ] | |
| proto_source = "webnn_graph_mojolpm_fuzzer.proto" | |
| proto_deps = [ "//services/webnn/public/mojom:mojom_mojolpm" ] | |
| testcase_proto_kind = "services.fuzzing.webnn_graph.proto.Testcase" | |
| seed_corpus_sources = | |
| [ "webnn_graph_mojolpm_fuzzer_seed_corpus/simple.textproto" ] | |
| deps = [ | |
| ":webnn_service", | |
| ":webnn_test_support", | |
| "//base", | |
| "//base/test:test_support", | |
| "//content/test/fuzzer:mojolpm_fuzzer_support", | |
| "//services/webnn/public/mojom:mojom_mojolpm", | |
| "//third_party/libprotobuf-mutator", | |
| ] | |
| } |