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

204 lines
8.2 KiB
C++

// Copyright © Advanced Micro Devices, Inc., or its affiliates.
// SPDX-License-Identifier: MIT
#pragma once
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <hipdnn_flatbuffers_sdk/data_objects/batchnorm_attributes_generated.h>
#include <hipdnn_flatbuffers_sdk/data_objects/batchnorm_backward_attributes_generated.h>
#include <hipdnn_flatbuffers_sdk/data_objects/batchnorm_inference_attributes_generated.h>
#include <hipdnn_flatbuffers_sdk/data_objects/batchnorm_inference_attributes_variance_ext_generated.h>
#include <hipdnn_flatbuffers_sdk/data_objects/pointwise_attributes_generated.h>
#include <hipdnn_flatbuffers_sdk/data_objects/tensor_attributes_generated.h>
namespace miopen_plugin
{
// --- Tensor Descriptor Value Object ---
struct BatchnormTensorDescriptor
{
std::vector<int64_t> dims;
std::vector<int64_t> strides;
std::vector<int64_t> strideOrder;
explicit BatchnormTensorDescriptor(
const hipdnn_flatbuffers_sdk::data_objects::TensorAttributes* attr);
size_t numDims() const
{
return dims.size();
}
bool isPacked() const;
};
// --- Validation Utilities ---
namespace validators
{
void validateDimensionCount(size_t numDims);
void validateConsistentDimensions(const std::vector<BatchnormTensorDescriptor>& tensors);
void validatePackedTensors(const std::vector<BatchnormTensorDescriptor>& tensors);
void validateSupportedLayout(const std::vector<int64_t>& strideOrder, size_t numDims);
void validateConsistentLayouts(const std::vector<BatchnormTensorDescriptor>& tensors);
void validateDataTypeIsSupported(
hipdnn_flatbuffers_sdk::data_objects::DataType dataType,
const std::unordered_set<hipdnn_flatbuffers_sdk::data_objects::DataType>& allowedTypes,
const std::string& errorMessage);
void validateConsistentDataTypes(
const std::vector<int64_t>& tensorIds,
const std::unordered_map<int64_t,
const hipdnn_flatbuffers_sdk::data_objects::TensorAttributes*>&
tensorMap,
const std::unordered_set<hipdnn_flatbuffers_sdk::data_objects::DataType>& allowedTypes,
const std::string& typeErrorMessage,
const std::string& consistencyErrorMessage);
void validateFixedDataType(
const std::vector<int64_t>& tensorIds,
const std::unordered_map<int64_t,
const hipdnn_flatbuffers_sdk::data_objects::TensorAttributes*>&
tensorMap,
hipdnn_flatbuffers_sdk::data_objects::DataType expectedType,
const std::string& errorMessage);
void validateConsistentShapes(
const std::vector<int64_t>& tensorIds,
const std::unordered_map<int64_t,
const hipdnn_flatbuffers_sdk::data_objects::TensorAttributes*>&
tensorMap,
const std::vector<int64_t>& referenceShape,
const std::string& errorMessage);
void validateSpatialDimensions(const std::vector<int64_t>& ioDims);
} // namespace validators
// --- Component Validators ---
void checkTensorLayoutsAndDimsSupported(
const std::unordered_map<int64_t,
const hipdnn_flatbuffers_sdk::data_objects::TensorAttributes*>&
tensorMap);
void checkTensorDataTypesSupported(
const std::vector<int64_t>& ioTensorIds,
const std::vector<int64_t>& affineTensorIds,
const std::vector<int64_t>& statTensorIds,
const std::vector<int64_t>& intermediateTensorIds,
const std::unordered_map<int64_t,
const hipdnn_flatbuffers_sdk::data_objects::TensorAttributes*>&
tensorMap);
void checkTensorShapesSupported(
const std::vector<int64_t>& ioTensorIds,
const std::vector<int64_t>& affineTensorIds,
const std::vector<int64_t>& statTensorIds,
const std::unordered_map<int64_t,
const hipdnn_flatbuffers_sdk::data_objects::TensorAttributes*>&
tensorMap,
bool isTraining);
// --- High-Level Configuration Validators ---
void checkBatchnormInferenceTensorConfigSupported(
const hipdnn_flatbuffers_sdk::data_objects::BatchnormInferenceAttributes& bnInfAttr,
const std::unordered_map<int64_t,
const hipdnn_flatbuffers_sdk::data_objects::TensorAttributes*>&
tensorMap);
void checkBatchnormInferenceVarianceExtTensorConfigSupported(
const hipdnn_flatbuffers_sdk::data_objects::BatchnormInferenceAttributesVarianceExt& bnInfAttr,
const std::unordered_map<int64_t,
const hipdnn_flatbuffers_sdk::data_objects::TensorAttributes*>&
tensorMap);
void checkBatchnormInferenceVarianceExtActivationTensorConfigSupported(
const hipdnn_flatbuffers_sdk::data_objects::BatchnormInferenceAttributesVarianceExt& bnInfAttr,
const hipdnn_flatbuffers_sdk::data_objects::PointwiseAttributes& actAttr,
const std::unordered_map<int64_t,
const hipdnn_flatbuffers_sdk::data_objects::TensorAttributes*>&
tensorMap);
void checkBatchnormInferenceActivationTensorConfigSupported(
const hipdnn_flatbuffers_sdk::data_objects::BatchnormInferenceAttributes& bnInfAttr,
const hipdnn_flatbuffers_sdk::data_objects::PointwiseAttributes& actAttr,
const std::unordered_map<int64_t,
const hipdnn_flatbuffers_sdk::data_objects::TensorAttributes*>&
tensorMap);
void checkBatchnormFwdTrainingTensorConfigSupported(
const hipdnn_flatbuffers_sdk::data_objects::BatchnormAttributes& bnAttr,
const std::unordered_map<int64_t,
const hipdnn_flatbuffers_sdk::data_objects::TensorAttributes*>&
tensorMap);
void checkBatchnormFwdTrainingActivationTensorConfigSupported(
const hipdnn_flatbuffers_sdk::data_objects::BatchnormAttributes& bnAttr,
const hipdnn_flatbuffers_sdk::data_objects::PointwiseAttributes& actAttr,
const std::unordered_map<int64_t,
const hipdnn_flatbuffers_sdk::data_objects::TensorAttributes*>&
tensorMap);
void checkBatchnormBackwardTensorConfigSupported(
const hipdnn_flatbuffers_sdk::data_objects::BatchnormBackwardAttributes& bnBwdAttr,
const std::unordered_map<int64_t,
const hipdnn_flatbuffers_sdk::data_objects::TensorAttributes*>&
tensorMap);
void checkBatchnormInferenceActivationBackwardTensorConfigSupported(
const hipdnn_flatbuffers_sdk::data_objects::BatchnormInferenceAttributes& bnInfAttr,
const hipdnn_flatbuffers_sdk::data_objects::PointwiseAttributes& actAttr,
const hipdnn_flatbuffers_sdk::data_objects::BatchnormBackwardAttributes& bnBwdAttr,
const std::unordered_map<int64_t,
const hipdnn_flatbuffers_sdk::data_objects::TensorAttributes*>&
tensorMap);
void checkBatchnormFwdActivationModeSupported(
const hipdnn_flatbuffers_sdk::data_objects::PointwiseAttributes& activAttr);
void checkBatchnormBwdActivationModeSupported(
const hipdnn_flatbuffers_sdk::data_objects::PointwiseAttributes& activAttr);
// --- Batchnorm Type Configuration ---
// MIOpen v6.x requirements:
// - IO tensors: same type (FLOAT, HALF, or BFLOAT16)
// - Affine/Stat/Intermediate tensors: FLOAT only
struct BnTensorTypes
{
hipdnn_flatbuffers_sdk::data_objects::DataType io;
hipdnn_flatbuffers_sdk::data_objects::DataType affine;
hipdnn_flatbuffers_sdk::data_objects::DataType stat;
hipdnn_flatbuffers_sdk::data_objects::DataType intermediate;
};
namespace bn_type_configs
{
using DT = hipdnn_flatbuffers_sdk::data_objects::DataType;
inline constexpr BnTensorTypes ALL_FLOAT = {DT::FLOAT, DT::FLOAT, DT::FLOAT, DT::FLOAT};
inline constexpr BnTensorTypes HALF_IO = {DT::HALF, DT::FLOAT, DT::FLOAT, DT::FLOAT};
inline constexpr BnTensorTypes BFLOAT16_IO = {DT::BFLOAT16, DT::FLOAT, DT::FLOAT, DT::FLOAT};
inline constexpr std::array<BnTensorTypes, 3> VALID = {ALL_FLOAT, HALF_IO, BFLOAT16_IO};
std::unordered_set<hipdnn_flatbuffers_sdk::data_objects::DataType> getAllowedIoTypes();
std::unordered_set<hipdnn_flatbuffers_sdk::data_objects::DataType> getAllowedAffineTypes();
std::unordered_set<hipdnn_flatbuffers_sdk::data_objects::DataType> getAllowedStatTypes();
std::unordered_set<hipdnn_flatbuffers_sdk::data_objects::DataType> getAllowedIntermediateTypes();
} // namespace bn_type_configs
} // namespace miopen_plugin