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

250 lines
8.7 KiB
C++

// Copyright © Advanced Micro Devices, Inc., or its affiliates.
// SPDX-License-Identifier: MIT
#include <algorithm>
#include <limits>
#include <vector>
#include <hipdnn_plugin_sdk/PluginException.hpp>
#include "MiopenConvDescriptor.hpp"
#include "MiopenUtils.hpp"
namespace miopen_plugin
{
namespace
{
void copyWithCheck(const flatbuffers::Vector<int64_t>* src,
std::vector<int>& dst,
size_t expectedSize,
const char* name,
const char* expectedSizeName)
{
if(src->size() != expectedSize)
{
throw hipdnn_plugin_sdk::HipdnnPluginException(HIPDNN_PLUGIN_STATUS_BAD_PARAM,
"MiopenConvDescriptor: " + std::string(name)
+ " size must be equal to "
+ std::string(expectedSizeName));
}
if(!std::all_of(src->begin(), src->end(), [](int64_t v) {
return v <= std::numeric_limits<int>::max();
}))
{
throw hipdnn_plugin_sdk::HipdnnPluginException(HIPDNN_PLUGIN_STATUS_BAD_PARAM,
"MiopenConvDescriptor: " + std::string(name)
+ " values must be less than INT_MAX");
}
std::copy(src->begin(), src->end(), dst.begin());
}
}
MiopenConvDescriptor::MiopenConvDescriptor(
size_t spatialDimCount,
const hipdnn_flatbuffers_sdk::data_objects::ConvolutionFwdAttributes& attributes,
int groupCount,
bool deterministicEnabled)
{
createDescriptorInternal(spatialDimCount,
attributes.pre_padding(),
attributes.post_padding(),
attributes.stride(),
attributes.dilation(),
attributes.conv_mode(),
groupCount,
deterministicEnabled);
}
MiopenConvDescriptor::MiopenConvDescriptor(
size_t spatialDimCount,
const hipdnn_flatbuffers_sdk::data_objects::ConvolutionBwdAttributes& attributes,
int groupCount,
bool deterministicEnabled)
{
createDescriptorInternal(spatialDimCount,
attributes.pre_padding(),
attributes.post_padding(),
attributes.stride(),
attributes.dilation(),
attributes.conv_mode(),
groupCount,
deterministicEnabled);
}
MiopenConvDescriptor::MiopenConvDescriptor(
size_t spatialDimCount,
const hipdnn_flatbuffers_sdk::data_objects::ConvolutionWrwAttributes& attributes,
int groupCount,
bool deterministicEnabled)
{
createDescriptorInternal(spatialDimCount,
attributes.pre_padding(),
attributes.post_padding(),
attributes.stride(),
attributes.dilation(),
attributes.conv_mode(),
groupCount,
deterministicEnabled);
}
MiopenConvDescriptor::MiopenConvDescriptor(MiopenConvDescriptor&& other) noexcept
: _descriptor(other._descriptor)
{
other._descriptor = nullptr;
}
MiopenConvDescriptor& MiopenConvDescriptor::operator=(MiopenConvDescriptor&& other) noexcept
{
if(this != &other)
{
if(_descriptor != nullptr)
{
LOG_ON_MIOPEN_FAILURE(miopenDestroyConvolutionDescriptor(_descriptor));
}
_descriptor = other._descriptor;
other._descriptor = nullptr;
}
return *this;
}
MiopenConvDescriptor::~MiopenConvDescriptor()
{
if(_descriptor != nullptr)
{
LOG_ON_MIOPEN_FAILURE(miopenDestroyConvolutionDescriptor(_descriptor));
}
}
miopenConvolutionDescriptor_t MiopenConvDescriptor::convDescriptor() const
{
return _descriptor;
}
void MiopenConvDescriptor::createDescriptorInternal(
size_t spatialDimCount,
const flatbuffers::Vector<int64_t>* attrPrePadding,
const flatbuffers::Vector<int64_t>* attrPostPadding,
const flatbuffers::Vector<int64_t>* attrStride,
const flatbuffers::Vector<int64_t>* attrDilation,
hipdnn_flatbuffers_sdk::data_objects::ConvMode convMode,
int groupCount,
bool deterministicEnabled)
{
if(spatialDimCount > std::numeric_limits<int>::max())
{
throw hipdnn_plugin_sdk::HipdnnPluginException(
HIPDNN_PLUGIN_STATUS_BAD_PARAM,
"MiopenConvDescriptor: spatialDimCount must be not greater than INT_MAX");
}
if(convMode != hipdnn_flatbuffers_sdk::data_objects::ConvMode::CROSS_CORRELATION)
{
throw hipdnn_plugin_sdk::HipdnnPluginException(
HIPDNN_PLUGIN_STATUS_BAD_PARAM,
"MiopenConvDescriptor: only ConvMode::CROSS_CORRELATION is supported");
}
if(attrPrePadding == nullptr)
{
throw hipdnn_plugin_sdk::HipdnnPluginException(
HIPDNN_PLUGIN_STATUS_BAD_PARAM, "MiopenConvDescriptor: pre_padding must be set");
}
if(attrPostPadding == nullptr)
{
throw hipdnn_plugin_sdk::HipdnnPluginException(
HIPDNN_PLUGIN_STATUS_BAD_PARAM, "MiopenConvDescriptor: post_padding must be set");
}
if(attrStride == nullptr)
{
throw hipdnn_plugin_sdk::HipdnnPluginException(HIPDNN_PLUGIN_STATUS_BAD_PARAM,
"MiopenConvDescriptor: stride must be set");
}
if(attrDilation == nullptr)
{
throw hipdnn_plugin_sdk::HipdnnPluginException(
HIPDNN_PLUGIN_STATUS_BAD_PARAM, "MiopenConvDescriptor: dilation must be set");
}
if(attrPrePadding->size() != attrPostPadding->size())
{
throw hipdnn_plugin_sdk::HipdnnPluginException(
HIPDNN_PLUGIN_STATUS_BAD_PARAM,
"MiopenConvDescriptor: pre_padding and post_padding sizes must be equal");
}
if(!std::equal(attrPrePadding->begin(), attrPrePadding->end(), attrPostPadding->begin()))
{
throw hipdnn_plugin_sdk::HipdnnPluginException(
HIPDNN_PLUGIN_STATUS_BAD_PARAM,
"MiopenConvDescriptor: asymmetric padding is not supported");
}
if(groupCount < 1)
{
throw hipdnn_plugin_sdk::HipdnnPluginException(
HIPDNN_PLUGIN_STATUS_BAD_PARAM,
"MiopenConvDescriptor: groupCount < 1 is not supported");
}
std::vector<int> padding(spatialDimCount);
std::vector<int> stride(spatialDimCount);
std::vector<int> dilation(spatialDimCount);
copyWithCheck(attrPrePadding, padding, spatialDimCount, "attrPadding", "spatialDimCount");
copyWithCheck(attrStride, stride, spatialDimCount, "attrStride", "spatialDimCount");
copyWithCheck(attrDilation, dilation, spatialDimCount, "attrDilation", "spatialDimCount");
if(!std::all_of(padding.begin(), padding.end(), [](int v) { return v >= 0; }))
{
throw hipdnn_plugin_sdk::HipdnnPluginException(
HIPDNN_PLUGIN_STATUS_BAD_PARAM,
"MiopenConvDescriptor: padding values must be non-negative");
}
if(!std::all_of(stride.begin(), stride.end(), [](int v) { return v > 0; }))
{
throw hipdnn_plugin_sdk::HipdnnPluginException(
HIPDNN_PLUGIN_STATUS_BAD_PARAM, "MiopenConvDescriptor: stride values must be positive");
}
if(!std::all_of(dilation.begin(), dilation.end(), [](int v) { return v > 0; }))
{
throw hipdnn_plugin_sdk::HipdnnPluginException(
HIPDNN_PLUGIN_STATUS_BAD_PARAM,
"MiopenConvDescriptor: dilation values must be positive");
}
THROW_ON_MIOPEN_FAILURE(miopenCreateConvolutionDescriptor(&_descriptor));
try
{
THROW_ON_MIOPEN_FAILURE(miopenInitConvolutionNdDescriptor(_descriptor,
static_cast<int>(spatialDimCount),
padding.data(),
stride.data(),
dilation.data(),
miopenConvolution));
THROW_ON_MIOPEN_FAILURE(miopenSetConvolutionGroupCount(_descriptor, groupCount));
if(deterministicEnabled)
{
THROW_ON_MIOPEN_FAILURE(miopenSetConvolutionAttribute(
_descriptor, MIOPEN_CONVOLUTION_ATTRIB_DETERMINISTIC, 1));
}
}
catch(...)
{
LOG_ON_MIOPEN_FAILURE(miopenDestroyConvolutionDescriptor(_descriptor));
_descriptor = nullptr;
throw;
}
}
}