blob: 439d67fb1de2013c81dc106dd2bed13cb9192331 [file] [log] [blame]
alexander3c798932021-03-26 21:42:19 +00001/*
Richard Burtonf32a86a2022-11-15 11:46:11 +00002 * SPDX-FileCopyrightText: Copyright 2021 Arm Limited and/or its affiliates <open-source-office@arm.com>
alexander3c798932021-03-26 21:42:19 +00003 * 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 Sisodia76a15802021-12-24 11:05:11 +000017#include "MicroNetKwsModel.hpp"
alexander3c798932021-03-26 21:42:19 +000018#include "Wav2LetterModel.hpp"
Kshitij Sisodiaaa4bcb12022-05-06 09:13:03 +010019#include "BufAttributes.hpp"
alexander3c798932021-03-26 21:42:19 +000020
21#include <catch.hpp>
22
Kshitij Sisodiaaa4bcb12022-05-06 09:13:03 +010023namespace 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
alexander3c798932021-03-26 21:42:19 +000038/* Skip this test, Wav2LetterModel if not Vela optimized but only from ML-zoo will fail. */
39TEST_CASE("Init two Models", "[.]")
40{
Kshitij Sisodia76a15802021-12-24 11:05:11 +000041 arm::app::MicroNetKwsModel model1;
42 arm::app::MicroNetKwsModel model2;
alexander3c798932021-03-26 21:42:19 +000043
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 Sisodiaaa4bcb12022-05-06 09:13:03 +010054 REQUIRE(model1.Init(arm::app::tensorArena,
55 sizeof(arm::app::tensorArena),
56 arm::app::kws::GetModelPointer(),
57 arm::app::kws::GetModelLen()));
alexander3c798932021-03-26 21:42:19 +000058
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 Sisodiaaa4bcb12022-05-06 09:13:03 +010063 REQUIRE(model2.Init(arm::app::tensorArena,
64 sizeof(arm::app::tensorArena),
65 arm::app::asr::GetModelPointer(),
66 arm::app::asr::GetModelLen(),
67 model1.GetAllocator()));
alexander3c798932021-03-26 21:42:19 +000068
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 Sisodiaaa4bcb12022-05-06 09:13:03 +010075}