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
98 lines
3.1 KiB
C++
98 lines
3.1 KiB
C++
// Copyright © Advanced Micro Devices, Inc., or its affiliates.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#include "FlatbufferUtilities.hpp"
|
|
#include "HipdnnException.hpp"
|
|
#include "descriptors/FlatbufferTestUtils.hpp"
|
|
#include "descriptors/TestMacros.hpp"
|
|
#include <flatbuffers/flatbuffers.h>
|
|
#include <gtest/gtest.h>
|
|
#include <hipdnn_flatbuffers_sdk/data_objects/graph_generated.h>
|
|
|
|
namespace hipdnn_backend
|
|
{
|
|
namespace testing
|
|
{
|
|
|
|
using namespace hipdnn_flatbuffers_sdk::data_objects;
|
|
using namespace hipdnn_backend::test_utilities;
|
|
|
|
class TestFlatbufferUtilities : public ::testing::Test
|
|
{
|
|
public:
|
|
static void verifyGraph(const hipdnn_flatbuffers_sdk::data_objects::GraphT& graph)
|
|
{
|
|
EXPECT_EQ(graph.name, "test");
|
|
EXPECT_EQ(graph.compute_data_type, DataType::FLOAT);
|
|
EXPECT_EQ(graph.intermediate_data_type, DataType::HALF);
|
|
EXPECT_EQ(graph.io_data_type, DataType::BFLOAT16);
|
|
EXPECT_EQ(graph.tensors.size(), 3);
|
|
EXPECT_EQ(graph.nodes.size(), 1);
|
|
}
|
|
};
|
|
|
|
TEST_F(TestFlatbufferUtilities, WillCorrectlyUnpackValidGraphBuffer)
|
|
{
|
|
auto builder = createValidGraph();
|
|
|
|
auto serializedGraph = builder.Release();
|
|
std::unique_ptr<hipdnn_flatbuffers_sdk::data_objects::GraphT> graph;
|
|
ASSERT_NO_THROW(flatbuffer_utilities::convertSerializedGraphToGraph(
|
|
serializedGraph.data(), serializedGraph.size(), graph));
|
|
|
|
verifyGraph(*graph);
|
|
}
|
|
|
|
TEST_F(TestFlatbufferUtilities, WillStillHaveValidGraphAfterBuilderDestructs)
|
|
{
|
|
std::unique_ptr<hipdnn_flatbuffers_sdk::data_objects::GraphT> graph;
|
|
{
|
|
auto builder = createValidGraph();
|
|
|
|
auto serializedGraph = builder.Release();
|
|
ASSERT_NO_THROW(flatbuffer_utilities::convertSerializedGraphToGraph(
|
|
serializedGraph.data(), serializedGraph.size(), graph));
|
|
}
|
|
|
|
verifyGraph(*graph);
|
|
}
|
|
|
|
TEST_F(TestFlatbufferUtilities, WillNotUnpackNullBuffer)
|
|
{
|
|
auto [buffer, size] = std::make_pair(static_cast<const uint8_t*>(nullptr), size_t(10));
|
|
|
|
std::unique_ptr<hipdnn_flatbuffers_sdk::data_objects::GraphT> graph;
|
|
ASSERT_THROW_HIPDNN_STATUS(
|
|
flatbuffer_utilities::convertSerializedGraphToGraph(buffer, size, graph),
|
|
HIPDNN_STATUS_BAD_PARAM);
|
|
ASSERT_EQ(graph, nullptr);
|
|
}
|
|
|
|
TEST_F(TestFlatbufferUtilities, WillNotUnpackInvalidBuffer)
|
|
{
|
|
auto arr = std::array<uint8_t, 10>{0};
|
|
auto [buffer, size] = std::make_pair(arr.data(), size_t(10));
|
|
|
|
std::unique_ptr<hipdnn_flatbuffers_sdk::data_objects::GraphT> graph;
|
|
ASSERT_THROW_HIPDNN_STATUS(
|
|
flatbuffer_utilities::convertSerializedGraphToGraph(buffer, size, graph),
|
|
HIPDNN_STATUS_BAD_PARAM);
|
|
ASSERT_EQ(graph, nullptr);
|
|
}
|
|
|
|
TEST_F(TestFlatbufferUtilities, WillNotUnpackWrongSizeBuffer)
|
|
{
|
|
auto builder = createValidGraph();
|
|
auto serializedGraph = builder.Release();
|
|
auto [buffer, size] = std::make_pair(serializedGraph.data(), serializedGraph.size() - 20);
|
|
|
|
std::unique_ptr<hipdnn_flatbuffers_sdk::data_objects::GraphT> graph;
|
|
ASSERT_THROW_HIPDNN_STATUS(
|
|
flatbuffer_utilities::convertSerializedGraphToGraph(buffer, size, graph),
|
|
HIPDNN_STATUS_BAD_PARAM);
|
|
ASSERT_EQ(graph, nullptr);
|
|
}
|
|
|
|
} // namespace testing
|
|
} // namespace hipdnn_backend
|