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
211 lines
8.1 KiB
C++
211 lines
8.1 KiB
C++
// Copyright © Advanced Micro Devices, Inc., or its affiliates.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#include <gtest/gtest.h>
|
|
#include <hipdnn_frontend/attributes/GraphAttributes.hpp>
|
|
|
|
TEST(TestGraphAttributes, CreateGraphAttributes)
|
|
{
|
|
hipdnn_frontend::graph::GraphAttributes graphAttributes;
|
|
|
|
// Set all properties
|
|
graphAttributes.set_name("TestGraph")
|
|
.set_compute_data_type(hipdnn_frontend::DataType::FLOAT)
|
|
.set_intermediate_data_type(hipdnn_frontend::DataType::HALF)
|
|
.set_io_data_type(hipdnn_frontend::DataType::BFLOAT16);
|
|
|
|
// Verify all properties
|
|
EXPECT_EQ(graphAttributes.get_name(), "TestGraph");
|
|
EXPECT_EQ(graphAttributes.get_compute_data_type(), hipdnn_frontend::DataType::FLOAT);
|
|
EXPECT_EQ(graphAttributes.get_intermediate_data_type(), hipdnn_frontend::DataType::HALF);
|
|
EXPECT_EQ(graphAttributes.get_io_data_type(), hipdnn_frontend::DataType::BFLOAT16);
|
|
}
|
|
|
|
TEST(TestGraphAttributes, DefaultValues)
|
|
{
|
|
const hipdnn_frontend::graph::GraphAttributes graphAttributes;
|
|
|
|
// Check default values
|
|
EXPECT_EQ(graphAttributes.get_name(), "");
|
|
EXPECT_EQ(graphAttributes.get_compute_data_type(), hipdnn_frontend::DataType::NOT_SET);
|
|
EXPECT_EQ(graphAttributes.get_intermediate_data_type(), hipdnn_frontend::DataType::NOT_SET);
|
|
EXPECT_EQ(graphAttributes.get_io_data_type(), hipdnn_frontend::DataType::NOT_SET);
|
|
}
|
|
|
|
TEST(TestGraphAttributes, SetName)
|
|
{
|
|
hipdnn_frontend::graph::GraphAttributes graphAttributes;
|
|
|
|
graphAttributes.set_name("MyCustomGraph");
|
|
EXPECT_EQ(graphAttributes.get_name(), "MyCustomGraph");
|
|
|
|
// Test empty string
|
|
graphAttributes.set_name("");
|
|
EXPECT_EQ(graphAttributes.get_name(), "");
|
|
|
|
// Test long name
|
|
const std::string longName = "VeryLongGraphNameThatShouldStillWorkProperly";
|
|
graphAttributes.set_name(longName);
|
|
EXPECT_EQ(graphAttributes.get_name(), longName);
|
|
}
|
|
|
|
TEST(TestGraphAttributes, SetComputeDataType)
|
|
{
|
|
hipdnn_frontend::graph::GraphAttributes graphAttributes;
|
|
|
|
graphAttributes.set_compute_data_type(hipdnn_frontend::DataType::FLOAT);
|
|
EXPECT_EQ(graphAttributes.get_compute_data_type(), hipdnn_frontend::DataType::FLOAT);
|
|
}
|
|
|
|
TEST(TestGraphAttributes, SetIntermediateDataType)
|
|
{
|
|
hipdnn_frontend::graph::GraphAttributes graphAttributes;
|
|
|
|
graphAttributes.set_intermediate_data_type(hipdnn_frontend::DataType::FLOAT);
|
|
EXPECT_EQ(graphAttributes.get_intermediate_data_type(), hipdnn_frontend::DataType::FLOAT);
|
|
}
|
|
|
|
TEST(TestGraphAttributes, SetIoDataType)
|
|
{
|
|
hipdnn_frontend::graph::GraphAttributes graphAttributes;
|
|
|
|
graphAttributes.set_io_data_type(hipdnn_frontend::DataType::HALF);
|
|
EXPECT_EQ(graphAttributes.get_io_data_type(), hipdnn_frontend::DataType::HALF);
|
|
}
|
|
|
|
TEST(TestGraphAttributes, MethodChaining)
|
|
{
|
|
hipdnn_frontend::graph::GraphAttributes graphAttributes;
|
|
|
|
// Test that all setters return reference to self for chaining
|
|
auto& ref1 = graphAttributes.set_name("ChainedGraph");
|
|
auto& ref2 = ref1.set_compute_data_type(hipdnn_frontend::DataType::FLOAT);
|
|
auto& ref3 = ref2.set_intermediate_data_type(hipdnn_frontend::DataType::HALF);
|
|
auto& ref4 = ref3.set_io_data_type(hipdnn_frontend::DataType::BFLOAT16);
|
|
|
|
// All references should point to the same object
|
|
EXPECT_EQ(&graphAttributes, &ref1);
|
|
EXPECT_EQ(&graphAttributes, &ref2);
|
|
EXPECT_EQ(&graphAttributes, &ref3);
|
|
EXPECT_EQ(&graphAttributes, &ref4);
|
|
|
|
// Verify all values were set correctly
|
|
EXPECT_EQ(graphAttributes.get_name(), "ChainedGraph");
|
|
EXPECT_EQ(graphAttributes.get_compute_data_type(), hipdnn_frontend::DataType::FLOAT);
|
|
EXPECT_EQ(graphAttributes.get_intermediate_data_type(), hipdnn_frontend::DataType::HALF);
|
|
EXPECT_EQ(graphAttributes.get_io_data_type(), hipdnn_frontend::DataType::BFLOAT16);
|
|
}
|
|
|
|
TEST(TestGraphAttributes, FillMissingPropertiesAllMissing)
|
|
{
|
|
hipdnn_frontend::graph::GraphAttributes target;
|
|
hipdnn_frontend::graph::GraphAttributes source;
|
|
|
|
// Set all properties in source
|
|
source.set_name("SourceGraph")
|
|
.set_compute_data_type(hipdnn_frontend::DataType::FLOAT)
|
|
.set_intermediate_data_type(hipdnn_frontend::DataType::HALF)
|
|
.set_io_data_type(hipdnn_frontend::DataType::BFLOAT16);
|
|
|
|
target.fill_missing_properties(source);
|
|
|
|
// All properties should be copied from source
|
|
EXPECT_EQ(target.get_name(), "SourceGraph");
|
|
EXPECT_EQ(target.get_compute_data_type(), hipdnn_frontend::DataType::FLOAT);
|
|
EXPECT_EQ(target.get_intermediate_data_type(), hipdnn_frontend::DataType::HALF);
|
|
EXPECT_EQ(target.get_io_data_type(), hipdnn_frontend::DataType::BFLOAT16);
|
|
}
|
|
|
|
TEST(TestGraphAttributes, FillMissingPropertiesPartialMissing)
|
|
{
|
|
hipdnn_frontend::graph::GraphAttributes target;
|
|
hipdnn_frontend::graph::GraphAttributes source;
|
|
|
|
// Set some properties in target
|
|
target.set_name("TargetGraph").set_compute_data_type(hipdnn_frontend::DataType::DOUBLE);
|
|
|
|
// Set all properties in source
|
|
source.set_name("SourceGraph")
|
|
.set_compute_data_type(hipdnn_frontend::DataType::FLOAT)
|
|
.set_intermediate_data_type(hipdnn_frontend::DataType::HALF)
|
|
.set_io_data_type(hipdnn_frontend::DataType::BFLOAT16);
|
|
|
|
// Fill missing properties
|
|
target.fill_missing_properties(source);
|
|
|
|
// Existing properties should not be overwritten
|
|
EXPECT_EQ(target.get_name(), "TargetGraph");
|
|
EXPECT_EQ(target.get_compute_data_type(), hipdnn_frontend::DataType::DOUBLE);
|
|
|
|
// Missing properties should be filled from source
|
|
EXPECT_EQ(target.get_intermediate_data_type(), hipdnn_frontend::DataType::HALF);
|
|
EXPECT_EQ(target.get_io_data_type(), hipdnn_frontend::DataType::BFLOAT16);
|
|
}
|
|
|
|
TEST(TestGraphAttributes, FillMissingPropertiesNoneMissing)
|
|
{
|
|
hipdnn_frontend::graph::GraphAttributes target;
|
|
hipdnn_frontend::graph::GraphAttributes source;
|
|
|
|
// Set all properties in target
|
|
target.set_name("TargetGraph")
|
|
.set_compute_data_type(hipdnn_frontend::DataType::DOUBLE)
|
|
.set_intermediate_data_type(hipdnn_frontend::DataType::FLOAT)
|
|
.set_io_data_type(hipdnn_frontend::DataType::INT32);
|
|
|
|
// Set all properties in source with different values
|
|
source.set_name("SourceGraph")
|
|
.set_compute_data_type(hipdnn_frontend::DataType::FLOAT)
|
|
.set_intermediate_data_type(hipdnn_frontend::DataType::HALF)
|
|
.set_io_data_type(hipdnn_frontend::DataType::BFLOAT16);
|
|
|
|
// Fill missing properties (none are missing)
|
|
target.fill_missing_properties(source);
|
|
|
|
// No properties should be changed
|
|
EXPECT_EQ(target.get_name(), "TargetGraph");
|
|
EXPECT_EQ(target.get_compute_data_type(), hipdnn_frontend::DataType::DOUBLE);
|
|
EXPECT_EQ(target.get_intermediate_data_type(), hipdnn_frontend::DataType::FLOAT);
|
|
EXPECT_EQ(target.get_io_data_type(), hipdnn_frontend::DataType::INT32);
|
|
}
|
|
|
|
TEST(TestGraphAttributes, FillMissingPropertiesEmptyName)
|
|
{
|
|
hipdnn_frontend::graph::GraphAttributes target;
|
|
hipdnn_frontend::graph::GraphAttributes source;
|
|
|
|
// Set empty name in target and non-empty in source
|
|
target.set_name("").set_compute_data_type(hipdnn_frontend::DataType::FLOAT);
|
|
|
|
source.set_name("SourceGraph").set_compute_data_type(hipdnn_frontend::DataType::DOUBLE);
|
|
|
|
// Fill missing properties
|
|
target.fill_missing_properties(source);
|
|
|
|
// Empty name should be filled from source
|
|
EXPECT_EQ(target.get_name(), "SourceGraph");
|
|
// Existing compute type should not change
|
|
EXPECT_EQ(target.get_compute_data_type(), hipdnn_frontend::DataType::FLOAT);
|
|
}
|
|
|
|
TEST(TestGraphAttributes, FillMissingPropertiesChaining)
|
|
{
|
|
hipdnn_frontend::graph::GraphAttributes target;
|
|
hipdnn_frontend::graph::GraphAttributes source;
|
|
|
|
source.set_name("SourceGraph")
|
|
.set_compute_data_type(hipdnn_frontend::DataType::FLOAT)
|
|
.set_intermediate_data_type(hipdnn_frontend::DataType::HALF)
|
|
.set_io_data_type(hipdnn_frontend::DataType::BFLOAT16);
|
|
|
|
// Test that fill_missing_properties returns reference for chaining
|
|
auto& ref = target.fill_missing_properties(source);
|
|
EXPECT_EQ(&target, &ref);
|
|
|
|
// Chain additional operations
|
|
ref.set_name("ModifiedAfterFill");
|
|
|
|
EXPECT_EQ(target.get_name(), "ModifiedAfterFill");
|
|
EXPECT_EQ(target.get_compute_data_type(), hipdnn_frontend::DataType::FLOAT);
|
|
}
|