blob: a0541b6a995b8dd8ee9caaa157d66d46cf3ab0bd [file] [log] [blame]
Michalis Spyrou11d49182020-03-26 10:31:32 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2020 Arm Limited.
Michalis Spyrou11d49182020-03-26 10:31:32 +00003 *
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
32namespace arm_compute
33{
34namespace test
35{
36namespace validation
37{
38TEST_SUITE(CL)
39TEST_SUITE(UNIT)
40TEST_SUITE(CompileContext)
41
42TEST_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");
Manuel Bottinie78ef6f2021-01-08 15:57:11 +000059 build_opts.emplace("-DVEC_SIZE_LEFTOVER=0");
Michalis Spyrou11d49182020-03-26 10:31:32 +000060 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
70TEST_SUITE_END() // CompileContext
71TEST_SUITE_END() // UNIT
72TEST_SUITE_END() // CL
73} // namespace validation
74} // namespace test
75} // namespace arm_compute