Skip to content

Conversation

@galv
Copy link
Contributor

@galv galv commented May 8, 2018

I noticed in a real world program that about 5% of time is spent
in this method, so this seems like a reasonable thing to force,
given the small nature of this function.

Note that I am not sure whether this will force icc to inline the
member functions. I doubt it.

See discussion at #2406

I noticed in a real world program that about 5% of time is spent
in this method, so this seems like a reasonable thing to force,
given the small nature of this function.

Note that I am not sure whether this will force icc to inline the
member functions. I doubt it.
@galv
Copy link
Contributor Author

galv commented May 8, 2018

Not tested on windows, or with intel's compiler. But put this up just to show how small the change is.

@jtrmal
Copy link
Contributor

jtrmal commented May 8, 2018 via email

@galv
Copy link
Contributor Author

galv commented May 8, 2018 via email

@jtrmal
Copy link
Contributor

jtrmal commented May 8, 2018 via email

@galv
Copy link
Contributor Author

galv commented May 8, 2018

Results (see the latest commit for the speed test's contents):

Nearly 2x the speed, from what I can tell.

Float, not inlined:

VectorBase::operator(),float,1024,5.00679e-06,seconds
VectorBase::operator(),float,2048,1.00136e-05,seconds
VectorBase::operator(),float,4096,2.00272e-05,seconds
VectorBase::operator(),float,8192,3.91006e-05,seconds

Float, inlined:

VectorBase::operator(),float,1024,3.09944e-06,seconds
VectorBase::operator(),float,2048,5.96046e-06,seconds
VectorBase::operator(),float,4096,1.19209e-05,seconds
VectorBase::operator(),float,8192,2.38419e-05,seconds

Double, not inlined:

VectorBase::operator(),double,1024,5.00679e-06,seconds
VectorBase::operator(),double,2048,1.00136e-05,seconds
VectorBase::operator(),double,4096,2.00272e-05,seconds
VectorBase::operator(),double,8192,4.00543e-05,seconds

Double, inlined:

VectorBase::operator(),double,1024,2.86102e-06,seconds
VectorBase::operator(),double,2048,5.96046e-06,seconds
VectorBase::operator(),double,4096,1.19209e-05,seconds
VectorBase::operator(),double,8192,2.40803e-05,seconds

@danpovey
Copy link
Contributor

danpovey commented May 8, 2018 via email

@galv
Copy link
Contributor Author

galv commented May 8, 2018

Yes, I can do it on Mac, where g++ masquerades as clang++. It'll likely wait until tonight, though.

::operator() uses KALDI_PARANOID_ASSERT(), so I thought that there is by default no bounds checking (regardless of the NDEBUG macros)? The fact that the implementation is otherwise just adding to a pointer and dereferencing made me surprised that this function is not inlined by default.

@danpovey
Copy link
Contributor

danpovey commented May 8, 2018 via email

@jtrmal
Copy link
Contributor

jtrmal commented May 8, 2018 via email

@jtrmal
Copy link
Contributor

jtrmal commented May 8, 2018 via email

@jtrmal
Copy link
Contributor

jtrmal commented May 8, 2018 via email

@galv
Copy link
Contributor Author

galv commented May 8, 2018 via email

@jtrmal
Copy link
Contributor

jtrmal commented May 8, 2018 via email

@danpovey
Copy link
Contributor

danpovey commented May 8, 2018 via email

@galv
Copy link
Contributor Author

galv commented May 8, 2018 via email

@danpovey
Copy link
Contributor

danpovey commented May 8, 2018 via email

@galv
Copy link
Contributor Author

galv commented May 8, 2018

What you propose sounds reasonable. I am sure I can do that at some point. I'll just need to make sure I put -O1 in the right location so that that setting can be overridden by the user specifying EXTRA_CXXFLAGS (e.g., if EXTRA_CXXFLAGS="-O2", then we should not compile with -O1), which involves studying the gcc man page for a bit.

@galv
Copy link
Contributor Author

galv commented May 9, 2018

Interestingly, it turns out that enabling -O2 by default (in an internal kaldi repo) has created a lot interesting new warnings (I guess because inlining allows for more whole-program analysis). For example:

kaldi-io.cc: In member function ‘virtual bool kaldi::OffsetFileInputImpl::Open(const string&, bool)’:
kaldi-io.cc:586:27: warning: ‘offset’ may be used uninitialized in this function [-Wmaybe-uninitialized]
       return (is_.tellg() == std::streampos(offset));
                           ^
kaldi-io.cc:624:14: note: ‘offset’ was declared here
       size_t offset;
              ^
kaldi-io.cc:586:27: warning: ‘offset’ may be used uninitialized in this function [-Wmaybe-uninitialized]
       return (is_.tellg() == std::streampos(offset));
                           ^
kaldi-io.cc:608:14: note: ‘offset’ was declared here
       size_t offset;
              ^
parse-options.cc: In member function ‘int32 kaldi::ParseOptions::ToInt(const string&)’:
parse-options.cc:599:10: warning: ‘ret’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   return ret;
          ^
parse-options.cc: In member function ‘uint32 kaldi::ParseOptions::ToUint(const string&)’:
parse-options.cc:606:10: warning: ‘ret’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   return ret;
          ^

So it won't be a small PR, most likely.

I'll get around to it later.

@galv
Copy link
Contributor Author

galv commented May 10, 2018

Superseded by #2411

@galv galv closed this May 10, 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.

3 participants