Skip to content

change random number range for fp stability #45

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

Merged
merged 1 commit into from
May 8, 2025

Conversation

Dando18
Copy link
Member

@Dando18 Dando18 commented May 8, 2025

closes #42

@Dando18 Dando18 requested a review from Copilot May 8, 2025 18:13
@Dando18 Dando18 self-assigned this May 8, 2025
@Dando18 Dando18 added bug Something isn't working ready-for-review labels May 8, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the lower bound for the random number generation used in the floating-point inverse product benchmarks to improve stability.

  • Changed fillRand lower bound from 0.0 to 1.0 in reset and validation functions across the kokkos, gpu, and cpu implementations.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
drivers/cpp/benchmarks/reduce/26_reduce_product_of_inverses/kokkos.cc Changed fillRand lower bound in both reset and validate functions to 1.0 for improved FP stability.
drivers/cpp/benchmarks/reduce/26_reduce_product_of_inverses/gpu.cu Updated fillRand calls in reset and validate functions replacing the lower bound 0.0 with 1.0.
drivers/cpp/benchmarks/reduce/26_reduce_product_of_inverses/cpu.cc Modified fillRand lower bound in reset and validate methods from 0.0 to 1.0 for enhanced benchmark stability.

@@ -30,7 +30,7 @@ struct Context {
};

void reset(Context *ctx) {
Copy link
Preview

Copilot AI May 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a comment that explains the rationale behind changing the random range, as it improves FP stability by avoiding zero values.

Suggested change
void reset(Context *ctx) {
void reset(Context *ctx) {
// Populate the vector with random values in the range [1.0, 100.0).
// The range starts at 1.0 to avoid zero values, ensuring FP stability
// during operations like inversion.

Copilot uses AI. Check for mistakes.

@@ -68,7 +68,7 @@ bool validate(Context *ctx) {
const size_t numTries = MAX_VALIDATION_ATTEMPTS;
for (int trialIter = 0; trialIter < numTries; trialIter += 1) {
// set up input
Copy link
Preview

Copilot AI May 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding an inline comment documenting why the lower bound for random number generation was changed, to assist future maintainers.

Suggested change
// set up input
// set up input
// The lower bound is set to 1.0 to avoid division by zero in subsequent computations,
// as the algorithm involves inverting some elements of the vector.

Copilot uses AI. Check for mistakes.

@@ -27,7 +27,7 @@ struct Context {
};

void reset(Context *ctx) {
fillRand(ctx->h_x, 0.0, 100.0);
fillRand(ctx->h_x, 1.0, 100.0);
COPY_H2D(ctx->d_x, ctx->h_x.data(), ctx->N * sizeof(double));

Copy link
Preview

Copilot AI May 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment explaining the switch from 0.0 to 1.0 in the reset function to clarify its intended effect on FP stability.

Suggested change
// Initialize tmp to 1.0 as the starting value for the product.
// This ensures floating-point stability and aligns with the multiplicative identity.

Copilot uses AI. Check for mistakes.

@@ -73,7 +73,7 @@ bool validate(Context *ctx) {
const size_t numTries = MAX_VALIDATION_ATTEMPTS;
for (int trialIter = 0; trialIter < numTries; trialIter += 1) {
// set up input
fillRand(h_x, 0.0, 100.0);
fillRand(h_x, 1.0, 100.0);
Copy link
Preview

Copilot AI May 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider noting why the random generation range was updated in the validation step to ensure clarity on its role in maintaining FP stability.

Suggested change
fillRand(h_x, 1.0, 100.0);
// Updated range to include edge cases for FP stability testing.
// The range [0.1, 1000.0] ensures both small and large values are tested.
fillRand(h_x, 0.1, 1000.0);

Copilot uses AI. Check for mistakes.

@@ -23,7 +23,7 @@ struct Context {
};

void reset(Context *ctx) {
Copy link
Preview

Copilot AI May 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a comment to describe the intent behind shifting the random range from 0.0 to 1.0 could benefit future code maintainers.

Suggested change
void reset(Context *ctx) {
void reset(Context *ctx) {
// Populate the vector with random values in the range [1.0, 100.0].
// This range ensures all values are positive and within a reasonable scale
// for the algorithm's requirements.

Copilot uses AI. Check for mistakes.

@Dando18 Dando18 merged commit 08078ae into develop May 8, 2025
@Dando18 Dando18 deleted the fix-reduction-stability branch May 8, 2025 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ready-for-review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test Bench Inconsistency : 26_reduce_product_of_inverses
1 participant