blob: 49451355a2fcf8a1f661d50c32ca69746f15d18d [file] [log] [blame]
# 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_CHROME_ML_API=$webnn_use_chrome_ml_api",
"WEBNN_ENABLE_TFLITE_PROFILER=$webnn_enable_tflite_profiler",
]
}
source_set("webnn_switches") {
sources = [
"webnn_switches.cc",
"webnn_switches.h",
]
deps = [
":buildflags",
"//base",
]
}
# Public WebNN native headers so they can be visible for dependencies
# of webnn native.
source_set("webnn_headers") {
sources = [
# Backend headers must be included here so that dependent targets can
# still include them, even if the backends are disabled.
"d3d12_backend.h",
]
public_deps = [ "//base" ]
}
component("webnn_service") {
defines = [ "IS_WEBNN_SERVICE_IMPL" ]
sources = [
"error.h",
"scoped_sequence.cc",
"scoped_sequence.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_headers",
":webnn_switches",
"//base",
"//gpu/command_buffer/service",
"//gpu/command_buffer/service:gles2",
"//gpu/config",
"//mojo/public/cpp/bindings",
"//services/webnn/public/mojom",
]
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) {
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",
]
deps += [
"//third_party/flatbuffers",
"//third_party/fp16",
"//third_party/tflite",
"//third_party/tflite:buildflags",
"//third_party/tflite:tflite_builtin_op_resolver",
"//third_party/tflite:tflite_public_headers",
]
if (build_tflite_with_xnnpack) {
deps += [ "//third_party/xnnpack" ]
}
if (enable_ml_internal) {
deps += [ "//services/on_device_model/ml" ]
defines += [ "ENABLE_ML_INTERNAL" ]
}
}
if (is_win) {
sources += [
"ort/buffer_content_ort.cc",
"ort/buffer_content_ort.h",
"ort/context_impl_ort.cc",
"ort/context_impl_ort.h",
"ort/context_provider_ort.cc",
"ort/context_provider_ort.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/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/ort_tensor.cc",
"ort/ort_tensor.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 += [ "//third_party/onnxruntime_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_mac || webnn_use_tflite) {
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",
"//gpu/command_buffer/service",
"//gpu/config",
"//mojo/public/cpp/bindings",
"//services/webnn/public/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 (is_win) {
sources += [
"dml/adapter_test.cc",
"dml/command_queue_test.cc",
"dml/command_recorder_test.cc",
"dml/context_impl_dml_test.cc",
"dml/graph_builder_dml_test.cc",
"dml/platform_functions_test.cc",
"dml/tensor_desc_test.cc",
"dml/test_base.cc",
"dml/test_base.h",
]
}
if (webnn_use_tflite || is_mac || is_win) {
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_headers",
":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",
]
}