|
| 1 | +// Copyright (C) 2024 Intel Corporation |
| 2 | +// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions. |
| 3 | +// See LICENSE.TXT |
| 4 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 5 | + |
| 6 | +#ifndef UR_CONFORMANCE_INCLUDE_KNOWN_FAILURE_H_INCLUDED |
| 7 | +#define UR_CONFORMANCE_INCLUDE_KNOWN_FAILURE_H_INCLUDED |
| 8 | + |
| 9 | +#include "uur/environment.h" |
| 10 | +#include "uur/utils.h" |
| 11 | +#include <string> |
| 12 | +#include <string_view> |
| 13 | +#include <tuple> |
| 14 | +#include <vector> |
| 15 | + |
| 16 | +namespace uur { |
| 17 | +struct Matcher { |
| 18 | + Matcher(uint32_t adapterVersion, ur_adapter_backend_t backend, |
| 19 | + std::vector<std::string> deviceNames) |
| 20 | + : adapterVersion(adapterVersion), backend(backend), names(deviceNames) { |
| 21 | + } |
| 22 | + |
| 23 | + uint32_t adapterVersion; |
| 24 | + ur_adapter_backend_t backend; |
| 25 | + std::vector<std::string> names; |
| 26 | +}; |
| 27 | + |
| 28 | +struct OpenCL : Matcher { |
| 29 | + OpenCL(std::initializer_list<std::string> il) |
| 30 | + : Matcher(1, UR_ADAPTER_BACKEND_OPENCL, {il.begin(), il.end()}) {} |
| 31 | +}; |
| 32 | + |
| 33 | +struct LevelZero : Matcher { |
| 34 | + LevelZero(std::initializer_list<std::string> il) |
| 35 | + : Matcher(1, UR_ADAPTER_BACKEND_LEVEL_ZERO, {il.begin(), il.end()}) {} |
| 36 | +}; |
| 37 | + |
| 38 | +struct LevelZeroV2 : Matcher { |
| 39 | + LevelZeroV2(std::initializer_list<std::string> il) |
| 40 | + : Matcher(2, UR_ADAPTER_BACKEND_LEVEL_ZERO, {il.begin(), il.end()}) {} |
| 41 | +}; |
| 42 | + |
| 43 | +struct CUDA : Matcher { |
| 44 | + CUDA(std::initializer_list<std::string> il) |
| 45 | + : Matcher(1, UR_ADAPTER_BACKEND_CUDA, {il.begin(), il.end()}) {} |
| 46 | +}; |
| 47 | + |
| 48 | +struct HIP : Matcher { |
| 49 | + HIP(std::initializer_list<std::string> il) |
| 50 | + : Matcher(1, UR_ADAPTER_BACKEND_HIP, {il.begin(), il.end()}) {} |
| 51 | +}; |
| 52 | + |
| 53 | +struct NativeCPU : Matcher { |
| 54 | + NativeCPU(std::initializer_list<std::string> il) |
| 55 | + : Matcher(1, UR_ADAPTER_BACKEND_NATIVE_CPU, {il.begin(), il.end()}) {} |
| 56 | +}; |
| 57 | + |
| 58 | +namespace detail { |
| 59 | +struct AdapterInfo { |
| 60 | + uint32_t version; |
| 61 | + ur_adapter_backend_t backend; |
| 62 | +}; |
| 63 | + |
| 64 | +inline AdapterInfo getAdapterInfo(ur_adapter_handle_t adapter) { |
| 65 | + AdapterInfo info; |
| 66 | + urAdapterGetInfo(adapter, UR_ADAPTER_INFO_VERSION, sizeof(info.version), |
| 67 | + &info.version, nullptr); |
| 68 | + urAdapterGetInfo(adapter, UR_ADAPTER_INFO_BACKEND, sizeof(info.backend), |
| 69 | + &info.backend, nullptr); |
| 70 | + return info; |
| 71 | +} |
| 72 | +} // namespace detail |
| 73 | + |
| 74 | +inline bool isKnownFailureOn(ur_adapter_handle_t adapter, |
| 75 | + const std::vector<Matcher> &matchers) { |
| 76 | + for (const auto &matcher : matchers) { |
| 77 | + auto adapterInfo = detail::getAdapterInfo(adapter); |
| 78 | + if (matcher.adapterVersion == adapterInfo.version && |
| 79 | + matcher.backend == adapterInfo.backend) { |
| 80 | + return true; |
| 81 | + } |
| 82 | + } |
| 83 | + return false; |
| 84 | +} |
| 85 | + |
| 86 | +template <class Param> |
| 87 | +inline bool |
| 88 | +isKnownFailureOn(const std::tuple<ur_platform_handle_t, Param> ¶m, |
| 89 | + const std::vector<Matcher> &matchers) { |
| 90 | + ur_platform_handle_t platform = std::get<0>(param); |
| 91 | + ur_adapter_handle_t adapter; |
| 92 | + urPlatformGetInfo(platform, UR_PLATFORM_INFO_ADAPTER, |
| 93 | + sizeof(ur_adapter_handle_t), &adapter, nullptr); |
| 94 | + for (const auto &matcher : matchers) { |
| 95 | + auto adapterInfo = detail::getAdapterInfo(adapter); |
| 96 | + if (matcher.adapterVersion != adapterInfo.version && |
| 97 | + matcher.backend != adapterInfo.backend) { |
| 98 | + continue; |
| 99 | + } |
| 100 | + if (matcher.names.empty()) { |
| 101 | + return true; |
| 102 | + } |
| 103 | + std::string name; |
| 104 | + uur::GetPlatformInfo<std::string>(platform, UR_PLATFORM_INFO_NAME, |
| 105 | + name); |
| 106 | + for (const auto &matcherName : matcher.names) { |
| 107 | + if (name.find(matcherName) != std::string::npos) { |
| 108 | + return true; |
| 109 | + } |
| 110 | + } |
| 111 | + } |
| 112 | + return false; |
| 113 | +} |
| 114 | + |
| 115 | +inline bool isKnownFailureOn(const DeviceTuple ¶m, |
| 116 | + const std::vector<Matcher> &matchers) { |
| 117 | + for (const auto &matcher : matchers) { |
| 118 | + auto adapterInfo = detail::getAdapterInfo(param.adapter); |
| 119 | + if (matcher.adapterVersion != adapterInfo.version && |
| 120 | + matcher.backend != adapterInfo.backend) { |
| 121 | + continue; |
| 122 | + } |
| 123 | + if (matcher.names.empty()) { |
| 124 | + return true; |
| 125 | + } |
| 126 | + std::string name; |
| 127 | + uur::GetDeviceInfo<std::string>(param.device, UR_DEVICE_INFO_NAME, |
| 128 | + name); |
| 129 | + for (const auto &matcherName : matcher.names) { |
| 130 | + if (name.find(matcherName) != std::string::npos) { |
| 131 | + return true; |
| 132 | + } |
| 133 | + } |
| 134 | + } |
| 135 | + return false; |
| 136 | +} |
| 137 | + |
| 138 | +template <class Param> |
| 139 | +inline bool isKnownFailureOn(const std::tuple<DeviceTuple, Param> ¶m, |
| 140 | + const std::vector<Matcher> &matchers) { |
| 141 | + return isKnownFailureOn(std::get<0>(param), matchers); |
| 142 | +} |
| 143 | + |
| 144 | +inline std::string knownFailureMessage(ur_adapter_handle_t adapter) { |
| 145 | + std::string backend = uur::GetAdapterBackendName(adapter); |
| 146 | + return "Known failure on: " + backend; |
| 147 | +} |
| 148 | + |
| 149 | +template <class Param> |
| 150 | +inline std::string |
| 151 | +knownFailureMessage(const std::tuple<ur_platform_handle_t, Param> ¶m) { |
| 152 | + ur_platform_handle_t platform = std::get<0>(param); |
| 153 | + ur_adapter_handle_t adapter; |
| 154 | + urPlatformGetInfo(platform, UR_PLATFORM_INFO_ADAPTER, |
| 155 | + sizeof(ur_adapter_handle_t), &adapter, nullptr); |
| 156 | + std::string backend = uur::GetAdapterBackendName(adapter); |
| 157 | + std::string platformName; |
| 158 | + uur::GetPlatformInfo<std::string>(platform, UR_PLATFORM_INFO_NAME, |
| 159 | + platformName); |
| 160 | + return "Known failure on: " + backend + ", " + platformName; |
| 161 | +} |
| 162 | + |
| 163 | +inline std::string knownFailureMessage(const DeviceTuple ¶m) { |
| 164 | + std::string backend = uur::GetAdapterBackendName(param.adapter); |
| 165 | + std::string platformName; |
| 166 | + uur::GetPlatformInfo<std::string>(param.platform, UR_PLATFORM_INFO_NAME, |
| 167 | + platformName); |
| 168 | + std::string deviceName; |
| 169 | + uur::GetDeviceInfo<std::string>(param.device, UR_DEVICE_INFO_NAME, |
| 170 | + deviceName); |
| 171 | + return "Known failure on: " + backend + ", " + platformName + ", " + |
| 172 | + deviceName; |
| 173 | +} |
| 174 | + |
| 175 | +template <class Param> |
| 176 | +inline std::string |
| 177 | +knownFailureMessage(const std::tuple<DeviceTuple, Param> ¶m) { |
| 178 | + return knownFailureMessage(std::get<0>(param)); |
| 179 | +} |
| 180 | + |
| 181 | +inline bool alsoRunKnownFailures() { |
| 182 | + if (const char *envvar = std::getenv("UR_CTS_ALSO_RUN_KNOWN_FAILURES")) { |
| 183 | + std::string_view value(envvar); |
| 184 | + return value == "1" || value == "ON" || value == "on" || |
| 185 | + value == "YES" || value == "yes" || value == "true" || |
| 186 | + value == "TRUE"; |
| 187 | + } |
| 188 | + return false; |
| 189 | +} |
| 190 | +} // namespace uur |
| 191 | + |
| 192 | +#define UUR_KNOWN_FAILURE_ON(...) \ |
| 193 | + if (uur::isKnownFailureOn(GetParam(), {__VA_ARGS__})) { \ |
| 194 | + auto message = uur::knownFailureMessage(GetParam()); \ |
| 195 | + if (uur::alsoRunKnownFailures()) { \ |
| 196 | + std::cerr << message << "\n"; \ |
| 197 | + } else { \ |
| 198 | + GTEST_SKIP() << message; \ |
| 199 | + } \ |
| 200 | + } \ |
| 201 | + (void)0 |
| 202 | + |
| 203 | +#endif // UR_CONFORMANCE_INCLUDE_KNOWN_FAILURE_H_INCLUDED |
0 commit comments