2 // Copyright (c) 2018 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
17 ///////////////////////////////////////////////////////////////////////////////////////////////////
18 #include <api/CPP/topology.hpp>
19 #include <api/CPP/network.hpp>
20 #include <api/CPP/engine.hpp>
21 #include <api/CPP/input_layout.hpp>
22 #include "test_utils/test_utils.h"
23 #include "api/CPP/arg_max_min.hpp"
25 using namespace cldnn;
26 using namespace tests;
32 static int g_run_once = 1;
33 static int g_qpc_availible;
34 static LARGE_INTEGER g_qpc_frec;
36 // Function for future use to measure performance
37 unsigned long GetMilliseconds(void)
40 LARGE_INTEGER qpc_ticks;
43 g_qpc_availible = QueryPerformanceFrequency(&g_qpc_frec);
44 // QPC returns nonzero value if HW supports high resolution perf counter
45 EXPECT_NE(g_qpc_availible, 0);
49 if (g_qpc_availible) {
50 QueryPerformanceCounter(&qpc_ticks);
51 ms = (unsigned long)(1000.0 * ((double)(qpc_ticks.QuadPart)) / ((double)(g_qpc_frec.QuadPart)));
53 // back up if High-Resolution Timer is not available
54 else ms = GetTickCount();
61 // Run some topology too see if command queue does work correctly
62 // Coppied from arg_max_gpu.base test.
63 void exexute_network(cldnn::engine engine)
66 static const int32_t x_size = 2, y_size = 2, feature_num = 3, batch_num = 2;
68 auto input = memory::allocate(engine, { data_types::f32, format::bfyx,{ batch_num, feature_num, x_size , y_size } });
70 topology.add(input_layout("input", input.get_layout()));
71 topology.add(arg_max_min("arg_max", "input", arg_max_min::max));
73 vector<float> input_vec = {
75 /*b0f0*/0.1f, -0.1f, 0.9f, 1.5f,
76 /*b0f1*/0.2f, 0.2f, -10.f, 5.2f,
77 /*b0f2*/0.2f, 0.2f, -10.f, 5.2f,
79 /*b1f0*/3.f, 0.5f, 7.f, 10.f,
80 /*b1f1*/4.f, 0.5f, 8.f, 8.2f,
81 /*b1f2*/0.2f, 0.2f, -10.f, 5.2f
83 set_values(input, input_vec);
85 network network(engine, topology);
87 network.set_input_data("input", input);
89 auto outputs = network.execute();
91 EXPECT_EQ(outputs.size(), size_t(1));
92 EXPECT_EQ(outputs.begin()->first, "arg_max");
94 auto output = outputs.at("arg_max").get_memory();
95 auto output_ptr = output.pointer<float>();
96 float out_buffer[batch_num];
97 for (uint32_t i = 0; i < batch_num; i++)
99 out_buffer[i] = get_value<float>(output_ptr, i);
101 int size = x_size * y_size * feature_num;
104 for (int i = 0; i < batch_num; i++) {
105 EXPECT_GE(out_buffer[i], 0);
106 EXPECT_LT(out_buffer[i], size);
107 index = (int)out_buffer[i];
108 value = input_vec[i*size + (int)index];
109 for (int j = 0; j < size; j++)
111 EXPECT_LE(input_vec[i*size + j], value);
116 TEST(command_queue_test, test_priority_hints) {
117 engine_configuration configuration =
118 engine_configuration(
120 false, // decorate_kernel_names
121 false, // dump_custom_program
124 true, // primitives_parallelisation
126 "", // sources_dumps_dir
127 priority_mode_types::low,
128 throttle_mode_types::disabled);
129 cldnn::engine engine(configuration);
130 exexute_network(engine);
133 TEST(command_queue_test, test_throttle_hints) {
134 engine_configuration configuration =
135 engine_configuration(
137 false, // decorate_kernel_names
138 false, // dump_custom_program
141 true, // primitives_parallelisation
143 "", // sources_dumps_dir
144 priority_mode_types::disabled,
145 throttle_mode_types::high);
146 cldnn::engine engine(configuration);
147 exexute_network(engine);
150 TEST(command_queue_test, test_priority_and_throttle_hints) {
151 engine_configuration configuration =
152 engine_configuration(
154 false, // decorate_kernel_names
155 false, // dump_custom_program
158 true, // primitives_parallelisation
160 "", // sources_dumps_dir
161 priority_mode_types::high,
162 throttle_mode_types::low);
163 cldnn::engine engine(configuration);
164 exexute_network(engine);