Skip to content

Commit a0da8b6

Browse files
Fix device code to provide trailing return type. (#738)
<!-- Thank you for contributing to cuOpt :) Here are some guidelines to help the review process go smoothly. Many thanks in advance for your cooperation! Note: The pull request title will be included in the CHANGELOG. --> ## Checklist - [x] I am familiar with the [Contributing Guidelines](https://github.com/NVIDIA/cuopt/blob/HEAD/CONTRIBUTING.md). - Testing - [ ] New or existing tests cover these changes - [ ] Added tests - [ ] Created an issue to follow-up - [x] NA - Documentation - [ ] The documentation is up to date with these changes - [ ] Added new documentation - [x] NA <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Corrected a validation check for the binary variable table so indices and bounds are validated consistently. * Made predicate behavior in internal parallel checks explicit to prevent mis-evaluation, improving reliability of solver validations. * No changes to external behavior or public interfaces; users should see more robust validation with no functional differences. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 3be4325 commit a0da8b6

File tree

3 files changed

+29
-27
lines changed

3 files changed

+29
-27
lines changed

cpp/src/mip/diversity/lns/rins.cu

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,16 @@ void rins_t<i_t, f_t>::run_rins()
135135
cuopt_assert(best_sol.assignment.size() == problem_copy->n_variables, "Assignment size mismatch");
136136

137137
rmm::device_uvector<i_t> vars_to_fix(problem_copy->n_integer_vars, rins_handle.get_stream());
138-
auto end = thrust::copy_if(rins_handle.get_thrust_policy(),
139-
problem_copy->integer_indices.begin(),
140-
problem_copy->integer_indices.end(),
141-
vars_to_fix.begin(),
142-
[lpopt = lp_opt_device.data(),
143-
pb = problem_copy->view(),
144-
incumbent = best_sol.assignment.data()] __device__(i_t var_idx) {
145-
return pb.integer_equal(lpopt[var_idx], incumbent[var_idx]);
146-
});
138+
auto end =
139+
thrust::copy_if(rins_handle.get_thrust_policy(),
140+
problem_copy->integer_indices.begin(),
141+
problem_copy->integer_indices.end(),
142+
vars_to_fix.begin(),
143+
[lpopt = lp_opt_device.data(),
144+
pb = problem_copy->view(),
145+
incumbent = best_sol.assignment.data()] __device__(i_t var_idx) -> bool {
146+
return pb.integer_equal(lpopt[var_idx], incumbent[var_idx]);
147+
});
147148
vars_to_fix.resize(end - vars_to_fix.begin(), rins_handle.get_stream());
148149
f_t fractional_ratio = (f_t)(vars_to_fix.size()) / (f_t)problem_copy->n_integer_vars;
149150

@@ -167,7 +168,7 @@ void rins_t<i_t, f_t>::run_rins()
167168
cuopt_assert(thrust::all_of(rins_handle.get_thrust_policy(),
168169
vars_to_fix.begin(),
169170
vars_to_fix.end(),
170-
[pb = problem_copy->view()] __device__(i_t var_idx) {
171+
[pb = problem_copy->view()] __device__(i_t var_idx) -> bool {
171172
return pb.is_integer_var(var_idx);
172173
}),
173174
"All variables to fix must be integer variables");

cpp/src/mip/feasibility_jump/feasibility_jump.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ void fj_t<i_t, f_t>::climber_init(i_t climber_idx, const rmm::cuda_stream_view&
554554
cuopt_assert(thrust::all_of(rmm::exec_policy(climber_stream),
555555
thrust::counting_iterator<i_t>(0),
556556
thrust::counting_iterator<i_t>(cstr_coeff_reciprocal.size()),
557-
[v = view] __device__(i_t offset) {
557+
[v = view] __device__(i_t offset) -> bool {
558558
return v.cstr_coeff_reciprocal[offset] != 0 &&
559559
isfinite(v.cstr_coeff_reciprocal[offset]);
560560
}),

cpp/src/mip/problem/problem.cu

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -698,23 +698,24 @@ void problem_t<i_t, f_t>::check_problem_representation(bool check_transposed,
698698
return true;
699699
}),
700700
"Some variables aren't referenced in the appropriate indice tables");
701-
cuopt_assert(thrust::all_of(handle_ptr->get_thrust_policy(),
702-
thrust::make_zip_iterator(thrust::make_counting_iterator<i_t>(0),
703-
is_binary_variable.cbegin()),
704-
thrust::make_zip_iterator(
705-
thrust::make_counting_iterator<i_t>(is_binary_variable.size()),
701+
cuopt_assert(
702+
thrust::all_of(
703+
handle_ptr->get_thrust_policy(),
704+
thrust::make_zip_iterator(thrust::make_counting_iterator<i_t>(0),
705+
is_binary_variable.cbegin()),
706+
thrust::make_zip_iterator(thrust::make_counting_iterator<i_t>(is_binary_variable.size()),
706707
is_binary_variable.cend()),
707-
[types = variable_types.data(),
708-
vars_bnd = make_span(variable_bounds),
709-
v = view()] __device__(const thrust::tuple<int, int> tuple) {
710-
i_t idx = thrust::get<0>(tuple);
711-
i_t pred = thrust::get<1>(tuple);
712-
auto bounds = vars_bnd[idx];
713-
return pred == (types[idx] != var_t::CONTINUOUS &&
714-
v.integer_equal(get_lower(bounds), 0.) &&
715-
v.integer_equal(get_upper(bounds), 1.));
716-
}),
717-
"The binary variable table is incorrect.");
708+
[types = variable_types.data(),
709+
vars_bnd = make_span(variable_bounds),
710+
v = view()] __device__(const thrust::tuple<int, int> tuple) -> bool {
711+
i_t idx = thrust::get<0>(tuple);
712+
i_t pred = thrust::get<1>(tuple);
713+
auto bounds = vars_bnd[idx];
714+
return pred ==
715+
(types[idx] != var_t::CONTINUOUS && v.integer_equal(get_lower(bounds), 0.) &&
716+
v.integer_equal(get_upper(bounds), 1.));
717+
}),
718+
"The binary variable table is incorrect.");
718719
if (!empty) {
719720
cuopt_assert(is_binary_pb == (n_variables == thrust::count(handle_ptr->get_thrust_policy(),
720721
is_binary_variable.begin(),

0 commit comments

Comments
 (0)