mirror of
https://github.com/ROCm/composable_kernel.git
synced 2026-04-20 06:49:15 +00:00
Batchnorm inference instances, external API, client examples and gtests (#531)
* File renaming and class renaming for device element-wise operation * Add batchnorm-infer instances, external API and client example * Add batchnorm-infer profiler module and gtests * Remove file device_elementwise_extension.hpp and move NormalizeInInfer operation to element_wise_operation.hpp * Remove the using of class aliasing for DeviceElementwiseForBatchNormInfer * Rename class and file due to conflict from device_elementwise_2d.hpp * Fix namespace in batcnnorm_infer_nhwc client example
This commit is contained in:
89
test/batchnorm/batchnorm_infer_rank_4.cpp
Normal file
89
test/batchnorm/batchnorm_infer_rank_4.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved.
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <initializer_list>
|
||||
#include <vector>
|
||||
#include <tuple>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "profiler/profile_batchnorm_infer_impl.hpp"
|
||||
|
||||
using F16 = ck::half_t;
|
||||
using F32 = float;
|
||||
using BF16 = ck::bhalf_t;
|
||||
using F64 = double;
|
||||
|
||||
template <typename Tuple>
|
||||
class TestBatchNormInferRank4 : public ::testing::Test
|
||||
{
|
||||
private:
|
||||
const double epsilon = std::numeric_limits<float>::epsilon();
|
||||
|
||||
protected:
|
||||
using XDataType = std::tuple_element_t<0, Tuple>;
|
||||
using YDataType = std::tuple_element_t<1, Tuple>;
|
||||
using AccDataType = std::tuple_element_t<2, Tuple>;
|
||||
using ScaleDataType = std::tuple_element_t<3, Tuple>;
|
||||
using BiasDataType = std::tuple_element_t<4, Tuple>;
|
||||
using MeanVarDataType = std::tuple_element_t<5, Tuple>;
|
||||
|
||||
std::vector<std::vector<size_t>> list_of_lengths = {
|
||||
{128, 16, 3, 1024}, {128, 16, 6, 512}, {4, 4, 4, 4}, {32, 32, 32, 32}};
|
||||
std::vector<int> reduceDims;
|
||||
|
||||
template <int NumReduceDim>
|
||||
void Run()
|
||||
{
|
||||
for(auto& inOutLengths : list_of_lengths)
|
||||
{
|
||||
bool pass = true;
|
||||
|
||||
EXPECT_FALSE(reduceDims.size() != NumReduceDim);
|
||||
|
||||
pass = pass && ck::profiler::profile_batchnorm_infer_impl<XDataType,
|
||||
YDataType,
|
||||
AccDataType,
|
||||
ScaleDataType,
|
||||
BiasDataType,
|
||||
MeanVarDataType,
|
||||
4,
|
||||
NumReduceDim>(
|
||||
true, 3, false, false, inOutLengths, reduceDims, epsilon);
|
||||
|
||||
pass = pass && ck::profiler::profile_batchnorm_infer_impl<XDataType,
|
||||
YDataType,
|
||||
AccDataType,
|
||||
ScaleDataType,
|
||||
BiasDataType,
|
||||
MeanVarDataType,
|
||||
4,
|
||||
NumReduceDim>(
|
||||
true, 3, false, false, inOutLengths, reduceDims, epsilon);
|
||||
|
||||
EXPECT_TRUE(pass);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
using KernelTypes = ::testing::Types<std::tuple<F16, F16, F32, F16, F16, F32>,
|
||||
std::tuple<F32, F32, F32, F32, F32, F32>,
|
||||
std::tuple<BF16, BF16, F32, BF16, BF16, F32>,
|
||||
std::tuple<F64, F64, F64, F64, F64, F64>>;
|
||||
|
||||
TYPED_TEST_SUITE(TestBatchNormInferRank4, KernelTypes);
|
||||
|
||||
// nhwc
|
||||
TYPED_TEST(TestBatchNormInferRank4, nhwc)
|
||||
{
|
||||
this->reduceDims = {0, 1, 2};
|
||||
this->template Run<3>();
|
||||
}
|
||||
|
||||
// nchw
|
||||
TYPED_TEST(TestBatchNormInferRank4, nchw)
|
||||
{
|
||||
this->reduceDims = {0, 2, 3};
|
||||
this->template Run<3>();
|
||||
}
|
||||
Reference in New Issue
Block a user