#include "services/webnn/tflite/graph_impl_tflite.h"
#include "base/containers/flat_map.h"
#include "base/location.h"
#include "base/memory/raw_ref.h"
#include "base/memory/scoped_refptr.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "base/types/expected_macros.h"
#include "mojo/public/cpp/bindings/self_owned_associated_receiver.h"
#include "services/webnn/buildflags.h"
#include "services/webnn/error.h"
#include "services/webnn/public/mojom/webnn_context_provider.mojom.h"
#include "services/webnn/public/mojom/webnn_error.mojom.h"
#include "services/webnn/public/mojom/webnn_graph.mojom.h"
#include "services/webnn/queueable_resource_state.h"
#include "services/webnn/queueable_resource_state_base.h"
#include "services/webnn/resource_task.h"
#include "services/webnn/tflite/buffer_content.h"
#include "services/webnn/tflite/buffer_impl_tflite.h"
#include "services/webnn/tflite/context_impl_tflite.h"
#include "services/webnn/tflite/graph_builder_tflite.h"
#include "services/webnn/tflite/op_resolver.h"
#include "services/webnn/webnn_graph_impl.h"
#include "third_party/flatbuffers/src/include/flatbuffers/flatbuffers.h"
#include "third_party/tflite/src/tensorflow/lite/interpreter_builder.h"
#include "third_party/tflite/src/tensorflow/lite/stderr_reporter.h"
#if BUILDFLAG(WEBNN_ENABLE_TFLITE_PROFILER)
#include "third_party/tflite/src/tensorflow/lite/profiling/buffered_profiler.h"
#include "third_party/tflite/src/tensorflow/lite/profiling/profile_summarizer.h"
#endif
namespace webnn::tflite {
namespace {
std::string_view TfLiteStatusToString(TfLiteStatus status) { … }
base::span<uint8_t> SpanFromTensor(TfLiteTensor* tensor) { … }
}
class GraphImplTflite::ComputeResources { … };
base::expected<std::unique_ptr<GraphImplTflite>, mojom::ErrorPtr>
GraphImplTflite::CreateAndBuild(mojom::GraphInfoPtr graph_info,
ComputeResourceInfo compute_resource_info,
ContextImplTflite* context) { … }
GraphImplTflite::~GraphImplTflite() = default;
GraphImplTflite::GraphImplTflite(
ComputeResourceInfo compute_resource_info,
scoped_refptr<QueueableResourceState<ComputeResources>>
compute_resources_state,
ContextImplTflite* context)
: … { … }
void GraphImplTflite::ComputeImpl(NamedBuffers named_inputs,
ComputeCallback callback) { … }
void GraphImplTflite::DispatchImpl(
const base::flat_map<std::string_view, WebNNBufferImpl*>& named_inputs,
const base::flat_map<std::string_view, WebNNBufferImpl*>& named_outputs) { … }
}