Skip to content

Commit de62f08

Browse files
authored
Unset NDEBUG in cmake in assert mode (#248)
Raft defines `RAFT_CHECK_CUDA` depending on if we run in release/Debug mode https://github.com/rapidsai/raft/blob/branch-25.06/cpp/include/raft/util/cuda_rt_essentials.hpp#L78-L82. In cuopt we have a special mode "assert" that undefines `NDEBUG` to run with optimizations but still enable runtime checks. https://github.com/rapidsai/raft/blob/branch-25.06/cpp/include/raft/util/cuda_rt_essentials.hpp#L78-L82 The first version of `RAFT_CHECK_CUDA` uses the stream argument therefore in debug mode and assert mode we should catch that error. However unsetting `NDEBUG` in our header results in `NDEBUG` being undefined in cuopt but still defined for our dependencies. So we were calling the wrong implementation of `RAFT_CUDA_CHECK`. To undefine `NDEBUG` in both cuopt and our dependencies we have to do it through cmake. This catches the compile error. Closes: #247 Authors: - Hugo Linsenmaier (https://github.com/hlinsen) - Alice Boucher (https://github.com/aliceb-nv) Approvers: - Ramakrishnap (https://github.com/rgsl888prabhu) - Alice Boucher (https://github.com/aliceb-nv) URL: #248
1 parent 8dc24a7 commit de62f08

File tree

6 files changed

+19
-4
lines changed

6 files changed

+19
-4
lines changed

cpp/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ elseif(CMAKE_CUDA_LINEINFO)
134134
set(CMAKE_CUDA_FLAGS_RELEASE "${CMAKE_CUDA_FLAGS_RELEASE} -lineinfo")
135135
endif(CMAKE_BUILD_TYPE MATCHES Debug)
136136

137+
# Undefine NDEBUG if assert mode is on
138+
if(DEFINE_ASSERT)
139+
message(STATUS "Undefining NDEBUG with assert mode enabled")
140+
add_definitions(-UNDEBUG)
141+
endif()
142+
137143

138144
# ##################################################################################################
139145
# - find CPM based dependencies ------------------------------------------------------------------

cpp/src/mip/diversity/assignment_hash_map.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ size_t assignment_hash_map_t<i_t, f_t>::hash_solution(solution_t<i_t, f_t>& solu
9797
hash_solution_kernel<i_t, f_t, TPB>
9898
<<<(integer_assignment.size() + TPB - 1) / TPB, TPB, 0, solution.handle_ptr->get_stream()>>>(
9999
cuopt::make_span(integer_assignment), cuopt::make_span(reduction_buffer));
100-
RAFT_CHECK_CUDA(handle_ptr->get_stream());
100+
RAFT_CHECK_CUDA(solution.handle_ptr->get_stream());
101101
// Get the number of blocks used in the hash_solution_kernel
102102
int num_blocks = (integer_assignment.size() + TPB - 1) / TPB;
103103

cpp/src/mip/solution/solution.cu

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,11 @@ f_t solution_t<i_t, f_t>::compute_max_int_violation()
541541
template <typename i_t, typename f_t>
542542
f_t solution_t<i_t, f_t>::compute_max_variable_violation()
543543
{
544+
cuopt_assert(problem_ptr->n_variables == assignment.size(), "Size mismatch");
545+
cuopt_assert(problem_ptr->n_variables == problem_ptr->variable_lower_bounds.size(),
546+
"Size mismatch");
547+
cuopt_assert(problem_ptr->n_variables == problem_ptr->variable_upper_bounds.size(),
548+
"Size mismatch");
544549
return thrust::transform_reduce(
545550
handle_ptr->get_thrust_policy(),
546551
thrust::make_counting_iterator(0),

cpp/src/utilities/macros.cuh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
// 2) medium
2424
// 3) heavy
2525
#ifdef ASSERT_MODE
26-
#undef NDEBUG
2726
#include <cassert>
2827
#define cuopt_assert(val, msg) assert(val&& msg)
2928
#define cuopt_func_call(func) func;

cpp/tests/mip/bounds_standardization_test.cu

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ void test_bounds_standardization_test(std::string test_instance)
7171
init_handler(op_problem.get_handle_ptr());
7272
// run the problem constructor of MIP, so that we do bounds standardization
7373
detail::problem_t<int, double> standardized_problem(op_problem);
74+
detail::problem_t<int, double> original_problem(op_problem);
7475
standardized_problem.preprocess_problem();
7576
detail::trivial_presolve(standardized_problem);
7677
detail::solution_t<int, double> solution_1(standardized_problem);
@@ -88,6 +89,7 @@ void test_bounds_standardization_test(std::string test_instance)
8889
// only consider the pdlp results
8990
EXPECT_TRUE(sol_1_feasible);
9091
standardized_problem.post_process_solution(solution_1);
92+
solution_1.problem_ptr = &original_problem;
9193
auto optimization_prob_solution =
9294
solution_1.get_solution(sol_1_feasible, solver_stats_t<int, double>{});
9395
test_objective_sanity(problem,

cpp/tests/mip/elim_var_remap_test.cu

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ void test_elim_var_solution(std::string test_instance)
154154
init_handler(op_problem.get_handle_ptr());
155155
// run the problem constructor of MIP, so that we do bounds standardization
156156
detail::problem_t<int, double> standardized_problem(op_problem);
157+
detail::problem_t<int, double> original_problem(op_problem);
157158
standardized_problem.preprocess_problem();
158159
trivial_presolve(standardized_problem);
159160
detail::problem_t<int, double> sub_problem(standardized_problem);
@@ -171,7 +172,8 @@ void test_elim_var_solution(std::string test_instance)
171172
bool sol_1_feasible = (int)result_1.get_termination_status() == CUOPT_TERIMINATION_STATUS_OPTIMAL;
172173
EXPECT_EQ((int)result_1.get_termination_status(), CUOPT_TERIMINATION_STATUS_OPTIMAL);
173174
standardized_problem.post_process_solution(solution_1);
174-
auto opt_sol_1 = solution_1.get_solution(sol_1_feasible, solver_stats_t<int, double>{});
175+
solution_1.problem_ptr = &original_problem;
176+
auto opt_sol_1 = solution_1.get_solution(sol_1_feasible, solver_stats_t<int, double>{});
175177
test_objective_sanity(
176178
mps_problem, opt_sol_1.get_solution(), opt_sol_1.get_objective_value(), 1e-3);
177179
test_constraint_sanity_per_row(
@@ -198,7 +200,8 @@ void test_elim_var_solution(std::string test_instance)
198200
bool sol_2_feasible = (int)result_2.get_termination_status() == CUOPT_TERIMINATION_STATUS_OPTIMAL;
199201
EXPECT_EQ((int)result_2.get_termination_status(), CUOPT_TERIMINATION_STATUS_OPTIMAL);
200202
sub_problem.post_process_solution(solution_2);
201-
auto opt_sol_2 = solution_2.get_solution(sol_2_feasible, solver_stats_t<int, double>{});
203+
solution_2.problem_ptr = &original_problem;
204+
auto opt_sol_2 = solution_2.get_solution(sol_2_feasible, solver_stats_t<int, double>{});
202205
test_objective_sanity(
203206
mps_problem, opt_sol_2.get_solution(), opt_sol_2.get_objective_value(), 1e-3);
204207
test_constraint_sanity_per_row(

0 commit comments

Comments
 (0)