|
| 1 | +/******************************************************************************* |
| 2 | + * |
| 3 | + * MIT License |
| 4 | + * |
| 5 | + * Copyright (c) 2023 Advanced Micro Devices, Inc. |
| 6 | + * |
| 7 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | + * of this software and associated documentation files (the "Software"), to deal |
| 9 | + * in the Software without restriction, including without limitation the rights |
| 10 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | + * copies of the Software, and to permit persons to whom the Software is |
| 12 | + * furnished to do so, subject to the following conditions: |
| 13 | + * |
| 14 | + * The above copyright notice and this permission notice shall be included in all |
| 15 | + * copies or substantial portions of the Software. |
| 16 | + * |
| 17 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 23 | + * SOFTWARE. |
| 24 | + * |
| 25 | + *******************************************************************************/ |
| 26 | + |
| 27 | +#pragma once |
| 28 | + |
| 29 | +#include <algorithm> |
| 30 | +#include <gtest/gtest.h> |
| 31 | +#include <iostream> |
| 32 | +#include <iterator> |
| 33 | +#include <miopen/env.hpp> |
| 34 | +#include <tuple> |
| 35 | +#include <sstream> |
| 36 | +#include <string> |
| 37 | +#include <vector> |
| 38 | + |
| 39 | +#include "../driver.hpp" |
| 40 | + |
| 41 | +void default_check(const std::string& err) { std::cout << err; } |
| 42 | + |
| 43 | +void tuning_check(const std::string& err) |
| 44 | +{ |
| 45 | + // TEST_TUNING - the test should fail if output contains "Error" or "failed". |
| 46 | + EXPECT_FALSE(err.find("Error") != std::string::npos || err.find("failed") != std::string::npos); |
| 47 | + default_check(err); |
| 48 | +} |
| 49 | + |
| 50 | +enum class Gpu : int |
| 51 | +{ |
| 52 | + Default = 0, |
| 53 | + gfx900 = 1 << 0, |
| 54 | + gfx906 = 1 << 1, |
| 55 | + gfx908 = 1 << 2, |
| 56 | + gfx90A = 1 << 3, |
| 57 | + gfx94X = 1 << 4, |
| 58 | + gfx103X = 1 << 5, |
| 59 | + gfx110X = 1 << 6 |
| 60 | +}; |
| 61 | + |
| 62 | +template <Gpu... bits> |
| 63 | +struct enabled |
| 64 | +{ |
| 65 | + static constexpr int val = (static_cast<int>(bits) | ...); |
| 66 | + static constexpr bool enabling = true; |
| 67 | +}; |
| 68 | + |
| 69 | +template <Gpu... bits> |
| 70 | +struct disabled |
| 71 | +{ |
| 72 | + static constexpr int val = ~((static_cast<int>(bits) | ...)); |
| 73 | + static constexpr bool enabling = false; |
| 74 | +}; |
| 75 | + |
| 76 | +template <typename disabled_mask, typename enabled_mask> |
| 77 | +bool IsTestSupportedForDevice() |
| 78 | +{ |
| 79 | + static_assert((~disabled_mask::val & enabled_mask::val) == 0, |
| 80 | + "Enabled and Disabled GPUs are overlapped"); |
| 81 | + static_assert(disabled_mask::enabling == false, |
| 82 | + "Wrong disabled mask, probably it has to be switched with enabled_mask"); |
| 83 | + static_assert(enabled_mask::enabling == true, |
| 84 | + "Wrong enabled mask, probably it has to be switched with disabled_mask"); |
| 85 | + |
| 86 | + static const auto dev = get_handle().GetDeviceName(); |
| 87 | + |
| 88 | + constexpr int def_val = enabled<Gpu::gfx900, Gpu::gfx906, Gpu::gfx908, Gpu::gfx90A>::val; |
| 89 | + constexpr int mask = (def_val & disabled_mask::val) | enabled_mask::val; |
| 90 | + constexpr auto test = [](Gpu bit) { return (mask & static_cast<int>(bit)) != 0; }; |
| 91 | + |
| 92 | + bool res = false; |
| 93 | + if constexpr(test(Gpu::gfx900)) |
| 94 | + res = res || (dev == "gfx900"); |
| 95 | + if constexpr(test(Gpu::gfx906)) |
| 96 | + res = res || (dev == "gfx906"); |
| 97 | + if constexpr(test(Gpu::gfx908)) |
| 98 | + res = res || (dev == "gfx908"); |
| 99 | + if constexpr(test(Gpu::gfx90A)) |
| 100 | + res = res || (dev == "gfx90A"); |
| 101 | + if constexpr(test(Gpu::gfx94X)) |
| 102 | + res = res || (miopen::StartsWith(dev, "gfx94")); |
| 103 | + if constexpr(test(Gpu::gfx103X)) |
| 104 | + res = res || (miopen::StartsWith(dev, "gfx103")); |
| 105 | + if constexpr(test(Gpu::gfx110X)) |
| 106 | + res = res || (miopen::StartsWith(dev, "gfx110")); |
| 107 | + |
| 108 | + return res; |
| 109 | +} |
| 110 | + |
| 111 | +template <typename Case> |
| 112 | +std::vector<std::string> get_args(const Case& param) |
| 113 | +{ |
| 114 | + const auto& [env_tuple, cmd] = param; |
| 115 | + std::apply( |
| 116 | + [](const auto&... env) { (miopen::UpdateEnvVar(std::get<0>(env), std::get<1>(env)), ...); }, |
| 117 | + env_tuple); |
| 118 | + |
| 119 | + std::stringstream ss(cmd); |
| 120 | + std::istream_iterator<std::string> begin(ss); |
| 121 | + std::istream_iterator<std::string> end; |
| 122 | + |
| 123 | + return {begin, end}; |
| 124 | +} |
| 125 | + |
| 126 | +template <template <class...> class Driver, typename TestCases, typename Check> |
| 127 | +void invoke_with_params(const TestCases& params, Check&& check) |
| 128 | +{ |
| 129 | + for(const auto& test_value : params) |
| 130 | + { |
| 131 | + std::vector<std::string> tokens = get_args(test_value); |
| 132 | + std::vector<const char*> ptrs; |
| 133 | + ptrs.reserve(tokens.size()); |
| 134 | + |
| 135 | + std::transform(tokens.begin(), tokens.end(), std::back_inserter(ptrs), [](const auto& str) { |
| 136 | + return str.data(); |
| 137 | + }); |
| 138 | + |
| 139 | + testing::internal::CaptureStderr(); |
| 140 | + test_drive<Driver>(ptrs.size(), ptrs.data()); |
| 141 | + check(testing::internal::GetCapturedStderr()); |
| 142 | + } |
| 143 | +} |
| 144 | + |
| 145 | +/// The types for env variables must be redefined, but |
| 146 | +/// do not mess up with the types - those variables are decalred in the library |
| 147 | +/// and if wrong type (STR|BOOl|UINT64) have been specified they won't be updated. Silently. |
| 148 | +/// There will be no compiler warnings or runtime errors. |
| 149 | +/// TODO: move ALL the env variables to the single header int the library to avoid such problems |
| 150 | +MIOPEN_DECLARE_ENV_VAR_STR(MIOPEN_DEBUG_FIND_ONLY_SOLVER) |
| 151 | +MIOPEN_DECLARE_ENV_VAR_STR(MIOPEN_FIND_MODE) |
| 152 | +MIOPEN_DECLARE_ENV_VAR_BOOL(MIOPEN_DEBUG_CONV_CK_IGEMM_FWD_V6R1_DLOPS_NCHW) |
| 153 | +MIOPEN_DECLARE_ENV_VAR_BOOL(MIOPEN_DEBUG_CONV_WINOGRAD) |
| 154 | +MIOPEN_DECLARE_ENV_VAR_BOOL(MIOPEN_DEBUG_CONV_FFT) |
| 155 | +MIOPEN_DECLARE_ENV_VAR_BOOL(MIOPEN_DEBUG_CONV_DIRECT) |
| 156 | +MIOPEN_DECLARE_ENV_VAR_BOOL(MIOPEN_DEBUG_CONV_GEMM) |
| 157 | +MIOPEN_DECLARE_ENV_VAR_BOOL(MIOPEN_DEBUG_CONV_IMPLICIT_GEMM) |
| 158 | +MIOPEN_DECLARE_ENV_VAR_UINT64(MIOPEN_LOG_LEVEL) |
| 159 | +MIOPEN_DECLARE_ENV_VAR_BOOL(MIOPEN_DRIVER_USE_GPU_REFERENCE) |
| 160 | +MIOPEN_DECLARE_ENV_VAR_STR(MIOPEN_FIND_ENFORCE) |
| 161 | +MIOPEN_DECLARE_ENV_VAR_BOOL(MIOPEN_DEBUG_CONV_IMPLICIT_GEMM_HIP_BWD_V1R1_XDLOPS) |
| 162 | +MIOPEN_DECLARE_ENV_VAR_BOOL(MIOPEN_DEBUG_CONV_IMPLICIT_GEMM_HIP_BWD_V4R1) |
| 163 | +MIOPEN_DECLARE_ENV_VAR_BOOL(MIOPEN_DEBUG_CONV_IMPLICIT_GEMM_HIP_FWD_V4R1) |
| 164 | +MIOPEN_DECLARE_ENV_VAR_BOOL(MIOPEN_DEBUG_CONV_IMPLICIT_GEMM_HIP_BWD_V4R1_XDLOPS) |
0 commit comments