Files
TheRock/rocm-libraries/projects/hipdnn/tools/DescriptorGenerator/templates/unpacker.hpp.j2
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

195 lines
7.7 KiB
Django/Jinja

// Copyright © Advanced Micro Devices, Inc., or its affiliates.
// SPDX-License-Identifier: MIT
#pragma once
#include <hipdnn_frontend/Types.hpp>
#include <hipdnn_frontend/attributes/{{ op.frontend.effective_attributes_include }}.hpp>
{% if op.data_fields_helper is defined and op.data_fields_helper %}
#include <hipdnn_frontend/detail/{{ op.data_fields_helper.include }}.hpp>
{% endif %}
#include <hipdnn_frontend/detail/DescriptorUnpackHelpers.hpp>
#include <memory>
#include <optional>
#include <unordered_map>
namespace hipdnn_frontend::detail
{
[[nodiscard]] inline Error {{ op.frontend.unpacker_function }}(
hipdnnBackendDescriptor_t opDesc,
std::unordered_map<int64_t, std::shared_ptr<graph::TensorAttributes>>& tensorMap,
graph::{{ op.frontend.attributes_class }}& attributes)
{
{% for tf in op.tensor_fields %}
{% set ft = op.tensor_field_frontend_map.get(tf.name) %}
{% if ft %}
// Unpack {{ ft.name }} tensor
std::shared_ptr<graph::TensorAttributes> {{ ft.camel_name }}Tensor;
{% if tf.required %}
HIPDNN_CHECK_ERROR(unpackAndRegisterTensor(
opDesc, {{ op.operation_attr_prefix }}_{{ tf.attr_suffix }}, tensorMap, {{ ft.camel_name }}Tensor, "{{ op.effective_error_label }} {{ tf.attr_suffix }} tensor"));
attributes.{{ ft.effective_setter_name }}({{ ft.camel_name }}Tensor);
{% else %}
HIPDNN_CHECK_ERROR(unpackOptionalTensor(
opDesc, {{ op.operation_attr_prefix }}_{{ tf.attr_suffix }}, tensorMap, {{ ft.camel_name }}Tensor, "{{ op.effective_error_label }} {{ tf.attr_suffix }} tensor"));
if({{ ft.camel_name }}Tensor)
{
attributes.{{ ft.effective_setter_name }}({{ ft.camel_name }}Tensor);
}
{% endif %}
{% endif %}
{% endfor %}
{% if op.data_fields_helper is defined and op.data_fields_helper %}
// Unpack shared {{ op.data_fields_helper.label }} parameters
HIPDNN_CHECK_ERROR({{ op.data_fields_helper.unpack_function }}(opDesc, attributes, "{{ op.effective_error_label }}"));
{% else %}
{% for df in op.data_fields %}
{% if df.is_vector %}
// Unpack {{ df.name }}
std::vector<int64_t> {{ df.camel_name }};
HIPDNN_CHECK_ERROR(getDescriptorAttrVec(
opDesc, {{ df.attr_name }}, {{ df.camel_name }}, "{{ op.effective_error_label }} {{ df.name }}"));
{% if df.frontend_uses_member_access %}
attributes.{{ df.frontend_member_name }} = std::move({{ df.camel_name }});
{% else %}
attributes.{{ df.frontend_setter_name }}(std::move({{ df.camel_name }}));
{% endif %}
{% elif df.is_mode %}
// Unpack {{ df.name }}
{{ df.test_c_type }} {{ df.camel_name }}{};
HIPDNN_CHECK_ERROR(getDescriptorAttrScalar(opDesc,
{{ df.attr_name }},
{{ df.backend_type }},
{{ df.camel_name }},
"{{ op.effective_error_label }} {{ df.name }}"));
auto [{{ df.camel_name }}Result, {{ df.camel_name }}Err] = {{ df.frontend_inverse_converter }}({{ df.camel_name }});
if({{ df.camel_name }}Err.is_bad())
{
return {{ df.camel_name }}Err;
}
{% if df.frontend_uses_member_access %}
attributes.{{ df.frontend_member_name }} = {{ df.camel_name }}Result;
{% else %}
attributes.{{ df.frontend_setter_name }}({{ df.camel_name }}Result);
{% endif %}
{% elif df.is_enum %}
// Unpack {{ df.name }}
int64_t {{ df.camel_name }}Raw = 0;
HIPDNN_CHECK_ERROR(getDescriptorAttrScalar(opDesc,
{{ df.attr_name }},
HIPDNN_TYPE_INT64,
{{ df.camel_name }}Raw,
"{{ op.effective_error_label }} {{ df.name }}"));
{% if df.frontend_uses_member_access %}
attributes.{{ df.frontend_member_name }} = static_cast<{{ df.cpp_enum }}>({{ df.camel_name }}Raw);
{% else %}
attributes.{{ df.frontend_setter_name }}(static_cast<{{ df.cpp_enum }}>({{ df.camel_name }}Raw));
{% endif %}
{% elif df.is_optional_scalar %}
// Unpack {{ df.name }} (optional)
{
std::optional<{{ df.cpp_type }}> {{ df.camel_name }};
HIPDNN_CHECK_ERROR(getDescriptorAttrOptionalScalar(opDesc,
{{ df.attr_name }},
{{ df.backend_type }},
{{ df.camel_name }},
"{{ op.effective_error_label }} {{ df.name }}"));
if({{ df.camel_name }}.has_value())
{
{% if df.frontend_uses_member_access %}
attributes.{{ df.frontend_member_name }} = *{{ df.camel_name }};
{% else %}
attributes.{{ df.frontend_setter_name }}(*{{ df.camel_name }});
{% endif %}
}
}
{% elif df.is_scalar %}
// Unpack {{ df.name }}
{% if df.type == "scalar_float" %}
float {{ df.camel_name }} = 0.0f;
{% elif df.type == "bool" %}
bool {{ df.camel_name }} = false;
{% else %}
{{ df.cpp_type }} {{ df.camel_name }} = 0;
{% endif %}
HIPDNN_CHECK_ERROR(getDescriptorAttrScalar(opDesc,
{{ df.attr_name }},
{{ df.backend_type }},
{{ df.camel_name }},
"{{ op.effective_error_label }} {{ df.name }}"));
{% if df.frontend_uses_member_access %}
attributes.{{ df.frontend_member_name }} = {{ df.camel_name }};
{% else %}
attributes.{{ df.frontend_setter_name }}({{ df.camel_name }});
{% endif %}
{% endif %}
{% endfor %}
{% if op.has_compute_data_type %}
// Unpack compute data type
auto [dt, dtErr]
= unpackGraphDataType(opDesc, {{ op.compute_data_type_attr }}, "{{ op.effective_error_label }} compute data type");
if(dtErr.is_bad())
{
return dtErr;
}
attributes.set_compute_data_type(dt);
{% endif %}
{% endif %}
{% for edt in op.extra_data_type_fields %}
// Unpack {{ edt.name }}
{
{% if edt.sentinel %}
// Packer omits this attribute when the value is {{ edt.sentinel }}; the
// backend reports count=0 in that case and unpackGraphDataType returns
// DataType::NOT_SET, which is the default we want to keep. Real
// backend failures (descriptor errors, type-conversion failures) still
// propagate via the explicit Err check.
{% endif %}
auto [{{ edt.camel_name }}, {{ edt.camel_name }}Err] = unpackGraphDataType(
opDesc, {{ edt.attr_name }}, "{{ op.effective_error_label }} {{ edt.effective_error_label }}");
if({{ edt.camel_name }}Err.is_bad())
{
return {{ edt.camel_name }}Err;
}
{% if edt.frontend_uses_member_access %}
attributes.{{ edt.frontend_member_name }} = {{ edt.camel_name }};
{% else %}
attributes.{{ edt.frontend_setter_name }}({{ edt.camel_name }});
{% endif %}
}
{% endfor %}
{% for taf in op.tensor_array_fields %}
// Unpack {{ taf.name }} tensor array
{
std::vector<std::shared_ptr<graph::TensorAttributes>> {{ taf.camel_name }}Attrs;
HIPDNN_CHECK_ERROR(unpackAndRegisterTensorArray(
opDesc, {{ taf.attr_name }}, tensorMap, {{ taf.camel_name }}Attrs,
"{{ op.effective_error_label }} {{ taf.name }}"));
if(!{{ taf.camel_name }}Attrs.empty())
{
attributes.{{ taf.frontend_setter_name }}({{ taf.camel_name }}Attrs);
}
}
{% endfor %}
// Unpack operation name
std::string opName;
HIPDNN_CHECK_ERROR(
getDescriptorAttrString(opDesc, HIPDNN_ATTR_OPERATION_NAME_EXT, opName, "operation name"));
attributes.set_name(opName);
return {};
}
} // namespace hipdnn_frontend::detail