1/*******************************************************************************
2* Copyright 2019-2022 Intel Corporation
3*
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
7*
8* http://www.apache.org/licenses/LICENSE-2.0
9*
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.
15*******************************************************************************/
16
17#include <algorithm>
18#include <iterator>
19#include <map>
20#include <set>
21
22#include "gtest/gtest.h"
23
24#include "oneapi/dnnl/dnnl.hpp"
25
26#include "tests/test_isa_common.hpp"
27
28namespace dnnl {
29
30TEST(isa_test_t, TestISA) {
31
32 // Use soft version of mayiuse that allows resetting the max_cpu_isa
33 const bool test_flag = true;
34 const cpu_isa cur_isa = get_max_cpu_isa(test_flag);
35
36 status st = set_max_cpu_isa(cur_isa);
37 // status::unimplemented if the feature was disabled at compile time
38 if (st == status::unimplemented) return;
39
40 ASSERT_TRUE(st == status::success);
41
42 const auto cur_internal_isa = get_max_cpu_isa_mask(test_flag);
43
44 const std::set<cpu_isa> &compatible_isa = compatible_cpu_isa(cur_isa);
45 const std::set<cpu_isa> &isa_list = cpu_isa_list();
46
47 std::set<cpu_isa> incompatible_isa;
48 std::set_difference(isa_list.cbegin(), isa_list.cend(),
49 compatible_isa.cbegin(), compatible_isa.cend(),
50 std::inserter(incompatible_isa, incompatible_isa.begin()));
51
52 for (const cpu_isa cmpt_isa : compatible_isa) {
53 const auto &internal_isa_set = masked_internal_cpu_isa(cmpt_isa);
54 for (auto internal_isa : internal_isa_set) {
55 ASSERT_TRUE((cur_internal_isa & internal_isa) == internal_isa);
56 }
57 }
58
59 for (const cpu_isa incmpt_isa : incompatible_isa) {
60 const auto &internal_isa = cvt_to_internal_cpu_isa(incmpt_isa);
61 ASSERT_TRUE((cur_internal_isa & internal_isa) != internal_isa);
62 }
63}
64
65} // namespace dnnl
66