Skip to content

Commit 2d55b39

Browse files
authored
Enable debug assertions in libstdc++ (#3924)
Adds a jenkins job that will run the unit tests with debug mode with libstdc++. To fix the debug issues I wrapped the instruction_ref in a class(actually reused the class thats used on windows).
1 parent c2b258d commit 2d55b39

File tree

7 files changed

+68
-30
lines changed

7 files changed

+68
-30
lines changed

Jenkinsfile

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,16 +208,22 @@ rocmtest clang_debug: rocmnode('mi200+') { cmake_build ->
208208
// cmake_build(flags: "-DCMAKE_BUILD_TYPE=release -DMIGRAPHX_USE_HIPRTC=On -DGPU_TARGETS='${gpu_targets}'")
209209
// }
210210
// }
211+
}, clang_release_navi: rocmnode('navi32') { cmake_build ->
212+
stage('HIP Clang Release Navi32') {
213+
def gpu_targets = getnavi3xtargets()
214+
cmake_build(flags: "-DCMAKE_BUILD_TYPE=release -DGPU_TARGETS='${gpu_targets}' -DMIGRAPHX_DISABLE_ONNX_TESTS=On")
215+
}
211216
}, clang_asan: rocmnode('nogpu') { cmake_build ->
212217
stage('Clang ASAN') {
213218
def sanitizers = "undefined,address"
214219
def debug_flags = "-g -O2 -fno-omit-frame-pointer -fsanitize=${sanitizers} -fno-sanitize-recover=${sanitizers}"
215220
cmake_build(flags: "-DCMAKE_BUILD_TYPE=debug -DMIGRAPHX_ENABLE_C_API_TEST=Off -DMIGRAPHX_ENABLE_PYTHON=Off -DMIGRAPHX_ENABLE_GPU=Off -DMIGRAPHX_ENABLE_CPU=On -DCMAKE_CXX_FLAGS_DEBUG='${debug_flags}'", compiler:'/usr/bin/clang++-14')
216221
}
217-
}, clang_release_navi: rocmnode('navi32') { cmake_build ->
218-
stage('HIP Clang Release Navi32') {
219-
def gpu_targets = getnavi3xtargets()
220-
cmake_build(flags: "-DCMAKE_BUILD_TYPE=release -DGPU_TARGETS='${gpu_targets}' -DMIGRAPHX_DISABLE_ONNX_TESTS=On")
222+
}, debub_libstdcxx: rocmnode('nogpu') { cmake_build ->
223+
stage('Debug libstdc++') {
224+
def sanitizers = "undefined"
225+
def debug_flags = "-g -O2 -fno-omit-frame-pointer -fsanitize=${sanitizers} -fno-sanitize-recover=${sanitizers} -D_GLIBCXX_DEBUG"
226+
cmake_build(flags: "-DCMAKE_BUILD_TYPE=debug -DMIGRAPHX_ENABLE_C_API_TEST=Off -DMIGRAPHX_ENABLE_PYTHON=Off -DMIGRAPHX_ENABLE_GPU=Off -DMIGRAPHX_ENABLE_CPU=Off -DCMAKE_CXX_FLAGS_DEBUG='${debug_flags}'", compiler:'/usr/bin/clang++-14')
221227
}
222228
}
223229

src/fuse_concat.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ struct fused_concat
6666
module_ref post_mod = mods.back();
6767
// post_mod has one input argument that is result of concat and will get generated from
6868
// pre-mods internally. Therefore deduct 1 from post_mod params while asserting.
69-
assert(input_iter + post_mod->get_parameter_names().size() - 1 == inputs.end());
69+
assert(input_iter + (post_mod->get_parameter_names().size() - 1) == inputs.end());
7070
auto type = std::prev(post_mod->end())->get_shape().type();
7171
const auto& first_shape_lens = concat_inputs.front().lens();
7272
auto mismatch_it =

src/include/migraphx/instruction_ref.hpp

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* The MIT License (MIT)
33
*
4-
* Copyright (c) 2015-2023 Advanced Micro Devices, Inc. All rights reserved.
4+
* Copyright (c) 2015-2025 Advanced Micro Devices, Inc. All rights reserved.
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -33,7 +33,15 @@ namespace migraphx {
3333
inline namespace MIGRAPHX_INLINE_NS {
3434

3535
struct instruction;
36-
#if defined(_WIN32) && !defined(NDEBUG) && !defined(CPPCHECK)
36+
37+
MIGRAPHX_EXPORT migraphx::instruction*
38+
as_address(const std::list<instruction>::iterator& ins) noexcept;
39+
MIGRAPHX_EXPORT const migraphx::instruction*
40+
as_address(const std::list<instruction>::const_iterator& ins) noexcept;
41+
42+
#if defined(CPPCHECK)
43+
using instruction_ref = std::list<instruction>::iterator;
44+
#else
3745
struct instruction_ref : std::list<instruction>::iterator
3846
{
3947
using instruction_iter = std::list<instruction>::iterator;
@@ -48,7 +56,7 @@ struct instruction_ref : std::list<instruction>::iterator
4856
std::is_same<U, instruction_ref>{})>
4957
friend bool operator==(const T& x, const U& y)
5058
{
51-
return x._Unwrapped()._Ptr == y._Unwrapped()._Ptr;
59+
return as_address(x) == as_address(y);
5260
}
5361

5462
template <class T,
@@ -60,18 +68,14 @@ struct instruction_ref : std::list<instruction>::iterator
6068
return not(x == y);
6169
}
6270
};
63-
#else
64-
using instruction_ref = std::list<instruction>::iterator;
6571
#endif
6672

67-
MIGRAPHX_EXPORT migraphx::instruction* as_address(const instruction_ref& ins) noexcept;
68-
6973
} // namespace MIGRAPHX_INLINE_NS
7074
} // namespace migraphx
7175

7276
namespace std {
7377
template <>
74-
struct hash<migraphx::instruction_ref> // NOLINT
78+
struct hash<migraphx::instruction_ref>
7579
{
7680
using argument_type = migraphx::instruction_ref;
7781
using result_type = std::size_t;
@@ -81,18 +85,6 @@ struct hash<migraphx::instruction_ref> // NOLINT
8185
}
8286
};
8387

84-
template <>
85-
struct equal_to<migraphx::instruction_ref> // NOLINT
86-
{
87-
using argument_type = migraphx::instruction_ref;
88-
using result_type = bool;
89-
result_type operator()(const migraphx::instruction_ref& x,
90-
const migraphx::instruction_ref& y) const noexcept
91-
{
92-
return migraphx::as_address(x) == migraphx::as_address(y);
93-
}
94-
};
95-
9688
} // namespace std
9789

9890
#ifdef _MSC_VER

src/include/migraphx/iterator.hpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* The MIT License (MIT)
33
*
4-
* Copyright (c) 2015-2022 Advanced Micro Devices, Inc. All rights reserved.
4+
* Copyright (c) 2015-2025 Advanced Micro Devices, Inc. All rights reserved.
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -26,6 +26,7 @@
2626

2727
#include <migraphx/config.hpp>
2828
#include <migraphx/rank.hpp>
29+
#include <memory>
2930

3031
namespace migraphx {
3132
inline namespace MIGRAPHX_INLINE_NS {
@@ -48,6 +49,34 @@ bool is_end(Iterator it, EndIterator last)
4849
return is_end(rank<2>{}, it, last);
4950
}
5051

52+
template <class Iterator>
53+
auto* iterator_address(rank<0>, Iterator it)
54+
{
55+
return std::addressof(*it);
56+
}
57+
58+
template <class Iterator>
59+
auto iterator_address(rank<1>, Iterator it) -> decltype(it._M_dereferenceable()
60+
? std::addressof(*it)
61+
: nullptr)
62+
{
63+
return it._M_dereferenceable() ? std::addressof(*it) : nullptr;
64+
}
65+
66+
template <class Iterator>
67+
auto iterator_address(rank<1>,
68+
Iterator it) -> decltype(std::addressof(it._Unwrapped()._Ptr->_Myval),
69+
std::addressof(*it))
70+
{
71+
return it._Unwrapped()._Ptr ? std::addressof(it._Unwrapped()._Ptr->_Myval) : nullptr;
72+
}
73+
74+
template <class Iterator>
75+
auto* iterator_address(Iterator it)
76+
{
77+
return iterator_address(rank<1>{}, it);
78+
}
79+
5180
} // namespace MIGRAPHX_INLINE_NS
5281
} // namespace migraphx
5382
#endif // MIGRAPHX_GUARD_MIGRAPHX_ITERATOR_HPP

src/include/migraphx/op/name.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* The MIT License (MIT)
33
*
4-
* Copyright (c) 2015-2022 Advanced Micro Devices, Inc. All rights reserved.
4+
* Copyright (c) 2015-2025 Advanced Micro Devices, Inc. All rights reserved.
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -26,6 +26,7 @@
2626

2727
#include <migraphx/config.hpp>
2828
#include <migraphx/type_name.hpp>
29+
#include <cassert>
2930

3031
namespace migraphx {
3132
inline namespace MIGRAPHX_INLINE_NS {
@@ -38,6 +39,7 @@ struct op_name
3839
std::string name() const
3940
{
4041
static const std::string& name = get_type_name<Derived>();
42+
assert((name.rfind("::") + 2) < name.size());
4143
return name.substr(name.rfind("::") + 2);
4244
}
4345
};

src/instruction.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <migraphx/module.hpp>
2828
#include <migraphx/ranges.hpp>
2929
#include <migraphx/output_iterator.hpp>
30+
#include <migraphx/iterator.hpp>
3031
#include <queue>
3132

3233
namespace migraphx {
@@ -543,9 +544,14 @@ std::vector<shape> try_compute_shape(const operation& op, const std::vector<shap
543544
return {new_shape};
544545
}
545546

546-
migraphx::instruction* as_address(const instruction_ref& ins) noexcept
547+
migraphx::instruction* as_address(const std::list<instruction>::iterator& ins) noexcept
547548
{
548-
return std::addressof(*ins);
549+
return iterator_address(ins);
550+
}
551+
552+
const migraphx::instruction* as_address(const std::list<instruction>::const_iterator& ins) noexcept
553+
{
554+
return iterator_address(ins);
549555
}
550556

551557
// DFS through inputs of `end` to find `start`.

test/tf/tests/assert_less_equal_test.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* The MIT License (MIT)
33
*
4-
* Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved.
4+
* Copyright (c) 2015-2025 Advanced Micro Devices, Inc. All rights reserved.
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -25,6 +25,8 @@
2525

2626
#include <tf_test.hpp>
2727

28+
// Skip this test for libstdc++ debug for now since it exposes a bug in protobuf
29+
#ifndef _GLIBCXX_DEBUG
2830
TEST_CASE(assert_less_equal_test)
2931
{
3032
migraphx::program p;
@@ -42,3 +44,4 @@ TEST_CASE(assert_less_equal_test)
4244

4345
EXPECT(p == prog);
4446
}
47+
#endif

0 commit comments

Comments
 (0)