From 4bd102c229d046a3eb649fd6dda517a22543251f Mon Sep 17 00:00:00 2001 From: Alexander Bengtsson Date: Mon, 14 Apr 2025 15:26:44 +0200 Subject: [PATCH] MLBEDSW-10714: Only allow CPU-fallback for Passthrough ops - Throw exception during scheduler_packing if a non-passthrough operation fails to map to NPU. Change-Id: I96ee2e28da841ee663bfeaff62b0646b87eeb431 Signed-off-by: Alexander Bengtsson --- ethosu/regor/compiler/scheduler_packing.cpp | 13 ++++++++----- ethosu/regor/test/test_scheduler_packing.cpp | 6 +++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/ethosu/regor/compiler/scheduler_packing.cpp b/ethosu/regor/compiler/scheduler_packing.cpp index a8e19b0e..9d0e651c 100644 --- a/ethosu/regor/compiler/scheduler_packing.cpp +++ b/ethosu/regor/compiler/scheduler_packing.cpp @@ -295,14 +295,17 @@ void SchedulerPacking::PrePackOperations() ArchRequirements oReq{}; Flags result = OperatorQuery(_arch, schedOp.get(), &oReq); assert(result.Any(QueryResult::Constrained) == false && "Constrained result from complete OperatorQuery"); - // Determine if each operation can run on NPU - if ( result.Any(QueryResult::Native) ) + if ( schedOp->Type() == OpType::Passthrough ) + { + schedOp->SetNpuOp(false); + } + else if ( result.Any(QueryResult::Native) ) { // TODO MLBEDSW-10643: This should be a direct-check against QueryResult::Native - // HasRequirements at this point should result in CPU-fallback + // HasRequirements at this point should result in failure if ( result.Any(QueryResult::HasRequirements) && oReq.req.Any(ArchRequirement::Decompose) ) { - schedOp->SetNpuOp(false); + throw std::runtime_error("Non-passthrough operation could not run on NPU."); } else { @@ -311,7 +314,7 @@ void SchedulerPacking::PrePackOperations() } else { - schedOp->SetNpuOp(false); + throw std::runtime_error("Non-passthrough operation could not run on NPU."); } // Examine elementwise and set a primary path for cascading. diff --git a/ethosu/regor/test/test_scheduler_packing.cpp b/ethosu/regor/test/test_scheduler_packing.cpp index 10656127..3bf954c5 100644 --- a/ethosu/regor/test/test_scheduler_packing.cpp +++ b/ethosu/regor/test/test_scheduler_packing.cpp @@ -1,5 +1,5 @@ // -// SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its affiliates +// SPDX-FileCopyrightText: Copyright 2024-2025 Arm Limited and/or its affiliates // // SPDX-License-Identifier: Apache-2.0 // @@ -46,7 +46,7 @@ TEST_CASE("test_scheduler_packing") // Validate that attr_axis still represents the reduced axis. std::vector> ops; auto ifm = CreateTensor("IFM", Shape(10, 10), DataType::Int8); - auto ofm = CreateTensor("OFM", Shape(1, 10), DataType::Int8); + auto ofm = CreateTensor("OFM", Shape(1, 10), DataType::Int32); auto op = CreateOperation(OpType::ArgMax, TensorUsage::IFM, ifm, TensorUsage::OFM, ofm); auto attr = op->Attribute(); attr->axis = 0; @@ -79,7 +79,7 @@ TEST_CASE("test_scheduler_packing") // Validate that attr_axis still represent the reduced axes. std::vector> ops; auto ifm = CreateTensor("IFM", Shape(10, 10, 10), DataType::Int8); - auto ofm = CreateTensor("OFM", Shape(10, 2, 10), DataType::Int8); + auto ofm = CreateTensor("OFM", Shape(10, 2, 10), DataType::Int32); // first op // reads 0,0,0 - shape 10,5,10 -- GitLab