host_tensor_generator.hpp 1.27 KB
Newer Older
Chao Liu's avatar
Chao Liu committed
1
2
#ifndef HOST_TENSOR_GENERATOR_HPP
#define HOST_TENSOR_GENERATOR_HPP
Chao Liu's avatar
Chao Liu committed
3

zjing14's avatar
zjing14 committed
4
#include <cmath>
Chao Liu's avatar
Chao Liu committed
5
6
7
8
9
10
#include "config.hpp"

struct GeneratorTensor_1
{
    int value = 1;

zjing14's avatar
zjing14 committed
11
    template <typename... Is>
Chao Liu's avatar
Chao Liu committed
12
13
14
15
16
17
18
19
20
21
22
    double operator()(Is... is)
    {
        return value;
    }
};

struct GeneratorTensor_2
{
    int min_value = 0;
    int max_value = 1;

zjing14's avatar
zjing14 committed
23
    template <typename... Is>
Chao Liu's avatar
Chao Liu committed
24
25
26
27
28
29
30
31
    double operator()(Is...)
    {
        return (std::rand() % (max_value - min_value)) + min_value;
    }
};

struct GeneratorTensor_3
{
zjing14's avatar
zjing14 committed
32
    template <typename... Is>
Chao Liu's avatar
Chao Liu committed
33
34
35
36
37
38
39
40
41
42
43
44
    double operator()(Is... is)
    {
        std::array<ck::index_t, sizeof...(Is)> dims = {{static_cast<ck::index_t>(is)...}};

        auto f_acc = [](auto a, auto b) { return 10 * a + b; };

        return std::accumulate(dims.begin(), dims.end(), ck::index_t(0), f_acc);
    }
};

struct GeneratorTensor_Checkboard
{
zjing14's avatar
zjing14 committed
45
    template <typename... Ts>
Chao Liu's avatar
Chao Liu committed
46
47
    double operator()(Ts... Xs) const
    {
48
        std::array<ck::index_t, sizeof...(Ts)> dims = {{static_cast<ck::index_t>(Xs)...}};
Chao Liu's avatar
Chao Liu committed
49
50
51
52
53
54
55
56
57
58
        return std::accumulate(dims.begin(),
                               dims.end(),
                               true,
                               [](bool init, ck::index_t x) -> int { return init != (x % 2); })
                   ? 1
                   : -1;
    }
};

#endif