xref: /aosp_15_r20/external/ComputeLibrary/tests/validation/CL/UNIT/CompileContext.cpp (revision c217d954acce2dbc11938adb493fc0abd69584f3)
1 /*
2  * Copyright (c) 2020 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 "arm_compute/core/CL/CLCompileContext.h"
25 #include "tests/AssetsLibrary.h"
26 #include "tests/Globals.h"
27 #include "tests/Utils.h"
28 #include "tests/framework/Asserts.h"
29 #include "tests/framework/Macros.h"
30 #include "tests/validation/Validation.h"
31 
32 namespace arm_compute
33 {
34 namespace test
35 {
36 namespace validation
37 {
38 TEST_SUITE(CL)
TEST_SUITE(UNIT)39 TEST_SUITE(UNIT)
40 TEST_SUITE(CompileContext)
41 
42 TEST_CASE(CompileContextCache, framework::DatasetMode::ALL)
43 {
44     // Create compile context
45     CLCompileContext compile_context(CLKernelLibrary::get().context(), CLKernelLibrary::get().get_device());
46 
47     // Check if the program cache is empty
48     ARM_COMPUTE_EXPECT(compile_context.get_built_programs().size() == 0, framework::LogLevel::ERRORS);
49 
50     // Create a kernel using the compile context
51     const std::string kernel_name  = "floor_layer";
52     const std::string program_name = CLKernelLibrary::get().get_program_name(kernel_name);
53     std::pair<std::string, bool> kernel_src = CLKernelLibrary::get().get_program(program_name);
54     const std::string kernel_path = CLKernelLibrary::get().get_kernel_path();
55 
56     std::set<std::string> build_opts;
57     build_opts.emplace("-DDATA_TYPE=float");
58     build_opts.emplace("-DVEC_SIZE=16");
59     build_opts.emplace("-DVEC_SIZE_LEFTOVER=0");
60     compile_context.create_kernel(kernel_name, program_name, kernel_src.first, kernel_path, build_opts, kernel_src.second);
61 
62     // Check if the program is stored in the cache
63     ARM_COMPUTE_EXPECT(compile_context.get_built_programs().size() == 1, framework::LogLevel::ERRORS);
64 
65     // Try to build the same program and check if the program cache stayed the same
66     compile_context.create_kernel(kernel_name, program_name, kernel_src.first, kernel_path, build_opts, kernel_src.second);
67     ARM_COMPUTE_EXPECT(compile_context.get_built_programs().size() == 1, framework::LogLevel::ERRORS);
68 }
69 
70 TEST_SUITE_END() // CompileContext
71 TEST_SUITE_END() // UNIT
72 TEST_SUITE_END() // CL
73 } // namespace validation
74 } // namespace test
75 } // namespace arm_compute
76