我目前正在探索boost_compute。不幸的是,文档页面和示例较少,比我需要了解要做什么。如何调用boost_compute'BOOST_COMPUTE_FUNCTION'定义的函数?
考虑下面的代码缩小的:
BOOST_COMPUTE_FUNCTION(bool, add, (int* values, int* results, int constant),
{
// Whats the indexing variable?
// In opencl it would be get_global_id(0)
int index = // ?
results[index] = values[index] + values[index + 1] + values[index + 2] + constant;
});
void compute(float* results, compute::context* ctx, compute::command_queue* queue)
{
compute::vector<float> device_values(100, *ctx);
compute::vector<float> device_results(98, *ctx);
compute::copy(
parameters->values.begin(), parameters->values.end(), device_values.begin(), *queue
);
// Actual computation
// HOW TO CALL 'add' for every device_results element?
compute::copy(
device_results.begin(), device_results.end(), results, *queue
);
}
如何调用“添加”功能,这是什么函数内的迭代变量?此外,我需要这种代码结构来进行更复杂的计算。
亲切的问候, 托尼
使用'计算:: transform',在这里的例子:http://www.boost.org/doc/libs/1_63_0/libs/compute/doc/html/boost_compute/advanced_topics.html# boost_compute.advanced_topics.custom_functions – ddemidov
boost :: compute中的函数应用于单个向量元素。你可能在寻找的是一个定制的内核。 – ddemidov
不幸的是,我无法想象调用正确的方式进行转换。这个例子没有回答我任何问题:/ – infotoni91