-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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 msvc build errors in block_cache_trace_analyzer.cc (#5746) #5838
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
#include <fstream> | ||
#include <iomanip> | ||
#include <iostream> | ||
#include <memory> | ||
#include <random> | ||
#include <sstream> | ||
|
||
|
@@ -650,7 +651,8 @@ void BlockCacheTraceAnalyzer::WriteCorrelationFeaturesToFile( | |
const std::map<std::string, Features>& label_features, | ||
const std::map<std::string, Predictions>& label_predictions, | ||
uint32_t max_number_of_values) const { | ||
std::default_random_engine rand_engine(env_->NowMicros()); | ||
std::default_random_engine rand_engine( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indentation. Can you |
||
static_cast<unsigned int>(env_->NowMicros())); | ||
for (auto const& label_feature_vectors : label_features) { | ||
const Features& past = label_feature_vectors.second; | ||
auto it = label_predictions.find(label_feature_vectors.first); | ||
|
@@ -1209,11 +1211,14 @@ void BlockCacheTraceAnalyzer::WriteBlockReuseTimeline( | |
TraverseBlocks(block_callback); | ||
|
||
// A cell is the number of blocks accessed in a reuse window. | ||
uint64_t reuse_table[reuse_vector_size][reuse_vector_size]; | ||
const std::unique_ptr<uint64_t[]> reuse_table( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MSVC supports two-dimensional arrays, but does not support variable length arrays, i.e. dimension sizes need to be known at compile time. Variable length array is not part of recent versions of C++ standard. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will the following compile and run on MSVC?
If not, this change is necessary. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does not compile: "error C2131: expression did not evaluate to a constant" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @hliu18 for verifying this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see this PR was imported but not checked in due to conflicts. Can someone help move this PR forward? I was going to fix a couple of build break on MSVC and noticed this. |
||
new uint64_t[reuse_vector_size * reuse_vector_size]); | ||
|
||
for (uint64_t start_time = 0; start_time < reuse_vector_size; start_time++) { | ||
// Initialize the reuse_table. | ||
const auto offset = start_time * reuse_vector_size; | ||
for (uint64_t i = 0; i < reuse_vector_size; i++) { | ||
reuse_table[start_time][i] = 0; | ||
reuse_table[offset + i] = 0; | ||
} | ||
// Examine all blocks. | ||
for (auto const& block : block_accessed) { | ||
|
@@ -1222,7 +1227,7 @@ void BlockCacheTraceAnalyzer::WriteBlockReuseTimeline( | |
// This block is accessed at start time and at the current time. We | ||
// increment reuse_table[start_time][i] since it is reused at the ith | ||
// window. | ||
reuse_table[start_time][i]++; | ||
reuse_table[offset + i]++; | ||
} | ||
} | ||
} | ||
|
@@ -1245,13 +1250,15 @@ void BlockCacheTraceAnalyzer::WriteBlockReuseTimeline( | |
out << header << std::endl; | ||
for (uint64_t start_time = 0; start_time < reuse_vector_size; start_time++) { | ||
std::string row(std::to_string(start_time * reuse_window)); | ||
const auto offset = start_time * reuse_vector_size; | ||
for (uint64_t j = 0; j < reuse_vector_size; j++) { | ||
row += ","; | ||
if (j < start_time) { | ||
row += "100.0"; | ||
} else { | ||
row += std::to_string(percent(reuse_table[start_time][j], | ||
reuse_table[start_time][start_time])); | ||
row += std::to_string(percent( | ||
reuse_table[offset + j], | ||
reuse_table[offset + start_time])); | ||
} | ||
} | ||
out << row << std::endl; | ||
|
@@ -1680,7 +1687,8 @@ void BlockCacheTraceAnalyzer::PrintAccessCountStats(bool user_access_only, | |
for (auto const& caller_access : block->caller_num_access_map) { | ||
if (!user_access_only || | ||
(user_access_only && is_user_access(caller_access.first))) { | ||
caller_naccesses[caller_access.first] += caller_access.second; | ||
caller_naccesses[caller_access.first] += | ||
static_cast<uint32_t>(caller_access.second); | ||
naccesses += caller_access.second; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<memory>
is already included by including other headers.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, I originally thought that was why the xcode build was failing. But it turns out xcode clang doesn't like std::make_unique at all, at least with the compiler options that are being used here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean we can use
#if defined()
to enclose this include?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would just remove it altogether. If I had looked more closely I would have realized that std::unique_ptr is already used in several other places in this file, so including is clearly not necessary for this new use of it.
Alternatively you could keep it in; some people would argue that each file should explicitly include the headers for what it uses so that it is not dependent on other header files including them first. All of those headers will have include guards so the impact on compile time should be negligible.