Compute Library
 21.08
CompileContext.cpp
Go to the documentation of this file.
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  */
25 #include "tests/AssetsLibrary.h"
26 #include "tests/Globals.h"
27 #include "tests/Utils.h"
29 #include "tests/framework/Macros.h"
31 
32 namespace arm_compute
33 {
34 namespace test
35 {
36 namespace validation
37 {
38 TEST_SUITE(CL)
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
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
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);
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
ARM_COMPUTE_EXPECT(has_error==expected, framework::LogLevel::ERRORS)
std::pair< std::string, bool > get_program(const std::string &program_name) const
Gets the source of the selected program.
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
Copyright (c) 2017-2021 Arm Limited.
DatasetMode
Possible dataset modes.
Definition: DatasetModes.h:40
TEST_SUITE_END() FIXTURE_DATA_TEST_CASE(RunSmall
[CLActivationLayer Test snippet]
TEST_SUITE(U8_to_S8) FIXTURE_DATA_TEST_CASE(RunSmall
Kernel create_kernel(const std::string &kernel_name, const std::string &program_name, const std::string &program_source, const std::string &kernel_path, const StringSet &build_options_set, bool is_binary) const
Creates an OpenCL kernel.
std::string get_program_name(const std::string &kernel_name) const
Returns the program name given a kernel name.
CLCompileContext class.
const std::map< std::string, cl::Program > & get_built_programs() const
Access the cache of built OpenCL programs.
std::string get_kernel_path()
Gets the path that the kernels reside in.
TEST_CASE(FusedActivation, framework::DatasetMode::ALL)
Validate fused activation expecting the following behaviours:
std::string kernel_name