verify_args.cpp 3.05 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84

#include <migraphx/verify_args.hpp>

namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {

bool verify_args(const std::string& name,
                 const argument& cpu_arg,
                 const argument& gpu_arg,
                 double tolerance)
{
    bool passed = true;
    visit_all(cpu_arg, gpu_arg)([&](auto cpu, auto gpu) {
        double error;
        passed = verify_range(cpu, gpu, tolerance, &error);
        if(not passed)
        {
            // TODO: Check for nans
            std::cout << "FAILED: " << name << std::endl;
            std::cout << "error: " << error << std::endl;
            if(cpu.size() < 32)
                std::cout << "cpu:" << cpu << std::endl;
            if(gpu.size() < 32)
                std::cout << "gpu:" << gpu << std::endl;
            if(range_zero(cpu))
                std::cout << "Cpu data is all zeros" << std::endl;
            if(range_zero(gpu))
                std::cout << "Gpu data is all zeros" << std::endl;

            auto mxdiff = max_diff(cpu, gpu);
            std::cout << "Max diff: " << mxdiff << std::endl;

            auto idx = mismatch_idx(cpu, gpu, float_equal);
            if(idx < range_distance(cpu))
            {
                std::cout << "Mismatch at " << idx << ": " << cpu[idx] << " != " << gpu[idx]
                          << std::endl;
            }

            auto cpu_nan_idx = find_idx(cpu, not_finite);
            if(cpu_nan_idx >= 0)
                std::cout << "Non finite number found in cpu at " << cpu_nan_idx << ": "
                          << cpu[cpu_nan_idx] << std::endl;

            auto gpu_nan_idx = find_idx(gpu, not_finite);
            if(gpu_nan_idx >= 0)
                std::cout << "Non finite number found in gpu at " << gpu_nan_idx << ": "
                          << gpu[gpu_nan_idx] << std::endl;
            std::cout << std::endl;
        }
        else
        {
            if(range_zero(cpu))
                std::cout << "Cpu data is all zeros" << std::endl;
            if(range_zero(gpu))
                std::cout << "Gpu data is all zeros" << std::endl;

            // auto mxdiff = max_diff(cpu, gpu);
            // std::cout << "Max diff: " << mxdiff << std::endl;

            // auto idx = mismatch_idx(cpu, gpu, float_equal);
            // if(idx < range_distance(cpu))
            // {
            //     std::cout << "Mismatch at " << idx << ": " << cpu[idx] << " != " << gpu[idx]
            //               << std::endl;
            // }

            auto cpu_nan_idx = find_idx(cpu, not_finite);
            if(cpu_nan_idx >= 0)
                std::cout << "Non finite number found in cpu at " << cpu_nan_idx << ": "
                          << cpu[cpu_nan_idx] << std::endl;

            auto gpu_nan_idx = find_idx(gpu, not_finite);
            if(gpu_nan_idx >= 0)
                std::cout << "Non finite number found in gpu at " << gpu_nan_idx << ": "
                          << gpu[gpu_nan_idx] << std::endl;
            // std::cout << std::endl;
        }
    });
    return passed;
}

} // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx