Skip to content

Commit 9ac3eba

Browse files
ai-edge-botcopybara-github
authored andcommitted
Refactor InferenceCalculatorWebNn to use InferenceRunnerLiteRt.
LiteRT-PiperOrigin-RevId: 820329122
1 parent 593ba98 commit 9ac3eba

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

litert/c/litert_options.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ LiteRtStatus LiteRtSetOptionsHardwareAccelerators(
4747
LRT_CHECK_NON_NULL(options);
4848
if ((hardware_accelerators &
4949
(kLiteRtHwAcceleratorCpu | kLiteRtHwAcceleratorGpu |
50-
kLiteRtHwAcceleratorNpu)) != hardware_accelerators) {
50+
kLiteRtHwAcceleratorNpu
51+
#ifdef __EMSCRIPTEN__
52+
| kLiteRtHwAcceleratorWebNn
53+
#endif // __EMSCRIPTEN__
54+
)) != hardware_accelerators) {
5155
LITERT_LOG(LITERT_ERROR,
5256
"Invalid bitfield value for hardware accelerator set: %d.",
5357
hardware_accelerators);

litert/runtime/compiled_model.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,15 @@ Expected<void> LiteRtCompiledModelT::InitializeRuntime(
187187
resolver.AddCustom(op_name, &sStubRegistration);
188188
}
189189
}
190+
#ifdef __EMSCRIPTEN__
191+
else if (hardware_accelerators & kLiteRtHwAcceleratorWebNn) {
192+
const char* accelerator_supported_custom_ops[] = {
193+
"Convolution2DTransposeBias"};
194+
for (const auto& op_name : accelerator_supported_custom_ops) {
195+
resolver.AddCustom(op_name, &sStubRegistration);
196+
}
197+
}
198+
#endif // __EMSCRIPTEN__
190199

191200
tflite::InterpreterOptions interpreter_options;
192201
interpreter_options.SetUseSignatureTensorNames(true);

0 commit comments

Comments
 (0)