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
152 lines
4.3 KiB
C++
152 lines
4.3 KiB
C++
// Copyright © Advanced Micro Devices, Inc., or its affiliates.
|
|
// SPDX-License-Identifier: MIT
|
|
#pragma once
|
|
|
|
#include "Node.hpp"
|
|
#include <hipdnn_frontend/Error.hpp>
|
|
#include <hipdnn_frontend/attributes/CustomOpAttributes.hpp>
|
|
#include <hipdnn_frontend/attributes/GraphAttributes.hpp>
|
|
#include <hipdnn_frontend/detail/CustomOpPacker.hpp>
|
|
#include <hipdnn_frontend/detail/CustomOpUnpacker.hpp>
|
|
|
|
namespace hipdnn_frontend::graph
|
|
{
|
|
class CustomOpNode : public INode
|
|
{
|
|
public:
|
|
CustomOpAttributes attributes;
|
|
|
|
CustomOpNode(CustomOpAttributes&& customOpAttributes, const GraphAttributes& graphAttrs)
|
|
: INode(graphAttrs)
|
|
, attributes(std::move(customOpAttributes))
|
|
{
|
|
}
|
|
|
|
Error unpack_from_descriptor(
|
|
hipdnnBackendDescriptor_t opDesc,
|
|
std::unordered_map<int64_t, std::shared_ptr<TensorAttributes>>& tensorMap) override
|
|
{
|
|
CustomOpAttributes customOpAttr;
|
|
HIPDNN_CHECK_ERROR(detail::unpackCustomOpOperation(opDesc, tensorMap, customOpAttr));
|
|
attributes = std::move(customOpAttr);
|
|
return {};
|
|
}
|
|
|
|
NodeType getNodeType() const override
|
|
{
|
|
return NodeType::CUSTOM_OP;
|
|
}
|
|
|
|
std::string getNodeName() const override
|
|
{
|
|
return attributes.get_name();
|
|
}
|
|
|
|
void gather_hipdnn_tensors(
|
|
std::unordered_set<std::shared_ptr<TensorAttributes>>& allTensors) const override
|
|
{
|
|
for(const auto& tensor : attributes.inputs)
|
|
{
|
|
if(tensor)
|
|
{
|
|
allTensors.insert(tensor);
|
|
}
|
|
}
|
|
|
|
for(const auto& tensor : attributes.outputs)
|
|
{
|
|
if(tensor)
|
|
{
|
|
allTensors.insert(tensor);
|
|
}
|
|
}
|
|
}
|
|
|
|
std::vector<std::shared_ptr<TensorAttributes>> getNodeInputTensorAttributes() const override
|
|
{
|
|
std::vector<std::shared_ptr<TensorAttributes>> result;
|
|
for(const auto& tensor : attributes.inputs)
|
|
{
|
|
if(tensor)
|
|
{
|
|
result.push_back(tensor);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
std::vector<std::shared_ptr<TensorAttributes>> getNodeOutputTensorAttributes() const override
|
|
{
|
|
std::vector<std::shared_ptr<TensorAttributes>> result;
|
|
for(const auto& tensor : attributes.outputs)
|
|
{
|
|
if(tensor)
|
|
{
|
|
result.push_back(tensor);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
Error pre_validate_node() const override
|
|
{
|
|
for(size_t i = 0; i < attributes.inputs.size(); ++i)
|
|
{
|
|
if(!attributes.inputs[i])
|
|
{
|
|
return {ErrorCode::INVALID_VALUE,
|
|
"Node " + attributes.name + " has null input tensor at index "
|
|
+ std::to_string(i)};
|
|
}
|
|
}
|
|
|
|
for(size_t i = 0; i < attributes.outputs.size(); ++i)
|
|
{
|
|
if(!attributes.outputs[i])
|
|
{
|
|
return {ErrorCode::INVALID_VALUE,
|
|
"Node " + attributes.name + " has null output tensor at index "
|
|
+ std::to_string(i)};
|
|
}
|
|
}
|
|
|
|
return {ErrorCode::OK, ""};
|
|
}
|
|
|
|
Error infer_properties_node() override
|
|
{
|
|
HIPDNN_CHECK_ERROR(attributes.fill_from_context(graph_attributes));
|
|
return {};
|
|
}
|
|
|
|
Error post_validate_node() const override
|
|
{
|
|
if(attributes.custom_op_id.empty())
|
|
{
|
|
return {ErrorCode::ATTRIBUTE_NOT_SET,
|
|
"Node " + attributes.name + " does not have a custom_op_id set"};
|
|
}
|
|
|
|
if(attributes.compute_data_type == DataType::NOT_SET)
|
|
{
|
|
return {ErrorCode::ATTRIBUTE_NOT_SET,
|
|
"Node " + attributes.name + " does not have a compute_data_type set"};
|
|
}
|
|
|
|
for(const auto& tensorAttr : getNodeOutputTensorAttributes())
|
|
{
|
|
HIPDNN_CHECK_ERROR(tensorAttr->validate());
|
|
}
|
|
|
|
return {ErrorCode::OK, ""};
|
|
}
|
|
|
|
Error create_operation(
|
|
std::unordered_map<int64_t, detail::ScopedHipdnnBackendDescriptor>& tensorDescs,
|
|
std::vector<detail::ScopedHipdnnBackendDescriptor>& operations) const override
|
|
{
|
|
return detail::createCustomOpOperation(attributes, tensorDescs, operations);
|
|
}
|
|
};
|
|
} // namespace hipdnn_frontend::graph
|