Skip to content
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

[gtest] conversion for code coverage tests #2580

Merged
merged 78 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
9a41dde
WIP: updatable env vars, first draft
amberhassaan Nov 7, 2023
1e63ea6
update env var declarations
cderb Nov 7, 2023
0222ee6
draw out env string definitions
cderb Nov 7, 2023
cd035e4
compilation fixes
cderb Nov 8, 2023
de4766e
Merge remote-tracking branch 'origin/develop' into cderb/env-var-update
cderb Nov 8, 2023
79446a4
fix
cderb Nov 8, 2023
9d4d4f5
fix
cderb Nov 8, 2023
541eea5
update driver envs
cderb Nov 8, 2023
5e59daf
env for test folder
cderb Nov 8, 2023
438aa34
compilation fixes
cderb Nov 8, 2023
fb292b3
format
cderb Nov 8, 2023
44a174f
tidy
cderb Nov 8, 2023
473b17c
quality improvements for env.h
cderb Nov 8, 2023
d33b9a9
convert to const string reference
cderb Nov 8, 2023
694a079
fix
cderb Nov 8, 2023
9c12c2f
fix string definition
cderb Nov 9, 2023
a3605ab
formatting
cderb Nov 9, 2023
688919c
fix
cderb Nov 9, 2023
5ea88a6
use std::string::compare
cderb Nov 9, 2023
434f154
rename IsDefault to IsUnset, check unset in disabled/enabled check
cderb Nov 9, 2023
708b472
Merge branch 'cderb/env-var-update' of https://github.com/ROCmSoftwar…
cderb Nov 9, 2023
55dfe4d
macro for bool + string envs
cderb Nov 9, 2023
c1a257a
fix macros
cderb Nov 9, 2023
e21d7da
relabel uint64 envs
cderb Nov 9, 2023
f037fe9
typo fix + format
cderb Nov 9, 2023
051538c
tidy
cderb Nov 10, 2023
fbc8558
Update src/include/miopen/env.hpp
cderb Nov 10, 2023
9074f83
update tests with env syntax
cderb Nov 10, 2023
dd38c5f
Merge branch 'cderb/env-var-update' of https://github.com/ROCmSoftwar…
cderb Nov 10, 2023
42893a9
Merge branch 'develop' into cderb/env-var-update
cderb Nov 10, 2023
57a80f5
format
cderb Nov 10, 2023
86c61c7
string references
cderb Nov 13, 2023
2d50b1d
Merge branch 'develop' into cderb/env-var-update
cderb Nov 13, 2023
4da821c
Merge branch 'develop' into cderb/env-var-update
cderb Nov 13, 2023
312a321
move generic_search env defaults into header
cderb Nov 13, 2023
34a21ca
Merge branch 'develop' into cderb/env-var-update
xinlipn Nov 14, 2023
9f85fae
Merge branch 'develop' into cderb/env-var-update
xinlipn Nov 15, 2023
cae82dc
mergefix
cderb Nov 15, 2023
2692bb8
mergefix
cderb Nov 16, 2023
3cfee15
missing include
cderb Nov 16, 2023
65f0f89
string fix
cderb Nov 16, 2023
61de002
Merge remote-tracking branch 'origin/develop' into cderb/env-var-update
cderb Nov 17, 2023
479d97e
mergefix
cderb Nov 17, 2023
f775ff1
Merge branch 'develop' into cderb/env-var-update
xinlipn Nov 20, 2023
6665114
address comments
cderb Nov 20, 2023
6be69d4
small performance remedy for find controls, remove log pollutants
cderb Nov 20, 2023
18cc17a
clang format
cderb Nov 20, 2023
a7b4344
revert find_controls changes
cderb Nov 20, 2023
a06e464
env namespace
cderb Nov 21, 2023
88bd707
fix
cderb Nov 21, 2023
eb46c35
fix
cderb Nov 21, 2023
a44b0d5
Merge remote-tracking branch 'origin/develop' into cderb/env-var-update
cderb Nov 21, 2023
263917e
mergefix
cderb Nov 22, 2023
2be776c
add Unset method for env, update assert string
cderb Nov 22, 2023
b597b81
fix
cderb Nov 22, 2023
5046fa5
immed_conv2d test update
cderb Nov 22, 2023
707ce2d
Merge branch 'develop' into cderb/env-var-update
cderb Nov 22, 2023
c1c8336
Merge branch 'develop' into cderb/env-var-update
cderb Nov 22, 2023
4dc46ef
Merge branch 'develop' into cderb/env-var-update
xinlipn Nov 26, 2023
64c53e1
Merge branch 'develop' into cderb/env-var-update
cderb Nov 27, 2023
1aea239
Merge remote-tracking branch 'origin/develop' into cderb/env-var-update
cderb Nov 28, 2023
11c11b2
Merge branch 'develop' into cderb/env-var-update
cderb Nov 28, 2023
589b8d1
Merge branch 'develop' into cderb/env-var-update
xinlipn Nov 30, 2023
66b8988
Merge remote-tracking branch 'origin/cderb/env-var-update' into cderb…
cderb Nov 30, 2023
9ca70e3
Merge remote-tracking branch 'origin/develop' into cderb/gtest_immed_…
cderb Nov 30, 2023
4da4d95
Merge remote-tracking branch 'origin/develop' into cderb/gtest_immed_…
cderb Dec 4, 2023
db4413e
update immed_conv2d gtest
cderb Dec 4, 2023
8deca20
format
cderb Dec 5, 2023
2fa7707
convert code coverage tests
cderb Dec 5, 2023
4bd3f1d
Merge branch 'develop' into cderb/gtest_immed_conv2d
cderb Dec 5, 2023
f4403d5
Reformat code
xinlipn Dec 6, 2023
b90ea4a
update const str ref
cderb Dec 6, 2023
42c1acf
move precision flags
cderb Dec 6, 2023
0bef850
Merge branch 'develop' into cderb/gtest_immed_conv2d
junliume Dec 8, 2023
fdb8c97
Merge remote-tracking branch 'origin/develop' into cderb/gtest_immed_…
cderb Dec 11, 2023
bf90c84
Merge branch 'develop' into cderb/gtest_immed_conv2d
cderb Dec 13, 2023
0fd9d59
re-enable long tests
cderb Dec 13, 2023
66b1234
Merge remote-tracking branch 'origin/develop' into cderb/gtest_immed_…
cderb Dec 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -673,20 +673,6 @@ function(add_custom_test NAME)
set_tests_properties(${NAME} PROPERTIES DISABLED On)
endif()
endfunction()
if(${CODECOV_TEST})
add_custom_test(test_conv3d_codecov
COMMAND $<TARGET_FILE:test_conv3d> ${MIOPEN_TEST_FLOAT_ARG} --input 2 4 4 4 4 --weights 2 4 1 1 1 --pads_strides_dilations 0 0 0 1 1 1 1 1 1 ${MIOPEN_TEST_FLAGS_ARGS}
)
add_custom_test(test_immed_conv2d_codecov
COMMAND $<TARGET_FILE:test_immed_conv2d> ${MIOPEN_TEST_FLOAT_ARG} --input 2 2 14 14 --weights 8 2 3 3 --pads_strides_dilations 0 0 1 1 1 1 ${MIOPEN_TEST_FLAGS_ARGS}
)
add_custom_test(test_immed_conv3d_codecov
COMMAND $<TARGET_FILE:test_immed_conv3d> ${MIOPEN_TEST_FLOAT_ARG} --input 1 4 4 4 4 --weights 2 4 3 3 3 --pads_strides_dilations 0 0 0 1 1 1 1 1 1 ${MIOPEN_TEST_FLAGS_ARGS}
)
add_custom_test(test_pooling2d_codecov
COMMAND $<TARGET_FILE:test_pooling2d> ${MIOPEN_TEST_FLOAT_ARG} --input 1, 192, 28, 28 --lens 2 2 --strides 2 2 --pads 0 0 ${MIOPEN_TEST_FLAGS_ARGS}
)
endif()

if(${MIOPEN_TEST_WITH_MIOPENDRIVER})
add_custom_test(test_miopendriver_regression_issue_1576 SKIP_UNLESS_ALL GFX94X_ENABLED GFX103X_ENABLED GFX110X_ENABLED FLOAT_DISABLED HALF_ENABLED
Expand Down Expand Up @@ -776,14 +762,6 @@ set(TEST_CONV_VERBOSE_F ${MIOPEN_TEST_FLOAT_ARG} --verbose --disable-backward-da
set(TEST_CONV_VERBOSE_B ${MIOPEN_TEST_FLOAT_ARG} --verbose --disable-forward --disable-backward-weights)
set(TEST_CONV_VERBOSE_W ${MIOPEN_TEST_FLOAT_ARG} --verbose --disable-forward --disable-backward-data)

add_custom_test(test_pooling2d_asymmetric SKIP_UNLESS_ALL HALF_ENABLED GFX94X_ENABLED GFX103X_ENABLED GFX110X_ENABLED
COMMAND $<TARGET_FILE:test_pooling2d> ${MIOPEN_TEST_FLOAT_ARG} --all --dataset 1 --limit 0 ${MIOPEN_TEST_FLAGS_ARGS}
)

add_custom_test(test_pooling2d_wide SKIP_UNLESS_ALL HALF_ENABLED GFX94X_ENABLED GFX103X_ENABLED GFX110X_ENABLED
COMMAND $<TARGET_FILE:test_pooling2d> ${MIOPEN_TEST_FLOAT_ARG} --all --dataset 2 --limit 0 ${MIOPEN_TEST_FLAGS_ARGS}
)
Comment on lines -779 to -785
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Recommendation] This is not a code coverage test. The title of PR should be changed.


set(IMPLICITGEMM_MLIR_ENV_F_XDLOPS ${IMPLICITGEMM_MLIR_ENV_BASE} MIOPEN_DEBUG_FIND_ONLY_SOLVER=ConvMlirIgemmFwdXdlops)
set(IMPLICITGEMM_MLIR_ENV_B_XDLOPS ${IMPLICITGEMM_MLIR_ENV_BASE} MIOPEN_DEBUG_FIND_ONLY_SOLVER=ConvMlirIgemmBwdXdlops)
set(IMPLICITGEMM_MLIR_ENV_W_XDLOPS ${IMPLICITGEMM_MLIR_ENV_BASE} MIOPEN_DEBUG_FIND_ONLY_SOLVER=ConvMlirIgemmWrWXdlops)
Expand Down
12 changes: 5 additions & 7 deletions test/immed_conv3d.cpp → test/conv3d.hpp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This must be reverted too due to the same reason.

Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
#include "conv_common.hpp"

template <class T>
struct conv3d_driver : conv_driver<T, ConvApi::Immediate>
struct conv3d_driver : conv_driver<T>
{
conv3d_driver() : conv_driver<T, ConvApi::Immediate>()
conv3d_driver() : conv_driver<T>()
{
this->add(this->input_dims, "input");
this->add(this->weight_tensor_dims, "weights");
Expand All @@ -37,16 +37,16 @@ struct conv3d_driver : conv_driver<T, ConvApi::Immediate>
this->generate_data_limited(this->get_batch_sizes(), 1, {8}));
this->add(this->input_channels,
"input_channels",
this->generate_data_limited(this->get_input_channels(), 1, {2}));
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, {16}));
this->generate_data_limited(this->get_output_channels(), 1, {32}));
this->add(this->spatial_dim_elements,
"spatial_dim_elements",
this->generate_data_limited(this->get_3d_spatial_dims(), 1, {16, 16, 16}));
this->add(this->filter_dims,
"filter_dims",
this->generate_data_limited(this->get_3d_filter_dims(), 2, {5, 5, 5}));
this->generate_data_limited(this->get_3d_filter_dims(), 2, {3, 3, 3}));
this->add(this->pads_strides_dilations,
"pads_strides_dilations",
this->generate_data_limited(this->get_3d_pads_strides_dilations(), 2));
Expand All @@ -58,5 +58,3 @@ struct conv3d_driver : conv_driver<T, ConvApi::Immediate>
this->add(this->out_layout, "out_layout", this->generate_data({"NCDHW"}));
}
};

int main(int argc, const char* argv[]) { test_drive<conv3d_driver>(argc, argv); }
7 changes: 6 additions & 1 deletion test/driver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,11 @@ void test_drive_impl_1(std::string program_name, std::vector<std::string> as)
Driver d{};
d.program_name = program_name;

std::cout << program_name << " ";
for(const auto& str : as)
std::cout << str << " ";
std::cout << std::endl;

std::set<std::string> keywords{
"--help", "-h", "--half", "--float", "--double", "--int8", "--bfloat16"};
d.parse(keyword_set{keywords});
Expand Down Expand Up @@ -1381,7 +1386,7 @@ template <template <class...> class Driver>
void test_drive(int argc, const char* argv[])
{
std::vector<std::string> as(argv + 1, argv + argc);
as.emplace_back("--float");
// as.emplace_back("--float");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this is necessary?

for(auto&& arg : as)
{
if(arg == "--half")
Expand Down
2 changes: 1 addition & 1 deletion test/gtest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function(add_gtest TEST_NAME)
endif()
if(NOT WIN32) # TODO: cannot run on Windows due to missing DLL dependencies
# Enable CMake to discover the test binary
gtest_discover_tests(test_${TEST_NAME} PROPERTIES ENVIRONMENT "MIOPEN_USER_DB_PATH=${CMAKE_CURRENT_BINARY_DIR};MIOPEN_TEST_FLOAT_ARG=${MIOPEN_TEST_FLOAT_ARG};MIOPEN_TEST_ALL=${MIOPEN_TEST_ALL};MIOPEN_TEST_MLIR=${MIOPEN_TEST_MLIR};MIOPEN_TEST_COMPOSABLEKERNEL=${MIOPEN_TEST_COMPOSABLEKERNEL}")
gtest_discover_tests(test_${TEST_NAME} PROPERTIES ENVIRONMENT "MIOPEN_USER_DB_PATH=${CMAKE_CURRENT_BINARY_DIR};MIOPEN_TEST_FLOAT_ARG=${MIOPEN_TEST_FLOAT_ARG};MIOPEN_TEST_ALL=${MIOPEN_TEST_ALL};MIOPEN_TEST_MLIR=${MIOPEN_TEST_MLIR};MIOPEN_TEST_COMPOSABLEKERNEL=${MIOPEN_TEST_COMPOSABLEKERNEL};CODECOV_TEST=${CODECOV_TEST}")
endif()

if(WIN32)
Expand Down
172 changes: 172 additions & 0 deletions test/gtest/conv3d_codecov.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
/*******************************************************************************
*
* 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 "conv3d.hpp"
#include "get_handle.hpp"
#include <miopen/env.hpp>
#include <gtest/gtest.h>

MIOPEN_DECLARE_ENV_VAR_BOOL(CODECOV_TEST)
MIOPEN_DECLARE_ENV_VAR_STR(MIOPEN_TEST_FLAGS_ARGS)

static bool SkipTest(void) { return !miopen::IsEnabled(ENV(CODECOV_TEST)); }

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 Conv3dFloat : public testing::TestWithParam<std::vector<std::string>>
{
};

class Conv3dHalf : public testing::TestWithParam<std::vector<std::string>>
{
};

class Conv3dBFloat16 : public testing::TestWithParam<std::vector<std::string>>
{
};

class Conv3dInt8 : public testing::TestWithParam<std::vector<std::string>>
{
};

void Run3dDriver(miopenDataType_t prec)
{

std::vector<std::string> params;
switch(prec)
{
case miopenHalf: params = Conv3dHalf::GetParam(); break;
case miopenBFloat16: params = Conv3dBFloat16::GetParam(); break;
case miopenFloat: params = Conv3dFloat::GetParam(); break;
case miopenInt8: params = Conv3dInt8::GetParam(); break;
case miopenFloat8:
case miopenBFloat8:
case miopenInt32:
case miopenDouble:
FAIL() << "miopenInt32, miopenDouble, miopenFloat8, miopenBFloat8 "
"data type not supported by "
"conv3d_codecov test";

default: params = Conv3dFloat::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<conv3d_driver>(ptrs.size(), ptrs.data());
auto capture = testing::internal::GetCapturedStderr();
std::cout << capture;
}
};

bool IsTestSupportedForDevice(const miopen::Handle& handle) { return true; }

TEST_P(Conv3dFloat, FloatTest)
{
const auto& handle = get_handle();
if(IsTestSupportedForDevice(handle) && !SkipTest())
{
Run3dDriver(miopenFloat);
}
else
{
GTEST_SKIP();
}
};

TEST_P(Conv3dHalf, HalfTest)
{
const auto& handle = get_handle();
if(IsTestSupportedForDevice(handle) && !SkipTest())
{
Run3dDriver(miopenHalf);
}
else
{
GTEST_SKIP();
}
};

TEST_P(Conv3dBFloat16, BFloat16Test)
{
const auto& handle = get_handle();
if(IsTestSupportedForDevice(handle) && !SkipTest())
{
Run3dDriver(miopenBFloat16);
}
else
{
GTEST_SKIP();
}
};

TEST_P(Conv3dInt8, Int8Test)
{
const auto& handle = get_handle();
if(IsTestSupportedForDevice(handle) && !SkipTest())
{
Run3dDriver(miopenInt8);
}
else
{
GTEST_SKIP();
}
};

std::vector<std::string> GetTestCases(const std::string& precision)
{
const auto& flag_arg = miopen::GetStringEnv(ENV(MIOPEN_TEST_FLAGS_ARGS));

const std::vector<std::string> test_cases = {
// clang-format off
{"test_conv3d " + precision + " --input 2 4 4 4 4 --weights 2 4 1 1 1 --pads_strides_dilations 0 0 0 1 1 1 1 1 1 "+flag_arg}
// clang-format on
};

return test_cases;
}

INSTANTIATE_TEST_SUITE_P(Conv3D, Conv3dFloat, testing::Values(GetTestCases("--float")));

INSTANTIATE_TEST_SUITE_P(Conv3D, Conv3dHalf, testing::Values(GetTestCases("--half")));

INSTANTIATE_TEST_SUITE_P(Conv3D, Conv3dBFloat16, testing::Values(GetTestCases("--bfloat16")));

INSTANTIATE_TEST_SUITE_P(Conv3D, Conv3dInt8, testing::Values(GetTestCases("--int8")));
66 changes: 0 additions & 66 deletions test/gtest/conv_2d.hpp

This file was deleted.

2 changes: 1 addition & 1 deletion test/gtest/conv_igemm_mlir_xdlops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <gtest/gtest.h>
#include <miopen/miopen.h>
#include <miopen/env.hpp>
#include "conv_2d.hpp"
#include "conv2d.hpp"
#include "get_handle.hpp"

MIOPEN_DECLARE_ENV_VAR_STR(MIOPEN_TEST_FLOAT_ARG)
Expand Down
Loading
Loading