blob: 5245044323820aa6e50de05a268f3f25b05e5953 [file] [log] [blame]
Michalis Spyrou11d49182020-03-26 10:31:32 +00001/*
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
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");
59 compile_context.create_kernel(kernel_name, program_name, kernel_src.first, kernel_path, build_opts, kernel_src.second);
60
61 // Check if the program is stored in the cache
62 ARM_COMPUTE_EXPECT(compile_context.get_built_programs().size() == 1, framework::LogLevel::ERRORS);
63
64 // Try to build the same program and check if the program cache stayed the same
65 compile_context.create_kernel(kernel_name, program_name, kernel_src.first, kernel_path, build_opts, kernel_src.second);
66 ARM_COMPUTE_EXPECT(compile_context.get_built_programs().size() == 1, framework::LogLevel::ERRORS);
67}
68
69TEST_SUITE_END() // CompileContext
70TEST_SUITE_END() // UNIT
71TEST_SUITE_END() // CL
72} // namespace validation
73} // namespace test
74} // namespace arm_compute