1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
6 #include <gtest/gtest.h>
7 #include <gmock/gmock-spec-builders.h>
8 #include "mkldnn_plugin/mkldnn_graph.h"
10 #include "../../../thirdparty/mkl-dnn/src/common/memory_desc_wrapper.hpp"
12 #include "tests_common.hpp"
14 using namespace ::testing;
16 using namespace mkldnn;
18 struct mkldnn2TD_test_params {
19 std::vector<size_t> dims;
21 mkldnn::memory::format mkldnnFormat;
24 class MKLDNN2TensorDescConvertTests: public TestsCommon,
25 public WithParamInterface<mkldnn2TD_test_params> {
27 virtual void TearDown() {
30 virtual void SetUp() {
33 mkldnn2TD_test_params p = ::testing::WithParamInterface<mkldnn2TD_test_params>::GetParam();
35 mkldnn::memory::dims mkldnnDims;
36 for (auto dim : p.dims) {
37 mkldnnDims.push_back(dim);
39 MKLDNNPlugin::MKLDNNMemoryDesc mkldnnMemoryDesc(mkldnnDims, mkldnn::memory::data_type::f32, p.mkldnnFormat);
40 mkldnn::memory::desc mkldnnDesc = mkldnnMemoryDesc;
41 mkldnn::impl::memory_desc_wrapper dst_d(mkldnnDesc.data);
42 InferenceEngine::TensorDesc tDesc = mkldnnMemoryDesc;
44 size_t total_size = std::accumulate(std::begin(p.dims), std::end(p.dims), (size_t) 1, std::multiplies<size_t>());
46 for (size_t i = 0; i < total_size; i++) {
47 ASSERT_EQ(tDesc.offset(i), dst_d.off_l(i));
49 } catch (const InferenceEngine::details::InferenceEngineException &e) {
55 TEST_P(MKLDNN2TensorDescConvertTests, TestsConvertation) {}
58 INSTANTIATE_TEST_CASE_P(
59 TestsConvertation, MKLDNN2TensorDescConvertTests,
61 mkldnn2TD_test_params{{5}, mkldnn::memory::format::x},
62 mkldnn2TD_test_params{{10, 3}, mkldnn::memory::format::nc},
63 mkldnn2TD_test_params{{1, 3, 8, 8}, mkldnn::memory::format::nhwc},
64 mkldnn2TD_test_params{{1, 3, 8, 8}, mkldnn::memory::format::nchw},
65 mkldnn2TD_test_params{{1, 32, 8, 8}, mkldnn::memory::format::nChw8c},
66 mkldnn2TD_test_params{{1, 8, 8, 8}, mkldnn::memory::format::nChw8c},
67 mkldnn2TD_test_params{{1, 32, 8, 8}, mkldnn::memory::format::nChw16c},
68 mkldnn2TD_test_params{{67, 34}, mkldnn::memory::format::oi},
69 mkldnn2TD_test_params{{1, 3, 8, 8}, mkldnn::memory::format::oihw},
70 mkldnn2TD_test_params{{1, 3, 8, 8}, mkldnn::memory::format::nChw8c},
71 mkldnn2TD_test_params{{1, 32, 8, 8}, mkldnn::memory::format::nChw16c},
72 mkldnn2TD_test_params{{1, 16, 8, 8}, mkldnn::memory::format::oIhw8i}
75 struct TD2mkldnn_test_params {
76 std::vector<size_t> dims;
77 std::vector<size_t> blocked_dims;
78 std::vector<size_t> order;
81 class TensorDesc2MKLDNNConvertTests: public TestsCommon,
82 public WithParamInterface<TD2mkldnn_test_params> {
84 virtual void TearDown() {
87 virtual void SetUp() {
90 TD2mkldnn_test_params p = ::testing::WithParamInterface<TD2mkldnn_test_params>::GetParam();
92 mkldnn::memory::dims mkldnnDims;
93 for (auto dim : p.dims) {
94 mkldnnDims.push_back(dim);
96 InferenceEngine::TensorDesc tDesc(InferenceEngine::Precision::FP32, p.dims, {p.blocked_dims, p.order});
97 MKLDNNPlugin::MKLDNNMemoryDesc desc(tDesc);
99 mkldnn::impl::memory_desc_wrapper dst_d(((mkldnn::memory::desc&)desc).data);
101 size_t total_size = std::accumulate(std::begin(p.dims), std::end(p.dims), (size_t) 1, std::multiplies<size_t>());
103 for (size_t i = 0; i < total_size; i++) {
104 ASSERT_EQ(tDesc.offset(i), dst_d.off_l(i));
106 } catch (const InferenceEngine::details::InferenceEngineException &e) {
112 TEST_P(TensorDesc2MKLDNNConvertTests, TestsConvertation) {}
115 INSTANTIATE_TEST_CASE_P(
116 TestsConvertation, TensorDesc2MKLDNNConvertTests,
118 TD2mkldnn_test_params{{5}, {5}, {0}},
119 TD2mkldnn_test_params{{10, 3}, {10, 3}, {0, 1}},
120 TD2mkldnn_test_params{{1, 3, 8, 8}, {1, 8, 8, 3}, {0, 2, 3, 1}},
121 TD2mkldnn_test_params{{1, 3, 8, 8}, {1, 3, 8, 8}, {0, 1, 2, 3}},
122 TD2mkldnn_test_params{{1, 8, 8, 8}, {1, 1, 8, 8, 8}, {0, 1, 2, 3, 1}},
123 TD2mkldnn_test_params{{1, 32, 8, 8}, {1, 2, 8, 8, 16}, {0, 1, 2, 3, 1}},
124 TD2mkldnn_test_params{{1, 3, 8}, {1, 3, 8}, {0, 1, 2}}
125 // TD2mkldnn_test_params{{1, 3, 8, 8}, mkldnn::memory::format::nchw},
126 // TD2mkldnn_test_params{{1, 3, 8, 8}, mkldnn::memory::format::nChw8c},
127 // TD2mkldnn_test_params{{1, 32, 8, 8}, mkldnn::memory::format::nChw16c},
128 // TD2mkldnn_test_params{{67, 34}, mkldnn::memory::format::oi},
129 // TD2mkldnn_test_params{{1, 3, 8, 8}, mkldnn::memory::format::oihw},
130 // TD2mkldnn_test_params{{5, 1, 3, 8, 8}, mkldnn::memory::format::goihw},
131 // TD2mkldnn_test_params{{1, 16, 8, 8}, mkldnn::memory::format::oIhw8i},
132 // TD2mkldnn_test_params{{1, 3, 8, 8}, mkldnn::memory::format::OhIw16o4i}