Skip to content
Open
Show file tree
Hide file tree
Changes from 141 commits
Commits
Show all changes
159 commits
Select commit Hold shift + click to select a range
45fa74f
Add sym::expr
pfultz2 Mar 20, 2026
3150f5a
Format
pfultz2 Mar 20, 2026
e1f4252
Move constructor inline
pfultz2 Mar 20, 2026
3e0d84b
Format
pfultz2 Mar 20, 2026
8752a2f
Move .cpp
pfultz2 Mar 20, 2026
31ca343
Format
pfultz2 Mar 20, 2026
a6552c1
Add comparison ops
pfultz2 Mar 20, 2026
e84dd47
Format
pfultz2 Mar 20, 2026
c2f3514
Add assign operators
pfultz2 Mar 21, 2026
0ba12f2
Add more functions
pfultz2 Mar 21, 2026
684d536
Format
pfultz2 Mar 21, 2026
90d30ac
Add to_string method
pfultz2 Mar 23, 2026
cecb90a
Format
pfultz2 Mar 23, 2026
c399c54
Add call associative
pfultz2 Mar 24, 2026
d2fc809
Foramt
pfultz2 Mar 24, 2026
92c716e
Add implicit const folding
pfultz2 Mar 25, 2026
7cb021a
Format
pfultz2 Mar 25, 2026
169c34a
Normalize subtract
pfultz2 Mar 25, 2026
2b01317
Format
pfultz2 Mar 25, 2026
cfdd0b0
Normalize subtraction
pfultz2 Mar 25, 2026
ed58ec1
Format
pfultz2 Mar 25, 2026
aeba6af
Some cleanup
pfultz2 Mar 25, 2026
f9364dd
Format
pfultz2 Mar 25, 2026
03f6064
Add normalize_expr
pfultz2 Mar 25, 2026
063645e
Add normalization
pfultz2 Mar 25, 2026
db9720d
Format
pfultz2 Mar 25, 2026
8b19cfc
Add rewrite rules
pfultz2 Mar 25, 2026
c55d529
Format
pfultz2 Mar 25, 2026
fd2c803
Add parser
pfultz2 Apr 9, 2026
cfa99b6
Format
pfultz2 Apr 9, 2026
0d8b391
Add first_of
pfultz2 Apr 9, 2026
910a68d
Format
pfultz2 Apr 9, 2026
fa5a44e
Add more operators
pfultz2 Apr 10, 2026
dd6670e
Format
pfultz2 Apr 10, 2026
14f4267
Add mod operator
pfultz2 Apr 10, 2026
f5cb5a2
Format
pfultz2 Apr 10, 2026
b50a9f0
Use call_function
pfultz2 Apr 10, 2026
1b18df4
Add lookup table
pfultz2 Apr 10, 2026
7526432
Format
pfultz2 Apr 10, 2026
07f5ba0
Add some missing methods
pfultz2 Apr 10, 2026
1120f04
Format
pfultz2 Apr 10, 2026
8476da0
Add print operators
pfultz2 Apr 10, 2026
6b3dfa0
Add to_value serialization
pfultz2 Apr 10, 2026
00a30e1
Format
pfultz2 Apr 10, 2026
3877b76
Add symlib
pfultz2 Apr 10, 2026
a9acf1d
Merge branch 'sym-expr' into sym-expr2
pfultz2 Apr 10, 2026
704d17a
Fix cmake
pfultz2 Apr 10, 2026
cc9ac2f
Fix ambiguous overloads
pfultz2 Apr 10, 2026
8f80176
Format
pfultz2 Apr 10, 2026
bd5bf3e
Fix some failures
pfultz2 Apr 10, 2026
8641ff8
Throw on missing variable
pfultz2 Apr 10, 2026
c6b44e5
Fix eval tests
pfultz2 Apr 10, 2026
b6bf47a
Use generic eval
pfultz2 Apr 10, 2026
b28a46a
Format
pfultz2 Apr 10, 2026
ffa3753
Make generic apply
pfultz2 Apr 10, 2026
53835f6
Format
pfultz2 Apr 10, 2026
314e4f0
Use generic_eval for string conversion
pfultz2 Apr 10, 2026
7b3e3f2
Reduce parens
pfultz2 Apr 10, 2026
9207d08
Normalize div
pfultz2 Apr 12, 2026
b1583f6
Format:
pfultz2 Apr 12, 2026
73c3e9e
Fix expression comparison
pfultz2 Apr 12, 2026
4bf7f5f
Format
pfultz2 Apr 12, 2026
2d4ea2b
Reorder
pfultz2 Apr 12, 2026
e2f0571
Format
pfultz2 Apr 12, 2026
89ca294
Switch order for mul
pfultz2 Apr 12, 2026
d98514b
Rename to scalar
pfultz2 Apr 12, 2026
3cb28d9
Format
pfultz2 Apr 12, 2026
a2e83a8
Simplify tuple creation
pfultz2 Apr 12, 2026
9664f59
Format
pfultz2 Apr 12, 2026
9f355aa
Use index method
pfultz2 Apr 12, 2026
f09949a
Simplify further
pfultz2 Apr 12, 2026
641a139
FOrmat
pfultz2 Apr 12, 2026
78a1e7b
Add fold_associative_args
pfultz2 Apr 12, 2026
ad867c7
Format
pfultz2 Apr 12, 2026
efe0002
Add unit tests
pfultz2 Apr 12, 2026
6917f91
Fix bug
pfultz2 Apr 13, 2026
2eed238
Update algorithm
pfultz2 Apr 13, 2026
2d64c2a
Use algorithms
pfultz2 Apr 13, 2026
8e2a187
Format
pfultz2 Apr 13, 2026
ffafd58
Use std::transform
pfultz2 Apr 13, 2026
0f47989
Cleanup the nasty loop
pfultz2 Apr 13, 2026
165e52a
Reuse subs
pfultz2 Apr 13, 2026
4a4af17
Format
pfultz2 Apr 13, 2026
089d3be
Unify associative
pfultz2 Apr 13, 2026
9697905
Format
pfultz2 Apr 13, 2026
6f39c04
Move to .cpp file
pfultz2 Apr 13, 2026
ff69c50
Remove simplify overload
pfultz2 Apr 13, 2026
b830f48
Adjust namespaces
pfultz2 Apr 13, 2026
89a4dab
Format
pfultz2 Apr 13, 2026
bdce060
Handle empty better
pfultz2 Apr 13, 2026
463a33f
Format
pfultz2 Apr 13, 2026
9f10d13
Fix associative ops
pfultz2 Apr 13, 2026
b481482
Add optimials
pfultz2 Apr 13, 2026
a88234b
Format
pfultz2 Apr 13, 2026
41e3d95
Use fix point combinator
pfultz2 Apr 13, 2026
53b36bc
Update eval
pfultz2 Apr 13, 2026
f7e37af
Format
pfultz2 Apr 13, 2026
cf81114
Use std::visit
pfultz2 Apr 13, 2026
becd81e
Format
pfultz2 Apr 13, 2026
ff856c9
Use static functions
pfultz2 Apr 13, 2026
ea0e0b9
Add clipping to make_scalar
pfultz2 Apr 13, 2026
2d3aeda
Format
pfultz2 Apr 13, 2026
dce28c0
Add tests for ceil div
pfultz2 Apr 13, 2026
a75d129
Throw div by zero
pfultz2 Apr 13, 2026
f2e162f
Fix eval tests
pfultz2 Apr 13, 2026
10a95e5
Update tests
pfultz2 Apr 13, 2026
d79be30
Improve printing
pfultz2 Apr 13, 2026
563165d
Format
pfultz2 Apr 13, 2026
34d75cb
use cached hash
pfultz2 Apr 13, 2026
314b257
Format
pfultz2 Apr 13, 2026
629b76a
Update type trait
pfultz2 Apr 13, 2026
2ed8ce9
Format
pfultz2 Apr 13, 2026
7b48135
Move ordered_as
pfultz2 Apr 13, 2026
c0eb314
Move ordered_as
pfultz2 Apr 13, 2026
50c3b30
Simplify overload
pfultz2 Apr 13, 2026
e017090
Remvoe the extra overload
pfultz2 Apr 13, 2026
d3ff9a8
Use float_equal
pfultz2 Apr 13, 2026
aadd5d6
Check div by zero
pfultz2 Apr 13, 2026
60136b2
Tidy fixits
pfultz2 Apr 13, 2026
c093a79
Format
pfultz2 Apr 13, 2026
7c5fa40
More tidy fixes
pfultz2 Apr 13, 2026
a6632b2
Format
pfultz2 Apr 13, 2026
e7b1d9d
Avoid copying the map
pfultz2 Apr 13, 2026
7ebfd5b
Format
pfultz2 Apr 13, 2026
640baf0
Remove unused template
pfultz2 Apr 13, 2026
3a1929e
Format
pfultz2 Apr 13, 2026
d631f84
Update license
pfultz2 Apr 13, 2026
4a8df17
Format
pfultz2 Apr 13, 2026
4a9a55b
Fix
pfultz2 Apr 13, 2026
5a12ce6
Update src/sym.cpp
pfultz2 Apr 13, 2026
8ed0d5e
Merge branch 'sym-expr2' of github.com:ROCm/AMDMIGraphX into sym-expr2
pfultz2 Apr 13, 2026
fa7874b
IMprove equality
pfultz2 Apr 13, 2026
1b8eeca
Format
pfultz2 Apr 13, 2026
e842038
Fix bug with serializing constraints
pfultz2 Apr 13, 2026
480b535
Format
pfultz2 Apr 13, 2026
2c97d17
Update year
pfultz2 Apr 13, 2026
d8de207
Format
pfultz2 Apr 13, 2026
d2e8522
Fix gcc warnings
pfultz2 Apr 13, 2026
87f463f
Add windows export
pfultz2 Apr 14, 2026
794c532
Call make_scalar
pfultz2 Apr 14, 2026
3e0c1ec
Format
pfultz2 Apr 14, 2026
93b46fb
Use hash method
pfultz2 Apr 23, 2026
177a0cb
Format
pfultz2 Apr 23, 2026
a2ad982
Use the provided hash functions
pfultz2 Apr 24, 2026
6f97ea3
Format
pfultz2 Apr 24, 2026
ebcf6ea
Add test for hash function
pfultz2 Apr 24, 2026
08220cd
Format
pfultz2 Apr 24, 2026
aacb571
Fix hashing
pfultz2 Apr 24, 2026
32abd4b
Format
pfultz2 Apr 24, 2026
6f8f0dc
Ignore constraints for equality
pfultz2 Apr 24, 2026
6caa980
Refactor eval_optimals
pfultz2 Apr 24, 2026
dbe8f16
Format
pfultz2 Apr 24, 2026
5835500
Merge branch 'develop' into sym-expr2
pfultz2 Apr 24, 2026
8a04ffb
Handle division by zero
pfultz2 Apr 24, 2026
fd08c6d
Format
pfultz2 Apr 24, 2026
a040784
Handl mod intervals with 0
pfultz2 Apr 24, 2026
98050ff
Merge branch 'develop' into sym-expr2
pfultz2 Apr 24, 2026
158cba8
Update src/sym.cpp
pfultz2 Apr 24, 2026
dc84048
Update test/sym.cpp
pfultz2 Apr 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CheckOptions:
- key: bugprone-unused-return-value.AllowCastToVoid
value: true
- key: cppcoreguidelines-macro-usage.AllowedRegexp
value: 'DEBUG|ASSERT|ASSUME|UNREACHABLE|FALLTHROUGH|DEPRECATED|STRINGIZE|_HAS_|_THROW|_REQUIRES|_DECLARE_|_VISIT_|_REGISTER_|_GENERATE_|_DETAIL_|_TIDY_|_MANAGE_PTR|_MATCHER|DEVICE_SHARED|_WORKAROUND_|_PP_'
value: 'DEBUG|ASSERT|ASSUME|UNREACHABLE|FALLTHROUGH|DEPRECATED|STRINGIZE|_HAS_|_THROW|_REQUIRES|_DECLARE_|_DEFINE_|_VISIT_|_REGISTER_|_GENERATE_|_DETAIL_|_TIDY_|_MANAGE_PTR|_MATCHER|DEVICE_SHARED|_WORKAROUND_|_PP_'
- key: modernize-loop-convert.MinConfidence
value: risky
- key: modernize-loop-convert.NamingStyle
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ add_library(migraphx
serialize.cpp
shape.cpp
shape_transform_descriptor.cpp
sym.cpp
simplify_algebra.cpp
simplify_dyn_ops.cpp
simplify_reshapes.cpp
split_single_dyn_dim.cpp
sym.cpp
target.cpp
tmp_dir.cpp
truncate_float.cpp
Expand Down
4 changes: 4 additions & 0 deletions src/include/migraphx/ranges.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@ struct iterator_range
Iterator start;
Iterator last;

bool empty() const { return start == last; }

std::size_t size() const { return std::distance(start, last); }
Comment on lines +272 to +274
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iterator_range::size() uses std::distance, but ranges.hpp doesn’t include <iterator>. Please include it explicitly rather than relying on transitive includes.

Copilot uses AI. Check for mistakes.

Iterator begin() const { return start; }

Iterator end() const { return last; }
Expand Down
229 changes: 229 additions & 0 deletions src/include/migraphx/simple_parser.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2025-2026 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.
*
*/
#ifndef MIGRAPHX_GUARD_MIGRAPHX_SIMPLE_PARSER_HPP
#define MIGRAPHX_GUARD_MIGRAPHX_SIMPLE_PARSER_HPP

#include <migraphx/config.hpp>
#include <migraphx/ranges.hpp>
#include <migraphx/errors.hpp>
#include <migraphx/stringutils.hpp>
#include <type_traits>
#include <vector>

namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {
namespace parser {

template <class Iterator, bool AutoSkipWhitespace = true, class View = iterator_range<Iterator>>
struct simple_parser
{
View buffer;
Iterator pos = buffer.begin();

static View make_view(Iterator begin, Iterator end)
{
if constexpr(std::is_constructible<View, decltype(std::addressof(*begin)), std::size_t>{})
{
auto n = std::distance(begin, end);
if(n == 0)
return {};
return {std::addressof(*begin), static_cast<std::size_t>(n)};
}
else
{
return {begin, end};
}
}

View peek() const
{
if(pos >= buffer.end())
return {};
return make_view(pos, buffer.end());
}

void advance(std::size_t n)
{
pos += n;
if(pos > buffer.end())
MIGRAPHX_THROW("Parser advanced past end of buffer");
if constexpr(AutoSkipWhitespace)
{
pos = std::find_if(
pos, buffer.end(), [](unsigned char c) { return not std::isspace(c); });
}
}

template <class Pred>
View parse_while(Pred p)
{
auto start = pos;
auto it = std::find_if(pos, buffer.end(), [&](auto c) { return not p(c); });
auto n = std::distance(pos, it);
advance(n);
return make_view(start, it);
}

bool starts_with(const View& prefix) const
{
auto tail = peek();
if(prefix.size() > tail.size())
return false;
else
return std::equal(prefix.begin(), prefix.end(), tail.begin());
}

bool done() const { return pos >= buffer.end(); }

bool match(const View& prefix)
{
if(not starts_with(prefix))
return false;
advance(prefix.size());
return true;
}

void expect(const View& str)
{
if(not starts_with(str))
MIGRAPHX_THROW(error_message("'" + std::string{str} + "'"));
advance(str.size());
}

char peek_char() const
{
if(done())
return '\0';
return *pos;
}

std::string error_message(std::string_view expected) const
{
auto offset = std::distance(buffer.begin(), pos);
return "Expected " + std::string(expected) + " at position " + std::to_string(offset) +
" in '" + std::string(buffer) + "'";
}

template <class F>
bool try_parse(F f)
{
auto copy = *this;
f(*this);
if(copy.pos != pos)
return true;
*this = copy;
return false;
}

View first_of(View view)
{
if(match(view))
return view;
return {};
}

template <class... Views>
View first_of(View view, Views... views)
{
if(match(view))
return view;
return first_of(views...);
}

template <class F>
auto first_of(F f) -> decltype(f(*this))
{
return f(*this);
}

template <class F, class G, class... Fs>
auto first_of(F f, G g, Fs... fs) -> decltype(f(*this))
{
auto copy = *this;
auto result = f(*this);
if(copy.pos != pos)
return result;
*this = copy;
return first_of(g, fs...);
}

template <class F>
auto repeat(F f)
{
using result_type = decltype(f(*this));
std::vector<result_type> results;
for(;;)
{
auto copy = *this;
results.push_back(f(*this));
if(copy.pos == pos)
{
results.pop_back();
break;
}
}
return results;
}
};

template <class F>
struct parser_action
{
F fn;

template <class Parser>
auto operator()(Parser& p) const -> decltype(fn(p))
{
return fn(p);
}
};

template <class F>
parser_action<std::decay_t<F>> action(F&& f)
{
return {std::forward<F>(f)};
}

template <class F1, class F2>
auto operator|(parser_action<F1> a, parser_action<F2> b)
{
return action([a = std::move(a), b = std::move(b)](auto& p) -> decltype(a(p)) {
return p.first_of(a, b);
});
}

template <class F>
auto operator*(parser_action<F> a)
{
return action([a = std::move(a)](auto& p) { return p.repeat(a); });
}

using simple_string_view_skip_parser =
simple_parser<std::string_view::const_iterator, true, std::string_view>;

} // namespace parser
} // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx
#endif // MIGRAPHX_GUARD_MIGRAPHX_SIMPLE_PARSER_HPP
Loading
Loading