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 "dnnl_test_common.hpp" |
18 | #include "gtest/gtest.h" |
19 | |
20 | #include "oneapi/dnnl/dnnl.h" |
21 | #include "oneapi/dnnl/dnnl_types.h" |
22 | |
23 | namespace dnnl { |
24 | |
25 | class pd_test_t : public ::testing::Test { |
26 | protected: |
27 | engine e = get_test_engine(); |
28 | memory::desc dat_md { |
29 | {16, 16, 16, 16}, memory::data_type::f32, memory::format_tag::nhwc}; |
30 | memory::desc wht_md { |
31 | {16, 16, 1, 1}, memory::data_type::f32, memory::format_tag::oihw}; |
32 | }; |
33 | |
34 | TEST_F(pd_test_t, ConvTestNotEmpty) { |
35 | bool no_exception = true; |
36 | bool is_empty = false; |
37 | |
38 | try { |
39 | auto default_attr = primitive_attr(); |
40 | auto pd = convolution_forward::primitive_desc {e, |
41 | prop_kind::forward_inference, algorithm::convolution_direct, |
42 | dat_md, wht_md, dat_md, {1, 1}, {0, 0}, {0, 0}, default_attr, |
43 | false}; |
44 | is_empty = pd.get(true) == nullptr; // not reached if !allow_empty |
45 | } catch (error &) { no_exception = false; } |
46 | |
47 | ASSERT_TRUE(no_exception); |
48 | ASSERT_TRUE(!is_empty); |
49 | } |
50 | |
51 | TEST_F(pd_test_t, ConvTestEmpty) { |
52 | auto attrs = primitive_attr {}; |
53 | attrs.set_scales_mask(DNNL_ARG_SRC, 0); |
54 | |
55 | for (bool allow_empty : {true, false}) { |
56 | bool no_exception = true; |
57 | bool is_empty = false; |
58 | |
59 | try { |
60 | auto pd = convolution_forward::primitive_desc {e, |
61 | prop_kind::forward_inference, algorithm::convolution_direct, |
62 | dat_md, wht_md, dat_md, {1, 1}, {0, 0}, {0, 0}, attrs, |
63 | allow_empty}; |
64 | is_empty = pd.get(true) == nullptr; // not reached if !allow_empty |
65 | } catch (error &) { no_exception = false; } |
66 | |
67 | ASSERT_TRUE(no_exception == allow_empty); |
68 | ASSERT_TRUE(is_empty == allow_empty); |
69 | } |
70 | } |
71 | |
72 | TEST_F(pd_test_t, TestOptionalQueries) { |
73 | memory::desc a_md { |
74 | {10, 10}, memory::data_type::f32, memory::format_tag::ab}; |
75 | memory::desc b_md { |
76 | {10, 10}, memory::data_type::f32, memory::format_tag::ab}; |
77 | memory::desc c_md { |
78 | {10, 10}, memory::data_type::f32, memory::format_tag::ab}; |
79 | |
80 | auto pd = matmul::primitive_desc(e, a_md, b_md, c_md); |
81 | |
82 | ASSERT_TRUE(pd.get_strides().empty()); |
83 | ASSERT_TRUE(pd.get_dilations().empty()); |
84 | ASSERT_TRUE(pd.get_padding_l().empty()); |
85 | ASSERT_TRUE(pd.get_padding_r().empty()); |
86 | ASSERT_TRUE(pd.get_kernel().empty()); |
87 | ASSERT_TRUE(pd.get_factors().empty()); |
88 | |
89 | ASSERT_EQ(pd.get_alpha(), 0.0f); |
90 | ASSERT_EQ(pd.get_beta(), 0.0f); |
91 | ASSERT_EQ(pd.get_epsilon(), 0.0f); |
92 | ASSERT_EQ(pd.get_k(), 0.0f); |
93 | ASSERT_EQ(pd.get_p(), 0.0f); |
94 | |
95 | ASSERT_EQ(pd.get_flags(), 0x0U); |
96 | ASSERT_EQ(pd.get_local_size(), 0); |
97 | ASSERT_EQ(pd.get_group_size(), 0); |
98 | ASSERT_EQ(pd.get_axis(), -1); |
99 | |
100 | ASSERT_EQ(pd.get_algorithm(), dnnl::algorithm::undef); |
101 | ASSERT_EQ(pd.get_cell_kind(), dnnl::algorithm::undef); |
102 | ASSERT_EQ(pd.get_activation_kind(), dnnl::algorithm::undef); |
103 | |
104 | ASSERT_EQ(pd.get_prop_kind(), dnnl::prop_kind::undef); |
105 | } |
106 | |
107 | } // namespace dnnl |
108 | |