Skip to content

Commit 3917ee6

Browse files
committed
Refactor: move finite-bound computation
1 parent 0742da9 commit 3917ee6

File tree

2 files changed

+42
-32
lines changed

2 files changed

+42
-32
lines changed

src/preconditioner.cu

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,12 @@ limitations under the License.
2727
__global__ void scale_variables_kernel(double *__restrict__ objective_vector,
2828
double *__restrict__ variable_lower_bound,
2929
double *__restrict__ variable_upper_bound,
30-
double *__restrict__ variable_lower_bound_finite_val,
31-
double *__restrict__ variable_upper_bound_finite_val,
3230
double *__restrict__ initial_primal_solution,
3331
const double *__restrict__ variable_rescaling,
3432
const double *__restrict__ inverse_variable_rescaling,
3533
int num_variables);
3634
__global__ void scale_constraints_kernel(double *__restrict__ constraint_lower_bound,
3735
double *__restrict__ constraint_upper_bound,
38-
double *__restrict__ constraint_lower_bound_finite_val,
39-
double *__restrict__ constraint_upper_bound_finite_val,
4036
double *__restrict__ initial_dual_solution,
4137
const double *__restrict__ constraint_rescaling,
4238
const double *__restrict__ inverse_constraint_rescaling,
@@ -70,8 +66,6 @@ __global__ void reduce_bound_norm_sq_kernel(
7066
__global__ void scale_bounds_kernel(
7167
double *__restrict__ constraint_lower_bound,
7268
double *__restrict__ constraint_upper_bound,
73-
double *__restrict__ constraint_lower_bound_finite_val,
74-
double *__restrict__ constraint_upper_bound_finite_val,
7569
double *__restrict__ initial_dual_solution,
7670
int num_constraints,
7771
double constraint_scale,
@@ -80,8 +74,6 @@ __global__ void scale_objective_kernel(
8074
double *__restrict__ objective_vector,
8175
double *__restrict__ variable_lower_bound,
8276
double *__restrict__ variable_upper_bound,
83-
double *__restrict__ variable_lower_bound_finite_val,
84-
double *__restrict__ variable_upper_bound_finite_val,
8577
double *__restrict__ initial_primal_solution,
8678
int num_variables,
8779
double constraint_scale,
@@ -108,8 +100,6 @@ static void scale_problem(
108100
state->objective_vector,
109101
state->variable_lower_bound,
110102
state->variable_upper_bound,
111-
state->variable_lower_bound_finite_val,
112-
state->variable_upper_bound_finite_val,
113103
state->initial_primal_solution,
114104
variable_rescaling,
115105
inverse_variable_rescaling,
@@ -118,8 +108,6 @@ static void scale_problem(
118108
scale_constraints_kernel<<<state->num_blocks_dual, THREADS_PER_BLOCK>>>(
119109
state->constraint_lower_bound,
120110
state->constraint_upper_bound,
121-
state->constraint_lower_bound_finite_val,
122-
state->constraint_upper_bound_finite_val,
123111
state->initial_dual_solution,
124112
constraint_rescaling,
125113
inverse_constraint_rescaling,
@@ -248,8 +236,6 @@ static void bound_objective_rescaling(
248236
scale_bounds_kernel<<<state->num_blocks_dual, THREADS_PER_BLOCK>>>(
249237
state->constraint_lower_bound,
250238
state->constraint_upper_bound,
251-
state->constraint_lower_bound_finite_val,
252-
state->constraint_upper_bound_finite_val,
253239
state->initial_dual_solution,
254240
num_constraints,
255241
constraint_scale,
@@ -259,8 +245,6 @@ static void bound_objective_rescaling(
259245
state->objective_vector,
260246
state->variable_lower_bound,
261247
state->variable_upper_bound,
262-
state->variable_lower_bound_finite_val,
263-
state->variable_upper_bound_finite_val,
264248
state->initial_primal_solution,
265249
num_variables,
266250
constraint_scale,
@@ -326,8 +310,6 @@ rescale_info_t *rescale_problem(
326310
__global__ void scale_variables_kernel(double *__restrict__ objective_vector,
327311
double *__restrict__ variable_lower_bound,
328312
double *__restrict__ variable_upper_bound,
329-
double *__restrict__ variable_lower_bound_finite_val,
330-
double *__restrict__ variable_upper_bound_finite_val,
331313
double *__restrict__ initial_primal_solution,
332314
const double *__restrict__ variable_rescaling,
333315
const double *__restrict__ inverse_variable_rescaling,
@@ -341,15 +323,11 @@ __global__ void scale_variables_kernel(double *__restrict__ objective_vector,
341323
objective_vector[j] *= inv_dj;
342324
variable_lower_bound[j] *= dj;
343325
variable_upper_bound[j] *= dj;
344-
variable_lower_bound_finite_val[j] *= dj;
345-
variable_upper_bound_finite_val[j] *= dj;
346326
initial_primal_solution[j] *= dj;
347327
}
348328

349329
__global__ void scale_constraints_kernel(double *__restrict__ constraint_lower_bound,
350330
double *__restrict__ constraint_upper_bound,
351-
double *__restrict__ constraint_lower_bound_finite_val,
352-
double *__restrict__ constraint_upper_bound_finite_val,
353331
double *__restrict__ initial_dual_solution,
354332
const double *__restrict__ constraint_rescaling,
355333
const double *__restrict__ inverse_constraint_rescaling,
@@ -362,8 +340,6 @@ __global__ void scale_constraints_kernel(double *__restrict__ constraint_lower_b
362340
double ei = constraint_rescaling[i];
363341
constraint_lower_bound[i] *= inv_ei;
364342
constraint_upper_bound[i] *= inv_ei;
365-
constraint_lower_bound_finite_val[i] *= inv_ei;
366-
constraint_upper_bound_finite_val[i] *= inv_ei;
367343
initial_dual_solution[i] *= ei;
368344
}
369345

@@ -504,8 +480,6 @@ __global__ void reduce_bound_norm_sq_kernel(
504480
__global__ void scale_bounds_kernel(
505481
double *__restrict__ constraint_lower_bound,
506482
double *__restrict__ constraint_upper_bound,
507-
double *__restrict__ constraint_lower_bound_finite_val,
508-
double *__restrict__ constraint_upper_bound_finite_val,
509483
double *__restrict__ initial_dual_solution,
510484
int num_constraints,
511485
double constraint_scale,
@@ -516,17 +490,13 @@ __global__ void scale_bounds_kernel(
516490
return;
517491
constraint_lower_bound[i] *= constraint_scale;
518492
constraint_upper_bound[i] *= constraint_scale;
519-
constraint_lower_bound_finite_val[i] *= constraint_scale;
520-
constraint_upper_bound_finite_val[i] *= constraint_scale;
521493
initial_dual_solution[i] *= objective_scale;
522494
}
523495

524496
__global__ void scale_objective_kernel(
525497
double *__restrict__ objective_vector,
526498
double *__restrict__ variable_lower_bound,
527499
double *__restrict__ variable_upper_bound,
528-
double *__restrict__ variable_lower_bound_finite_val,
529-
double *__restrict__ variable_upper_bound_finite_val,
530500
double *__restrict__ initial_primal_solution,
531501
int num_variables,
532502
double constraint_scale,
@@ -537,8 +507,6 @@ __global__ void scale_objective_kernel(
537507
return;
538508
variable_lower_bound[j] *= constraint_scale;
539509
variable_upper_bound[j] *= constraint_scale;
540-
variable_lower_bound_finite_val[j] *= constraint_scale;
541-
variable_upper_bound_finite_val[j] *= constraint_scale;
542510
objective_vector[j] *= objective_scale;
543511
initial_primal_solution[j] *= constraint_scale;
544512
}

src/solver.cu

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ __global__ void build_transpose_map(const int *__restrict__ A_row_ind,
3737
const int *__restrict__ At_col_ind,
3838
int nnz,
3939
int *__restrict__ A_to_At);
40+
__global__ void fill_finite_bounds_kernel(const double *__restrict__ lower_bound,
41+
const double *__restrict__ upper_bound,
42+
double *__restrict__ lower_bound_finite_val,
43+
double *__restrict__ upper_bound_finite_val,
44+
int num_elements);
4045
__global__ void compute_next_pdhg_primal_solution_kernel(const double *current_primal,
4146
double *reflected_primal,
4247
const double *dual_product,
@@ -402,6 +407,25 @@ static pdhg_solver_state_t *initialize_solver_state(
402407
rescale_info->var_rescale = NULL;
403408
rescale_info_free(rescale_info);
404409

410+
CUDA_CHECK(cudaMalloc(&state->constraint_lower_bound_finite_val, con_bytes));
411+
CUDA_CHECK(cudaMalloc(&state->constraint_upper_bound_finite_val, con_bytes));
412+
CUDA_CHECK(cudaMalloc(&state->variable_lower_bound_finite_val, var_bytes));
413+
CUDA_CHECK(cudaMalloc(&state->variable_upper_bound_finite_val, var_bytes));
414+
415+
fill_finite_bounds_kernel<<<state->num_blocks_dual, THREADS_PER_BLOCK>>>(
416+
state->constraint_lower_bound,
417+
state->constraint_upper_bound,
418+
state->constraint_lower_bound_finite_val,
419+
state->constraint_upper_bound_finite_val,
420+
n_cons);
421+
422+
fill_finite_bounds_kernel<<<state->num_blocks_primal, THREADS_PER_BLOCK>>>(
423+
state->variable_lower_bound,
424+
state->variable_upper_bound,
425+
state->variable_lower_bound_finite_val,
426+
state->variable_upper_bound_finite_val,
427+
n_vars);
428+
405429
CUDA_CHECK(cudaFree(state->constraint_matrix->row_ind));
406430
state->constraint_matrix->row_ind = NULL;
407431
CUDA_CHECK(cudaFree(state->constraint_matrix_t->row_ind));
@@ -571,6 +595,24 @@ __global__ void build_transpose_map(
571595
A_to_At[k] = pos;
572596
}
573597

598+
__global__ void fill_finite_bounds_kernel(
599+
const double *__restrict__ lb,
600+
const double *__restrict__ ub,
601+
double *__restrict__ lb_finite,
602+
double *__restrict__ ub_finite,
603+
int num_elements)
604+
{
605+
int i = blockIdx.x * blockDim.x + threadIdx.x;
606+
if (i >= num_elements)
607+
return;
608+
609+
double Li = lb[i];
610+
double Ui = ub[i];
611+
612+
lb_finite[i] = isfinite(Li) ? Li : 0.0;
613+
ub_finite[i] = isfinite(Ui) ? Ui : 0.0;
614+
}
615+
574616
__global__ void compute_next_pdhg_primal_solution_kernel(
575617
const double *current_primal, double *reflected_primal,
576618
const double *dual_product, const double *objective, const double *var_lb,

0 commit comments

Comments
 (0)