Multiple Outputs/zip_iterator as output
- Dominant language
- C++
- Stars
- 1.7k
- Forks
- 340
- PR merge metrics
- No merged PRs in 30d
Description
Is there any way to have multiple outputs in general? `zip_iterators` work for multiple inputs, but don't allow for multiple outputs. I would ideally expect the following to work, but it doesn't:
```
#include
#include
#include
namespace bc = boost::compute;
int main(int argc, char *argv[]) {
bc::vector data(bc::counting_iterator(0),
bc::counting_iterator(10));
bc::vector output_1(data.size());
bc::vector output_2(data.size());
// BOOST_COMPUTE_FUNCTION can't handle templated return types
auto duplicate = bc::detail::make_function_impl(int)>(
"duplicate", BOOST_COMPUTE_STRINGIZE_SOURCE((int value)),
BOOST_COMPUTE_STRINGIZE_SOURCE({
return (boost_tuple_int_int_t){value, value};
}));
bc::transform(data.begin(), data.end(),
bc::make_zip_iterator(
boost::make_tuple(output_1.begin(), output_2.begin())),
duplicate);
std::vector output_1_cpu(data.size());
std::vector output_2_cpu(data.size());
bc::copy(output_1.begin(), output_1.end(), output_1_cpu.begin());
bc::copy(output_2.begin(), output_2.end(), output_2_cpu.begin());
for (size_t i = 0; i < output_1_cpu.size(); ++i) {
std::cout << "1: " << output_1_cpu[i] << " 2: " << output_2_cpu[i] << "\n";
}
return 0;
}
```
It fails because the generated kernel doesn't assign to output_1 and output_2. Instead, a new struct/tuple is constructed and assigned to.
Contributor guide
Assessment
This issue has not been assessed yet.