1 /******************************************************************************* 2 * Copyright 2017-2020 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 29 namespace self { 30 31 #define 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 CHECK_EQ(a, b) CHECK((a) == (b), "%d != %d", (int)(a), (int)(b)) 43 #define CHECK_NE(a, b) CHECK((a) != (b), "%d == %d", (int)(a), (int)(b)) 44 #define CHECK_CASE_STR_EQ(a, b) CHECK(!strcasecmp(a, b), "'%s' != '%s'", a, b) 45 #define CHECK_CASE_STR_NE(a, b) CHECK(strcasecmp(a, b), "'%s' == '%s'", a, b) 46 #define CHECK_CASE_CPP_STR_EQ(a, b) \ 47 CHECK(!strcasecmp(a.c_str(), b), "'%s' != '%s'", a.c_str(), b) 48 #define CHECK_CASE_CPP_STR_NE(a, b) \ 49 CHECK(strcasecmp(a.c_str(), b), "'%s' == '%s'", a.c_str(), b) 50 #define CHECK_PRINT_EQ2(obj, expect_str1, expect_str2) \ 51 do { \ 52 std::stringstream ss; \ 53 ss << obj; \ 54 std::string obj_str = ss.str(); \ 55 if (std::string(expect_str1) == std::string(expect_str2) \ 56 && strcasecmp(obj_str.c_str(), expect_str1)) \ 57 CHECK(false, "Expected '%s', got '%s'", expect_str1, \ 58 obj_str.c_str()); \ 59 else if (strcasecmp(obj_str.c_str(), expect_str1) \ 60 && strcasecmp(obj_str.c_str(), expect_str2)) \ 61 CHECK(false, "Expected one of ('%s', '%s'), got '%s'", \ 62 expect_str1, expect_str2, obj_str.c_str()); \ 63 } while (0) 64 #define CHECK_PRINT_EQ(obj, expect_str) \ 65 CHECK_PRINT_EQ2(obj, expect_str, expect_str) 66 67 #define RUN(f) \ 68 do { \ 69 BENCHDNN_PRINT(1, "%s ...\n", STRINGIFY(f)); \ 70 int rc = f; \ 71 benchdnn_stat.tests++; \ 72 if (rc == OK) \ 73 benchdnn_stat.passed++; \ 74 else \ 75 benchdnn_stat.failed++; \ 76 } while (0) 77 78 void common(); 79 void conv(); 80 void bnorm(); 81 82 int bench(int argc, char **argv); 83 84 } // namespace self 85 86 #endif 87