mirror of
https://github.com/ROCm/composable_kernel.git
synced 2026-05-12 01:10:17 +00:00
61 lines
1.2 KiB
C++
61 lines
1.2 KiB
C++
#ifndef HOST_TENSOR_GENERATOR_HPP
|
|
#define HOST_TENSOR_GENERATOR_HPP
|
|
|
|
#include <cmath>
|
|
#include "config.hpp"
|
|
|
|
struct GeneratorTensor_1
|
|
{
|
|
int value = 1;
|
|
|
|
template <typename... Is>
|
|
float operator()(Is... is)
|
|
{
|
|
return value;
|
|
}
|
|
};
|
|
|
|
struct GeneratorTensor_2
|
|
{
|
|
int min_value = 0;
|
|
int max_value = 1;
|
|
|
|
template <typename... Is>
|
|
float operator()(Is...)
|
|
{
|
|
return (std::rand() % (max_value - min_value)) + min_value;
|
|
}
|
|
};
|
|
|
|
template <typename T>
|
|
struct GeneratorTensor_3
|
|
{
|
|
T min_value = 0;
|
|
T max_value = 1;
|
|
|
|
template <typename... Is>
|
|
float operator()(Is...)
|
|
{
|
|
float tmp = float(std::rand()) / float(RAND_MAX);
|
|
|
|
return min_value + tmp * (max_value - min_value);
|
|
}
|
|
};
|
|
|
|
struct GeneratorTensor_Checkboard
|
|
{
|
|
template <typename... Ts>
|
|
float operator()(Ts... Xs) const
|
|
{
|
|
std::array<ck::index_t, sizeof...(Ts)> dims = {{static_cast<ck::index_t>(Xs)...}};
|
|
return std::accumulate(dims.begin(),
|
|
dims.end(),
|
|
true,
|
|
[](bool init, ck::index_t x) -> int { return init != (x % 2); })
|
|
? 1
|
|
: -1;
|
|
}
|
|
};
|
|
|
|
#endif
|