1/*******************************************************************************
2* Copyright 2017-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#ifndef SELF_HPP
18#define SELF_HPP
19
20#include <stdio.h>
21#include <stdlib.h>
22#include <string.h>
23
24#include <sstream>
25
26#include "common.hpp"
27#include "dnnl_common.hpp"
28
29namespace self {
30
31#define SELF_CHECK(c, ...) \
32 do { \
33 if (!(c)) { \
34 printf("[%s:%d] '%s' FAILED ==> ", __PRETTY_FUNCTION__, __LINE__, \
35 STRINGIFY(c)); \
36 printf(" " __VA_ARGS__); \
37 printf("\n"); \
38 return FAIL; \
39 } \
40 } while (0)
41
42#define SELF_CHECK_EQ(a, b) \
43 SELF_CHECK((a) == (b), "%d != %d", (int)(a), (int)(b))
44#define SELF_CHECK_NE(a, b) \
45 SELF_CHECK((a) != (b), "%d == %d", (int)(a), (int)(b))
46#define SELF_CHECK_CASE_STR_EQ(a, b) \
47 SELF_CHECK(!strcasecmp(a, b), "'%s' != '%s'", a, b)
48#define SELF_CHECK_CASE_STR_NE(a, b) \
49 SELF_CHECK(strcasecmp(a, b), "'%s' == '%s'", a, b)
50#define SELF_CHECK_CASE_CPP_STR_EQ(a, b) \
51 SELF_CHECK(!strcasecmp(a.c_str(), b), "'%s' != '%s'", a.c_str(), b)
52#define SELF_CHECK_CASE_CPP_STR_NE(a, b) \
53 SELF_CHECK(strcasecmp(a.c_str(), b), "'%s' == '%s'", a.c_str(), b)
54#define SELF_CHECK_PRINT_EQ2(obj, expect_str1, expect_str2) \
55 do { \
56 std::stringstream ss; \
57 ss << obj; \
58 std::string obj_str = ss.str(); \
59 if (std::string(expect_str1) == std::string(expect_str2) \
60 && strcasecmp(obj_str.c_str(), expect_str1)) \
61 SELF_CHECK(false, "Expected '%s', got '%s'", expect_str1, \
62 obj_str.c_str()); \
63 else if (strcasecmp(obj_str.c_str(), expect_str1) \
64 && strcasecmp(obj_str.c_str(), expect_str2)) \
65 SELF_CHECK(false, "Expected one of ('%s', '%s'), got '%s'", \
66 expect_str1, expect_str2, obj_str.c_str()); \
67 } while (0)
68#define SELF_CHECK_PRINT_EQ(obj, expect_str) \
69 SELF_CHECK_PRINT_EQ2(obj, expect_str, expect_str)
70
71#define RUN(f) \
72 do { \
73 BENCHDNN_PRINT(1, "%s ...\n", STRINGIFY(f)); \
74 int rc = f; \
75 benchdnn_stat.tests++; \
76 if (rc == OK) \
77 benchdnn_stat.passed++; \
78 else \
79 benchdnn_stat.failed++; \
80 } while (0)
81
82void common();
83void res();
84void conv();
85void bnorm();
86void memory();
87
88int bench(int argc, char **argv);
89
90} // namespace self
91
92#endif
93