thrust


Code at the speed of light

What is Thrust?

Thrust is a parallel algorithms library which resembles the C++ Standard Template Library (STL). Thrust's high-level interface greatly enhances developer productivity while enabling performance portability between GPUs and multicore CPUs. Interoperability with established technologies (such as CUDA, TBB and OpenMP) facilitates integration with existing software. Develop high-performance applications rapidly with Thrust!
Read the Quick Start guide.

Github

We no longer maintain the Thrust project on Google Code. Find Thrust's new home at http://thrust.github.com'>thrust.github.com



News

  • Thrust is now hosted on Github!
  • Thrust v1.6.0 has been released! Refer to the CHANGELOG for changes since v1.5.1
  • Thrust v1.5.1 has been released! Version 1.5.1 is distributed with CUDA 4.1 and fixes an uncommon sorting bug (see CHANGELOG).
  • Thrust v1.5.0 has been released! Refer to the CHANGELOG for changes since v1.4.0
  • Content from Rapid Problem Solving Using Thrust webinar is available (Stream, MP4, PDF, Code)
  • Posted Thrust chapter from the upcoming GPU Computing Gems book.
  • Thrust v1.4.0 has been released! Refer to the CHANGELOG for changes since v1.3.0
  • Thrust v1.4.0 will be featured in the CUDA 4.0 toolkit
  • Do your civic duty and fill out the 2-minute Thrust user survey!.
  • Thrust v1.3.0 has been released! Refer to the CHANGELOG for changes since v1.2.1
  • GTC2010 presentations are now online.
  • Thrust v1.2.1 has been released! v1.2.1 contains compatibility fixes for CUDA 3.1.
  • Posted An Introduction to Thrust presentation.

Examples

Thrust is best explained through examples. The following source code generates random numbers on the host and transfers them to the device where they are sorted.

#include <thrust/host_vector.h>

#include <thrust/device_vector.h>
#include <thrust/generate.h>
#include <thrust/sort.h>
#include <thrust/copy.h>
#include <cstdlib>

int main(void)
{
// generate 32M random numbers on the host
thrust::host_vector<int> h_vec(32 << 20);
thrust::generate(h_vec.begin(), h_vec.end(), rand);

// transfer data to the device
thrust::device_vector<int> d_vec = h_vec;

// sort data on the device (846M keys per second on GeForce GTX 480)
thrust::sort(d_vec.begin(), d_vec.end());

// transfer data back to host
thrust::copy(d_vec.begin(), d_vec.end(), h_vec.begin());

return 0;
}

This code sample computes the sum of 100 random numbers on the GPU.

#include <thrust/host_vector.h>

#include <thrust/device_vector.h>
#include <thrust/generate.h>
#include <thrust/reduce.h>
#include <thrust/functional.h>
#include <cstdlib>

int main(void)
{
// generate random data on the host
thrust::host_vector<int> h_vec(100);
thrust::generate(h_vec.begin(), h_vec.end(), rand);

// transfer to device and compute sum
thrust::device_vector<int> d_vec = h_vec;
int x = thrust::reduce(d_vec.begin(), d_vec.end(), 0, thrust::plus<int>());
return 0;
}

Refer to the QuickStartGuide page for further information and examples.


Contributors

The primary developers of Thrust are http://research.nvidia.com/users/jared-hoberock'>Jared Hoberock and http://research.nvidia.com/users/nathan-bell'>Nathan Bell. A complete list of contributors is available http://code.google.com/p/thrust/source/browse/THANKS'>here.

Project Information

Labels:
CUDA GPU Parallel Template nvcc CPlusPlus STL Library GPGPU Sorting Reduction Scan Multicore TBB OpenMP