mirror of
https://github.com/ROCm/composable_kernel.git
synced 2026-05-12 17:26:00 +00:00
* Convolution ND * Code unification across dimensions for generating tensor descriptors. * Example * Instances * Move convnd f32 instance file to comply with repo structure. * Conv 1D tensor layouts. * Formatting and use ReferenceConv * Reference ConvFwd supporting 1D and 2D convolution. * Debug printing TensorLayout name. * Conv fwd 1D instance f32 * Refactor conv ND example. Needed to support various conv dimensio. Needed to support various conv dimensions * Rename conv nd example director to prevent conflicts. * Refactor some common utility to single file. Plus some tests. * Refactor GetHostTensorDescriptor + UT. * Add 1D test case. * Test reference convolution 1d/2d * Remove some leftovers. * Fix convolution example error for 1D * Refactor test check errors utility function. * Test Conv2D Fwd XDL * More UT for 1D case. * Parameterize input & weight initializers. * Rename example to prevent conflicts. * Split convnd instance into separate files for 1d/2d * Address review comments. * Fix data type for flops/gbytes calculations. * Assign example number 11. Co-authored-by: Adam Osewski <aosewski@amd.com> Co-authored-by: Chao Liu <chao.liu2@amd.com>
85 lines
2.4 KiB
C++
85 lines
2.4 KiB
C++
#ifndef TEST_UTIL_HPP
|
|
#define TEST_UTIL_HPP
|
|
|
|
#include <cmath>
|
|
#include <cstdlib>
|
|
#include <iostream>
|
|
#include <iomanip>
|
|
#include <limits>
|
|
#include <type_traits>
|
|
#include <vector>
|
|
|
|
namespace test_util {
|
|
|
|
template <typename T>
|
|
typename std::enable_if<std::is_floating_point<T>::value, bool>::type
|
|
check_err(const std::vector<T>& out,
|
|
const std::vector<T>& ref,
|
|
const std::string& msg,
|
|
T rtol = static_cast<T>(1e-5),
|
|
T atol = static_cast<T>(1e-8))
|
|
{
|
|
if(out.size() != ref.size())
|
|
{
|
|
std::cout << "out.size() != ref.size(), :" << out.size() << " != " << ref.size()
|
|
<< std::endl
|
|
<< msg << std::endl;
|
|
return false;
|
|
}
|
|
|
|
bool res{true};
|
|
int err_count = 0;
|
|
T err = 0;
|
|
T max_err = std::numeric_limits<T>::min();
|
|
for(std::size_t i = 0; i < ref.size(); ++i)
|
|
{
|
|
err = std::abs(out[i] - ref[i]);
|
|
if(err > atol + rtol * std::abs(ref[i]) || !std::isfinite(out[i]) || !std::isfinite(ref[i]))
|
|
{
|
|
max_err = err > max_err ? err : max_err;
|
|
err_count++;
|
|
if(err_count < 5)
|
|
{
|
|
std::cout << std::setw(12) << std::setprecision(7) << "out[" << i << "] != ref["
|
|
<< i << "]: " << out[i] << "!=" << ref[i] << std::endl
|
|
<< msg << std::endl;
|
|
}
|
|
res = false;
|
|
}
|
|
}
|
|
if(!res)
|
|
{
|
|
std::cout << std::setw(12) << std::setprecision(7) << "max err: " << max_err << std::endl;
|
|
}
|
|
return res;
|
|
}
|
|
|
|
template <typename T>
|
|
typename std::enable_if<std::is_integral<T>::value, bool>::type check_err(
|
|
const std::vector<T>& out, const std::vector<T>& ref, const std::string& msg, T = 0, T = 0)
|
|
{
|
|
if(out.size() != ref.size())
|
|
{
|
|
std::cout << "out.size() != ref.size(), :" << out.size() << " != " << ref.size()
|
|
<< std::endl
|
|
<< msg << std::endl;
|
|
return false;
|
|
}
|
|
|
|
for(std::size_t i = 0; i < ref.size(); ++i)
|
|
{
|
|
if(out[i] != ref[i])
|
|
{
|
|
std::cout << "out[" << i << "] != ref[" << i << "]: " << out[i] << "!=" << ref[i]
|
|
<< std::endl
|
|
<< msg << std::endl;
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
} // namespace test_util
|
|
|
|
#endif
|