-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #315: JTest uses a flawed RNG setup #347
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
002aeae
Replaced JPerfUtils with JBenchUtils (class format), set event number…
RaiqaRasool c23544f
JBenchUtils Seed setting moved from constructor to separate function
RaiqaRasool c17259d
Merge branch 'master' into rasool_issue315SeedRNGFix
RaiqaRasool cfb8195
JBenchUtils header files added
RaiqaRasool 61ef6f3
Remove JPerfUtils
nathanwbrei File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
|
||
// Copyright 2020, Jefferson Science Associates, LLC. | ||
// Subject to the terms in the LICENSE file found in the top-level directory. | ||
|
||
|
||
#include "JBenchUtils.h" | ||
|
||
|
||
JBenchUtils::JBenchUtils(size_t event_number, std::string caller_name) | ||
{ | ||
std::hash<std::string> hasher; | ||
long seed = event_number ^ hasher(caller_name); | ||
m_generator = std::mt19937(seed); | ||
} | ||
|
||
|
||
size_t JBenchUtils::rand_size(size_t avg, double spread) { | ||
auto delta = static_cast<size_t>(avg*spread); | ||
std::uniform_int_distribution<size_t> distribution(avg-delta, avg+delta); | ||
return distribution(m_generator); | ||
} | ||
|
||
|
||
int JBenchUtils::randint(int min, int max) { | ||
std::uniform_int_distribution<int> distribution(min, max); | ||
return distribution(m_generator); | ||
} | ||
|
||
double JBenchUtils::randdouble(double min, double max) { | ||
std::uniform_real_distribution<double> dist(min, max); | ||
return dist(m_generator); | ||
} | ||
|
||
float JBenchUtils::randfloat(float min, float max) { | ||
std::uniform_real_distribution<float> dist(min, max); | ||
return dist(m_generator); | ||
} | ||
|
||
uint64_t JBenchUtils::consume_cpu_ms(uint64_t millisecs, double spread, bool fix_flops) { | ||
|
||
uint64_t sampled = rand_size(millisecs, spread); | ||
uint64_t result = 0; | ||
|
||
if (fix_flops) { | ||
// Perform a fixed amount of work in a variable time | ||
const uint64_t appx_iters_per_millisec = 14000; | ||
sampled *= appx_iters_per_millisec; | ||
|
||
for (uint64_t i=0; i<sampled; ++i) { | ||
double a = (m_generator)(); | ||
double b = sqrt(a * pow(1.23, -a)) / a; | ||
result += long(b); | ||
} | ||
} | ||
else { | ||
// Perform a variable amount of work in a fixed time | ||
auto duration = std::chrono::milliseconds(sampled); | ||
auto start_time = std::chrono::steady_clock::now(); | ||
while ((std::chrono::steady_clock::now() - start_time) < duration) { | ||
|
||
double a = (m_generator)(); | ||
double b = sqrt(a * pow(1.23, -a)) / a; | ||
result += long(b); | ||
} | ||
} | ||
return result; | ||
} | ||
|
||
uint64_t JBenchUtils::read_memory(const std::vector<char>& buffer) { | ||
|
||
auto length = buffer.size(); | ||
uint64_t sum = 0; | ||
for (unsigned i=0; i<length; ++i) { | ||
sum += buffer[i]; | ||
} | ||
return sum; | ||
} | ||
|
||
uint64_t JBenchUtils::write_memory(std::vector<char>& buffer, uint64_t bytes, double spread) { | ||
|
||
uint64_t sampled = rand_size(bytes, spread); | ||
for (unsigned i=0; i<sampled; ++i) { | ||
buffer.push_back(2); | ||
} | ||
return sampled*2; | ||
} | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
// Copyright 2020, Jefferson Science Associates, LLC. | ||
// Subject to the terms in the LICENSE file found in the top-level directory. | ||
|
||
#pragma once | ||
|
||
#include <vector> | ||
#include <random> | ||
#include <string> | ||
#include <algorithm> | ||
#include <string> | ||
#include <typeinfo> | ||
#include <chrono> | ||
|
||
|
||
class JBenchUtils { | ||
|
||
std::mt19937 m_generator; | ||
|
||
public: | ||
|
||
JBenchUtils(size_t event_number, std::string caller_name); | ||
|
||
size_t rand_size(size_t avg, double spread); | ||
int randint(int min, int max); | ||
double randdouble(double min=0.0, double max=1000.0); | ||
float randfloat(float min=0.0, float max=1000.0); | ||
|
||
uint64_t consume_cpu_ms(uint64_t millisecs, double spread=0.0, bool fix_flops=true); | ||
uint64_t read_memory(const std::vector<char>& buffer); | ||
uint64_t write_memory(std::vector<char>& buffer, uint64_t bytes, double spread=0.0); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The constructor for JBenchUtils might be expensive, so I'd consider adding a method to reset the seed rather than recreating the object on every event. If you make
bench_utils
be a member variable, you can construct it exactly once and then reset the seed on every event. Also, you don't need the unique_ptr here because ownership stays with the component and there's no inheritance hierarchy to watch out for.