Boost
arrow_drop_down
Boost.Compute
M
D

本次发布

Kyle Lutz
Kyle Lutz
作者

依赖项

Boost.Compute

Build Status Build status Coverage Status Gitter

Boost.Compute 是一个基于 OpenCL 的 C++ GPU/并行计算库。

核心库是一个薄的 C++ OpenCL API 封装,提供对计算设备、上下文、命令队列和内存缓冲区的访问。

在核心库之上,是一个通用的、类似 STL 的接口,提供常用的算法(例如 transform(), accumulate(), sort())和常用的容器(例如 vector<T>, flat_set<T>)。它还包含一些扩展,包括并行计算算法(例如 exclusive_scan(), scatter(), reduce())和一些高级迭代器(例如 transform_iterator<>, permutation_iterator<>, zip_iterator<>)。

完整文档可在 http://boostorg.github.io/compute/ 找到。

示例

以下示例展示了如何在 GPU 上对浮点数向量进行排序

#include <vector>
#include <algorithm>
#include <boost/compute.hpp>

namespace compute = boost::compute;

int main()
{
    // get the default compute device
    compute::device gpu = compute::system::default_device();

    // create a compute context and command queue
    compute::context ctx(gpu);
    compute::command_queue queue(ctx, gpu);

    // generate random numbers on the host
    std::vector<float> host_vector(1000000);
    std::generate(host_vector.begin(), host_vector.end(), rand);

    // create vector on the device
    compute::vector<float> device_vector(1000000, ctx);

    // copy data to the device
    compute::copy(
        host_vector.begin(), host_vector.end(), device_vector.begin(), queue
    );

    // sort data on the device
    compute::sort(
        device_vector.begin(), device_vector.end(), queue
    );

    // copy data back to the host
    compute::copy(
        device_vector.begin(), device_vector.end(), host_vector.begin(), queue
    );

    return 0;
}

Boost.Compute 是一个仅头文件的库,因此不需要链接。上面的示例可以使用以下命令编译:

g++ -I/path/to/compute/include sort.cpp -lOpenCL

更多示例可以在 教程examples 目录中找到。

支持

关于该库的问题(包括使用和开发)可以发布到 邮件列表

错误和功能请求可以通过 问题跟踪器 报告。

也欢迎随时通过电子邮件发送您遇到的问题、疑问或反馈。

求贤

Boost.Compute 项目目前正在寻找对并行计算感兴趣的额外开发者。

请发送电子邮件至 Kyle Lutz (kyle.r.lutz@gmail.com) 获取更多信息。

全部时间

Jakub Szuppe
Jakub Szuppe
贡献者
Anthony C
Anthony C
贡献者
Peter Dimov
Peter Dimov
贡献者
Denis Davydov
Denis Davydov
贡献者
Lakshay Garg
Lakshay Garg
贡献者
Kristian Popov
Kristian Popov
贡献者
Dmitry Trifonov
Dmitry Trifonov
贡献者
Jeff Hammond
贡献者
Henry Schreiner
Henry Schreiner
贡献者
Amir Shavit
Amir Shavit
贡献者
Janusz Rupar
Janusz Rupar
贡献者
Anton Matosov
Anton Matosov
贡献者
Raul Ferreira
Raul Ferreira
贡献者
Huan Zhang
Huan Zhang
贡献者
pradeep
pradeep
贡献者
Ronan Keryell
Ronan Keryell
贡献者
Adam Wulkiewicz
Adam Wulkiewicz
贡献者
Frieder Bluemle
Frieder Bluemle
贡献者
Kohei Takahashi
Kohei Takahashi
贡献者
koosha94
koosha94
贡献者
Ken Barker
Ken Barker
贡献者
dPavelDev
dPavelDev
贡献者
Ravi0li
Ravi0li
贡献者
Rene Rivera
Rene Rivera
贡献者
Mateusz Krawiec
Mateusz Krawiec
贡献者
Umar Arshad
Umar Arshad
贡献者
mmitti
mmitti
贡献者