Skip to content
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 handling of RNG seed #1369

Merged
merged 1 commit into from
Sep 18, 2024
Merged

Fix handling of RNG seed #1369

merged 1 commit into from
Sep 18, 2024

Conversation

jthornblad
Copy link
Contributor

@jthornblad jthornblad commented Sep 17, 2024

Hi,

There are a couple of problems with the handling of the RNG seed.

First, the seed value used for the deterministic RNG is being truncated from 64 bits to 32 (int instead of uint64) when written to the header of the output JSON file.

When using the --seed option on the command line, the argument needs to be a signed value.

If using the --seed or --randomize-seed option, it is not the originally supplied or randomized seed value that is written to the output JSON file, but a value that has been run through the rngseed() function, which permutes the value before it is stored and then used for the output JSON file.

This patch fixes these problems.

Regards
Jonas

@@ -42,7 +42,7 @@ struct Property
};

Property();
Property(int64_t intval, int width = 32);
Property(int64_t intval, int width = 64);
Copy link
Member

Choose a reason for hiding this comment

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

I'm concerned this might end up having unwanted consequences elsewhere - perhaps you could just instantiate it 64 bits wide in the one place where seed is being saved?

@jthornblad
Copy link
Contributor Author

Does this look ok?

@@ -565,7 +565,8 @@ void CommandHandler::setupContext(Context *ctx)

ctx->settings[ctx->id("arch.name")] = std::string(ctx->archId().c_str(ctx));
ctx->settings[ctx->id("arch.type")] = std::string(ctx->archArgsToId(ctx->archArgs()).c_str(ctx));
ctx->settings[ctx->id("seed")] = ctx->rngstate;
Property seed_property(ctx->rngstate, 64);
ctx->settings[ctx->id("seed")] = seed_property;
Copy link
Member

Choose a reason for hiding this comment

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

what about ctx->settings[ctx->id("seed")] = Property(ctx->rngstate, 64);? that's closer to the style we tend to use.

* Fix truncation of output seed value from 64 bits to 32 bits (int
  instead of uint64) when written to json file.

* Fix input seed value conversion when --seed option is used.

* Remove input seed value scrambling (use of rngseed()) when --seed
  or --randomize-seed option is used since the output seed value will
  be the scrambled value and not the seed that was actually supplied
  or generated.
@jthornblad
Copy link
Contributor Author

Good suggestion, done.

@gatecat gatecat merged commit 6ca6452 into YosysHQ:master Sep 18, 2024
7 of 8 checks passed
@gatecat
Copy link
Member

gatecat commented Sep 18, 2024

Thanks!

@jthornblad
Copy link
Contributor Author

I see that the CI is failing for this patch. I'm not quite sure what the problem is, do you have any idea?

@gatecat
Copy link
Member

gatecat commented Sep 19, 2024

Looks like one of the tests is timing out (probably a latent instability)

@rowanG077
Copy link
Contributor

rowanG077 commented Sep 19, 2024

Input seed handling has changed which means some fixed seeds in the test suite are causing issues. YosysHQ/nextpnr-tests#12 should fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants