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
5df808fc
Commit
5df808fc
authored
Aug 20, 2018
by
Paul
Browse files
Update generate to try to normalize the data
parent
abb27ba0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
4 deletions
+44
-4
src/include/migraph/generate.hpp
src/include/migraph/generate.hpp
+24
-2
src/include/migraph/requires.hpp
src/include/migraph/requires.hpp
+20
-2
No files found.
src/include/migraph/generate.hpp
View file @
5df808fc
...
@@ -7,10 +7,31 @@
...
@@ -7,10 +7,31 @@
namespace
migraph
{
namespace
migraph
{
template
<
class
T
,
MIGRAPH_REQUIRES
(
std
::
is_floating_point
<
T
>{})
>
T
normalize
(
T
z
)
{
if
(
z
==
0
)
return
0
;
return
(
2.0
/
z
)
-
1.0
;
}
template
<
class
T
,
MIGRAPH_REQUIRES
(
std
::
is_signed
<
T
>{})
>
T
normalize
(
T
z
)
{
const
auto
max
=
std
::
numeric_limits
<
T
>::
max
();
const
auto
half_max
=
max
/
2
;
return
half_max
-
(
z
%
max
);
}
template
<
class
T
,
MIGRAPH_REQUIRES
(
not
std
::
is_signed
<
T
>{}
and
std
::
is_integral
<
T
>
{})
>
T
normalize
(
T
z
)
{
const
auto
max
=
std
::
numeric_limits
<
T
>::
max
();
return
z
%
max
;
}
template
<
class
T
>
template
<
class
T
>
struct
xorshf96_generator
struct
xorshf96_generator
{
{
long
max
=
16
;
unsigned
long
x
=
123456789
;
unsigned
long
x
=
123456789
;
unsigned
long
y
=
362436069
;
unsigned
long
y
=
362436069
;
unsigned
long
z
=
521288629
;
unsigned
long
z
=
521288629
;
...
@@ -26,7 +47,8 @@ struct xorshf96_generator
...
@@ -26,7 +47,8 @@ struct xorshf96_generator
y
=
z
;
y
=
z
;
z
=
t
^
x
^
y
;
z
=
t
^
x
^
y
;
return
z
%
max
-
(
max
+
1
);
return
normalize
(
z
);
}
}
};
};
...
...
src/include/migraph/requires.hpp
View file @
5df808fc
...
@@ -13,12 +13,30 @@ struct and_ : std::is_same<and_<Bs...>, and_<(Bs || true)...>> // NOLINT
...
@@ -13,12 +13,30 @@ struct and_ : std::is_same<and_<Bs...>, and_<(Bs || true)...>> // NOLINT
template
<
bool
B
>
template
<
bool
B
>
using
bool_c
=
std
::
integral_constant
<
bool
,
B
>
;
using
bool_c
=
std
::
integral_constant
<
bool
,
B
>
;
template
<
int
N
>
struct
requires_enum
{
enum
e
{
A
=
0
};
};
#define MIGRAPH_REQUIRES_CAT(x, y) x ## y
#ifdef CPPCHECK
#ifdef CPPCHECK
#define MIGRAPH_REQUIRES(...) class = void
#define MIGRAPH_REQUIRES(...) class = void
#else
#else
#if 0
// TODO: This current crashed on clang
#define MIGRAPH_REQUIRES(...) \
#define MIGRAPH_REQUIRES(...) \
bool PrivateRequires##__LINE__ = true, \
typename migraph::requires_enum<__LINE__>::e MIGRAPH_REQUIRES_CAT(PrivateRequires, __LINE__) = migraph::requires_enum<__LINE__>::A, \
class = typename std::enable_if<and_<__VA_ARGS__, PrivateRequires##__LINE__>{}>::type
class = typename std::enable_if<and_<__VA_ARGS__, MIGRAPH_REQUIRES_CAT(PrivateRequires, __LINE__) == migraph::requires_enum<__LINE__>::A>{}>::type
#else
#define MIGRAPH_REQUIRES(...) \
typename migraph::requires_enum<__LINE__>::e MIGRAPH_REQUIRES_CAT(PrivateRequires, __LINE__) = migraph::requires_enum<__LINE__>::A, \
class = typename std::enable_if<and_<__VA_ARGS__>{}>::type
#endif
#endif
#endif
}
// namespace migraph
}
// namespace migraph
...
...
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