"megatron/data/ict_dataset.py" did not exist on "03feecbca3e28ba8b95f5280fef042dba2e59b65"
host_tensor_generator.hpp 1.21 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>
12
    float operator()(Is... is)
Chao Liu's avatar
Chao Liu committed
13
14
15
16
17
18
19
20
21
22
    {
        return value;
    }
};

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

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

30
template <typename T>
Chao Liu's avatar
Chao Liu committed
31
32
struct GeneratorTensor_3
{
33
34
35
    T min_value = 0;
    T max_value = 1;

zjing14's avatar
zjing14 committed
36
    template <typename... Is>
37
    float operator()(Is...)
Chao Liu's avatar
Chao Liu committed
38
    {
39
        float tmp = float(std::rand()) / float(RAND_MAX);
Chao Liu's avatar
Chao Liu committed
40

41
        return min_value + tmp * (max_value - min_value);
Chao Liu's avatar
Chao Liu committed
42
43
44
45
46
    }
};

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

#endif