Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
MIGraphX
Commits
9bc18287
Commit
9bc18287
authored
Nov 09, 2023
by
Umang Yadav
Browse files
cppcheck fixes
parent
df7f8a35
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
28 deletions
+21
-28
src/include/migraphx/migraphx_f8_impl.hpp
src/include/migraphx/migraphx_f8_impl.hpp
+6
-15
src/include/migraphx/migraphx_float8.hpp
src/include/migraphx/migraphx_float8.hpp
+15
-13
No files found.
src/include/migraphx/migraphx_f8_impl.hpp
View file @
9bc18287
...
...
@@ -22,12 +22,8 @@
#ifndef MIGRAPHX_FP8_IMPL_HPP
#define MIGRAPHX_FP8_IMPL_HPP
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wreserved-identifier"
#endif
#define CONST_FOLD(x) (__builtin_constant_p(x) ? (x) : (x))
#define
MIGRAPHX_
CONST_FOLD(x) (__builtin_constant_p(x) ? (x) : (x))
namespace
migraphx_f8_impl
{
namespace
detail
{
template
<
bool
B
,
class
T
,
class
F
>
...
...
@@ -47,11 +43,10 @@ inline constexpr To bit_cast(From fr) noexcept
{
static_assert
(
sizeof
(
To
)
==
sizeof
(
From
));
#if defined(__GNUC__) and !defined(__clang__)
To
x
=
CONST_FOLD
(
*
reinterpret_cast
<
To
*>
(
&
fr
));
return
MIGRAPHX_
CONST_FOLD
(
*
reinterpret_cast
<
To
*>
(
&
fr
));
#else
To
x
=
__builtin_bit_cast
(
To
,
fr
);
return
__builtin_bit_cast
(
To
,
fr
);
#endif
return
x
;
}
}
// namespace detail
...
...
@@ -102,7 +97,6 @@ constexpr uint8_t cast_to_f8(T _x, bool stoch, uint32_t rng)
}
else
{
// if(__hisinf(x) || __hisnan(x))
if
((
x
&
0x7C00
)
==
0x7C00
)
return
0x80
;
}
...
...
@@ -112,12 +106,12 @@ constexpr uint8_t cast_to_f8(T _x, bool stoch, uint32_t rng)
if
(
sizeof
(
T
)
==
4
)
{
if
((
x
&
0x7F800000
)
==
0x7F800000
)
return
signed_inf
+
(
mantissa
!=
0
?
1
:
0
);
return
signed_inf
+
(
mantissa
!=
0
?
1
:
0
);
// cppcheck-suppress InvertedLogic
}
else
{
if
((
x
&
0x7C00
)
==
0x7C00
)
return
signed_inf
+
(
mantissa
!=
0
?
1
:
0
);
return
signed_inf
+
(
mantissa
!=
0
?
1
:
0
);
// cppcheck-suppress InvertedLogic
}
}
// handle positive zero
...
...
@@ -241,7 +235,7 @@ this case, the fp16 mantissa should be shift left by 1 */
}
}
if
(
f8_exponent
==
0
&&
mantissa
==
0
)
if
(
f8_exponent
==
0
and
mantissa
==
0
)
return
negative_zero_nan
?
0
:
(
sign
<<
7
);
mantissa
&=
(
1
<<
wm
)
-
1
;
return
(
sign
<<
7
)
|
(
f8_exponent
<<
wm
)
|
mantissa
;
...
...
@@ -314,7 +308,4 @@ constexpr T cast_from_f8(uint8_t x)
}
}
// namespace migraphx_f8_impl
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
#endif // MIGRAPHX_FP8_IMPL_HPP
src/include/migraphx/migraphx_float8.hpp
View file @
9bc18287
...
...
@@ -26,7 +26,6 @@
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wold-style-cast"
#pragma clang diagnostic ignored "-Wfloat-equal"
#pragma clang diagnostic ignored "-Wmacro-redefined"
#pragma clang diagnostic ignored "-Wc++20-extensions"
#endif // __clang__
...
...
@@ -36,6 +35,7 @@
// We are clipping in down conversion by default
#define MIGRAPHX_F8_DOWNCAST_CLIPPING 1
#include <cmath>
#include <cstdint>
#include <climits>
...
...
@@ -79,7 +79,7 @@ class numeric_limits;
template
<
migraphx_fp8
::
f8_type
T
=
migraphx_fp8
::
f8_type
::
fp8
>
struct
float8
{
uint8_t
data
;
uint8_t
data
=
0x00
;
// default constructor
constexpr
float8
()
=
default
;
// default copy constructor
...
...
@@ -141,7 +141,7 @@ struct float8
}
else
{
return
(
data
==
0x00
)
||
(
data
==
0x80
);
return
(
data
==
0x00
)
or
(
data
==
0x80
);
}
}
...
...
@@ -155,15 +155,15 @@ struct float8
{
if
(
T
==
migraphx_fp8
::
f8_type
::
bf8
)
{
return
(
data
==
0x7d
)
||
(
data
==
0x7e
)
||
(
data
==
0x7f
)
||
(
data
==
0xfd
)
||
(
data
==
0xfe
)
||
(
data
==
0xff
);
return
(
data
==
0x7d
)
or
(
data
==
0x7e
)
or
(
data
==
0x7f
)
or
(
data
==
0xfd
)
or
(
data
==
0xfe
)
or
(
data
==
0xff
);
}
else
{
return
(
data
==
0x79
)
||
(
data
==
0x7a
)
||
(
data
==
0x7b
)
||
(
data
==
0x7c
)
||
(
data
==
0x7d
)
||
(
data
==
0x7e
)
||
(
data
==
0x7f
)
||
(
data
==
0xf9
)
||
(
data
==
0xfa
)
||
(
data
==
0xfb
)
||
(
data
==
0xfc
)
||
(
data
==
0xfd
)
||
(
data
==
0xfe
)
||
(
data
==
0xff
);
return
(
data
==
0x79
)
or
(
data
==
0x7a
)
or
(
data
==
0x7b
)
or
(
data
==
0x7c
)
or
(
data
==
0x7d
)
or
(
data
==
0x7e
)
or
(
data
==
0x7f
)
or
(
data
==
0xf9
)
or
(
data
==
0xfa
)
or
(
data
==
0xfb
)
or
(
data
==
0xfc
)
or
(
data
==
0xfd
)
or
(
data
==
0xfe
)
or
(
data
==
0xff
);
}
}
}
...
...
@@ -178,11 +178,11 @@ struct float8
{
if
(
T
==
migraphx_fp8
::
f8_type
::
bf8
)
{
return
(
data
==
0x7c
)
||
(
data
==
0xfc
);
return
(
data
==
0x7c
)
or
(
data
==
0xfc
);
}
else
{
return
(
data
==
0x78
)
||
(
data
==
0xf8
);
return
(
data
==
0x78
)
or
(
data
==
0xf8
);
}
}
}
...
...
@@ -217,10 +217,10 @@ struct float8
inline
constexpr
bool
operator
==
(
const
float8
&
rhs
)
const
{
if
((
rhs
.
is_zero
()
&&
this
->
is_zero
())
||
if
((
rhs
.
is_zero
()
and
this
->
is_zero
())
or
(
fabs
(
rhs
-
*
this
)
<
migraphx_fp8
::
numeric_limits
<
float8
<
T
>>::
epsilon
()))
return
true
;
else
if
(
rhs
.
is_nan
()
||
rhs
.
is_inf
()
||
this
->
is_nan
()
||
this
->
is_inf
())
else
if
(
rhs
.
is_nan
()
or
rhs
.
is_inf
()
or
this
->
is_nan
()
or
this
->
is_inf
())
return
false
;
return
false
;
...
...
@@ -373,6 +373,8 @@ class numeric_limits<migraphx_fp8::float8<migraphx_fp8::f8_type::bf8>>
}
};
}
// namespace migraphx_fp8
// =================================================================================================
// define numeric limits for the new data type
namespace
std
{
inline
bool
isfinite
(
migraphx_fp8
::
float8
<
migraphx_fp8
::
f8_type
::
fp8
>
x
)
// NOLINT
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment