Skip to content

Commit

Permalink
Update kp_sampler_skip.cpp: putting in seed
Browse files Browse the repository at this point in the history
User can input seed for RNG for probabilistic sampling
  • Loading branch information
vlkale authored Oct 23, 2023
1 parent 9df6748 commit b629300
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion common/kokkos-sampler/kp_sampler_skip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ static uint64_t kernelSampleSkip = std::numeric_limits<uint64_t>::max();
static double tool_prob_num = -1.0;
static int tool_verbosity = 0;
static int tool_globFence = 0;
static unsigned int tool_seed = 1;

// a hash table mapping kID to nestedkID
static std::unordered_map<uint64_t, uint64_t> infokIDSample;
Expand Down Expand Up @@ -81,6 +82,8 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer,
const uint32_t devInfoCount, void* deviceInfo) {
const char* tool_verbose_str = getenv("KOKKOS_TOOLS_SAMPLER_VERBOSE");
const char* tool_globFence_str = getenv("KOKKOS_TOOLS_GLOBALFENCES");
const char* tool_seed_str = getenv("KOKKOS_TOOLS_SEED");

if (NULL != tool_verbose_str) {
tool_verbosity = atoi(tool_verbose_str);
} else {
Expand All @@ -91,6 +94,11 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer,
} else {
tool_globFence = 0;
}
if (NULL != tool_seed_str) {
tool_seed = atoi(tool_seed_str);
} else {
tool_seed = 1;
}

char* profileLibrary = getenv("KOKKOS_TOOLS_LIBS");
if (NULL == profileLibrary) {
Expand Down Expand Up @@ -234,11 +242,24 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer,
printf("KokkosP: Sampling rate set to: %llu\n",
(unsigned long long)(kernelSampleSkip));
printf("KokkosP: Sampling probability set to %f\n", tool_prob_num);
}

if(0 > tool_seed) {
srand(time(NULL));
if(tool_verbosity > 0) {
printf(
"KokkosP: seeding Random Number Generator using clock for "
"probabilistic sampling.\n");
}
}
srand(time(NULL));
else {
srand(tool_seed);
if(tool_verbosity > 0) {
printf(
"KokkosP: seeding Random Number Generator using seed %u for "
"probabilistic sampling.\n", tool_seed);
}
}

if ((NULL != tool_probability) && (NULL != tool_sample)) {
printf(
Expand Down

0 comments on commit b629300

Please sign in to comment.