Files
TheRock/rocm-libraries/projects/miopen/test/gtest/api_convbiasactiv.cpp
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

207 lines
8.9 KiB
C++

/*******************************************************************************
*
* MIT License
*
* Copyright (c) 2022 Advanced Micro Devices, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*******************************************************************************/
#include <miopen/miopen.h>
#define WORKAROUND_ISSUE_2212 1
#if MIOPEN_BACKEND_HIP
#include <gtest/gtest.h>
#include <miopen/miopen.h>
#include <miopen/solver_id.hpp>
#include <serialize.hpp>
#include <fusionHost.hpp>
#include "tensor_util.hpp"
#include "get_handle.hpp"
#include "gtest_common.hpp"
struct CBATestCase
{
size_t N;
size_t C;
size_t H;
size_t W;
size_t k;
size_t y;
size_t x;
size_t pad_x;
size_t pad_y;
size_t stride_x;
size_t stride_y;
size_t dialtion_x;
size_t dilation_y;
miopenActivationMode_t activ_mode;
miopenConvolutionMode_t conv_mode;
friend std::ostream& operator<<(std::ostream& os, const CBATestCase& tc)
{
return os << "N: " << tc.N << " C:" << tc.C << " H:" << tc.H << " W:" << tc.W
<< " k: " << tc.k << " y:" << tc.y << " x:" << tc.x << " pad_y:" << tc.pad_y
<< " pad_x:" << tc.pad_x << " stride_y:" << tc.stride_y
<< " dilation_y:" << tc.dilation_y << " activ_mode:" << tc.activ_mode
<< " conv_mode:" << tc.conv_mode;
}
};
bool IsTestSupportedForDevice()
{
#if WORKAROUND_ISSUE_2212
using namespace miopen::debug;
using e_mask = enabled<Gpu::gfx900, Gpu::gfx906, Gpu::gfx908, Gpu::gfx90A, Gpu::gfx103X>;
using d_mask = disabled<Gpu::gfx94X, Gpu::gfx110X, Gpu::gfx115X>;
return ::IsTestSupportedForDevMask<d_mask, e_mask>();
#else
return true;
#endif
}
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(GPU_ConvBiasActivFwd_FP32);
struct GPU_ConvBiasActivFwd_FP32
: public ::testing::TestWithParam<std::tuple<miopenConvFwdAlgorithm_t, CBATestCase>>
{
protected:
void SetUp() override
{
if(!IsTestSupportedForDevice())
{
GTEST_SKIP();
}
std::tie(algo, cba_config) = GetParam();
const double double_zero = 0.0f;
input = tensor<float>{cba_config.N, cba_config.C, cba_config.H, cba_config.W};
weights = tensor<float>{cba_config.k, cba_config.C, cba_config.x, cba_config.y};
input.generate(tensor_elem_gen_integer{17});
weights.generate(tensor_elem_gen_integer{17});
miopenCreateConvolutionDescriptor(&conv_desc);
miopenCreateActivationDescriptor(&activ_desc);
miopenSetActivationDescriptor(
activ_desc, cba_config.activ_mode, double_zero, double_zero, double_zero);
miopenInitConvolutionDescriptor(conv_desc,
cba_config.conv_mode,
cba_config.pad_y,
cba_config.pad_x,
cba_config.stride_y,
cba_config.stride_x,
cba_config.dilation_y,
cba_config.dialtion_x);
int n, c, h, w;
miopenGetConvolutionForwardOutputDim(conv_desc, &input.desc, &weights.desc, &n, &c, &h, &w);
output = tensor<float>{static_cast<size_t>(n),
static_cast<size_t>(c),
static_cast<size_t>(h),
static_cast<size_t>(w)};
ref_out = tensor<float>{static_cast<size_t>(n),
static_cast<size_t>(c),
static_cast<size_t>(h),
static_cast<size_t>(w)};
bias = tensor<float>{1, static_cast<size_t>(c), 1, 1};
bias.generate(tensor_elem_gen_integer{17});
std::fill(output.begin(), output.end(), 0.0f);
std::fill(ref_out.begin(), ref_out.end(), 0.0f);
std::fill(bias.begin(), bias.end(), 0.0f);
auto&& handle = get_handle();
in_dev = handle.Write(input.data);
wei_dev = handle.Write(weights.data);
out_dev = handle.Write(output.data);
bias_dev = handle.Write(bias.data);
}
void TearDown() override
{
const double double_zero = 0.0f;
int bias_mode = 1; // zero disables bias
convHostForward(input, ref_out, weights, bias_mode, bias, conv_desc);
activationHostInfer(cba_config.activ_mode,
double_zero,
double_zero,
double_zero,
ref_out.data,
ref_out.data);
auto&& handle = get_handle();
output.data = handle.Read<float>(out_dev, output.data.size());
EXPECT_FALSE(miopen::range_zero(ref_out)) << "Cpu data is all zeros";
EXPECT_FALSE(miopen::range_zero(output)) << "Gpu data is all zeros";
const auto mxdiff = miopen::max_diff(output, ref_out);
std::ignore = mxdiff;
auto idx = miopen::mismatch_idx(ref_out, output, miopen::float_equal);
EXPECT_FALSE(miopen::find_idx(ref_out, miopen::not_finite) >= 0)
<< "Non finite number found in the CPU data";
EXPECT_FALSE(idx < miopen::range_distance(ref_out));
miopenDestroyConvolutionDescriptor(conv_desc);
miopenDestroyActivationDescriptor(activ_desc);
}
CBATestCase cba_config;
miopenConvolutionDescriptor_t conv_desc;
miopenActivationDescriptor_t activ_desc;
tensor<float> input;
tensor<float> weights;
tensor<float> output;
tensor<float> bias;
tensor<float> ref_out;
miopen::Allocator::ManageDataPtr in_dev;
miopen::Allocator::ManageDataPtr wei_dev;
miopen::Allocator::ManageDataPtr out_dev;
miopen::Allocator::ManageDataPtr bias_dev;
miopenConvFwdAlgorithm_t algo = miopenConvolutionFwdAlgoDirect;
};
TEST_P(GPU_ConvBiasActivFwd_FP32, DISABLED_DriveAPI)
{
tensor<float> z{};
const float alpha = 1.0f;
const auto status = miopenConvolutionBiasActivationForward(&get_handle(),
&alpha,
&input.desc,
in_dev.get(),
&weights.desc,
wei_dev.get(),
conv_desc,
algo,
nullptr,
0,
&alpha,
&z.desc,
nullptr,
&bias.desc,
bias_dev.get(),
activ_desc,
&output.desc,
out_dev.get());
EXPECT_EQ(status, miopenStatusSuccess);
}
// Extra layer of indirection introduced since GTEST_SKIP() cannot be called from non-void function.
std::vector<CBATestCase> GetTestValues()
{
return {
{16, 128, 16, 16, 128, 3, 3, 0, 0, 1, 1, 1, 1, miopenActivationRELU, miopenConvolution}};
}
INSTANTIATE_TEST_SUITE_P(Full,
GPU_ConvBiasActivFwd_FP32,
testing::Combine(testing::Values(miopenConvolutionFwdAlgoDirect,
miopenConvolutionFwdAlgoWinograd),
testing::ValuesIn(GetTestValues())));
#endif