Skip to content

Commit

Permalink
fix thrust link error for now by using std::vector as return types
Browse files Browse the repository at this point in the history
  • Loading branch information
neilkichler committed Oct 10, 2024
1 parent 1029e3c commit 46b9fe0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 16 deletions.
6 changes: 3 additions & 3 deletions tests/tests_bisect.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <cuda_runtime.h>
#include <omp.h>
#include <thrust/host_vector.h>
#include <vector>

#include <cuinterval/interval.h>

Expand Down Expand Up @@ -186,7 +186,7 @@ void tests_mince(cuda_buffer buffer, cudaStream_t stream, cudaEvent_t event)
};
}

thrust::host_vector<interval<double>> test_bisection_kernel(cudaStream_t stream, cuda_buffer buffer, interval<double> x, double tolerance);
std::vector<interval<double>> test_bisection_kernel(cudaStream_t stream, cuda_buffer buffer, interval<double> x, double tolerance);

void tests_bisection(cuda_buffer buffer, cudaStream_t stream, cudaEvent_t event)
{
Expand All @@ -205,7 +205,7 @@ void tests_bisection(cuda_buffer buffer, cudaStream_t stream, cudaEvent_t event)
};

constexpr double tolerance = 1e-12;
thrust::host_vector<I> h_roots = test_bisection_kernel(stream, buffer, x, tolerance);
std::vector<I> h_roots = test_bisection_kernel(stream, buffer, x, tolerance);

for (std::size_t i = 0; i < h_roots.size(); i++) {
contains(h_roots[i], ref_roots[i]);
Expand Down
11 changes: 8 additions & 3 deletions tests/tests_bisect.cu
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@

#include <cuinterval/interval.h>
#include <cuinterval/examples/bisection.cuh>
#include <cuinterval/interval.h>

#include <thrust/async/copy.h>
#include <thrust/device_vector.h>
#include <thrust/host_vector.h>

#include <vector>

#include "tests_common.h"
#include "tests_ops.cuh"

Expand All @@ -30,7 +32,10 @@ __host__ __device__ I f(I x)
typedef interval<double> (*fn_t)(interval<double>);
__device__ fn_t d_f = f<interval<double>>;

thrust::host_vector<interval<double>> test_bisection_kernel(cudaStream_t stream, cuda_buffer buffer, interval<double> x, double tolerance)
std::vector<interval<double>> test_bisection_kernel(cudaStream_t stream,
cuda_buffer buffer,
interval<double> x,
double tolerance)
{
using T = double;
using I = interval<T>;
Expand All @@ -48,7 +53,7 @@ thrust::host_vector<interval<double>> test_bisection_kernel(cudaStream_t stream,
bisection<T, max_depth><<<1, 1, 0, stream>>>(h_f, x, tolerance, d_roots, d_max_roots);

CUDA_CHECK(cudaMemcpyAsync(&max_roots, d_max_roots, sizeof(*d_max_roots), cudaMemcpyDeviceToHost, stream));
thrust::host_vector<I> h_roots(max_roots);
std::vector<I> h_roots(max_roots);
CUDA_CHECK(cudaStreamSynchronize(stream));
thrust::device_event e = thrust::async::copy(roots.begin(), roots.begin() + max_roots, h_roots.begin());

Expand Down
11 changes: 6 additions & 5 deletions tests/tests_loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
#include <cuinterval/interval.h>

#include <numbers>
#include <vector>

#include <omp.h>
#include <thrust/host_vector.h>

using cu::interval;
using cu::split;

thrust::host_vector<interval<double>> compute_pi_approximation(cudaStream_t stream);
std::vector<interval<double>> compute_pi_approximation(cudaStream_t stream);

void tests_pi_approximation(cudaStream_t stream, cudaEvent_t event)
{
Expand All @@ -23,7 +23,7 @@ void tests_pi_approximation(cudaStream_t stream, cudaEvent_t event)

printf("Pi Approx: Inside OpenMP thread %i\n", omp_get_thread_num());

thrust::host_vector<I> h_pi = compute_pi_approximation(stream);
std::vector<I> h_pi = compute_pi_approximation(stream);

for (I pi_approx : h_pi) {
contains(pi_approx, std::numbers::pi);
Expand All @@ -32,7 +32,7 @@ void tests_pi_approximation(cudaStream_t stream, cudaEvent_t event)
}
}

thrust::host_vector<interval<double>> compute_horner(cudaStream_t stream);
std::vector<interval<double>> compute_horner(cudaStream_t stream);

void tests_horner(cudaStream_t stream, cudaEvent_t event)
{
Expand All @@ -43,7 +43,8 @@ void tests_horner(cudaStream_t stream, cudaEvent_t event)

printf("Horner: Inside OpenMP thread %i\n", omp_get_thread_num());

thrust::host_vector<I> res = compute_horner(stream);
// thrust::host_vector<I> res = compute_horner(stream);
std::vector<I> res = compute_horner(stream);

I exp_approx = res[res.size() - 1];
T exp_true = std::numbers::e;
Expand Down
18 changes: 13 additions & 5 deletions tests/tests_loop.cu
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#include <vector>

#include <cuinterval/cuinterval.h>

// #include <thrust/execution_policy.h>
// #include <thrust/fill.h>
// #include <thrust/functional.h>
// #include <thrust/sequence.h>

#include <thrust/copy.h>
#include <thrust/device_vector.h>
#include <thrust/host_vector.h>
#include <thrust/iterator/transform_iterator.h>
Expand Down Expand Up @@ -78,7 +81,7 @@ struct final_decrement_fn
}
};

thrust::host_vector<interval<double>> compute_pi_approximation(cudaStream_t stream)
std::vector<interval<double>> compute_pi_approximation(cudaStream_t stream)
{
using T = double;
using I = interval<T>;
Expand Down Expand Up @@ -107,7 +110,9 @@ thrust::host_vector<interval<double>> compute_pi_approximation(cudaStream_t stre
thrust::transform(thrust::cuda::par.on(stream), d_pi.begin(), d_pi.end(), d_pi.begin(), final_decrement_fn(n));
thrust::transform(thrust::cuda::par.on(stream), d_pi.begin(), d_pi.end(), d_pi.begin(), scale_fn());

thrust::host_vector<I> h_pi = d_pi;
std::vector<I> h_pi(d_pi.size());
thrust::copy(d_pi.begin(), d_pi.end(), h_pi.begin());

return h_pi;
}

Expand Down Expand Up @@ -136,7 +141,7 @@ struct horner_fn
}
};

thrust::host_vector<interval<double>> compute_horner(cudaStream_t stream)
std::vector<interval<double>> compute_horner(cudaStream_t stream)
{
using T = double;
using I = interval<T>;
Expand All @@ -162,6 +167,9 @@ thrust::host_vector<interval<double>> compute_horner(cudaStream_t stream)
thrust::inclusive_scan(d_coefficients.rbegin(), d_coefficients.rend(), d_res.begin(), horner_fn<I>(x));

thrust::host_vector<I> coefficients = d_coefficients;
thrust::host_vector<I> res = d_res;
return res;

std::vector<I> h_res(d_res.size());
thrust::copy(d_res.begin(), d_res.end(), h_res.begin());

return h_res;
}

0 comments on commit 46b9fe0

Please sign in to comment.