template Boost closure

15 views
Skip to first unread message

Gianluigi Caddeo

unread,
Mar 2, 2020, 8:34:21 AM3/2/20
to boost-compute

Hello,
looking this BOOST_COMPUTE_FUNCTION as a template (https://groups.google.com/forum/#!topic/boost-compute/hn4pOiVojvk),
I tempted to do something similar with BOOST_COMPUTE_CLOSURE.

But despite my best efforts I was unable to use correctly BOOST_COMPUTE_CLOSURE.

This is my problem:

class Point3d
{
   private:   
   float p[3];
}

Point3d *points;  // raw vector of thousand of points and more;
const Matrix4d matrix;

namespace compute = boost::compute;
compute::device device = compute::system::default_device();
compute::context context(device);
compute::command_queue queue(context, device);
compute::vector<Point3d> device_vector(groupDescriptor->gpc->getNumPoints(), context);
compute::copy(points, points + groupDescriptor->gpc->getNumPoints(), device_vector.begin(), queue);

auto foo = [&]<typename T>(const T& point)->compute::function<T(T)>
{
    BOOST_COMPUTE_CLOSURE(T, apply_matrix, (const T point), (matrix), { return matrix*point; }); // In matrix*point the * operator is oveloaded, but I can perform multiplication without this, no problem.
    return apply_matrix;
};

using boost::compute::lambda::_1;
compute::transform(
device_vector.begin(), device_vector.end(), device_vector.begin(), foo<Vector3fl>(), queue
);

compute::copy(device_vector.begin(), device_vector.end(), points, queue);

can sameone help me in this?
In boost compute there is a way to perform the multiplication matrix*point ? How to do?

many thanks,
Best regards
Gianluigi

Gianluigi Caddeo

unread,
Mar 2, 2020, 8:40:54 AM3/2/20
to boost-compute
I apologize,
there was some error in my post, this is the correct form:
Hello,
looking this BOOST_COMPUTE_FUNCTION as a template (https://groups.google.com/forum/#!topic/boost-compute/hn4pOiVojvk),
I tempted to do something similar with BOOST_COMPUTE_CLOSURE.

But despite my best efforts I was unable to use correctly BOOST_COMPUTE_CLOSURE.

This is my problem:

class Point3d
{
   private:   
   float p[3];
}

Point3d *points;  // raw vector of thousand of points and more;
const Matrix4d matrix;

namespace compute = boost::compute;
compute::device device = compute::system::default_device();
compute::context context(device);
compute::command_queue queue(context, device);
compute::vector<Point3d> device_vector(size, context);
compute::copy(points, points + size, device_vector.begin(), queue);


auto foo = [&]<typename T>(const T& point)->compute::function<T(T)>
{
    BOOST_COMPUTE_CLOSURE(T, apply_matrix, (const T point), (matrix), { return matrix*point; }); // In matrix*point the * operator is oveloaded, but I can perform multiplication without this, no problem.
    return apply_matrix;
};

compute::copy(device_vector.begin(), device_vector.end(), points, queue);

can sameone help me in this?
In boost compute there is a way to perform the multiplication matrix*point ? How to do?

many thanks,
Best regards
Gianluigi
On Mon, Mar 2, 2020 at 2:34 PM Gianluigi Caddeo <ggi...@gmail.com> wrote:
Hello,
looking this BOOST_COMPUTE_FUNCTION as a template (https://groups.google.com/forum/#!topic/boost-compute/hn4pOiVojvk),
I tempted to do something similar with BOOST_COMPUTE_CLOSURE.

But despite my best efforts I was unable to use correctly BOOST_COMPUTE_CLOSURE.

This is my problem:

class Point3d
{
   private:   
   float p[3];
}

Point3d *points;  // raw vector of thousand of points and more;
const Matrix4d matrix;

namespace compute = boost::compute;
compute::device device = compute::system::default_device();
compute::context context(device);
compute::command_queue queue(context, device);
compute::vector<Point3d> device_vector(size, context);
compute::copy(points, points + size, device_vector.begin(), queue);


auto foo = [&]<typename T>(const T& point)->compute::function<T(T)>
{
    BOOST_COMPUTE_CLOSURE(T, apply_matrix, (const T point), (matrix), { return matrix*point; }); // In matrix*point the * operator is oveloaded, but I can perform multiplication without this, no problem.
    return apply_matrix;
};

compute::copy(device_vector.begin(), device_vector.end(), points, queue);

can sameone help me in this?
In boost compute there is a way to perform the multiplication matrix*point ? How to do?

many thanks,
Best regards
Gianluigi

--
You received this message because you are subscribed to the Google Groups "boost-compute" group.
To unsubscribe from this group and stop receiving emails from it, send an email to boost-comput...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/boost-compute/70f8a142-d9ac-410a-852b-14b43ea6e3e9%40googlegroups.com.

Gianluigi Caddeo

unread,
Mar 2, 2020, 8:46:00 AM3/2/20
to boost-compute
On Mon, Mar 2, 2020 at 2:40 PM Gianluigi Caddeo <ggi...@gmail.com> wrote:
I apologize,
there was some error in my post, this is the correct form:
Hello,
looking this BOOST_COMPUTE_FUNCTION as a template (https://groups.google.com/forum/#!topic/boost-compute/hn4pOiVojvk),
I tempted to do something similar with BOOST_COMPUTE_CLOSURE.

But despite my best efforts I was unable to use correctly BOOST_COMPUTE_CLOSURE.

This is my problem:

class Point3d
{
   private:   
   float p[3];
}

Point3d *points;  // raw vector of thousand of points and more;
const Matrix4d matrix;

namespace compute = boost::compute;
compute::device device = compute::system::default_
device();
compute::context context(device);
compute::command_queue queue(context, device);
compute::vector<Point3d> device_vector(size, context);
compute::copy(points, points + size, device_vector.begin(), queue);

auto foo = [&]<typename T>(const T& point)->compute::function<T(T)
>
{
    BOOST_COMPUTE_CLOSURE(T, apply_matrix, (const T point), (matrix), { return matrix*point; }); // In matrix*point the * operator is oveloaded, but I can perform multiplication without this, no problem.
    return apply_matrix;
};
 
compute::transform(
device_vector.begin(), device_vector.end(), device_vector.begin(), foo<Point3d>(), queue);
Reply all
Reply to author
Forward
0 new messages