Skip to content

Commit 5a5d736

Browse files
committed
model cache poc
1 parent 2c22283 commit 5a5d736

32 files changed

+775
-1
lines changed

services/webnn/BUILD.gn

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ component("webnn_service") {
5555
"//gpu/command_buffer/service:gles2",
5656
"//gpu/config",
5757
"//mojo/public/cpp/bindings",
58+
"//services/webnn:webnn_proto",
5859
"//services/webnn/public/mojom",
5960
]
6061

@@ -260,3 +261,13 @@ mojolpm_fuzzer_test("webnn_graph_mojolpm_fuzzer") {
260261
"//third_party/libprotobuf-mutator",
261262
]
262263
}
264+
265+
proto_library("webnn_proto") {
266+
sources = [ "compute_resource_info.proto" ]
267+
268+
# deps = [
269+
# "//services/webnn/public/mojom:mojom_mojolpm",
270+
# ]
271+
272+
cc_generator_options = "lite"
273+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2025 The Chromium Authors
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// Message format for the MojoLPM fuzzer for the webnn service interface.
6+
7+
syntax = "proto2";
8+
9+
package services.webnn.proto;
10+
11+
enum OperandDataType {
12+
kFloat32 = 10;
13+
kFloat16 = 1;
14+
kInt32 = 2;
15+
kUint32 = 3;
16+
kInt64 = 4;
17+
kUint64 = 5;
18+
kInt8 = 6;
19+
kUint8 = 7;
20+
kInt4 = 8;
21+
kUint4 = 9;
22+
}
23+
24+
message OperandDescriptor {
25+
required OperandDataType data_type = 1;
26+
repeated uint32 dim = 2;
27+
}
28+
29+
message OperationIds {
30+
repeated uint64 id = 1;
31+
}
32+
33+
message ComputeResourceInfo {
34+
map<string, OperandDescriptor> input_names_to_descriptors = 1;
35+
map<string, OperandDescriptor> output_names_to_descriptors = 2;
36+
map<uint64, OperationIds> operand_to_dependent_operations = 3;
37+
}
38+
39+
// //
40+
// message NameMapping {
41+
// map<string, string> ori_name_to_real_name = 1;
42+
// }

services/webnn/coreml/context_impl_coreml.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ class API_AVAILABLE(macos(14.0)) ContextImplCoreml final
5353
mojom::TensorInfoPtr tensor_info,
5454
CreateTensorImplCallback callback) override;
5555

56+
void LoadGraphImpl(
57+
mojo::PendingAssociatedReceiver<mojom::WebNNGraph> receiver,
58+
std::string key,
59+
LoadGraphImplCallback callback) override;
60+
5661
base::WeakPtrFactory<ContextImplCoreml> weak_factory_{this};
5762
};
5863

services/webnn/coreml/context_impl_coreml.mm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,11 @@
5555
std::move(tensor_info)));
5656
}
5757

58+
void ContextImplCoreml::LoadGraphImpl(
59+
mojo::PendingAssociatedRemote<mojom::WebNNGraph> remote,
60+
std::string key,
61+
LoadGraphImplCallback callback) {
62+
NOTIMPLEMENTED();
63+
}
64+
5865
} // namespace webnn::coreml

services/webnn/coreml/graph_impl_coreml.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ class API_AVAILABLE(macos(14.0)) GraphImplCoreml final : public WebNNGraphImpl {
133133
const base::flat_map<std::string_view, WebNNTensorImpl*>& named_outputs)
134134
override;
135135

136+
void SaveGraphImpl(std::string_view key) override;
137+
136138
private:
137139
class ComputeResources;
138140

services/webnn/coreml/graph_impl_coreml.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,10 @@ void DidDispatch(base::ElapsedTimer model_predict_timer,
630630
task->Enqueue();
631631
}
632632

633+
void GraphImplCoreml::SaveGraphImpl(std::string_view key) {
634+
NOTIMPLEMENTED();
635+
}
636+
633637
GraphImplCoreml::Params::Params(
634638
ComputeResourceInfo compute_resource_info,
635639
base::flat_map<std::string, std::string> coreml_name_to_operand_name)

services/webnn/dml/context_impl_dml.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,4 +944,11 @@ void ContextImplDml::RemoveDeviceForTesting() {
944944
d3d12_device_5->RemoveDevice();
945945
}
946946

947+
void ContextImplDml::LoadGraphImpl(
948+
mojo::PendingAssociatedReceiver<mojom::WebNNGraph> receiver,
949+
std::string key,
950+
LoadGraphImplCallback callback) {
951+
NOTIMPLEMENTED();
952+
}
953+
947954
} // namespace webnn::dml

services/webnn/dml/context_impl_dml.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ class COMPONENT_EXPORT(WEBNN_SERVICE) ContextImplDml final
9494
mojom::TensorInfoPtr tensor_info,
9595
CreateTensorImplCallback callback) override;
9696

97+
void LoadGraphImpl(
98+
mojo::PendingAssociatedReceiver<mojom::WebNNGraph> receiver,
99+
std::string key,
100+
LoadGraphImplCallback callback) override;
101+
97102
// Begins recording commands needed for context operations.
98103
// If recording failed, calling this function will recreate the recorder to
99104
// allow recording to start again.

services/webnn/dml/graph_impl_dml.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7129,4 +7129,9 @@ void GraphImplDml::OnDispatchComplete(
71297129
graph_resources_ = std::move(graph_resources);
71307130
}
71317131
}
7132+
7133+
void GraphImplDml::SaveGraphImpl(std::string_view key) {
7134+
NOTIMPLEMENTED();
7135+
}
7136+
71327137
} // namespace webnn::dml

services/webnn/dml/graph_impl_dml.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ class GraphImplDml final : public WebNNGraphImpl {
287287
const base::flat_map<std::string_view, WebNNTensorImpl*>& named_outputs)
288288
override;
289289

290+
void SaveGraphImpl(std::string_view key) override;
291+
290292
// The persistent resource is allocated after the compilation work is
291293
// completed for the graph initialization and will be used for the following
292294
// graph executions. It could be nullptr which means it isn't required by the

0 commit comments

Comments
 (0)