Compute Library
 22.05
Context.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 Arm Limited.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #include "tests/validation/fixtures/UNIT/ContextFixture.h"
25 
26 #include "src/cpu/CpuContext.h"
27 
28 namespace arm_compute
29 {
30 namespace test
31 {
32 namespace validation
33 {
34 TEST_SUITE(CPU)
35 TEST_SUITE(UNIT)
36 TEST_SUITE(Context)
37 
38 /** Test-case for AclCreateContext
39  *
40  * Validate that AclCreateContext behaves as expected on invalid target
41  *
42  * Test Steps:
43  * - Call AclCreateContext with invalid target
44  * - Confirm that AclUnsupportedTarget is reported
45  * - Confirm that context is still nullptr
46  */
47 TEST_CASE(CreateContextWithInvalidTarget, framework::DatasetMode::ALL)
48 {
49  AclTarget invalid_target = static_cast<AclTarget>(-1);
50  AclContext ctx = nullptr;
51  ARM_COMPUTE_ASSERT(AclCreateContext(&ctx, invalid_target, nullptr) == AclStatus::AclUnsupportedTarget);
52  ARM_COMPUTE_ASSERT(ctx == nullptr);
53 }
54 
55 /** Test-case for AclCreateContext
56  *
57  * Validate that AclCreateContext behaves as expected on invalid context options
58  *
59  * Test Steps:
60  * - Call AclCreateContext with valid target but invalid context options
61  * - Confirm that AclInvalidArgument is reported
62  * - Confirm that context is still nullptr
63  */
64 TEST_CASE(CreateContextWithInvalidOptions, framework::DatasetMode::ALL)
65 {
66  AclContextOptions invalid_ctx_opts;
67  invalid_ctx_opts.mode = static_cast<AclExecutionMode>(-1);
68  invalid_ctx_opts.capabilities = AclCpuCapabilitiesAuto;
69  invalid_ctx_opts.max_compute_units = 0;
70  invalid_ctx_opts.enable_fast_math = false;
71  invalid_ctx_opts.kernel_config_file = "";
72  AclContext ctx = nullptr;
74  ARM_COMPUTE_ASSERT(ctx == nullptr);
75 }
76 
77 EMPTY_BODY_FIXTURE_TEST_CASE(DestroyInvalidContext, DestroyInvalidContextFixture<AclTarget::AclCpu>, framework::DatasetMode::ALL)
78 EMPTY_BODY_FIXTURE_TEST_CASE(SimpleContextCApi, SimpleContextCApiFixture<AclTarget::AclCpu>, framework::DatasetMode::ALL)
79 EMPTY_BODY_FIXTURE_TEST_CASE(SimpleContextCppApi, SimpleContextCppApiFixture<acl::Target::Cpu>, framework::DatasetMode::ALL)
80 EMPTY_BODY_FIXTURE_TEST_CASE(MultipleContexts, MultipleContextsFixture<AclTarget::AclCpu>, framework::DatasetMode::ALL)
81 
82 /** Test-case for CpuCapabilities
83  *
84  * Validate that CpuCapabilities are set correctly
85  *
86  * Test Steps:
87  * - Create a context with a given list of capabilities
88  * - Confirm that AclSuccess is reported
89  * - Validate that all capabilities are set correctly
90  */
91 TEST_CASE(CpuCapabilities, framework::DatasetMode::ALL)
92 {
96 
101 
102  arm_compute::cpu::CpuContext ctx_legacy(nullptr);
103  ARM_COMPUTE_ASSERT(ctx_legacy.capabilities().cpu_info.has_neon() == true);
104 }
105 
106 TEST_SUITE_END() // Context
107 TEST_SUITE_END() // UNIT
108 TEST_SUITE_END() // CPU
109 } // namespace validation
110 } // namespace test
111 } // namespace arm_compute
#define ARM_COMPUTE_ASSERT(cond)
Definition: Validate.h:37
AclContextOptions copts
Definition: Acl.hpp:363
AclTarget
Definition: AclTypes.h:63
< Context options
Definition: Acl.hpp:321
Automatic discovery of capabilities.
Definition: AclTypes.h:79
const char * kernel_config_file
Kernel cofiguration file.
Definition: AclTypes.h:139
int32_t max_compute_units
Max compute units that can be used by a queue created from the context.
Definition: AclTypes.h:140
Enable paths that use the mmla integer instructions.
Definition: AclTypes.h:91
Copyright (c) 2017-2022 Arm Limited.
AclExecutionMode mode
Execution mode to use.
Definition: AclTypes.h:136
bool has_dotprod() const
Definition: CpuInfo.h:86
AclTargetCapabilities capabilities
Target capabilities.
Definition: AclTypes.h:137
Call failed as invalid argument was passed.
Definition: AclTypes.h:57
Call failed as an invalid backend was requested.
Definition: AclTypes.h:55
Cpu target that uses SIMD extensions.
Definition: AclTypes.h:65
DatasetMode
Possible dataset modes.
Definition: DatasetModes.h:40
TEST_SUITE_END() FIXTURE_DATA_TEST_CASE(RunSmall
[CLActivationLayer Test snippet]
const CpuCapabilities & capabilities() const
Cpu Capabilities accessor.
Definition: CpuContext.cpp:161
Enable SVE2 optimized paths.
Definition: AclTypes.h:83
#define EMPTY_BODY_FIXTURE_TEST_CASE(TEST_NAME, FIXTURE, MODE)
Definition: Macros.h:233
bool enable_fast_math
Allow precision loss.
Definition: AclTypes.h:138
TEST_CASE(FusedActivation, framework::DatasetMode::ALL)
Validate fused activation expecting the following behaviours:
CPU context implementation class.
Definition: CpuContext.h:43
Enable paths that use the udot/sdot instructions.
Definition: AclTypes.h:90
TEST_SUITE(QASYMM8_to_F32) FIXTURE_DATA_TEST_CASE(RunSmall
AclExecutionMode
Execution mode types.
Definition: AclTypes.h:70
AclStatus AclCreateContext(AclContext *ctx, AclTarget target, const AclContextOptions *options)
__cplusplus
Definition: AclContext.cpp:78