Files
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

151 lines
4.3 KiB
C++

// Copyright © Advanced Micro Devices, Inc., or its affiliates.
// SPDX-License-Identifier: MIT
/**
* @file ReductionAttributes.hpp
* @brief Attributes for reduction operations
*
* This file defines the ReductionAttributes class for configuring reduction
* operations that reduce a tensor along all dimensions.
*/
#pragma once
#include "Attributes.hpp"
#include "TensorAttributes.hpp"
#include <hipdnn_frontend/Types.hpp>
#include <memory>
#include <optional>
#include <unordered_map>
namespace hipdnn_frontend::graph
{
/**
* @class ReductionAttributes
* @brief Configuration for reduction operations
*
* ReductionAttributes specifies the parameters for reduction operations that
* reduce an input tensor to a scalar or lower-dimensional tensor.
*
* @code{.cpp}
* // Sum reduction
* auto y = graph.reduction(x, ReductionAttributes()
* .set_mode(ReductionMode::ADD));
*
* // Absolute maximum reduction
* auto y = graph.reduction(x, ReductionAttributes()
* .set_mode(ReductionMode::AMAX)
* .set_name("amax_op"));
* @endcode
*
* @see Graph::reduction(), ReductionMode
*/
class ReductionAttributes : public Attributes<ReductionAttributes>
{
public:
ReductionAttributes() = default;
/// Input tensor identifiers
// NOLINTNEXTLINE(readability-identifier-naming)
enum class input_names
{
X = 0, ///< Input tensor
};
/// Output tensor identifiers
// NOLINTNEXTLINE(readability-identifier-naming)
enum class output_names
{
Y = 0, ///< Output tensor
};
std::unordered_map<input_names, std::shared_ptr<TensorAttributes>> inputs; ///< Input tensors
std::unordered_map<output_names, std::shared_ptr<TensorAttributes>> outputs; ///< Output tensors
// NOLINTBEGIN(readability-identifier-naming)
std::optional<ReductionMode> mode = std::nullopt; ///< The reduction mode
bool is_deterministic = false; ///< Whether to use deterministic algorithms
// NOLINTEND(readability-identifier-naming)
/// @brief Get the reduction mode
// NOLINTNEXTLINE(readability-identifier-naming)
std::optional<ReductionMode> get_mode() const
{
return mode;
}
/**
* @brief Set the reduction operation mode
* @param value The reduction operation to perform (see ReductionMode enum)
* @return Reference to this for method chaining
*/
// NOLINTNEXTLINE(readability-identifier-naming)
ReductionAttributes& set_mode(ReductionMode value)
{
mode = value;
return *this;
}
/// @brief Get whether deterministic algorithms are requested
// NOLINTNEXTLINE(readability-identifier-naming)
bool get_is_deterministic() const
{
return is_deterministic;
}
/**
* @brief Request deterministic reduction algorithms
* @param value True to require deterministic behavior
* @return Reference to this for method chaining
*/
// NOLINTNEXTLINE(readability-identifier-naming)
ReductionAttributes& set_is_deterministic(bool value)
{
is_deterministic = value;
return *this;
}
/// @brief Get the input tensor X
// NOLINTNEXTLINE(readability-identifier-naming)
std::shared_ptr<TensorAttributes> get_x() const
{
return getInput(input_names::X);
}
/// @brief Get the output tensor Y
// NOLINTNEXTLINE(readability-identifier-naming)
std::shared_ptr<TensorAttributes> get_y() const
{
return getOutput(output_names::Y);
}
// NOLINTNEXTLINE(readability-identifier-naming)
ReductionAttributes& set_x(const std::shared_ptr<TensorAttributes>& x)
{
return setInput(input_names::X, x);
}
// NOLINTNEXTLINE(readability-identifier-naming)
ReductionAttributes& set_x(std::shared_ptr<TensorAttributes>&& x)
{
return setInput(input_names::X, std::move(x));
}
// NOLINTNEXTLINE(readability-identifier-naming)
ReductionAttributes& set_y(const std::shared_ptr<TensorAttributes>& y)
{
return setOutput(output_names::Y, y);
}
// NOLINTNEXTLINE(readability-identifier-naming)
ReductionAttributes& set_y(std::shared_ptr<TensorAttributes>&& y)
{
return setOutput(output_names::Y, std::move(y));
}
};
typedef ReductionAttributes Reduction_attributes; // NOLINT(readability-identifier-naming)
} // namespace hipdnn_frontend::graph