"test/git@developer.sourcefind.cn:gaoqiong/migraphx.git" did not exist on "a0b570b2b963d45907b283ef10bdff2022c33b0f"
verify_args.cpp 4.04 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
/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2015-2022 Advanced Micro Devices, Inc. All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
24
25
26
27
28
29
30

#include <migraphx/verify_args.hpp>

namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {

bool verify_args(const std::string& name,
31
32
                 const argument& ref_arg,
                 const argument& target_arg,
33
34
35
                 double tolerance)
{
    bool passed = true;
36
    visit_all(ref_arg, target_arg)([&](auto ref, auto target) {
37
        double error;
Umang Yadav's avatar
Umang Yadav committed
38
        passed = verify::verify_range(ref, target, tolerance, &error);
39
40
41
42
43
        if(not passed)
        {
            // TODO: Check for nans
            std::cout << "FAILED: " << name << std::endl;
            std::cout << "error: " << error << std::endl;
44
45
46
47
            if(ref.size() < 32)
                std::cout << "ref:" << ref << std::endl;
            if(target.size() < 32)
                std::cout << "target:" << target << std::endl;
Umang Yadav's avatar
Umang Yadav committed
48
            if(verify::range_zero(ref))
49
                std::cout << "Ref data is all zeros" << std::endl;
Umang Yadav's avatar
Umang Yadav committed
50
            if(verify::range_zero(target))
51
                std::cout << "Target data is all zeros" << std::endl;
52

Umang Yadav's avatar
Umang Yadav committed
53
            auto mxdiff = verify::max_diff(ref, target);
54
55
            std::cout << "Max diff: " << mxdiff << std::endl;

Umang Yadav's avatar
Umang Yadav committed
56
57
            auto idx = verify::mismatch_idx(ref, target, float_equal);
            if(idx < verify::range_distance(ref))
58
            {
59
                std::cout << "Mismatch at " << idx << ": " << ref[idx] << " != " << target[idx]
60
61
62
                          << std::endl;
            }

Umang Yadav's avatar
Umang Yadav committed
63
            auto ref_nan_idx = find_idx(ref, verify::not_finite);
64
65
66
            if(ref_nan_idx >= 0)
                std::cout << "Non finite number found in ref at " << ref_nan_idx << ": "
                          << ref[ref_nan_idx] << std::endl;
67

Umang Yadav's avatar
Umang Yadav committed
68
            auto target_nan_idx = find_idx(target, verify::not_finite);
69
70
71
            if(target_nan_idx >= 0)
                std::cout << "Non finite number found in target at " << target_nan_idx << ": "
                          << target[target_nan_idx] << std::endl;
72
73
74
75
            std::cout << std::endl;
        }
        else
        {
Umang Yadav's avatar
Umang Yadav committed
76
            if(verify::range_zero(ref))
77
                std::cout << "Ref data is all zeros" << std::endl;
Umang Yadav's avatar
Umang Yadav committed
78
            if(verify::range_zero(target))
79
                std::cout << "Target data is all zeros" << std::endl;
80

Umang Yadav's avatar
Umang Yadav committed
81
            auto ref_nan_idx = find_idx(ref, verify::not_finite);
82
83
84
            if(ref_nan_idx >= 0)
                std::cout << "Non finite number found in ref at " << ref_nan_idx << ": "
                          << ref[ref_nan_idx] << std::endl;
85

Umang Yadav's avatar
Umang Yadav committed
86
            auto target_nan_idx = find_idx(target, verify::not_finite);
87
88
89
            if(target_nan_idx >= 0)
                std::cout << "Non finite number found in target at " << target_nan_idx << ": "
                          << target[target_nan_idx] << std::endl;
90
            std::cout << "MIGraphX verification passed successfully." << std::endl;
91
92
93
94
95
96
97
        }
    });
    return passed;
}

} // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx