alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2021 Arm Limited. All rights reserved. |
| 3 | * SPDX-License-Identifier: Apache-2.0 |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
Kshitij Sisodia | 76a1580 | 2021-12-24 11:05:11 +0000 | [diff] [blame] | 17 | #include "MicroNetKwsModel.hpp" |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 18 | #include "Wav2LetterModel.hpp" |
Kshitij Sisodia | aa4bcb1 | 2022-05-06 09:13:03 +0100 | [diff] [blame] | 19 | #include "BufAttributes.hpp" |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 20 | |
| 21 | #include <catch.hpp> |
| 22 | |
Kshitij Sisodia | aa4bcb1 | 2022-05-06 09:13:03 +0100 | [diff] [blame] | 23 | namespace arm { |
| 24 | namespace app { |
| 25 | static uint8_t tensorArena[ACTIVATION_BUF_SZ] ACTIVATION_BUF_ATTRIBUTE; |
| 26 | |
| 27 | namespace asr { |
| 28 | extern uint8_t* GetModelPointer(); |
| 29 | extern size_t GetModelLen(); |
| 30 | } |
| 31 | namespace kws { |
| 32 | extern uint8_t* GetModelPointer(); |
| 33 | extern size_t GetModelLen(); |
| 34 | } |
| 35 | } /* namespace app */ |
| 36 | } /* namespace arm */ |
| 37 | |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 38 | /* Skip this test, Wav2LetterModel if not Vela optimized but only from ML-zoo will fail. */ |
| 39 | TEST_CASE("Init two Models", "[.]") |
| 40 | { |
Kshitij Sisodia | 76a1580 | 2021-12-24 11:05:11 +0000 | [diff] [blame] | 41 | arm::app::MicroNetKwsModel model1; |
| 42 | arm::app::MicroNetKwsModel model2; |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 43 | |
| 44 | /* Ideally we should load the wav2letter model here, but there is |
| 45 | * none available to run on native (ops not supported on unoptimised |
| 46 | * version). However, we can certainly create two instances of the |
| 47 | * same type of model to see if our tensor arena re-use works as |
| 48 | * intended. |
| 49 | * |
| 50 | * @TODO: uncomment this when this model can run on native pipeline. */ |
| 51 | //arm::app::Wav2LetterModel model2; /* model2. */ |
| 52 | |
| 53 | /* Load/initialise the first model. */ |
Kshitij Sisodia | aa4bcb1 | 2022-05-06 09:13:03 +0100 | [diff] [blame] | 54 | REQUIRE(model1.Init(arm::app::tensorArena, |
| 55 | sizeof(arm::app::tensorArena), |
| 56 | arm::app::kws::GetModelPointer(), |
| 57 | arm::app::kws::GetModelLen())); |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 58 | |
| 59 | /* Allocator instance should have been created. */ |
| 60 | REQUIRE(nullptr != model1.GetAllocator()); |
| 61 | |
| 62 | /* Load the second model using the same allocator as model 1. */ |
Kshitij Sisodia | aa4bcb1 | 2022-05-06 09:13:03 +0100 | [diff] [blame] | 63 | REQUIRE(model2.Init(arm::app::tensorArena, |
| 64 | sizeof(arm::app::tensorArena), |
| 65 | arm::app::asr::GetModelPointer(), |
| 66 | arm::app::asr::GetModelLen(), |
| 67 | model1.GetAllocator())); |
alexander | 3c79893 | 2021-03-26 21:42:19 +0000 | [diff] [blame] | 68 | |
| 69 | /* Make sure they point to the same allocator object. */ |
| 70 | REQUIRE(model1.GetAllocator() == model2.GetAllocator()); |
| 71 | |
| 72 | /* Both models should report being initialised. */ |
| 73 | REQUIRE(true == model1.IsInited()); |
| 74 | REQUIRE(true == model2.IsInited()); |
Kshitij Sisodia | aa4bcb1 | 2022-05-06 09:13:03 +0100 | [diff] [blame] | 75 | } |