@@ -24,6 +24,24 @@ using executorch::runtime::BackendExecutionContext;
2424using executorch::runtime::Error;
2525using executorch::runtime::Span;
2626
27+ // Compatibility hooks for multi-device driver / non-multi-device driver code
28+ // When multi-device driver code is available, these declarations are overridden
29+ extern " C" __attribute__((weak)) int ethosu_get_product_config_from_cop_data (
30+ const void *,
31+ const int ,
32+ uint32_t * product_out,
33+ uint32_t * log2_macs_out) {
34+ *product_out = 0 ;
35+ *log2_macs_out = 0 ;
36+ return 0 ;
37+ }
38+
39+ extern " C" __attribute__((weak)) struct ethosu_driver * ethosu_reserve_driver_ex (
40+ uint32_t ,
41+ uint32_t ) {
42+ return ethosu_reserve_driver ();
43+ }
44+
2745namespace executorch {
2846namespace backends {
2947namespace arm {
@@ -48,12 +66,20 @@ Error platform_execute(
4866 int output_count,
4967 Span<executorch::runtime::EValue*> args,
5068 char * ethosu_scratch) {
69+ // Parse product config from command stream to reserve the correct driver
70+ uint32_t product, log2_macs;
71+ if (ethosu_get_product_config_from_cop_data (
72+ handles.cmd_data , handles.cmd_data_size , &product, &log2_macs) != 0 ) {
73+ ET_LOG (Error, " Failed to parse product config from command stream" );
74+ return Error::InvalidProgram;
75+ }
76+
5177 // Allocate driver handle and synchronously invoke driver
5278 auto driver =
5379 std::unique_ptr<ethosu_driver, decltype (ðosu_release_driver)>(
54- ethosu_reserve_driver ( ), ethosu_release_driver);
80+ ethosu_reserve_driver_ex (product, log2_macs ), ethosu_release_driver);
5581 if (driver == nullptr ) {
56- ET_LOG (Error, " ethosu_reserve_driver failed" );
82+ ET_LOG (Error, " ethosu_reserve_driver_ex failed" );
5783 return Error::InvalidState;
5884 }
5985
0 commit comments