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
100 lines
3.5 KiB
C++
100 lines
3.5 KiB
C++
// Copyright © Advanced Micro Devices, Inc., or its affiliates.
|
|
// SPDX-License-Identifier: MIT
|
|
#pragma once
|
|
|
|
#include <miopen/miopen.h>
|
|
|
|
#include <vector>
|
|
|
|
// RAII wrapper for MIOpen descriptor types to prevent memory leaks.
|
|
// Template parameters:
|
|
// DescType - the descriptor handle type (e.g. miopenTensorDescriptor_t)
|
|
// CreateFn - function that allocates the descriptor
|
|
// DestroyFn - function that frees the descriptor
|
|
template <typename DescType,
|
|
miopenStatus_t (*CreateFn)(DescType*),
|
|
miopenStatus_t (*DestroyFn)(DescType)>
|
|
class DescGuard
|
|
{
|
|
public:
|
|
DescGuard() : status(CreateFn(&desc)) {}
|
|
|
|
~DescGuard()
|
|
{
|
|
if(desc != nullptr)
|
|
DestroyFn(desc);
|
|
}
|
|
|
|
operator DescType() { return desc; }
|
|
|
|
DescType get() { return desc; }
|
|
miopenStatus_t getStatus() const { return status; }
|
|
|
|
DescGuard(const DescGuard&) = delete;
|
|
DescGuard& operator=(const DescGuard&) = delete;
|
|
DescGuard(DescGuard&&) = delete;
|
|
DescGuard& operator=(DescGuard&&) = delete;
|
|
|
|
private:
|
|
DescType desc = nullptr;
|
|
miopenStatus_t status;
|
|
};
|
|
|
|
using TensorDescGuard = DescGuard<miopenTensorDescriptor_t,
|
|
miopenCreateTensorDescriptor,
|
|
miopenDestroyTensorDescriptor>;
|
|
|
|
using ConvDescGuard = DescGuard<miopenConvolutionDescriptor_t,
|
|
miopenCreateConvolutionDescriptor,
|
|
miopenDestroyConvolutionDescriptor>;
|
|
|
|
using DropoutDescGuard = DescGuard<miopenDropoutDescriptor_t,
|
|
miopenCreateDropoutDescriptor,
|
|
miopenDestroyDropoutDescriptor>;
|
|
|
|
using RNNDescGuard =
|
|
DescGuard<miopenRNNDescriptor_t, miopenCreateRNNDescriptor, miopenDestroyRNNDescriptor>;
|
|
|
|
// Frees the internal DropoutDescriptor allocated by miopen::RNNDescriptor's
|
|
// default and 8-arg constructors. The library has no destructor for this
|
|
// field, so any test that creates an RNN descriptor and then calls
|
|
// miopenSetRNNDescriptor[_V2] on it must invoke this helper:
|
|
// 1. Before each Set* call (frees the default-allocated internal one).
|
|
// 2. After the run, only when no user-supplied DropoutDescriptor was passed
|
|
// via the _V2 path (in that path the internal pointer aliases the
|
|
// user-owned descriptor — freeing it would double-free).
|
|
inline void DestroyInternalRnnDropoutDesc(miopenRNNDescriptor_t rnnDesc)
|
|
{
|
|
miopenDropoutDescriptor_t dropDesc = nullptr;
|
|
miopenGetRNNDescriptor_V2(
|
|
rnnDesc, nullptr, nullptr, &dropDesc, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
|
|
if(dropDesc != nullptr)
|
|
miopenDestroyDropoutDescriptor(dropDesc);
|
|
}
|
|
|
|
// Owns a vector of miopenTensorDescriptor_t handles and destroys them on scope exit,
|
|
// so an ASSERT_* failure mid-test does not leak descriptors.
|
|
class TensorDescVecGuard
|
|
{
|
|
public:
|
|
TensorDescVecGuard() = default;
|
|
~TensorDescVecGuard()
|
|
{
|
|
for(auto* d : descs)
|
|
{
|
|
if(d != nullptr)
|
|
miopenDestroyTensorDescriptor(d);
|
|
}
|
|
}
|
|
|
|
TensorDescVecGuard(const TensorDescVecGuard&) = delete;
|
|
TensorDescVecGuard& operator=(const TensorDescVecGuard&) = delete;
|
|
TensorDescVecGuard(TensorDescVecGuard&&) = delete;
|
|
TensorDescVecGuard& operator=(TensorDescVecGuard&&) = delete;
|
|
|
|
miopenTensorDescriptor_t* data() { return descs.data(); }
|
|
miopenTensorDescriptor_t& operator[](std::size_t i) { return descs[i]; }
|
|
|
|
std::vector<miopenTensorDescriptor_t> descs;
|
|
};
|