#include <boost/compute/core.hpp>
#include <boost/compute/algorithm/transform.hpp>
#include <boost/compute/container/vector.hpp>
using namespace boost::compute;
// Ray-triangle intersection test
bool intersect_ray_triangle(float3 ray_origin, float3 ray_direction,
float3 v0, float3 v1, float3 v2)
{
// ...
}
int main()
{
// Create GPU device and context
gpu::device gpu(0);
context ctx(gpu);
// Triangle vertices
float3 v0(1.0f, 0.0f, 0.0f);
float3 v1(0.0f, 1.0f, 0.0f);
float3 v2(0.0f, 0.0f, 1.0f);
// Ray origins and directions
std::vector<float3> ray_origins = {...};
std::vector<float3> ray_directions = {...};
// Transfer data to the GPU
vector<float3> d_ray_origins(ray_origins.begin(), ray_origins.end(), ctx);
vector<float3> d_ray_directions(ray_directions.begin(), ray_directions.end(), ctx);
// Intersect rays in parallel
vector<bool> results(ray_origins.size(), ctx);
transform(d_ray_origins.begin(), d_ray_origins.end(),
d_ray_directions.begin(), results.begin(),
intersect_ray_triangle, v0, v1, v2,
ctx);
// Copy results back to the host
std::vector<bool> h_results(results.size());
copy(results.begin(), results.end(), h_results.begin(), ctx);
}