|
| 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 | +#include <miopen/miopen.h> |
| 27 | +#include <gtest/gtest.h> |
| 28 | +#include <miopen/env.hpp> |
| 29 | +#include "../gru.hpp" |
| 30 | +#include "get_handle.hpp" |
| 31 | + |
| 32 | +MIOPEN_DECLARE_ENV_VAR_BOOL(MIOPEN_TEST_DEEPBENCH) |
| 33 | + |
| 34 | +namespace deepbench_gru { |
| 35 | +static bool SkipTest(void) { return !miopen::IsEnabled(ENV(MIOPEN_TEST_DEEPBENCH)); } |
| 36 | + |
| 37 | +void GetArgs(const std::string& param, std::vector<std::string>& tokens) |
| 38 | +{ |
| 39 | + std::stringstream ss(param); |
| 40 | + std::istream_iterator<std::string> begin(ss); |
| 41 | + std::istream_iterator<std::string> end; |
| 42 | + while(begin != end) |
| 43 | + tokens.push_back(*begin++); |
| 44 | +} |
| 45 | + |
| 46 | +class DeepBenchGRUConfigWithFloat : public testing::TestWithParam<std::vector<std::string>> |
| 47 | +{ |
| 48 | +}; |
| 49 | + |
| 50 | +void Run2dDriverFloat(void) |
| 51 | +{ |
| 52 | + std::vector<std::string> params = DeepBenchGRUConfigWithFloat::GetParam(); |
| 53 | + |
| 54 | + for(const auto& test_value : params) |
| 55 | + { |
| 56 | + std::vector<std::string> tokens; |
| 57 | + GetArgs(test_value, tokens); |
| 58 | + std::vector<const char*> ptrs; |
| 59 | + |
| 60 | + std::transform(tokens.begin(), tokens.end(), std::back_inserter(ptrs), [](const auto& str) { |
| 61 | + return str.data(); |
| 62 | + }); |
| 63 | + |
| 64 | + testing::internal::CaptureStderr(); |
| 65 | + test_drive<gru_driver>(ptrs.size(), ptrs.data()); |
| 66 | + auto capture = testing::internal::GetCapturedStderr(); |
| 67 | + std::cout << capture; |
| 68 | + } |
| 69 | +}; |
| 70 | + |
| 71 | +std::vector<std::string> GetTestCases(void) |
| 72 | +{ |
| 73 | + std::string flags = " --verbose"; |
| 74 | + std::string commonFlags = |
| 75 | + " --num-layers 1 --in-mode 1 --bias-mode 0 -dir-mode 0 --rnn-mode 0 --flat-batch-fill"; |
| 76 | + |
| 77 | + const std::vector<std::string> test_cases = { |
| 78 | + // clang-format off |
| 79 | + {flags + " --batch-size 32 --seq-len 1500 --vector-len 2816 --hidden-size 2816" + commonFlags}, |
| 80 | + {flags + " --batch-size 32 --seq-len 750 --vector-len 2816 --hidden-size 2816" + commonFlags}, |
| 81 | + {flags + " --batch-size 32 --seq-len 375 --vector-len 2816 --hidden-size 2816" + commonFlags}, |
| 82 | + {flags + " --batch-size 32 --seq-len 187 --vector-len 2816 --hidden-size 2816" + commonFlags}, |
| 83 | + {flags + " --batch-size 32 --seq-len 1500 --vector-len 2048 --hidden-size 2048" + commonFlags}, |
| 84 | + {flags + " --batch-size 32 --seq-len 750 --vector-len 2048 --hidden-size 2048" + commonFlags}, |
| 85 | + {flags + " --batch-size 32 --seq-len 375 --vector-len 2048 --hidden-size 2048" + commonFlags}, |
| 86 | + {flags + " --batch-size 32 --seq-len 187 --vector-len 2048 --hidden-size 2048" + commonFlags}, |
| 87 | + {flags + " --batch-size 32 --seq-len 1500 --vector-len 1536 --hidden-size 1536" + commonFlags}, |
| 88 | + {flags + " --batch-size 32 --seq-len 750 --vector-len 1536 --hidden-size 1536" + commonFlags}, |
| 89 | + {flags + " --batch-size 32 --seq-len 375 --vector-len 1536 --hidden-size 1536" + commonFlags}, |
| 90 | + {flags + " --batch-size 32 --seq-len 187 --vector-len 1536 --hidden-size 1536" + commonFlags}, |
| 91 | + {flags + " --batch-size 32 --seq-len 1500 --vector-len 2560 --hidden-size 2560" + commonFlags}, |
| 92 | + {flags + " --batch-size 32 --seq-len 750 --vector-len 2560 --hidden-size 2560" + commonFlags}, |
| 93 | + {flags + " --batch-size 32 --seq-len 375 --vector-len 2560 --hidden-size 2560" + commonFlags}, |
| 94 | + {flags + " --batch-size 32 --seq-len 187 --vector-len 2560 --hidden-size 2560" + commonFlags}, |
| 95 | + {flags + " --batch-size 32 --seq-len 1 --vector-len 512 --hidden-size 512" + commonFlags}, |
| 96 | + {flags + " --batch-size 32 --seq-len 1500 --vector-len 1024 --hidden-size 1024" + commonFlags}, |
| 97 | + {flags + " --batch-size 64 --seq-len 1500 --vector-len 1024 --hidden-size 1024" + commonFlags} |
| 98 | + // clang-format on |
| 99 | + }; |
| 100 | + |
| 101 | + return test_cases; |
| 102 | +} |
| 103 | + |
| 104 | +} // namespace deepbench_gru |
| 105 | + |
| 106 | +using namespace deepbench_gru; |
| 107 | + |
| 108 | +TEST_P(DeepBenchGRUConfigWithFloat, FloatTest_deepbench_gru) |
| 109 | +{ |
| 110 | + if(SkipTest()) |
| 111 | + { |
| 112 | + GTEST_SKIP(); |
| 113 | + } |
| 114 | + else |
| 115 | + { |
| 116 | + Run2dDriverFloat(); |
| 117 | + } |
| 118 | +}; |
| 119 | + |
| 120 | +INSTANTIATE_TEST_SUITE_P(ConvTrans, DeepBenchGRUConfigWithFloat, testing::Values(GetTestCases())); |
0 commit comments