|
| 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/utils.h" |
| 10 | +#include <string> |
| 11 | +#include <string_view> |
| 12 | +#include <vector> |
| 13 | + |
| 14 | +namespace uur { |
| 15 | +struct DeviceMatcher { |
| 16 | + DeviceMatcher(uint32_t adapterVersion, ur_platform_backend_t backend, |
| 17 | + std::vector<std::string> deviceNames) |
| 18 | + : adapterVersion(adapterVersion), backend(backend), |
| 19 | + deviceNames(deviceNames) {} |
| 20 | + |
| 21 | + uint32_t adapterVersion; |
| 22 | + ur_platform_backend_t backend; |
| 23 | + std::vector<std::string> deviceNames; |
| 24 | +}; |
| 25 | + |
| 26 | +struct OpenCL : DeviceMatcher { |
| 27 | + OpenCL(std::initializer_list<std::string> il) |
| 28 | + : DeviceMatcher(1, UR_PLATFORM_BACKEND_OPENCL, {il.begin(), il.end()}) { |
| 29 | + } |
| 30 | +}; |
| 31 | + |
| 32 | +struct LevelZero : DeviceMatcher { |
| 33 | + LevelZero(std::initializer_list<std::string> il) |
| 34 | + : DeviceMatcher(1, UR_PLATFORM_BACKEND_LEVEL_ZERO, |
| 35 | + {il.begin(), il.end()}) {} |
| 36 | +}; |
| 37 | + |
| 38 | +struct LevelZeroV2 : DeviceMatcher { |
| 39 | + LevelZeroV2(std::initializer_list<std::string> il) |
| 40 | + : DeviceMatcher(2, UR_PLATFORM_BACKEND_LEVEL_ZERO, |
| 41 | + {il.begin(), il.end()}) {} |
| 42 | +}; |
| 43 | + |
| 44 | +struct CUDA : DeviceMatcher { |
| 45 | + CUDA(std::initializer_list<std::string> il) |
| 46 | + : DeviceMatcher(1, UR_PLATFORM_BACKEND_CUDA, {il.begin(), il.end()}) {} |
| 47 | +}; |
| 48 | + |
| 49 | +struct HIP : DeviceMatcher { |
| 50 | + HIP(std::initializer_list<std::string> il) |
| 51 | + : DeviceMatcher(1, UR_PLATFORM_BACKEND_HIP, {il.begin(), il.end()}) {} |
| 52 | +}; |
| 53 | + |
| 54 | +struct NativeCPU : DeviceMatcher { |
| 55 | + NativeCPU(std::initializer_list<std::string> il) |
| 56 | + : DeviceMatcher(1, UR_PLATFORM_BACKEND_NATIVE_CPU, |
| 57 | + {il.begin(), il.end()}) {} |
| 58 | +}; |
| 59 | + |
| 60 | +inline bool isKnownFailureOn(ur_adapter_handle_t adapter, |
| 61 | + ur_platform_handle_t platform, |
| 62 | + ur_device_handle_t device, |
| 63 | + std::vector<DeviceMatcher> deviceMatchers) { |
| 64 | + for (const auto &deviceMatcher : deviceMatchers) { |
| 65 | + uint32_t adapterVersion = 0; |
| 66 | + urAdapterGetInfo(adapter, UR_ADAPTER_INFO_VERSION, |
| 67 | + sizeof(adapterVersion), &adapterVersion, nullptr); |
| 68 | + ur_platform_backend_t backend = UR_PLATFORM_BACKEND_UNKNOWN; |
| 69 | + uur::GetPlatformInfo<ur_platform_backend_t>( |
| 70 | + platform, UR_PLATFORM_INFO_BACKEND, backend); |
| 71 | + if (deviceMatcher.adapterVersion != adapterVersion && |
| 72 | + deviceMatcher.backend != backend) { |
| 73 | + continue; |
| 74 | + } |
| 75 | + if (deviceMatcher.deviceNames.empty()) { |
| 76 | + return true; |
| 77 | + } |
| 78 | + std::string deviceName; |
| 79 | + uur::GetDeviceInfo<std::string>(device, UR_DEVICE_INFO_NAME, |
| 80 | + deviceName); |
| 81 | + for (const auto &unsupportedDeviceName : deviceMatcher.deviceNames) { |
| 82 | + if (deviceName.find(unsupportedDeviceName) != std::string::npos) { |
| 83 | + return true; |
| 84 | + } |
| 85 | + } |
| 86 | + } |
| 87 | + return false; |
| 88 | +} |
| 89 | +} // namespace uur |
| 90 | + |
| 91 | +#define UUR_KNOWN_FAILURE_ON(...) \ |
| 92 | + if (uur::isKnownFailureOn(adapter, platform, device, {__VA_ARGS__})) { \ |
| 93 | + using namespace std::literals; \ |
| 94 | + std::string platformName; \ |
| 95 | + uur::GetPlatformInfo<std::string>(platform, UR_PLATFORM_INFO_NAME, \ |
| 96 | + platformName); \ |
| 97 | + std::string deviceName; \ |
| 98 | + uur::GetDeviceInfo<std::string>(device, UR_DEVICE_INFO_NAME, \ |
| 99 | + deviceName); \ |
| 100 | + const char *alsoRunKnownFailures = \ |
| 101 | + std::getenv("UR_CTS_ALSO_RUN_KNOWN_FAILURES"); \ |
| 102 | + if (alsoRunKnownFailures && (alsoRunKnownFailures == "1"sv || \ |
| 103 | + alsoRunKnownFailures == "yes"sv || \ |
| 104 | + alsoRunKnownFailures == "YES"sv || \ |
| 105 | + alsoRunKnownFailures == "on"sv || \ |
| 106 | + alsoRunKnownFailures == "ON"sv || \ |
| 107 | + alsoRunKnownFailures == "true"sv || \ |
| 108 | + alsoRunKnownFailures == "TRUE"sv)) { \ |
| 109 | + std::cerr << "Known failure on: " << platformName << ", " \ |
| 110 | + << deviceName << "\n"; \ |
| 111 | + } else { \ |
| 112 | + GTEST_SKIP() << "Known failure on: " << platformName << ", " \ |
| 113 | + << deviceName; \ |
| 114 | + } \ |
| 115 | + } |
| 116 | + |
| 117 | +#endif // UR_CONFORMANCE_INCLUDE_KNOWN_FAILURE_H_INCLUDED |
0 commit comments