zhujiang73 发表于 2016-05-24 00:17

boost 里都有 GPU 并行计算了



   "Boost.Compute is a GPU/parallel-computing library for C++ based on OpenCL.

            The core library is a thin C++ wrapper over the OpenCL API and provides access to compute devices, contexts, command queues and memory buffers."

            https://github.com/boostorg/compute

         还有例子:  

    "The following example shows how to sort a vector of floats on the 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;
}

hellioncu 发表于 2016-05-24 08:37

copy来copy去需要占多少时间?

fender0107401 发表于 2016-05-24 08:57

Boost威武!

fender0107401 发表于 2016-05-24 08:58

本帖最后由 fender0107401 于 2016-05-24 08:58 编辑

之前研究过GPU计算,不过没怎么深入弄,感觉暂时还用不到,不过Boost里面有这个感觉还是很好的。

VIP_fuck 发表于 2016-05-24 09:10

boost搞这么庞大,奔着 Java 去了?

fender0107401 发表于 2016-05-24 09:21

http://www.boost.org/doc/libs/1_61_0/libs/compute/doc/html/index.html

:em17:

fender0107401 发表于 2016-05-24 09:24

Introduction

The Boost Compute library provides a C++ interface to multi-core CPU and GPGPU computing platforms based on OpenCL.

The project is hosted on GitHub at https://github.com/boostorg/compute. Click the arrow below to see the guide on Getting Started.

multi-core 似乎没啥用,直接用thread搞定。

不过GPU这个挺有用的。

而且这个不是基于CUDA而是基于OpenCL,感觉比较好。

之前Nvidia的一个负责人说CUDA是开放的,但是Nvidia的显卡驱动永远不会开放。

wlmqgzm 发表于 2016-05-24 12:41

这个比较牛, 以后做并行计算要简单多了, {:1_1:}

folklore 发表于 2016-05-24 15:36

good job.

页: [1]
查看完整版本: boost 里都有 GPU 并行计算了