@@ -155,27 +155,31 @@ onnxruntime::common::Status Model::Compute(const InlinedHashMap<std::string, Onn
155
155
onnxruntime::common::Status Model::Dispatch (const InlinedHashMap<std::string, OnnxTensorData>& inputs,
156
156
const InlinedHashMap<std::string, OnnxTensorData>& outputs) {
157
157
auto jsepEnsureBuffer = emscripten::val::module_property (" jsepEnsureBuffer" );
158
- for (const auto & input : inputs) {
159
- const std::string& name = input.first ;
160
- const struct OnnxTensorData tensor = input.second ;
158
+ auto promises = emscripten::val::array ();
159
+ for (const auto & [_, tensor] : inputs) {
161
160
emscripten::val shape = emscripten::val::array ();
162
161
for (const auto & dim : tensor.tensor_info .shape ) {
163
162
uint32_t dim_val = SafeInt<uint32_t >(dim);
164
163
shape.call <void >(" push" , dim_val);
165
164
}
166
165
auto buffer = jsepEnsureBuffer (reinterpret_cast <intptr_t >(tensor.buffer ), tensor.tensor_info .data_type , shape);
167
- wnn_inputs_. set (name , buffer);
166
+ promises. call < void >( " push " , buffer);
168
167
}
169
- for (const auto & output : outputs) {
170
- const std::string& name = output.first ;
171
- const struct OnnxTensorData tensor = output.second ;
168
+ for (const auto & [_, tensor] : outputs) {
172
169
emscripten::val shape = emscripten::val::array ();
173
170
for (const auto & dim : tensor.tensor_info .shape ) {
174
171
uint32_t dim_val = SafeInt<uint32_t >(dim);
175
172
shape.call <void >(" push" , dim_val);
176
173
}
177
174
auto buffer = jsepEnsureBuffer (reinterpret_cast <intptr_t >(tensor.buffer ), tensor.tensor_info .data_type , shape);
178
- wnn_outputs_.set (name, buffer);
175
+ promises.call <void >(" push" , buffer);
176
+ }
177
+ auto buffers = emscripten::val::global (" Promise" ).call <emscripten::val>(" all" , promises).await ();
178
+ for (const auto & [name, _] : inputs) {
179
+ wnn_inputs_.set (name, buffers.call <emscripten::val>(" shift" ));
180
+ }
181
+ for (const auto & [name, _] : outputs) {
182
+ wnn_outputs_.set (name, buffers.call <emscripten::val>(" shift" ));
179
183
}
180
184
wnn_context_.call <void >(" dispatch" , wnn_graph_, wnn_inputs_, wnn_outputs_);
181
185
0 commit comments