xref: /aosp_15_r20/external/ComputeLibrary/tests/validation/cpu/unit/Context.cpp (revision c217d954acce2dbc11938adb493fc0abd69584f3)
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)
TEST_SUITE(UNIT)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  */
TEST_CASE(CreateContextWithInvalidOptions,framework::DatasetMode::ALL)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;
73     ARM_COMPUTE_ASSERT(AclCreateContext(&ctx, AclCpu, &invalid_ctx_opts) == AclStatus::AclInvalidArgument);
74     ARM_COMPUTE_ASSERT(ctx == nullptr);
75 }
76 
EMPTY_BODY_FIXTURE_TEST_CASE(DestroyInvalidContext,DestroyInvalidContextFixture<AclTarget::AclCpu>,framework::DatasetMode::ALL)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 {
93     acl::Context::Options opts;
94     opts.copts.capabilities = AclCpuCapabilitiesDot | AclCpuCapabilitiesMmlaInt8 | AclCpuCapabilitiesSve2;
95     arm_compute::cpu::CpuContext ctx(&opts.copts);
96 
97     ARM_COMPUTE_ASSERT(ctx.capabilities().cpu_info.has_dotprod() == true);
98     ARM_COMPUTE_ASSERT(ctx.capabilities().cpu_info.has_i8mm() == true);
99     ARM_COMPUTE_ASSERT(ctx.capabilities().cpu_info.has_sve2() == true);
100     ARM_COMPUTE_ASSERT(ctx.capabilities().cpu_info.has_fp16() == false);
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
112