boostorg / boostorg/compute

transform algorithm with constant iterator

Open
#507 10 comments 0 reactions 0 assignees View on GitHub
driver bug
Dominant language
C++
Stars
1.7k
Forks
340
PR merge metrics
No merged PRs in 30d

Description

My tests revealed that when using constant iterator tupled and zipped gives segfault.
Here is the code which shows that:

``` c++
#include
#include
#include
#include
#include
#include
#include
#include

int main (int argc, const char* argv[])
{
namespace compute = boost::compute;

try {
int size = 128;
compute::vector xVector (size, 1.f);
compute::vector yVector (size, 2.f);
compute::vector zVector (size, 3.f);

compute::vector rVector (size, 0.f);

BOOST_COMPUTE_FUNCTION(float, function_tuple_3, (boost::tuple t),
{
return boost_tuple_get(t, 0);
});
BOOST_COMPUTE_FUNCTION(float, function_tuple_2, (boost::tuple t),
{
return boost_tuple_get(t, 0);
});

/*This was my original code where I found the bug*/
/*
compute::transform(
//first
compute::make_zip_iterator(
boost::make_tuple(
xVector.begin(),
yVector.begin(),
//zVector.begin() //when using zVector instead of constant_iterator it is working correctly.
compute::make_constant_iterator(4.f)
)
),
//last
compute::make_zip_iterator(
boost::make_tuple(
xVector.end(),
yVector.end(),
//zVector.end() // change it here accordingly
compute::make_constant_iterator(4.f, size)
)
),

rVector.begin(),
//function
function_tuple_3
);
*/

/* when not zipping constant iterator it seems fine */
/*
compute::transform(compute::make_constant_iterator(4.f),
compute::make_constant_iterator(4.f, size),
rVector.begin(),
compute::identity()
);
*/

/* when start to zip it, program crashes */
compute::transform(
compute::make_zip_iterator(
boost::make_tuple(
compute::make_constant_iterator(4.f),
compute::make_constant_iterator(4.f)
)
),
compute::make_zip_iterator(
boost::make_tuple(
compute::make_constant_iterator(4.f, size),
compute::make_constant_iterator(4.f, size)
)
),
rVector.begin(),
function_tuple_2
);
}
catch (compute::opencl_error &err)
{
std::cerr << err.what() << std::endl;
return -1;
}
catch (...)
{
std::cerr << "Boost compute failed with transforn operation" << std::endl;
return -2;
}
return 0;
}

```
##

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.