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

Fixed strict-aliasing issue using union in const ARPA related code; A… #211

Merged
merged 1 commit into from
Oct 6, 2015

Conversation

chenguoguo
Copy link
Contributor

…lso fixed some style issue that I saw in the related code. Tested this on WSJ and I was able to generate the same binary G.carpa as before.

…lso fixed some style issue that I saw in the related code
arpa_line.logprob = *reinterpret_cast<float*>(lm_state);
arpa_line.backoff_logprob = *reinterpret_cast<float*>(lm_state + 1);
Int32AndFloat logprob_i(*lm_state);
arpa_line.logprob = logprob_i.f;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see why a temporary is needed... just use lm_state->f.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

lm_state has type of int32*. Or perhaps you mean casting lm_state to
Int32AndFloat using something like ((union Int32AndFloat *)lm_state)->f?
That may still cause strict aliasing problem?

Guoguo

On Mon, Oct 5, 2015 at 8:00 PM, Daniel Povey notifications@github.com
wrote:

In src/lm/const-arpa-lm.cc
#211 (comment):

@@ -937,8 +944,10 @@ void ConstArpaLm::WriteArpaRecurse(int32* lm_state,
// Inserts the current LmState to .
ArpaLine arpa_line;
arpa_line.words = seq;

  • arpa_line.logprob = reinterpret_cast<float>(lm_state);
  • arpa_line.backoff_logprob = reinterpret_cast<float>(lm_state + 1);
  • Int32AndFloat logprob_i(*lm_state);
  • arpa_line.logprob = logprob_i.f;

I don't see why a temporary is needed... just use lm_state->f.


Reply to this email directly or view it on GitHub
https://github.com/kaldi-asr/kaldi/pull/211/files#r41213113.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, I see. I had assumed that you had redefined lm_state to be that union.
Probably the compiler can optimize this fine..
did you see whether it affects speed? [I don't expect it will, but just
wonder, if it's easy to test.]

Dan

On Mon, Oct 5, 2015 at 8:11 PM, chenguoguo notifications@github.com wrote:

In src/lm/const-arpa-lm.cc
#211 (comment):

@@ -937,8 +944,10 @@ void ConstArpaLm::WriteArpaRecurse(int32* lm_state,
// Inserts the current LmState to .
ArpaLine arpa_line;
arpa_line.words = seq;

  • arpa_line.logprob = reinterpret_cast<float>(lm_state);
  • arpa_line.backoff_logprob = reinterpret_cast<float>(lm_state + 1);
  • Int32AndFloat logprob_i(*lm_state);
  • arpa_line.logprob = logprob_i.f;

lm_state has type of int32_. Or perhaps you mean casting lm_state to
Int32AndFloat using something like ((union Int32AndFloat *)lm_state)->f?
That may still cause strict aliasing problem? Guoguo
… <#1503a7d7b26b61b2_>
On Mon, Oct 5, 2015 at 8:00 PM, Daniel Povey notifications@github.com
wrote: In src/lm/const-arpa-lm.cc <
https://github.com/kaldi-asr/kaldi/pull/211#discussion_r41213113>: > @@
-937,8 +944,10 @@ void ConstArpaLm::WriteArpaRecurse(int32_ lm_state, > //
Inserts the current LmState to . > ArpaLine arpa_line; >
arpa_line.words = seq; > - arpa_line.logprob =
reinterpret_cast<float>(lm_state); > - arpa_line.backoff_logprob =
reinterpret_cast<float>(lm_state + 1); > + Int32AndFloat
logprob_i(*lm_state); > + arpa_line.logprob = logprob_i.f; I don't see why
a temporary is needed... just use lm_state->f. — Reply to this email
directly or view it on GitHub <
https://github.com/kaldi-asr/kaldi/pull/211/files#r41213113>.


Reply to this email directly or view it on GitHub
https://github.com/kaldi-asr/kaldi/pull/211/files#r41213815.

@chenguoguo
Copy link
Contributor Author

My reply somehow didn't get posted here, not sure if you received.

"On WSJ it doesn't seem to have an impact on the speed."

@danpovey
Copy link
Contributor

danpovey commented Oct 6, 2015

OK thanks, merging then.

danpovey added a commit that referenced this pull request Oct 6, 2015
Fixed strict-aliasing issue using union in const ARPA related code; A…
@danpovey danpovey merged commit 06112ad into kaldi-asr:master Oct 6, 2015
@chenguoguo chenguoguo deleted the guoguo-bugfix branch November 27, 2015 15:12
hainan-xv pushed a commit to hainan-xv/kaldi that referenced this pull request Jul 24, 2018
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.

2 participants