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
OpenDAS
dgl
Commits
25eabbb4
Unverified
Commit
25eabbb4
authored
Jan 04, 2024
by
Muhammed Fatih BALIN
Committed by
GitHub
Jan 04, 2024
Browse files
[GraphBolt] Setting manual seed also sets the seed now. (#6900)
parent
107b4347
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
1 deletion
+12
-1
graphbolt/src/random.cc
graphbolt/src/random.cc
+8
-1
graphbolt/src/random.h
graphbolt/src/random.h
+4
-0
No files found.
graphbolt/src/random.cc
View file @
25eabbb4
...
@@ -28,11 +28,13 @@ inline uint32_t GetThreadId() {
...
@@ -28,11 +28,13 @@ inline uint32_t GetThreadId() {
};
// namespace
};
// namespace
std
::
mutex
RandomEngine
::
manual_seed_mutex
;
std
::
optional
<
uint64_t
>
RandomEngine
::
manual_seed
;
std
::
optional
<
uint64_t
>
RandomEngine
::
manual_seed
;
/** @brief Constructor with default seed. */
/** @brief Constructor with default seed. */
RandomEngine
::
RandomEngine
()
{
RandomEngine
::
RandomEngine
()
{
std
::
random_device
rd
;
std
::
random_device
rd
;
std
::
lock_guard
lock
(
manual_seed_mutex
);
uint64_t
seed
=
manual_seed
.
value_or
(
rd
());
uint64_t
seed
=
manual_seed
.
value_or
(
rd
());
SetSeed
(
seed
);
SetSeed
(
seed
);
}
}
...
@@ -59,6 +61,11 @@ void RandomEngine::SetSeed(uint64_t seed, uint64_t stream) {
...
@@ -59,6 +61,11 @@ void RandomEngine::SetSeed(uint64_t seed, uint64_t stream) {
}
}
/** @brief Manually fix the seed. */
/** @brief Manually fix the seed. */
void
RandomEngine
::
SetManualSeed
(
int64_t
seed
)
{
manual_seed
=
seed
;
}
void
RandomEngine
::
SetManualSeed
(
int64_t
seed
)
{
// Intentionally set the seed for current thread also.
RandomEngine
::
ThreadLocal
()
->
SetSeed
(
seed
);
std
::
lock_guard
lock
(
manual_seed_mutex
);
manual_seed
=
seed
;
}
}
// namespace graphbolt
}
// namespace graphbolt
graphbolt/src/random.h
View file @
25eabbb4
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
#include <dmlc/thread_local.h>
#include <dmlc/thread_local.h>
#include <mutex>
#include <optional>
#include <optional>
#include <pcg_random.hpp>
#include <pcg_random.hpp>
#include <random>
#include <random>
...
@@ -36,6 +37,9 @@ class RandomEngine {
...
@@ -36,6 +37,9 @@ class RandomEngine {
void
SetSeed
(
uint64_t
seed
);
void
SetSeed
(
uint64_t
seed
);
void
SetSeed
(
uint64_t
seed
,
uint64_t
stream
);
void
SetSeed
(
uint64_t
seed
,
uint64_t
stream
);
/** @brief Protect manual seed accesses. */
static
std
::
mutex
manual_seed_mutex
;
/** @brief Manually fix the seed. */
/** @brief Manually fix the seed. */
static
std
::
optional
<
uint64_t
>
manual_seed
;
static
std
::
optional
<
uint64_t
>
manual_seed
;
static
void
SetManualSeed
(
int64_t
seed
);
static
void
SetManualSeed
(
int64_t
seed
);
...
...
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