Files
TheRock/rocm-libraries/projects/hipdnn/frontend/tests/TestGraphOverrideValidation.cpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

173 lines
6.4 KiB
C++

// Copyright © Advanced Micro Devices, Inc., or its affiliates.
// SPDX-License-Identifier: MIT
#include <gtest/gtest.h>
#include <hipdnn_frontend/detail/GraphOverrideValidation.hpp>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
using namespace hipdnn_frontend;
using namespace hipdnn_frontend::graph;
namespace
{
std::shared_ptr<TensorAttributes> makeTensor(const std::vector<int64_t>& dims,
const std::vector<int64_t>& strides)
{
auto tensor = std::make_shared<TensorAttributes>();
tensor->set_uid(1).set_dim(dims).set_stride(strides).set_data_type(DataType::FLOAT);
return tensor;
}
std::unordered_map<int64_t, std::shared_ptr<TensorAttributes>>
makeTensorMap(const std::vector<int64_t>& dims = {1, 3, 4, 4},
const std::vector<int64_t>& strides = {48, 16, 4, 1})
{
return {{1, makeTensor(dims, strides)}};
}
struct PlanOnlyRejectCase
{
const char* name;
std::vector<int64_t> uids;
std::vector<std::vector<int64_t>> shapes;
std::vector<std::vector<int64_t>> strides;
const char* expectedMessage;
};
class TestPlanOnlyOverrideValidation : public ::testing::TestWithParam<PlanOnlyRejectCase>
{
};
struct GraphBackedRejectCase
{
const char* name;
std::unordered_map<int64_t, std::shared_ptr<TensorAttributes>> tensorsByUid;
std::vector<int64_t> uids;
std::vector<std::vector<int64_t>> shapes;
std::vector<std::vector<int64_t>> strides;
const char* expectedMessage;
};
class TestGraphBackedOverrideValidation : public ::testing::TestWithParam<GraphBackedRejectCase>
{
};
} // namespace
TEST(TestPlanOnlyOverrideValidation, AcceptsStructurallyValidOverrides)
{
auto result = detail::validatePlanOnlyOverrideArguments(
{1, 2}, {{1, 3, 4, 4}, {1, 3, 2, 2}}, {{48, 16, 4, 1}, {12, 4, 2, 1}});
EXPECT_TRUE(result.is_good()) << result.err_msg;
}
TEST_P(TestPlanOnlyOverrideValidation, RejectsInvalidOverrides)
{
const auto& testCase = GetParam();
auto result = detail::validatePlanOnlyOverrideArguments(
testCase.uids, testCase.shapes, testCase.strides);
EXPECT_EQ(result.code, ErrorCode::INVALID_VALUE);
EXPECT_NE(result.err_msg.find(testCase.expectedMessage), std::string::npos) << result.err_msg;
}
INSTANTIATE_TEST_SUITE_P(
InvalidPlanOnlyOverrides,
TestPlanOnlyOverrideValidation,
::testing::Values(
PlanOnlyRejectCase{"ArraySizeMismatch",
{1, 2},
{{1, 3, 4, 4}},
{{48, 16, 4, 1}, {48, 16, 4, 1}},
"inconsistent sizes"},
PlanOnlyRejectCase{
"ShapeStrideRankMismatch", {1}, {{1, 3, 4}}, {{48, 16, 4, 1}}, "rank mismatch"},
PlanOnlyRejectCase{"ZeroRankOverride", {1}, {{}}, {{}}, "must be non-zero"},
PlanOnlyRejectCase{
"NonPositiveShape", {1}, {{1, 3, 0, 4}}, {{48, 16, 4, 1}}, "must be positive"},
PlanOnlyRejectCase{
"NonPositiveStride", {1}, {{1, 3, 4, 4}}, {{48, 16, 0, 1}}, "must be positive"},
PlanOnlyRejectCase{"DuplicateUid",
{1, 1},
{{1, 3, 4, 4}, {1, 3, 4, 4}},
{{48, 16, 4, 1}, {48, 16, 4, 1}},
"Duplicate UID"}),
[](const auto& info) { return std::string(info.param.name); });
TEST(TestGraphBackedOverrideValidation, AcceptsValidOverrides)
{
auto result = detail::validateGraphBackedOverrideArguments(
makeTensorMap(), {1}, {{1, 3, 4, 4}}, {{48, 16, 4, 1}});
EXPECT_TRUE(result.is_good()) << result.err_msg;
}
TEST(TestGraphBackedOverrideValidation, AcceptsWildcardDeclaredDimension)
{
auto result = detail::validateGraphBackedOverrideArguments(
makeTensorMap({1, 3, -1, 4}, {48, 16, 4, 1}), {1}, {{1, 3, 128, 4}}, {{1536, 512, 4, 1}});
EXPECT_TRUE(result.is_good()) << result.err_msg;
}
TEST_P(TestGraphBackedOverrideValidation, RejectsInvalidOverrides)
{
const auto& testCase = GetParam();
auto result = detail::validateGraphBackedOverrideArguments(
testCase.tensorsByUid, testCase.uids, testCase.shapes, testCase.strides);
EXPECT_EQ(result.code, ErrorCode::INVALID_VALUE);
EXPECT_NE(result.err_msg.find(testCase.expectedMessage), std::string::npos) << result.err_msg;
}
INSTANTIATE_TEST_SUITE_P(
InvalidGraphBackedOverrides,
TestGraphBackedOverrideValidation,
::testing::Values(
GraphBackedRejectCase{"ArraySizeMismatch",
makeTensorMap(),
{1, 2},
{{1, 3, 4, 4}},
{{48, 16, 4, 1}, {48, 16, 4, 1}},
"rule 1"},
GraphBackedRejectCase{"DuplicateUid",
makeTensorMap(),
{1, 1},
{{1, 3, 4, 4}, {1, 3, 4, 4}},
{{48, 16, 4, 1}, {48, 16, 4, 1}},
"rule 2"},
GraphBackedRejectCase{
"UnknownUid", makeTensorMap(), {99}, {{1, 3, 4, 4}}, {{48, 16, 4, 1}}, "rule 3"},
GraphBackedRejectCase{
"RankMismatch", makeTensorMap(), {1}, {{1, 3, 4}}, {{16, 4, 1}}, "rule 4"},
GraphBackedRejectCase{
"NonPositiveShape", makeTensorMap(), {1}, {{1, 3, 0, 4}}, {{48, 16, 4, 1}}, "rule 5"},
GraphBackedRejectCase{
"NonPositiveStride", makeTensorMap(), {1}, {{1, 3, 4, 4}}, {{48, 16, 0, 1}}, "rule 6"},
GraphBackedRejectCase{"ShapeExceedsDeclared",
makeTensorMap(),
{1},
{{1, 3, 8, 4}},
{{96, 32, 4, 1}},
"rule 7"},
GraphBackedRejectCase{"DeclaredStrideRankMismatch",
makeTensorMap({1, 3, 4, 4}, {16, 4, 1}),
{1},
{{1, 3, 4, 4}},
{{48, 16, 4, 1}},
"rule 8"},
GraphBackedRejectCase{"StrideOrderingMismatch",
makeTensorMap(),
{1},
{{1, 3, 4, 4}},
{{1, 4, 16, 48}},
"rule 8"}),
[](const auto& info) { return std::string(info.param.name); });