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

[Windows] Copy NominalCPUFrequency from Abseil #16905

Merged
merged 2 commits into from
Feb 28, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions tensorflow/core/platform/windows/port.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ limitations under the License.
#endif

#include <Windows.h>
#include <shlwapi.h>

#include "tensorflow/core/platform/cpu_info.h"
#include "tensorflow/core/platform/demangle.h"
Expand Down Expand Up @@ -149,11 +150,16 @@ bool Snappy_Uncompress(const char* input, size_t length, char* output) {
string Demangle(const char* mangled) { return mangled; }

double NominalCPUFrequency() {
#ifdef TENSORFLOW_USE_ABSL
return absl::base_internal::NominalCPUFrequency();
#else
DWORD data;
DWORD data_size = sizeof(data);
#pragma comment(lib, "shlwapi.lib") // For SHGetValue().
Copy link
Member

Choose a reason for hiding this comment

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

Can we avoid using this?

Copy link
Member

Choose a reason for hiding this comment

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

Or I guess we have to add #include <shlwapi.h> ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you want to avoid this pragma, then we will have to add shlwapi.lib to linker flags. For Bazel it will be -defaultlib:shlwapi.lib or Bazel will think shlwapi.lib is a label.

Copy link
Member

Choose a reason for hiding this comment

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

I understand, but don't we need #include <shlwapi.h> as well to use SHGetValue()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for missing your point. Yes, shlwapi.h needs to be included explicitly, I wrongly assumed that it is already included in windows.h. Done.

Copy link
Member

Choose a reason for hiding this comment

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

Thank you!

if (SUCCEEDED(
SHGetValueA(HKEY_LOCAL_MACHINE,
"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0",
"~MHz", nullptr, &data, &data_size))) {
return data * 1e6; // Value is MHz.
}
return 1.0;
#endif
}

int64 AvailableRam() {
Expand Down