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: Windows build warnings #4686

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion vowpalwabbit/allreduce/src/allreduce_sockets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void VW::all_reduce_sockets::all_reduce_init(VW::io::logger& logger)
if (lastError != 0) THROWERRNO("WSAStartup() returned error:" << lastError);
#endif

class hostent* master = gethostbyname(_span_server.c_str());
struct hostent* master = gethostbyname(_span_server.c_str());

if (master == nullptr) THROWERRNO("gethostbyname(" << _span_server << ")");

Expand Down
5 changes: 3 additions & 2 deletions vowpalwabbit/core/include/vw/core/action_score.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "vw/core/v_array.h"
#include "vw/core/vw_fwd.h"

#include <cstdint>
#include <iterator>
#include <string>

Expand Down Expand Up @@ -46,7 +47,7 @@ class action_scores_score_iterator
public:
using iterator_category = std::random_access_iterator_tag;
using value_type = float;
using difference_type = long;
using difference_type = intptr_t;
using pointer = float*;
using reference = float;

Expand Down Expand Up @@ -104,4 +105,4 @@ inline VW::action_scores_score_iterator begin_scores(VW::action_scores& a_s) { r

VW_DEPRECATED("ACTION_SCORE::end_scores renamed to VW::end_scores. ACTION_SCORE::end_scores will be removed in VW 10.")
inline VW::action_scores_score_iterator end_scores(VW::action_scores& a_s) { return VW::end_scores(a_s); }
} // namespace ACTION_SCORE
} // namespace ACTION_SCORE
2 changes: 1 addition & 1 deletion vowpalwabbit/core/include/vw/core/automl_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ class interaction_config_manager
bool count_namespaces(const multi_ex& ecs, std::map<namespace_index, uint64_t>& ns_counter);
void apply_config(example* ec, interaction_vec_t* live_interactions);
bool is_allowed_to_remove(const namespace_index ns);
void clear_non_champ_weights(dense_parameters& weights, uint32_t total, uint32_t& feature_width);
//void clear_non_champ_weights(dense_parameters& weights, uint32_t total, uint32_t& feature_width);
bool worse();

// all possible states of automl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ class countable_discrete_base
countable_discrete_base(double tol_x = 1e-6, bool is_brentq = false, double eta = 0.95f, double k = 1.5,
double lambda_max = 0.5, double xi = 1.6);
double get_ci(double alpha) const;
double get_lam_sqrt_tp1(double j) const;
double get_lam_sqrt_tp1(uint64_t j) const;
double get_v_impl(std::map<uint64_t, double>& memo, uint64_t j) const;
double log_wealth_mix(double mu, double s, double thres, std::map<uint64_t, double>& memo) const;
double root_bisect(double s, double thres, std::map<uint64_t, double>& memo, double min_mu, double max_mu) const;
double root_brentq(double s, double thres, std::map<uint64_t, double>& memo, double min_mu, double max_mu) const;
double log_sum_exp(const std::vector<double>& combined) const;
double lb_log_wealth(double alpha) const;
double get_log_weight(double j) const;
double get_log_remaining_weight(double j) const;
double get_log_weight(uint64_t j) const;
double get_log_remaining_weight(uint64_t j) const;
double get_s() const;
double get_v(double lam_sqrt_tp1) const;
void add_obs(double x);
Expand Down
4 changes: 2 additions & 2 deletions vowpalwabbit/core/include/vw/core/hashstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ VW_STD14_CONSTEXPR inline uint32_t hashstring(const char* s, size_t len, uint32_
else { return VW::uniform_hash(front, len, h); }
}

return ret + h;
return static_cast<uint32_t>(ret + h);
}
} // namespace details

Expand All @@ -51,4 +51,4 @@ hash_func_t get_hasher(const std::string& s);
using hash_func_t VW_DEPRECATED("Moved into VW namespace") = VW::hash_func_t;

VW_DEPRECATED("Moved into VW namespace")
VW::hash_func_t get_hasher(const std::string& s);
VW::hash_func_t get_hasher(const std::string& s);
4 changes: 2 additions & 2 deletions vowpalwabbit/core/include/vw/core/multi_model_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ inline void reduce_innermost_model_weights(dense_parameters& weights, const size
}
for (auto weights_it = weights.begin(); weights_it < weights.end(); weights_it += total_feature_width)
{
uint32_t cb_ind = weights_it.index() / innermost_feature_width_size;
uint32_t cb_ind = static_cast<uint32_t>(weights_it.index() / innermost_feature_width_size);
for (size_t outer_offset = 0; outer_offset < overall_without_innermost_feature_width_size; ++outer_offset)
{
for (size_t stride_offset = 0; stride_offset < weights.stride(); ++stride_offset)
Expand All @@ -133,4 +133,4 @@ inline void reduce_innermost_model_weights(dense_parameters& weights, const size
}
} // namespace multi_model
} // namespace reductions
} // namespace VW
} // namespace VW
12 changes: 6 additions & 6 deletions vowpalwabbit/core/include/vw/core/vw.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,32 +295,32 @@ inline uint64_t hash_space_cstr(VW::workspace& all, const char* fstr)
// Then use it as the seed for hashing features.
inline uint64_t hash_feature(VW::workspace& all, const std::string& s, uint64_t u)
{
return all.parser_runtime.example_parser->hasher(s.data(), s.length(), u) & all.runtime_state.parse_mask;
return all.parser_runtime.example_parser->hasher(s.data(), s.length(), static_cast<uint32_t>(u)) & all.runtime_state.parse_mask;
}
inline uint64_t hash_feature_static(const std::string& s, uint64_t u, const std::string& h, uint32_t num_bits)
{
size_t parse_mark = (1 << num_bits) - 1;
return get_hasher(h)(s.data(), s.length(), u) & parse_mark;
return get_hasher(h)(s.data(), s.length(), static_cast<uint32_t>(u)) & parse_mark;
}

inline uint64_t hash_feature_cstr(VW::workspace& all, const char* fstr, uint64_t u)
{
return all.parser_runtime.example_parser->hasher(fstr, strlen(fstr), u) & all.runtime_state.parse_mask;
return all.parser_runtime.example_parser->hasher(fstr, strlen(fstr), static_cast<uint32_t>(u)) & all.runtime_state.parse_mask;
}

inline uint64_t chain_hash(VW::workspace& all, const std::string& name, const std::string& value, uint64_t u)
{
// chain hash is hash(feature_value, hash(feature_name, namespace_hash)) & parse_mask
return all.parser_runtime.example_parser->hasher(
value.data(), value.length(), all.parser_runtime.example_parser->hasher(name.data(), name.length(), u)) &
value.data(), value.length(), all.parser_runtime.example_parser->hasher(name.data(), name.length(), static_cast<uint32_t>(u))) &
all.runtime_state.parse_mask;
}

inline uint64_t chain_hash_static(
const std::string& name, const std::string& value, uint64_t u, hash_func_t hash_func, uint64_t parse_mask)
{
// chain hash is hash(feature_value, hash(feature_name, namespace_hash)) & parse_mask
return hash_func(value.data(), value.length(), hash_func(name.data(), name.length(), u)) & parse_mask;
return hash_func(value.data(), value.length(), hash_func(name.data(), name.length(), static_cast<uint32_t>(u))) & parse_mask;
}

inline float get_weight(VW::workspace& all, uint32_t index, uint32_t offset)
Expand All @@ -335,7 +335,7 @@ inline void set_weight(VW::workspace& all, uint32_t index, uint32_t offset, floa

inline uint32_t num_weights(VW::workspace& all) { return static_cast<uint32_t>(all.length()); }

inline uint32_t get_stride(VW::workspace& all) { return all.weights.stride(); }
inline uint32_t get_stride(VW::workspace& all) { return static_cast<uint32_t>(all.weights.stride()); }

inline void init_features(primitive_feature_space& fs, size_t features_count)
{
Expand Down
8 changes: 4 additions & 4 deletions vowpalwabbit/core/src/confidence_sequence.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void confidence_sequence::update(double w, double r, double p_drop, double n_dro
double bhigh = t + 1.0;
sumxhathighsq += std::pow(ahigh, 2) * (approxpolygammaone(bhigh) - approxpolygammaone(bhigh + n_drop));

t += n_drop;
t += static_cast<int>(n_drop);
}

sumXlow = (sumwr - sumw * rmin) / (rmax - rmin);
Expand Down Expand Up @@ -129,8 +129,8 @@ void confidence_sequence::persist(metric_sink& metrics, const std::string& suffi
metrics.set_uint("upcnt" + suffix, update_count);
metrics.set_float("lb" + suffix, lower_bound());
metrics.set_float("ub" + suffix, upper_bound());
metrics.set_float("last_w" + suffix, last_w);
metrics.set_float("last_r" + suffix, last_r);
metrics.set_float("last_w" + suffix, static_cast<float>(last_w));
metrics.set_float("last_r" + suffix, static_cast<float>(last_r));
}

void confidence_sequence::reset_stats()
Expand Down Expand Up @@ -295,4 +295,4 @@ size_t write_model_field(
return bytes;
}
} // namespace model_utils
} // namespace VW
} // namespace VW
20 changes: 10 additions & 10 deletions vowpalwabbit/core/src/confidence_sequence_robust.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

void g_tilde::histo_insert(double x)
{
uint64_t n = std::floor(std::log(x) / log_k);
uint64_t n = static_cast<uint64_t>(std::floor(std::log(x) / log_k));
double x1 = std::pow(k, n);
double alpha = (k * x1 - x) / ((k - 1.0) * x1);
// TODO: Kahan summation
Expand Down Expand Up @@ -107,9 +107,9 @@

double countable_discrete_base::get_ci(double alpha) const { return lb_log_wealth(alpha); }

double countable_discrete_base::get_lam_sqrt_tp1(double j) const
double countable_discrete_base::get_lam_sqrt_tp1(uint64_t j) const
{
double log_den = (j + 0.5) * log_xi - 0.5 * std::log(t + 1);
double log_den = (static_cast<double>(j) + 0.5) * log_xi - 0.5 * std::log(t + 1);
return lambda_max * std::exp(-log_den);
}

Expand Down Expand Up @@ -282,9 +282,9 @@
else { return root_bisect(s, thres, memo, min_mu, max_mu); }
}

double countable_discrete_base::get_log_weight(double j) const { return log_scale_fac + log_xi_m1 - (1 + j) * log_xi; }
double countable_discrete_base::get_log_weight(size_t j) const { return log_scale_fac + log_xi_m1 - (1 + static_cast<double>(j)) * log_xi; }

Check failure on line 285 in vowpalwabbit/core/src/confidence_sequence_robust.cc

View workflow job for this annotation

GitHub Actions / asan.macos-latest.vcpkg-asan-debug

out-of-line definition of 'get_log_weight' does not match any declaration in 'VW::details::countable_discrete_base'

Check failure on line 285 in vowpalwabbit/core/src/confidence_sequence_robust.cc

View workflow job for this annotation

GitHub Actions / macos-latest-vcpkg-release-Vcpkg build

out-of-line definition of 'get_log_weight' does not match any declaration in 'VW::details::countable_discrete_base'

Check failure on line 285 in vowpalwabbit/core/src/confidence_sequence_robust.cc

View workflow job for this annotation

GitHub Actions / macos-latest-vcpkg-debug-Vcpkg build

out-of-line definition of 'get_log_weight' does not match any declaration in 'VW::details::countable_discrete_base'

Check failure on line 285 in vowpalwabbit/core/src/confidence_sequence_robust.cc

View workflow job for this annotation

GitHub Actions / asan.macos-latest.vcpkg-ubsan-debug

out-of-line definition of 'get_log_weight' does not match any declaration in 'VW::details::countable_discrete_base'

double countable_discrete_base::get_log_remaining_weight(double j) const { return log_scale_fac - j * log_xi; }
double countable_discrete_base::get_log_remaining_weight(size_t j) const { return log_scale_fac - static_cast<double>(j) * log_xi; }

Check failure on line 287 in vowpalwabbit/core/src/confidence_sequence_robust.cc

View workflow job for this annotation

GitHub Actions / asan.macos-latest.vcpkg-asan-debug

out-of-line definition of 'get_log_remaining_weight' does not match any declaration in 'VW::details::countable_discrete_base'

Check failure on line 287 in vowpalwabbit/core/src/confidence_sequence_robust.cc

View workflow job for this annotation

GitHub Actions / macos-latest-vcpkg-release-Vcpkg build

out-of-line definition of 'get_log_remaining_weight' does not match any declaration in 'VW::details::countable_discrete_base'

Check failure on line 287 in vowpalwabbit/core/src/confidence_sequence_robust.cc

View workflow job for this annotation

GitHub Actions / macos-latest-vcpkg-debug-Vcpkg build

out-of-line definition of 'get_log_remaining_weight' does not match any declaration in 'VW::details::countable_discrete_base'

Check failure on line 287 in vowpalwabbit/core/src/confidence_sequence_robust.cc

View workflow job for this annotation

GitHub Actions / asan.macos-latest.vcpkg-ubsan-debug

out-of-line definition of 'get_log_remaining_weight' does not match any declaration in 'VW::details::countable_discrete_base'

double countable_discrete_base::get_s() const { return gt.get_s(); }

Expand Down Expand Up @@ -324,10 +324,10 @@
void confidence_sequence_robust::persist(metric_sink& metrics, const std::string& suffix)
{
metrics.set_uint("upcnt" + suffix, update_count);
metrics.set_float("lb" + suffix, lower_bound());
metrics.set_float("ub" + suffix, upper_bound());
metrics.set_float("last_w" + suffix, last_w);
metrics.set_float("last_r" + suffix, last_r);
metrics.set_float("lb" + suffix, static_cast<float>(lower_bound()));
metrics.set_float("ub" + suffix, static_cast<float>(upper_bound()));
metrics.set_float("last_w" + suffix, static_cast<float>(last_w));
metrics.set_float("last_r" + suffix, static_cast<float>(last_r));
}

void confidence_sequence_robust::reset_stats()
Expand Down Expand Up @@ -408,4 +408,4 @@
return bytes;
}
} // namespace model_utils
} // namespace VW
} // namespace VW
6 changes: 3 additions & 3 deletions vowpalwabbit/core/src/cressieread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ void cressieread::reset_stats(double alpha, double tau)
update_count = 0;
}

float cressieread::lower_bound() { return chisq.cressieread_lower_bound(); }
float cressieread::lower_bound() { return static_cast<float>(chisq.cressieread_lower_bound()); }

float cressieread::upper_bound() { return chisq.cressieread_upper_bound(); }
float cressieread::upper_bound() { return static_cast<float>(chisq.cressieread_upper_bound()); }
} // namespace estimators

namespace model_utils
Expand All @@ -69,4 +69,4 @@ size_t write_model_field(io_buf& io, const VW::estimators::cressieread& sc, cons
return bytes;
}
} // namespace model_utils
} // namespace VW
} // namespace VW
2 changes: 1 addition & 1 deletion vowpalwabbit/core/src/merge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ VW::model_delta merge_deltas(const std::vector<const VW::model_delta*>& deltas_t
// Get example counts and compute weighting of models
std::vector<float> example_counts;
example_counts.reserve(workspaces_to_merge.size());
for (const auto* delta : workspaces_to_merge) { example_counts.push_back(delta->sd->weighted_labeled_examples); }
for (const auto* delta : workspaces_to_merge) { example_counts.push_back(static_cast<float>(delta->sd->weighted_labeled_examples)); }
const auto per_model_weighting = calc_per_model_weighting(example_counts);

// Iterate through learners and merge each one
Expand Down
2 changes: 1 addition & 1 deletion vowpalwabbit/core/src/parse_args.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ uint64_t hash_file_contents(VW::io::reader* file_reader)

bool directory_exists(const std::string& path)
{
class stat info;
struct stat info;
if (stat(path.c_str(), &info) != 0) { return false; }
else { return (info.st_mode & S_IFDIR) > 0; }
// boost::filesystem::path p(path);
Expand Down
41 changes: 37 additions & 4 deletions vowpalwabbit/core/src/reductions/automl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,41 @@
#include "vw/core/reductions/gd.h"
#include "vw/core/setup_base.h"

#include <time.h>
#include <cfloat>
#include <iomanip>

using namespace VW::config;
using namespace VW::LEARNER;
using namespace VW::reductions::automl;

// Under the Windows VC++ runtime, localtime_s is not available in the C++ standard library; instead
// a pre-standard implementation (which reverses the order of the arguments from the standard) exists.
// Note that if _CRT_USE_CONFORMING_ANNEX_K_TIME is defined and set to 1, localtime_s is available in
// the C++ standard library.
#ifdef _WIN32

// If we do not have a standard-compliant localtime_s, we need to define it here.
#if !defined(_CRT_USE_CONFORMING_ANNEX_K_TIME) || _CRT_USE_CONFORMING_ANNEX_K_TIME == 0
namespace std
{
errno_t localtime_s(const time_t* _Time, struct tm* _Tm)
{
return ::localtime_s(_Tm, _Time);
}
} // namespace std
#else
// If we do have a standard-compliant localtime_s, we need to forward to it.
namespace std
{
errno_t localtime_s(const time_t* _Time, struct tm* _Tm)
{
return ::localtime_s(_Time, _Tm);
}
} // namespace std
#endif
#endif

namespace
{
template <typename CMType, bool is_explore>
Expand Down Expand Up @@ -159,11 +187,16 @@

if (trace_logging)
{
struct tm lc;
auto t = std::time(nullptr);
auto lc = *std::localtime(&t);
std::ostringstream oss;
oss << std::put_time(&lc, "%d%m.%H%M%S");
trace_file_name_prefix = oss.str();

if (std::localtime_s(&t, &lc) == 0)

Check failure on line 193 in vowpalwabbit/core/src/reductions/automl.cc

View workflow job for this annotation

GitHub Actions / ubuntu-latest-vcpkg-release-Vcpkg build

‘localtime_s’ is not a member of ‘std’; did you mean ‘localtime’?

Check failure on line 193 in vowpalwabbit/core/src/reductions/automl.cc

View workflow job for this annotation

GitHub Actions / ubuntu-latest-vcpkg-debug-Vcpkg build

‘localtime_s’ is not a member of ‘std’; did you mean ‘localtime’?

Check failure on line 193 in vowpalwabbit/core/src/reductions/automl.cc

View workflow job for this annotation

GitHub Actions / asan.ubuntu-latest.vcpkg-ubsan-debug

‘localtime_s’ is not a member of ‘std’; did you mean ‘localtime’?

Check failure on line 193 in vowpalwabbit/core/src/reductions/automl.cc

View workflow job for this annotation

GitHub Actions / asan.ubuntu-latest.vcpkg-asan-debug

‘localtime_s’ is not a member of ‘std’; did you mean ‘localtime’?
{
std::ostringstream oss;
oss << std::put_time(&lc, "%d%m.%H%M%S");
trace_file_name_prefix = oss.str();
}
else { trace_file_name_prefix = "trace"; }
}

auto cm = VW::make_unique<config_manager_type>(default_lease, max_live_configs, all.get_random_state(),
Expand Down
2 changes: 1 addition & 1 deletion vowpalwabbit/core/src/reductions/bs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void output_example_prediction_bs(
const auto min_max = std::minmax_element(data.pred_vec.begin(), data.pred_vec.end());
for (auto& sink : all.output_runtime.final_prediction_sink)
{
print_result(sink.get(), ec.pred.scalar, ec.tag, *min_max.first, *min_max.second, logger);
print_result(sink.get(), ec.pred.scalar, ec.tag, float(*min_max.first), float(*min_max.second), logger);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class A_triplet_constructor
{
if (feature_value != 0.f)
{
_triplets.emplace_back(Eigen::Triplet<float>(_row_index, index & _weights_mask, feature_value));
_triplets.emplace_back(Eigen::Triplet<float>(static_cast<int>(_row_index), static_cast<int>(index & _weights_mask), feature_value));
if ((index & _weights_mask) > _max_col) { _max_col = (index & _weights_mask); }
}
}
Expand Down Expand Up @@ -240,6 +240,7 @@ cb_explore_adf_large_action_space<T, S>::cb_explore_adf_large_action_space(uint6
, _all(all)
, _seed(seed)
, _impl_type(impl_type)
, _non_degenerate_singular_values(0)
, spanner_state(c, d)
, shrink_fact_config(apply_shrink_factor)
, impl(all, d, _seed, total_size, thread_pool_size, block_size, action_cache_slack, use_explicit_simd)
Expand Down Expand Up @@ -294,7 +295,7 @@ std::shared_ptr<VW::LEARNER::learner> make_las_with_impl(VW::setup_base_i& stack
bool apply_shrink_factor, size_t thread_pool_size, size_t block_size, size_t action_cache_slack,
bool use_explicit_simd)
{
float seed = (all.get_random_state()->get_random() + 1) * 10.f;
uint64_t seed = static_cast<uint64_t>((all.get_random_state()->get_random() + 1) * 10.f);

auto data = VW::make_unique<cb_explore_adf_large_action_space<T, S>>(d, c, apply_shrink_factor, &all, seed,
1 << all.initial_weights_config.num_bits, thread_pool_size, block_size, action_cache_slack, use_explicit_simd,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ inline void kernel_impl(float feature_value, uint64_t index, uint64_t weights_ma
constexpr static std::array<float, 4> VALUE_MAP = {0.f, 0.f, 1.f, -1.f};

#ifdef _MSC_VER
int select_sparsity = __popcnt((index & weights_mask) + column_index) & 1;
// TODO: should we be using __popcnt64 here?
int select_sparsity = __popcnt(static_cast<unsigned int>((index & weights_mask) + column_index)) & 1;
int sparsity_index = INDEX_MAP[select_sparsity];
int select_sign = __popcnt((index & weights_mask) + column_index + seed) & 1;
int select_sign = __popcnt(static_cast<unsigned int>((index & weights_mask) + column_index + seed)) & 1;
int value_index = sparsity_index + select_sign;
float val = VALUE_MAP[value_index];
#else
Expand All @@ -35,6 +36,8 @@ inline void kernel_impl(float feature_value, uint64_t index, uint64_t weights_ma
float val = VALUE_MAP[value_index];
#endif



final_dot_product += feature_value * val;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void one_pass_svd_impl::generate_AOmega(const multi_ex& examples, const std::vec
}
}

const float scaling_factor = 1.f / std::sqrt(p);
const float scaling_factor = static_cast<float>(1.f / std::sqrt(p));
// resize is a no-op if size does not change
AOmega.resize(num_actions, p);

Expand Down Expand Up @@ -194,4 +194,4 @@ one_pass_svd_impl::one_pass_svd_impl(VW::workspace* all, uint64_t d, uint64_t se
}

} // namespace cb_explore_adf
} // namespace VW
} // namespace VW
Loading
Loading