-
Notifications
You must be signed in to change notification settings - Fork 224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test_conv_embed_db (ctest -> gtest) #2168
Changes from 27 commits
89c8fe2
dc3b8b9
6f1d5b0
ba9cd2a
9f3fe10
251bb89
61e49ec
17aedb8
1b5e8c1
f5d3cf1
c5cbb1a
8a8176d
ae29c5d
beb7fcb
d86eb8d
4760a5a
29afc6d
2b656e5
77dc83d
70d1d9c
d087a00
6abced7
da3594e
79eb207
20ad346
bae1221
0979c73
c987d64
20532ed
45e89ca
a6e6f1a
444ee2b
ee3adb8
878aa00
35f72a8
e4b5296
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/******************************************************************************* | ||
* | ||
* MIT License | ||
* | ||
* Copyright (c) 2023 Advanced Micro Devices, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
* | ||
*******************************************************************************/ | ||
#pragma once | ||
|
||
#include "../conv_common.hpp" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add guard (proposed name: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well I actually prefer macros (due to flexibility and portability) but this is fine. [Resolved] |
||
|
||
template <class T> | ||
struct conv2d_driver : conv_driver<T> | ||
{ | ||
conv2d_driver() : conv_driver<T>() | ||
{ | ||
this->add(this->input_dims, "input"); | ||
this->add(this->weight_tensor_dims, "weights"); | ||
this->add(this->batch_size, | ||
"batch_size", | ||
this->generate_data_limited(this->get_batch_sizes(), 1)); | ||
this->add(this->input_channels, | ||
"input_channels", | ||
this->generate_data_limited(this->get_input_channels(), 1, {32})); | ||
this->add(this->output_channels, | ||
"output_channels", | ||
this->generate_data_limited(this->get_output_channels(), 1, {64})); | ||
this->add(this->spatial_dim_elements, | ||
"spatial_dim_elements", | ||
this->generate_data_limited(this->get_2d_spatial_dims(), 1, {28, 28})); | ||
this->add(this->filter_dims, | ||
"filter_dims", | ||
this->generate_data_limited(this->get_2d_filter_dims(), 2, {3, 3})); | ||
this->add(this->pads_strides_dilations, | ||
"pads_strides_dilations", | ||
this->generate_data_limited(this->get_2d_pads_strides_dilations(), 2)); | ||
this->add(this->trans_output_pads, | ||
"trans_output_pads", | ||
this->generate_data(this->get_2d_trans_output_pads())); | ||
this->add(this->in_layout, "in_layout", this->generate_data({"NCHW"})); | ||
this->add(this->fil_layout, "fil_layout", this->generate_data({"NCHW"})); | ||
this->add(this->out_layout, "out_layout", this->generate_data({"NCHW"})); | ||
this->add(this->deterministic, "deterministic", this->generate_data({false})); | ||
this->add(this->tensor_vect, "tensor_vect", this->generate_data({0})); | ||
this->add(this->vector_length, "vector_length", this->generate_data({1})); | ||
// Only valid for int8 input and weights | ||
this->add(this->output_type, "output_type", this->generate_data({"int32"})); | ||
this->add(this->int8_vectorize, "int8_vectorize", this->generate_data({false})); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is partial copy of test/conv2d.cpp. Please do not make copies of existing code, refactor instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [notice] Copying the code is the worst thing that we can do from the maintenance point of view. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Refactored by moving common code to conv_common.hpp There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is 2D-specific and should not be moved there. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Reverted and re-refactored conv2d_driver related changes. This may look out of the place since the header is in test/gtest and this file is in test/. All previous conv2d CTest cases may be refactored by using this header as we continue moving toward gTest, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @xinlipn Yeah, Please rename this header to test/conv2d.hpp.
Moving code from test/ to test/gtest/ is a separate task. Let's do that later, separately. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Notice] Not resolved yet. Let's either fix or discuss. |
||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,229 @@ | ||
/******************************************************************************* | ||
* | ||
* MIT License | ||
* | ||
* Copyright (c) 2023 Advanced Micro Devices, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
* | ||
*******************************************************************************/ | ||
#include <tuple> | ||
JehandadKhan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#include <miopen/miopen.h> | ||
#include <gtest/gtest.h> | ||
#include <miopen/miopen.h> | ||
#include <miopen/env.hpp> | ||
#include "conv_2d.hpp" | ||
#include "get_handle.hpp" | ||
|
||
void GetArgs(const std::string& param, std::vector<std::string>& tokens) | ||
{ | ||
std::stringstream ss(param); | ||
std::istream_iterator<std::string> begin(ss); | ||
std::istream_iterator<std::string> end; | ||
while(begin != end) | ||
tokens.push_back(*begin++); | ||
} | ||
|
||
class ConfigWithHalf : public testing::TestWithParam<std::vector<std::string>> | ||
{ | ||
}; | ||
class ConfigWithInt8 : public testing::TestWithParam<std::vector<std::string>> | ||
{ | ||
}; | ||
class ConfigWithBFloat16 : public testing::TestWithParam<std::vector<std::string>> | ||
{ | ||
}; | ||
class ConfigWithFloat : public testing::TestWithParam<std::vector<std::string>> | ||
{ | ||
}; | ||
JehandadKhan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
void Run2dDriver(miopenDataType_t prec) | ||
{ | ||
|
||
std::vector<std::string> params; | ||
switch(prec) | ||
{ | ||
case miopenFloat: params = ConfigWithFloat::GetParam(); break; | ||
case miopenHalf: params = ConfigWithHalf::GetParam(); break; | ||
case miopenInt8: params = ConfigWithInt8::GetParam(); break; | ||
case miopenBFloat16: params = ConfigWithBFloat16::GetParam(); break; | ||
case miopenInt8x4: | ||
case miopenInt32: | ||
case miopenDouble: | ||
MIOPEN_THROW(miopenStatusBadParm, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please do not use MIOPEN_THROW in tests. This one is for library. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just fail the test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Resolved] |
||
"miopenInt8x4, miopenInt32, miopenDouble data type not supported by " | ||
"conv_embed_db test"); | ||
|
||
default: params = ConfigWithFloat::GetParam(); | ||
} | ||
|
||
for(const auto& test_value : params) | ||
{ | ||
std::vector<std::string> tokens; | ||
GetArgs(test_value, tokens); | ||
std::vector<const char*> ptrs; | ||
|
||
std::transform(tokens.begin(), tokens.end(), std::back_inserter(ptrs), [](const auto& str) { | ||
return str.data(); | ||
}); | ||
|
||
testing::internal::CaptureStderr(); | ||
test_drive<conv2d_driver>(ptrs.size(), ptrs.data()); | ||
auto capture = testing::internal::GetCapturedStderr(); | ||
EXPECT_FALSE(capture.find("Perf Db: record not found") != std::string::npos); | ||
} | ||
}; | ||
|
||
bool IsTestSupportedForDevice(const miopen::Handle& handle) | ||
{ | ||
std::string devName = handle.GetDeviceName(); | ||
if(devName == "gfx900" || devName == "gfx906") | ||
return true; | ||
else | ||
return false; | ||
} | ||
|
||
TEST_P(ConfigWithFloat, FloatTest) | ||
{ | ||
#if MIOPEN_EMBED_DB | ||
xinlipn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const auto& handle = get_handle(); | ||
const auto& envVar = miopen::GetEnv("MIOPEN_TEST_FLOAT_ARG"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use miopen::GetStringEnv() as it implements caching. Example: MIOPEN_DECLARE_ENV_VAR(MIOPEN_TEST_FLOAT_ARG)
...
static std::string GetFloatArg()
{
const char* p = miopen::GetStringEnv(MIOPEN_TEST_FLOAT_ARG{});
if(p == nullptr)
{
// Fail the test (preferred) or return "--float" by default.
}
return {p};
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This matches the proven pattern that we use in MIOpen when we need to read a string. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Resolved] |
||
|
||
if(IsTestSupportedForDevice(handle) && (!envVar.empty() && envVar.front() == "--float")) | ||
{ | ||
Run2dDriver(miopenFloat); | ||
} | ||
else | ||
{ | ||
GTEST_SKIP(); | ||
} | ||
|
||
#else | ||
GTEST_SKIP(); | ||
#endif | ||
}; | ||
|
||
TEST_P(ConfigWithHalf, HalfTest) | ||
{ | ||
#if MIOPEN_EMBED_DB | ||
|
||
const auto& handle = get_handle(); | ||
const auto& envVar = miopen::GetEnv("MIOPEN_TEST_FLOAT_ARG"); | ||
|
||
if(IsTestSupportedForDevice(handle) && (!envVar.empty() && envVar.front() == "--half")) | ||
{ | ||
Run2dDriver(miopenHalf); | ||
} | ||
else | ||
{ | ||
GTEST_SKIP(); | ||
} | ||
|
||
#else | ||
GTEST_SKIP(); | ||
#endif | ||
}; | ||
|
||
TEST_P(ConfigWithInt8, Int8Test) | ||
{ | ||
#if MIOPEN_EMBED_DB | ||
|
||
const auto& handle = get_handle(); | ||
const auto& envVar = miopen::GetEnv("MIOPEN_TEST_FLOAT_ARG"); | ||
|
||
if(IsTestSupportedForDevice(handle) && (!envVar.empty() && envVar.front() == "--int8")) | ||
{ | ||
Run2dDriver(miopenInt8); | ||
} | ||
else | ||
{ | ||
GTEST_SKIP(); | ||
} | ||
|
||
#else | ||
GTEST_SKIP(); | ||
#endif | ||
}; | ||
|
||
TEST_P(ConfigWithBFloat16, BFloat16Test) | ||
{ | ||
#if MIOPEN_EMBED_DB | ||
|
||
const auto& handle = get_handle(); | ||
const auto& envVar = miopen::GetEnv("MIOPEN_TEST_FLOAT_ARG"); | ||
|
||
if(IsTestSupportedForDevice(handle) && (!envVar.empty() && envVar.front() == "--bfloat16")) | ||
{ | ||
Run2dDriver(miopenBFloat16); | ||
} | ||
else | ||
{ | ||
GTEST_SKIP(); | ||
} | ||
|
||
#else | ||
GTEST_SKIP(); | ||
#endif | ||
}; | ||
|
||
std::vector<std::string> GetTestCases(const std::string& precision) | ||
{ | ||
std::string flags = " --disable-validation --verbose "; | ||
const auto& envVar = miopen::GetEnv("MIOPEN_TEST_FLOAT_ARG"); | ||
|
||
// If precision env var is not set | ||
if(envVar.empty()) | ||
flags.insert(0, precision); | ||
|
||
const std::vector<std::string> test_cases = { | ||
// clang-format off | ||
{flags + "--input 128 128 28 28 --weights 128 128 3 3 --pads_strides_dilations 1 1 1 1 1 1"}, | ||
{flags + "--input 128 256 56 56 --weights 512 256 1 1 --pads_strides_dilations 0 0 2 2 1 1"}, | ||
{flags + "--input 128 3 230 230 --weights 64 3 7 7 --pads_strides_dilations 0 0 2 2 1 1"}, | ||
{flags + "--input 128 64 56 56 --weights 64 64 3 3 --pads_strides_dilations 1 1 1 1 1 1"}, | ||
{flags + "--input 128 256 14 14 --weights 256 256 3 3 --pads_strides_dilations 1 1 1 1 1 1"}, | ||
{flags + "--input 128 512 7 7 --weights 512 512 3 3 --pads_strides_dilations 1 1 1 1 1 1"}, | ||
{flags + "--input 128 1024 14 14 --weights 512 1024 1 1 --pads_strides_dilations 0 0 2 2 1 1"}, | ||
{flags + "--input 128 1024 14 14 --weights 2048 1024 1 1 --pads_strides_dilations 0 0 2 2 1 1"}, | ||
{flags + "--input 128 256 14 14 --weights 1024 256 1 1 --pads_strides_dilations 0 0 1 1 1 1"}, | ||
{flags + "--input 128 512 28 28 --weights 256 512 1 1 --pads_strides_dilations 0 0 2 2 1 1"}, | ||
{flags + "--input 128 1024 14 14 --weights 256 1024 1 1 --pads_strides_dilations 0 0 1 1 1 1"}, | ||
{flags + "--input 128 64 56 56 --weights 256 64 1 1 --pads_strides_dilations 0 0 1 1 1 1"}, | ||
{flags + "--input 128 64 56 56 --weights 64 64 1 1 --pads_strides_dilations 0 0 1 1 1 1"}, | ||
{flags + "--input 128 128 28 28 --weights 512 128 1 1 --pads_strides_dilations 0 0 1 1 1 1"}, | ||
{flags + "--input 128 256 56 56 --weights 128 256 1 1 --pads_strides_dilations 0 0 2 2 1 1"}, | ||
{flags + "--input 128 256 56 56 --weights 64 256 1 1 --pads_strides_dilations 0 0 1 1 1 1"}, | ||
{flags + "--input 128 512 28 28 --weights 1024 512 1 1 --pads_strides_dilations 0 0 2 2 1 1"}, | ||
{flags + "--input 128 512 28 28 --weights 128 512 1 1 --pads_strides_dilations 0 0 1 1 1 1"}, | ||
{flags + "--input 128 512 7 7 --weights 2048 512 1 1 --pads_strides_dilations 0 0 1 1 1 1"}, | ||
{flags + "--input 128 2048 7 7 --weights 512 2048 1 1 --pads_strides_dilations 0 0 1 1 1 1"} | ||
// clang-format on | ||
}; | ||
|
||
return test_cases; | ||
} | ||
|
||
INSTANTIATE_TEST_SUITE_P(ConvEmbedDB, ConfigWithFloat, testing::Values(GetTestCases("--float"))); | ||
INSTANTIATE_TEST_SUITE_P(ConvEmbedDB, ConfigWithHalf, testing::Values(GetTestCases("--half"))); | ||
INSTANTIATE_TEST_SUITE_P(ConvEmbedDB, ConfigWithInt8, testing::Values(GetTestCases("--int8"))); | ||
INSTANTIATE_TEST_SUITE_P(ConvEmbedDB, | ||
ConfigWithBFloat16, | ||
testing::Values(GetTestCases("--bfloat16"))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JehandadKhan [Notice] just in case - it seems that this code is working, but actually it should be
if(NOT MIOPEN_EMBED_DB STREQUAL "")
here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@atamazov , I have been thinking if this line would be necessary in this case
https://github.com/ROCmSoftwarePlatform/MIOpen/blob/29afc6d0d4d98a2e821a420ac3613d74d51b9b9b/test/gtest/conv_embed_db.cpp#L105