Skip to content

Commit 5127437

Browse files
authored
Merge branch 'develop' into dependabot/pip/docs/sphinx/rocm-docs-core-1.22.0
2 parents b0b4d36 + 2840377 commit 5127437

34 files changed

+1478
-157
lines changed

Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ node("(rocmtest || migraphx)") {
138138
checkout scm
139139
def calculateImageTagScript = """
140140
shopt -s globstar
141-
sha256sum **/Dockerfile **/*requirements.txt **/install_prereqs.sh **/rbuild.ini | sha256sum | cut -d " " -f 1
141+
sha256sum **/Dockerfile **/*requirements.txt **/install_prereqs.sh **/rbuild.ini **/test/onnx/.onnxrt-commit | sha256sum | cut -d " " -f 1
142142
"""
143143
env.IMAGE_TAG = sh(script: "bash -c '${calculateImageTagScript}'", returnStdout: true).trim()
144144
imageExists = sh(script: "docker manifest inspect ${DOCKER_IMAGE}:${IMAGE_TAG}", returnStatus: true) == 0

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ pybind/pybind11@3e9dfa2866941655c56877882565e7577de6fc7b --build
2828
msgpack/msgpack-c@cpp-3.3.0 -DMSGPACK_BUILD_TESTS=Off -DCMAKE_POLICY_VERSION_MINIMUM=3.5
2929
sqlite3@3.43.2 -DCMAKE_POSITION_INDEPENDENT_CODE=On
3030
ROCm/composable_kernel@b7775add2d28251674d81e220cd4a857b90b997a -DCK_BUILD_JIT_LIB=On -DCMAKE_POSITION_INDEPENDENT_CODE=On
31-
ROCm/rocMLIR@59c57483d3bf9b738c586580dbb793b05aa41c3e -DBUILD_FAT_LIBROCKCOMPILER=On -DLLVM_INCLUDE_TESTS=Off
31+
ROCm/rocMLIR@ff95d9286f1c273c1adc7a04db248a018be15550 -DBUILD_FAT_LIBROCKCOMPILER=On -DLLVM_INCLUDE_TESTS=Off

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ register_migraphx_ops(
230230
nonzero
231231
onehot
232232
outline
233+
pack_fp4
233234
pack_int4
234235
pad
235236
pointwise
@@ -294,6 +295,7 @@ register_migraphx_ops(
294295
undefined
295296
unique
296297
unknown
298+
unpack_fp4
297299
unpack_int4
298300
unsqueeze
299301
where

src/api/api.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ static shape::type_t to_shape_type(migraphx_shape_datatype_t t)
9898
switch(t)
9999
{
100100
case migraphx_shape_tuple_type: return shape::tuple_type;
101+
case migraphx_shape_fp4x2_type: return shape::fp4x2_type;
101102
#define MIGRAPHX_DETAIL_SHAPE_CASE_CONVERT(x, y) \
102103
case migraphx_shape_##x: return shape::x;
103104
MIGRAPHX_SHAPE_VISIT_TYPES(MIGRAPHX_DETAIL_SHAPE_CASE_CONVERT)
@@ -111,6 +112,7 @@ static migraphx_shape_datatype_t to_shape_type(shape::type_t t)
111112
switch(t)
112113
{
113114
case shape::tuple_type: return migraphx_shape_tuple_type;
115+
case shape::fp4x2_type: return migraphx_shape_fp4x2_type;
114116
#define MIGRAPHX_DETAIL_SHAPE_CASE_CONVERT(x, y) \
115117
case shape::x: return migraphx_shape_##x;
116118
MIGRAPHX_SHAPE_VISIT_TYPES(MIGRAPHX_DETAIL_SHAPE_CASE_CONVERT)

src/api/include/migraphx/migraphx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ typedef enum
7171
typedef enum
7272
{
7373
migraphx_shape_tuple_type,
74+
migraphx_shape_fp4x2_type,
7475
MIGRAPHX_SHAPE_VISIT_TYPES(MIGRAPHX_SHAPE_GENERATE_ENUM_TYPES)
7576
} migraphx_shape_datatype_t;
7677
#undef MIGRAPHX_SHAPE_GENERATE_ENUM_TYPES

src/include/migraphx/bit_cast.hpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
1-
/* ************************************************************************
2-
* Copyright (C) 2015-2025 Advanced Micro Devices, Inc. All rights reserved.
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2015-2025 Advanced Micro Devices, Inc. All rights reserved.
35
*
46
* Permission is hereby granted, free of charge, to any person obtaining a copy
57
* of this software and associated documentation files (the "Software"), to deal
68
* in the Software without restriction, including without limitation the rights
7-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell cop-
8-
* ies of the Software, and to permit persons to whom the Software is furnished
9-
* to do so, subject to the following conditions:
10-
*
11-
* The above copyright notice and this permission notice shall be included in all
12-
* copies or substantial portions of the Software.
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
1312
*
14-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IM-
15-
* PLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16-
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17-
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18-
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNE-
19-
* CTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
2015
*
21-
* ************************************************************************ */
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
2224
#ifndef MIGRAPHX_GUARD_RTGLIB_BITCAST_HPP
2325
#define MIGRAPHX_GUARD_RTGLIB_BITCAST_HPP
2426
#include <type_traits>
@@ -42,6 +44,7 @@ template <typename To,
4244
std::is_trivially_copyable<From>{})>
4345
constexpr To bit_cast(From fr) noexcept
4446
{
47+
// NOLINTNEXTLINE(bugprone-sizeof-expression)
4548
static_assert(sizeof(To) == sizeof(From));
4649
#if defined(__GNUC__) and !defined(__clang__)
4750
return MIGRAPHX_CONST_FOLD(*reinterpret_cast<To*>(&fr));

src/include/migraphx/fp4_casts.hpp

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2015-2025 Advanced Micro Devices, Inc. All rights reserved.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
#ifndef MIGRAPHX_GUARD_RTGLIB_FLOAT4_CASTS_HPP
25+
#define MIGRAPHX_GUARD_RTGLIB_FLOAT4_CASTS_HPP
26+
27+
#include <cstdint>
28+
#include <algorithm>
29+
#include <array>
30+
#include <cmath>
31+
#include <iterator>
32+
#include <migraphx/errors.hpp>
33+
34+
namespace migraphx {
35+
inline namespace MIGRAPHX_INLINE_NS {
36+
37+
namespace fp4_detail {
38+
static constexpr std::array<float, 16> fp4_lut = {
39+
0.0, 0.5, 1.0, 1.5, 2.0, 3.0, 4.0, 6.0, -0.0, -0.5, -1.0, -1.5, -2.0, -3.0, -4.0, -6.0};
40+
41+
// pair is {fp4_tie_value, round_to_zero}
42+
// if round_to_zero round tie towards zero, else round tie away from zero
43+
static constexpr std::array<std::pair<float, uint8_t>, 7> fp4_even_round = {
44+
{{0.25, 1}, {0.75, 0}, {1.25, 1}, {1.75, 0}, {2.5, 1}, {3.5, 0}, {5, 1}}};
45+
} // namespace fp4_detail
46+
47+
// converts 4 LSB to float
48+
constexpr float fp4_to_float(uint8_t x)
49+
{
50+
return fp4_detail::fp4_lut[x % fp4_detail::fp4_lut.size()];
51+
}
52+
53+
// rounding mode = roundToNearestRoundTiesToEven
54+
// Reference quantization code from Microsoft:
55+
// https://github.com/microsoft/microxcaling/blob/main/mx/elemwise_ops.py#L82
56+
// Not constexpr because std::signbit is not constexpr until C++23
57+
inline uint8_t float_to_fp4(float f_x)
58+
{
59+
using fp4_detail::fp4_even_round;
60+
using fp4_detail::fp4_lut;
61+
if(std::isnan(f_x))
62+
{
63+
return 0;
64+
}
65+
bool sign = std::signbit(f_x);
66+
uint8_t sign_add = sign ? fp4_lut.size() / 2 : 0u;
67+
float abs_f = std::abs(f_x);
68+
// index value is the positive fp4 value
69+
uint8_t i = std::upper_bound(fp4_even_round.begin(),
70+
fp4_even_round.end(),
71+
std::make_pair(abs_f, uint8_t{0})) -
72+
fp4_even_round.begin();
73+
74+
return i + sign_add;
75+
}
76+
77+
} // namespace MIGRAPHX_INLINE_NS
78+
} // namespace migraphx
79+
80+
#endif

src/include/migraphx/iota_iterator.hpp

Lines changed: 36 additions & 97 deletions
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,134 +26,73 @@
2626

2727
#include <migraphx/config.hpp>
2828
#include <migraphx/functional.hpp>
29+
#include <migraphx/iterator.hpp>
2930
#include <iterator>
30-
#include <type_traits>
3131

3232
namespace migraphx {
3333
inline namespace MIGRAPHX_INLINE_NS {
3434

3535
template <class F, class Iterator = std::ptrdiff_t>
36-
struct basic_iota_iterator
36+
struct basic_iota_iterator : iterator_operators<basic_iota_iterator<F, Iterator>>,
37+
iterator_types<decltype(std::declval<F>()(std::declval<Iterator>())),
38+
std::random_access_iterator_tag>
3739
{
3840
Iterator index;
3941
F f;
4042

41-
using difference_type = std::ptrdiff_t;
42-
using reference = decltype(f(std::declval<Iterator>()));
43-
using value_type = typename std::remove_reference<reference>::type;
44-
using pointer = typename std::add_pointer<value_type>::type;
45-
using iterator_category = std::random_access_iterator_tag;
43+
using reference = decltype(std::declval<F>()(std::declval<Iterator>()));
4644

47-
basic_iota_iterator& operator+=(int n)
45+
// cppcheck-suppress uninitMemberVar
46+
constexpr basic_iota_iterator() = default;
47+
48+
template <class... Ts>
49+
constexpr basic_iota_iterator(Iterator i, Ts&&... xs) : index(i), f{std::forward<Ts>(xs)...}
50+
{
51+
}
52+
53+
constexpr basic_iota_iterator::reference operator*() const { return f(index); }
54+
55+
template <class U>
56+
static constexpr auto increment(U& x) -> decltype(++x.index)
4857
{
49-
index += n;
50-
return *this;
58+
return ++x.index;
5159
}
5260

53-
basic_iota_iterator& operator-=(int n)
61+
template <class U>
62+
static constexpr auto decrement(U& x) -> decltype(--x.index)
5463
{
55-
index -= n;
56-
return *this;
64+
return --x.index;
5765
}
5866

59-
basic_iota_iterator& operator++()
67+
template <class U, class I>
68+
static constexpr auto advance(U& x, I n) -> decltype(x.index += n)
6069
{
61-
index++;
62-
return *this;
70+
return x.index += n;
6371
}
6472

65-
basic_iota_iterator& operator--()
73+
template <class U, class V>
74+
static constexpr auto distance(const U& x, const V& y) -> decltype(y.index - x.index)
6675
{
67-
index--;
68-
return *this;
76+
return y.index - x.index;
6977
}
7078

71-
basic_iota_iterator operator++(int) // NOLINT
79+
template <class U, class V>
80+
static constexpr auto equal(const U& x, const V& y) -> decltype(x.index == y.index)
7281
{
73-
basic_iota_iterator it = *this;
74-
index++;
75-
return it;
82+
return x.index == y.index;
7683
}
7784

78-
basic_iota_iterator operator--(int) // NOLINT
85+
template <class Stream>
86+
friend Stream& operator<<(Stream& s, const basic_iota_iterator& x)
7987
{
80-
basic_iota_iterator it = *this;
81-
index--;
82-
return it;
88+
return s << x.index;
8389
}
84-
reference operator*() const { return f(index); }
85-
pointer operator->() const { return &f(index); }
86-
reference operator[](int n) const { return f(index + n); }
8790
};
8891

8992
template <class T, class F>
90-
inline basic_iota_iterator<F, T> make_basic_iota_iterator(T x, F f)
91-
{
92-
return basic_iota_iterator<F, T>{x, f};
93-
}
94-
95-
template <class F, class Iterator>
96-
inline basic_iota_iterator<F, Iterator> operator+(basic_iota_iterator<F, Iterator> x,
97-
std::ptrdiff_t y)
98-
{
99-
return x += y;
100-
}
101-
102-
template <class F, class Iterator>
103-
inline basic_iota_iterator<F, Iterator> operator+(std::ptrdiff_t x,
104-
basic_iota_iterator<F, Iterator> y)
105-
{
106-
return y + x;
107-
}
108-
109-
template <class F, class Iterator>
110-
inline std::ptrdiff_t operator-(basic_iota_iterator<F, Iterator> x,
111-
basic_iota_iterator<F, Iterator> y)
112-
{
113-
return x.index - y.index;
114-
}
115-
116-
template <class F, class Iterator>
117-
inline basic_iota_iterator<F, Iterator> operator-(basic_iota_iterator<F, Iterator> x,
118-
std::ptrdiff_t y)
119-
{
120-
return x -= y;
121-
}
122-
123-
template <class F, class Iterator>
124-
inline bool operator==(basic_iota_iterator<F, Iterator> x, basic_iota_iterator<F, Iterator> y)
125-
{
126-
return x.index == y.index;
127-
}
128-
129-
template <class F, class Iterator>
130-
inline bool operator!=(basic_iota_iterator<F, Iterator> x, basic_iota_iterator<F, Iterator> y)
131-
{
132-
return x.index != y.index;
133-
}
134-
135-
template <class F, class Iterator>
136-
inline bool operator<(basic_iota_iterator<F, Iterator> x, basic_iota_iterator<F, Iterator> y)
137-
{
138-
return x.index < y.index;
139-
}
140-
141-
template <class F, class Iterator>
142-
inline bool operator>(basic_iota_iterator<F, Iterator> x, basic_iota_iterator<F, Iterator> y)
143-
{
144-
return x.index > y.index;
145-
}
146-
147-
template <class F, class Iterator>
148-
inline bool operator>=(basic_iota_iterator<F, Iterator> x, basic_iota_iterator<F, Iterator> y)
149-
{
150-
return x.index >= y.index;
151-
}
152-
153-
template <class F, class Iterator>
154-
inline bool operator<=(basic_iota_iterator<F, Iterator> x, basic_iota_iterator<F, Iterator> y)
93+
basic_iota_iterator<F, T> make_basic_iota_iterator(T x, F f)
15594
{
156-
return x.index <= y.index;
95+
return {x, f};
15796
}
15897

15998
using iota_iterator = basic_iota_iterator<id>;

0 commit comments

Comments
 (0)