Davide Grohmann | 6d2e5b7 | 2022-08-24 17:01:40 +0200 | [diff] [blame] | 1 | /* |
Mikael Olsson | 3918eea | 2024-01-16 11:11:28 +0100 | [diff] [blame] | 2 | * SPDX-FileCopyrightText: Copyright 2022-2024 Arm Limited and/or its affiliates <open-source-office@arm.com> |
Davide Grohmann | 6d2e5b7 | 2022-08-24 17:01:40 +0200 | [diff] [blame] | 3 | * SPDX-License-Identifier: Apache-2.0 |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the License); you may |
| 6 | * not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * 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, WITHOUT |
| 13 | * 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 | */ |
| 17 | |
| 18 | #include <ethosu.hpp> |
| 19 | #include <uapi/ethosu.h> |
| 20 | |
| 21 | #include <cstring> |
| 22 | #include <iostream> |
| 23 | #include <list> |
| 24 | #include <memory> |
| 25 | #include <sstream> |
| 26 | #include <stdio.h> |
| 27 | #include <string> |
| 28 | #include <unistd.h> |
| 29 | |
| 30 | #include "input.h" |
| 31 | #include "model.h" |
| 32 | #include "output.h" |
| 33 | #include "test_assertions.hpp" |
| 34 | |
| 35 | using namespace EthosU; |
| 36 | |
| 37 | namespace { |
| 38 | |
| 39 | int64_t defaultTimeout = 60000000000; |
| 40 | |
| 41 | void testCancelInference(const Device &device) { |
| 42 | try { |
Mikael Olsson | c081e59 | 2023-10-30 11:10:56 +0100 | [diff] [blame] | 43 | auto network = std::make_shared<Network>(device, networkModelData, sizeof(networkModelData)); |
Davide Grohmann | 6d2e5b7 | 2022-08-24 17:01:40 +0200 | [diff] [blame] | 44 | |
| 45 | std::vector<std::shared_ptr<Buffer>> inputBuffers; |
| 46 | std::vector<std::shared_ptr<Buffer>> outputBuffers; |
| 47 | |
| 48 | auto inputBuffer = std::make_shared<Buffer>(device, sizeof(inputData)); |
Davide Grohmann | 6d2e5b7 | 2022-08-24 17:01:40 +0200 | [diff] [blame] | 49 | std::memcpy(inputBuffer->data(), inputData, sizeof(inputData)); |
| 50 | |
| 51 | inputBuffers.push_back(inputBuffer); |
| 52 | outputBuffers.push_back(std::make_shared<Buffer>(device, sizeof(expectedOutputData))); |
| 53 | std::vector<uint8_t> enabledCounters(Inference::getMaxPmuEventCounters()); |
| 54 | |
| 55 | auto inference = std::make_shared<Inference>(network, |
| 56 | inputBuffers.begin(), |
| 57 | inputBuffers.end(), |
| 58 | outputBuffers.begin(), |
| 59 | outputBuffers.end(), |
| 60 | enabledCounters, |
| 61 | false); |
| 62 | |
| 63 | InferenceStatus status = inference->status(); |
| 64 | TEST_ASSERT(status == InferenceStatus::RUNNING); |
| 65 | |
| 66 | bool success = inference->cancel(); |
| 67 | TEST_ASSERT(success); |
| 68 | |
| 69 | status = inference->status(); |
| 70 | TEST_ASSERT(status == InferenceStatus::ABORTED); |
| 71 | |
| 72 | bool timedout = inference->wait(defaultTimeout); |
| 73 | TEST_ASSERT(!timedout); |
| 74 | |
| 75 | } catch (std::exception &e) { throw TestFailureException("Inference run test: ", e.what()); } |
| 76 | } |
| 77 | |
Davide Grohmann | 6d2e5b7 | 2022-08-24 17:01:40 +0200 | [diff] [blame] | 78 | } // namespace |
| 79 | |
| 80 | int main() { |
| 81 | Device device; |
| 82 | |
| 83 | try { |
| 84 | testCancelInference(device); |
Davide Grohmann | 6d2e5b7 | 2022-08-24 17:01:40 +0200 | [diff] [blame] | 85 | } catch (TestFailureException &e) { |
| 86 | std::cerr << "Test failure: " << e.what() << std::endl; |
| 87 | return 1; |
| 88 | } |
| 89 | |
| 90 | return 0; |
| 91 | } |