Skip to content

Commit 9a344ec

Browse files
committed
fix: remove thrust dependency for HIP build compatibility
1 parent 59b468d commit 9a344ec

1 file changed

Lines changed: 13 additions & 24 deletions

File tree

src/preconditioner.cu

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ limitations under the License.
1919

2020
#include <math.h>
2121
#include <stdio.h>
22-
#include <thrust/iterator/counting_iterator.h>
23-
#include <thrust/iterator/transform_iterator.h>
2422
#include <time.h>
2523

2624
#define SCALING_EPSILON 1e-12
@@ -81,6 +79,7 @@ __global__ void scale_objective_kernel(double *__restrict__ objective_vector,
8179
double constraint_scale,
8280
double objective_scale);
8381
__global__ void fill_ones_kernel(double *__restrict__ x, int num_variables);
82+
__global__ void max_csr_row_length_kernel(const int *__restrict__ row_ptr, int num_rows, int *__restrict__ result);
8483
__global__ void geometric_mean_iteration_kernel(const int *__restrict__ row_ptr,
8584
const int *__restrict__ col_ind,
8685
const double *__restrict__ matrix_vals,
@@ -195,33 +194,16 @@ static int log2_vector_width(long long num_nonzeros, int num_rows, int longest_r
195194
return log2_width;
196195
}
197196

198-
struct csr_row_nnz_op
199-
{
200-
const int *row_ptr;
201-
__host__ __device__ int operator()(int i) const
202-
{
203-
return row_ptr[i + 1] - row_ptr[i];
204-
}
205-
};
206-
207197
static void longest_csr_rows(const pdhg_solver_state_t *state, int *longest)
208198
{
209199
int *device_longest = NULL;
210200
CUDA_CHECK(cudaMalloc(&device_longest, 2 * sizeof(int)));
201+
CUDA_CHECK(cudaMemset(device_longest, 0, 2 * sizeof(int)));
211202

212-
const csr_row_nnz_op row_nnz = {state->constraint_matrix->row_ptr};
213-
const csr_row_nnz_op col_nnz = {state->constraint_matrix_t->row_ptr};
214-
const auto row_lengths = thrust::make_transform_iterator(thrust::make_counting_iterator(0), row_nnz);
215-
const auto col_lengths = thrust::make_transform_iterator(thrust::make_counting_iterator(0), col_nnz);
216-
217-
void *temp_storage = NULL;
218-
size_t row_bytes = 0, col_bytes = 0;
219-
CUDA_CHECK(cub::DeviceReduce::Max(temp_storage, row_bytes, row_lengths, device_longest, state->num_constraints));
220-
CUDA_CHECK(cub::DeviceReduce::Max(temp_storage, col_bytes, col_lengths, device_longest + 1, state->num_variables));
221-
CUDA_CHECK(cudaMalloc(&temp_storage, row_bytes > col_bytes ? row_bytes : col_bytes));
222-
CUDA_CHECK(cub::DeviceReduce::Max(temp_storage, row_bytes, row_lengths, device_longest, state->num_constraints));
223-
CUDA_CHECK(cub::DeviceReduce::Max(temp_storage, col_bytes, col_lengths, device_longest + 1, state->num_variables));
224-
CUDA_CHECK(cudaFree(temp_storage));
203+
max_csr_row_length_kernel<<<state->num_blocks_dual, THREADS_PER_BLOCK>>>(
204+
state->constraint_matrix->row_ptr, state->num_constraints, device_longest);
205+
max_csr_row_length_kernel<<<state->num_blocks_primal, THREADS_PER_BLOCK>>>(
206+
state->constraint_matrix_t->row_ptr, state->num_variables, device_longest + 1);
225207

226208
CUDA_CHECK(cudaMemcpy(longest, device_longest, 2 * sizeof(int), cudaMemcpyDeviceToHost));
227209
CUDA_CHECK(cudaFree(device_longest));
@@ -634,6 +616,13 @@ __global__ void fill_ones_kernel(double *__restrict__ x, int num_variables)
634616
x[i] = 1.0;
635617
}
636618

619+
__global__ void max_csr_row_length_kernel(const int *__restrict__ row_ptr, int num_rows, int *__restrict__ result)
620+
{
621+
int i = blockIdx.x * blockDim.x + threadIdx.x;
622+
if (i < num_rows)
623+
atomicMax(result, row_ptr[i + 1] - row_ptr[i]);
624+
}
625+
637626
__global__ void geometric_mean_iteration_kernel(const int *__restrict__ row_ptr,
638627
const int *__restrict__ col_ind,
639628
const double *__restrict__ matrix_vals,

0 commit comments

Comments
 (0)