blob: 06b4a8392538f7c926bd9f49e42c68f893f4d3e8 [file] [log] [blame]
Georgios Pinitas8a5146f2021-01-12 15:51:07 +00001/*
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/framework/Asserts.h"
25#include "tests/framework/Macros.h"
26#include "tests/validation/Validation.h"
27
28#include "arm_compute/Acl.hpp"
29
30#include "src/gpu/cl/ClContext.h"
31
32using namespace arm_compute::mlgo;
33
34namespace arm_compute
35{
36namespace test
37{
38namespace validation
39{
40TEST_SUITE(CL)
41TEST_SUITE(UNIT)
42TEST_SUITE(Context)
43
44/** Test-case for AclCreateContext and AclDestroy Context
45 *
46 * Validate that AclCreateContext can create and destroy a context
47 *
48 * Test Steps:
49 * - Call AclCreateContext with valid target
50 * - Confirm that context is not nullptr and error code is AclSuccess
51 * - Destroy context
52 * - Confirm that AclSuccess is reported
53 */
54TEST_CASE(SimpleContextCApi, framework::DatasetMode::ALL)
55{
56 AclContext ctx = nullptr;
57 ARM_COMPUTE_ASSERT(AclCreateContext(&ctx, AclGpuOcl, nullptr) == AclStatus::AclSuccess);
58 ARM_COMPUTE_ASSERT(ctx != nullptr);
59 ARM_COMPUTE_ASSERT(AclDestroyContext(ctx) == AclStatus::AclSuccess);
60}
61
62/** Test-case for Context from the C++ interface
63 *
64 * Test Steps:
65 * - Create a Context obejct
66 * - Confirm that StatusCode::Success is reported
67 * - Confirm that equality operator works
68 * - Confirm that inequality operator works
69 */
70TEST_CASE(SimpleContextCppApi, framework::DatasetMode::ALL)
71{
72 acl::StatusCode status = acl::StatusCode::Success;
73 acl::Context ctx(acl::Target::GpuOcl, &status);
74 ARM_COMPUTE_ASSERT(status == acl::StatusCode::Success);
75
76 auto ctx_eq = ctx;
77 ARM_COMPUTE_ASSERT(ctx_eq == ctx);
78
79 acl::Context ctx_ienq(acl::Target::GpuOcl, &status);
80 ARM_COMPUTE_ASSERT(status == acl::StatusCode::Success);
81 ARM_COMPUTE_ASSERT(ctx_ienq != ctx);
82}
83
84/** Test-case for CpuCapabilities
85 *
86 * Validate that AclCreateContext can create/destroy multiple contexts with different options
87 *
88 * Test Steps:
89 * - Call AclCreateContext with different targets
90 * - Confirm that AclSuccess is reported
91 * - Destroy all contexts
92 * - Confirm that AclSuccess is reported
93 */
94TEST_CASE(MultipleContexts, framework::DatasetMode::ALL)
95{
96 const unsigned int num_tests = 5;
97 std::array<AclContext, num_tests> ctxs{};
98 for(unsigned int i = 0; i < num_tests; ++i)
99 {
100 ARM_COMPUTE_ASSERT(AclCreateContext(&ctxs[i], AclTarget::AclGpuOcl, nullptr) == AclStatus::AclSuccess);
101 ARM_COMPUTE_ASSERT(ctxs[i] != nullptr);
102 ARM_COMPUTE_ASSERT(AclDestroyContext(ctxs[i]) == AclStatus::AclSuccess);
103 }
104}
105
106/** Test-case for MLGO kernel configuration file
107 *
108 * Validate that CpuCapabilities are set correctly
109 *
110 * Test Steps:
111 * - Create a file with the MLGO configuration
112 * - Pass the kernel file to the Context during creation
113 * - Validate that the MLGO file has been parsed successfully
114 */
115TEST_CASE(CheckMLGO, framework::DatasetMode::ALL)
116{
117 // Create test mlgo file
118 std::string mlgo_str = R"_(
119
120 <header>
121
122 gemm-version, [1,2,1]
123 ip-type,gpu
124 </header>
125 <heuristics-table>
126 0, g76 , 8, f32, best-performance, static, gemm-type, [m,n,k,n]
127 1, g76 , 8, f16, best-performance, static, gemm-config-reshaped, [m,n,k,n]
128 </heuristics-table>
129 <heuristic, 0>
130 b , 0, var, m, ==, num, 10., 1, 2
131 l , 1, gemm-type, reshaped
132 b , 2, var, r_mn, >=, num, 2., 3, 6
133
134 b , 3, var, n, >=, num, 200., 4, 5
135 l, 4, gemm-type, reshaped-only-rhs
136 l , 5, gemm-type, reshaped
137 l , 6, gemm-type, reshaped-only-rhs
138 </heuristic>
139
140 <heuristic, 1>
141 l ,0,gemm-config-reshaped,[4,2,4,2,8,1,0,1,0]
142 </heuristic>
143
144 )_";
145 const std::string mlgo_filename = "test.mlgo";
146 std::ofstream ofs(mlgo_filename, std::ofstream::trunc);
147 ARM_COMPUTE_EXPECT(ofs, framework::LogLevel::ERRORS);
148 ofs << mlgo_str;
149 ofs.close();
150
151 AclContextOptions opts = acl_default_ctx_options;
152 opts.kernel_config_file = mlgo_filename.c_str();
153 arm_compute::gpu::opencl::ClContext ctx(&opts);
154
155 const MLGOHeuristics &heuristics = ctx.mlgo();
156
157 ARM_COMPUTE_EXPECT(heuristics.query_gemm_type(Query{ "g76", DataType::F32, 10, 1024, 20, 1 }).second == GEMMType::RESHAPED,
158 framework::LogLevel::ERRORS);
159 ARM_COMPUTE_EXPECT((heuristics.query_gemm_config_reshaped(Query{ "g76", DataType::F16, 100, 100, 20, 32 }).second == GEMMConfigReshaped{ 4, 2, 4, 2, 8, true, false, true, false }),
160 framework::LogLevel::ERRORS);
161}
162
163TEST_SUITE_END() // Context
164TEST_SUITE_END() // UNIT
165TEST_SUITE_END() // CL
166} // namespace validation
167} // namespace test
168} // namespace arm_compute