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
271 lines
8.2 KiB
C++
271 lines
8.2 KiB
C++
// Copyright © Advanced Micro Devices, Inc., or its affiliates.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#include <gtest/gtest.h>
|
|
#include <hipdnn_data_sdk/utilities/ShapeUtilities.hpp>
|
|
#include <hipdnn_frontend/Types.hpp>
|
|
#include <hipdnn_frontend/attributes/CustomOpAttributes.hpp>
|
|
#include <hipdnn_frontend/attributes/GraphAttributes.hpp>
|
|
#include <hipdnn_frontend/node/CustomOpNode.hpp>
|
|
|
|
using namespace hipdnn_frontend;
|
|
using namespace hipdnn_frontend::graph;
|
|
|
|
namespace
|
|
{
|
|
std::shared_ptr<TensorAttributes> makeTensor(const std::string& name,
|
|
int64_t uid,
|
|
const std::vector<int64_t>& dims,
|
|
DataType dtype)
|
|
{
|
|
auto tensor = std::make_shared<TensorAttributes>();
|
|
tensor->set_name(name)
|
|
.set_uid(uid)
|
|
.set_dim(dims)
|
|
.set_stride(hipdnn_data_sdk::utilities::generateStrides(dims))
|
|
.set_data_type(dtype);
|
|
return tensor;
|
|
}
|
|
} // namespace
|
|
|
|
TEST(TestCustomOpNode, GetNodeName)
|
|
{
|
|
GraphAttributes graphAttrs;
|
|
graphAttrs.set_compute_data_type(DataType::FLOAT);
|
|
|
|
CustomOpAttributes attr;
|
|
attr.set_name("my_custom_op");
|
|
|
|
const CustomOpNode node(std::move(attr), graphAttrs);
|
|
EXPECT_EQ(node.getNodeName(), "my_custom_op");
|
|
}
|
|
|
|
TEST(TestCustomOpNode, GatherTensors)
|
|
{
|
|
GraphAttributes graphAttrs;
|
|
graphAttrs.set_compute_data_type(DataType::FLOAT);
|
|
|
|
auto input = makeTensor("input", 1, {2, 3}, DataType::FLOAT);
|
|
auto output = makeTensor("output", 2, {2, 3}, DataType::FLOAT);
|
|
|
|
CustomOpAttributes attr;
|
|
attr.set_name("test_op").set_inputs({input}).set_outputs({output});
|
|
|
|
const CustomOpNode node(std::move(attr), graphAttrs);
|
|
|
|
std::unordered_set<std::shared_ptr<TensorAttributes>> allTensors;
|
|
node.gather_hipdnn_tensors(allTensors);
|
|
|
|
EXPECT_EQ(allTensors.size(), 2u);
|
|
EXPECT_TRUE(allTensors.count(input));
|
|
EXPECT_TRUE(allTensors.count(output));
|
|
}
|
|
|
|
TEST(TestCustomOpNode, GetInputOutputTensorAttributes)
|
|
{
|
|
GraphAttributes graphAttrs;
|
|
graphAttrs.set_compute_data_type(DataType::FLOAT);
|
|
|
|
auto inputA = makeTensor("input_a", 1, {2, 3}, DataType::FLOAT);
|
|
auto inputB = makeTensor("input_b", 2, {2, 3}, DataType::FLOAT);
|
|
auto output = makeTensor("output", 3, {2, 3}, DataType::FLOAT);
|
|
|
|
CustomOpAttributes attr;
|
|
attr.set_name("test_op").set_inputs({inputA, inputB}).set_outputs({output});
|
|
|
|
const CustomOpNode node(std::move(attr), graphAttrs);
|
|
|
|
auto inputs = node.getNodeInputTensorAttributes();
|
|
auto outputs = node.getNodeOutputTensorAttributes();
|
|
|
|
EXPECT_EQ(inputs.size(), 2u);
|
|
EXPECT_EQ(outputs.size(), 1u);
|
|
}
|
|
|
|
TEST(TestCustomOpNode, PreValidateSucceeds)
|
|
{
|
|
GraphAttributes graphAttrs;
|
|
graphAttrs.set_compute_data_type(DataType::FLOAT);
|
|
|
|
auto input = makeTensor("input", 1, {2, 3}, DataType::FLOAT);
|
|
auto output = makeTensor("output", 2, {2, 3}, DataType::FLOAT);
|
|
|
|
CustomOpAttributes attr;
|
|
attr.set_name("test_op")
|
|
.set_custom_op_id("example.my_add")
|
|
.set_inputs({input})
|
|
.set_outputs({output});
|
|
|
|
const CustomOpNode node(std::move(attr), graphAttrs);
|
|
|
|
auto err = node.pre_validate_node();
|
|
EXPECT_EQ(err.code, ErrorCode::OK);
|
|
}
|
|
|
|
TEST(TestCustomOpNode, PreValidateSucceedsWithMultipleInputsAndOutputs)
|
|
{
|
|
GraphAttributes graphAttrs;
|
|
graphAttrs.set_compute_data_type(DataType::FLOAT);
|
|
|
|
auto inputA = makeTensor("input_a", 1, {2, 3}, DataType::FLOAT);
|
|
auto inputB = makeTensor("input_b", 2, {2, 3}, DataType::FLOAT);
|
|
auto inputC = makeTensor("input_c", 3, {2, 3}, DataType::FLOAT);
|
|
auto outputA = makeTensor("output_a", 4, {2, 3}, DataType::FLOAT);
|
|
auto outputB = makeTensor("output_b", 5, {2, 3}, DataType::FLOAT);
|
|
|
|
CustomOpAttributes attr;
|
|
attr.set_name("test_op")
|
|
.set_custom_op_id("example.multi_io")
|
|
.set_inputs({inputA, inputB, inputC})
|
|
.set_outputs({outputA, outputB});
|
|
|
|
const CustomOpNode node(std::move(attr), graphAttrs);
|
|
|
|
auto err = node.pre_validate_node();
|
|
EXPECT_EQ(err.code, ErrorCode::OK);
|
|
}
|
|
|
|
TEST(TestCustomOpNode, PreValidateSucceedsWithNoInputs)
|
|
{
|
|
GraphAttributes graphAttrs;
|
|
graphAttrs.set_compute_data_type(DataType::FLOAT);
|
|
|
|
auto output = makeTensor("output", 1, {2, 3}, DataType::FLOAT);
|
|
|
|
CustomOpAttributes attr;
|
|
attr.set_name("test_op").set_custom_op_id("example.generator").set_outputs({output});
|
|
|
|
const CustomOpNode node(std::move(attr), graphAttrs);
|
|
|
|
auto err = node.pre_validate_node();
|
|
EXPECT_EQ(err.code, ErrorCode::OK);
|
|
}
|
|
|
|
TEST(TestCustomOpNode, PreValidateFailsWithNullInput)
|
|
{
|
|
GraphAttributes graphAttrs;
|
|
graphAttrs.set_compute_data_type(DataType::FLOAT);
|
|
|
|
auto output = makeTensor("output", 2, {2, 3}, DataType::FLOAT);
|
|
|
|
CustomOpAttributes attr;
|
|
attr.set_name("test_op")
|
|
.set_custom_op_id("example.my_add")
|
|
.set_inputs({nullptr})
|
|
.set_outputs({output});
|
|
|
|
const CustomOpNode node(std::move(attr), graphAttrs);
|
|
|
|
auto err = node.pre_validate_node();
|
|
EXPECT_EQ(err.code, ErrorCode::INVALID_VALUE);
|
|
}
|
|
|
|
TEST(TestCustomOpNode, PreValidateFailsWithNullOutput)
|
|
{
|
|
GraphAttributes graphAttrs;
|
|
graphAttrs.set_compute_data_type(DataType::FLOAT);
|
|
|
|
auto input = makeTensor("input", 1, {2, 3}, DataType::FLOAT);
|
|
|
|
CustomOpAttributes attr;
|
|
attr.set_name("test_op")
|
|
.set_custom_op_id("example.my_add")
|
|
.set_inputs({input})
|
|
.set_outputs({nullptr});
|
|
|
|
const CustomOpNode node(std::move(attr), graphAttrs);
|
|
|
|
auto err = node.pre_validate_node();
|
|
EXPECT_EQ(err.code, ErrorCode::INVALID_VALUE);
|
|
}
|
|
|
|
TEST(TestCustomOpNode, PostValidateSucceeds)
|
|
{
|
|
GraphAttributes graphAttrs;
|
|
graphAttrs.set_compute_data_type(DataType::FLOAT);
|
|
|
|
auto input = makeTensor("input", 1, {2, 3}, DataType::FLOAT);
|
|
auto output = makeTensor("output", 2, {2, 3}, DataType::FLOAT);
|
|
|
|
CustomOpAttributes attr;
|
|
attr.set_name("test_op")
|
|
.set_custom_op_id("example.my_add")
|
|
.set_compute_data_type(DataType::FLOAT)
|
|
.set_inputs({input})
|
|
.set_outputs({output});
|
|
|
|
const CustomOpNode node(std::move(attr), graphAttrs);
|
|
|
|
auto err = node.post_validate_node();
|
|
EXPECT_EQ(err.code, ErrorCode::OK);
|
|
}
|
|
|
|
TEST(TestCustomOpNode, PostValidateFailsWithoutCustomOpId)
|
|
{
|
|
GraphAttributes graphAttrs;
|
|
graphAttrs.set_compute_data_type(DataType::FLOAT);
|
|
|
|
auto input = makeTensor("input", 1, {2, 3}, DataType::FLOAT);
|
|
auto output = makeTensor("output", 2, {2, 3}, DataType::FLOAT);
|
|
|
|
CustomOpAttributes attr;
|
|
attr.set_name("test_op")
|
|
.set_compute_data_type(DataType::FLOAT)
|
|
.set_inputs({input})
|
|
.set_outputs({output});
|
|
|
|
const CustomOpNode node(std::move(attr), graphAttrs);
|
|
|
|
auto err = node.post_validate_node();
|
|
EXPECT_EQ(err.code, ErrorCode::ATTRIBUTE_NOT_SET);
|
|
}
|
|
|
|
TEST(TestCustomOpNode, PostValidateFailsWithoutComputeDataType)
|
|
{
|
|
const GraphAttributes graphAttrs;
|
|
|
|
auto input = makeTensor("input", 1, {2, 3}, DataType::FLOAT);
|
|
auto output = makeTensor("output", 2, {2, 3}, DataType::FLOAT);
|
|
|
|
CustomOpAttributes attr;
|
|
attr.set_name("test_op")
|
|
.set_custom_op_id("example.my_add")
|
|
.set_inputs({input})
|
|
.set_outputs({output});
|
|
|
|
const CustomOpNode node(std::move(attr), graphAttrs);
|
|
|
|
auto err = node.post_validate_node();
|
|
EXPECT_EQ(err.code, ErrorCode::ATTRIBUTE_NOT_SET);
|
|
}
|
|
|
|
TEST(TestCustomOpNode, InferPropertiesPropagatesContext)
|
|
{
|
|
GraphAttributes graphAttrs;
|
|
graphAttrs.set_compute_data_type(DataType::FLOAT);
|
|
graphAttrs.set_io_data_type(DataType::HALF);
|
|
|
|
auto input = std::make_shared<TensorAttributes>();
|
|
input->set_uid(1).set_dim({2, 3}).set_stride({3, 1});
|
|
|
|
auto output = std::make_shared<TensorAttributes>();
|
|
output->set_uid(2).set_dim({2, 3}).set_stride({3, 1});
|
|
|
|
CustomOpAttributes attr;
|
|
attr.set_name("test_op").set_inputs({input}).set_outputs({output});
|
|
|
|
CustomOpNode node(std::move(attr), graphAttrs);
|
|
|
|
auto err = node.infer_properties_node();
|
|
EXPECT_EQ(err.code, ErrorCode::OK);
|
|
EXPECT_EQ(input->get_data_type(), DataType::HALF);
|
|
EXPECT_EQ(output->get_data_type(), DataType::HALF);
|
|
}
|
|
|
|
TEST(TestCustomOpNode, GetNodeTypeReturnsCustomOp)
|
|
{
|
|
const GraphAttributes graphAttrs;
|
|
const CustomOpNode node(CustomOpAttributes{}, graphAttrs);
|
|
EXPECT_EQ(node.getNodeType(), NodeType::CUSTOM_OP);
|
|
}
|