Generated by GPT-5-mini| thrust (library) | |
|---|---|
| Name | Thrust |
| Title | Thrust |
| Developer | NVIDIA |
| Released | 2010 |
| Programming language | C++ |
| Operating system | Cross-platform |
| Genre | Parallel algorithms library |
| License | Apache License 2.0 |
thrust (library) is a parallel algorithms library designed to provide a high-level interface for parallel programming in C++ on heterogeneous platforms. It exposes STL-like containers and algorithms to enable expressive code for data-parallel operations while targeting accelerators such as GPUs and multicore CPUs. The library aims to bridge productivity and performance by integrating with existing toolchains and platforms developed by major vendors.
Thrust offers an algorithms library modeled after the C++ Standard Template Library C++ Standard Library, facilitating operations like sort, scan, transform, reduce, gather, and scatter on device and host memory. It is developed by NVIDIA to complement technologies such as CUDA and to interoperate with toolchains including GNU Compiler Collection and Clang (compiler frontend). Thrust abstracts low-level details present in projects like cuBLAS, cuFFT, and cuSPARSE while providing a higher-level programming model comparable to Intel oneAPI, TBB (Threading Building Blocks), and OpenMP. The library is commonly used alongside frameworks such as PyTorch, TensorFlow, and Caffe in performance-critical code paths.
Thrust originated as an internal project at NVIDIA and was publicly introduced around 2010 to simplify GPU programming for C++ developers. Its design drew inspiration from the C++ Standard Library and from contemporary parallel libraries like STLPort and Boost (C++ libraries). Over time, Thrust evolved through contributions and integrations with vendor ecosystems including AMD, Microsoft, and researchers affiliated with institutions such as Stanford University and MIT. Significant milestones include integration into CUDA Toolkit releases and adaptation to support backend portability initiatives influenced by projects like ROCm and LLVM.
Thrust's architecture centers on a small set of core components: sequence containers (e.g., device_vector, host_vector), iterator adaptors, and algorithm templates. Containers mirror std::vector semantics while providing device-aware allocation compatible with CUDA Runtime API and interoperability with libraries such as cuDNN and cuBLAS. Iterator primitives enable expression of complex data movement patterns similar to those used in Boost.Iterator and C++20 ranges. The algorithm layer maps high-level operations to execution backends; backends include a CUDA backend, an OpenMP backend, and experimental backends leveraging SYCL and HIP (Heterogeneous-compute Interface for Portability). Thrust also integrates with build systems like CMake to manage cross-platform compilation and linkage.
Thrust adopts a declarative, template-based API patterned after the C++ Standard Template Library with functions such as thrust::sort, thrust::reduce, thrust::transform, and thrust::scan. Programmers manipulate device_vector and host_vector types and use iterator adapters to express strided, zip, and transform iterators analogous to patterns in Boost.Range and C++20 ranges. Execution policies allow selection of backends at call sites, a concept similar to execution policies introduced by the Parallelism TS and later in C++17 proposals. Error handling and debugging workflows commonly interoperate with CUDA-GDB and performance tools like Nsight Compute and Nsight Systems.
Thrust emphasizes high throughput by leveraging backend-specific optimizations: parallel radix sort for integers, segmented reductions for irregular data patterns, and stream-aware memory operations to exploit PCI Express bandwidth and GPU concurrency. Performance tuning involves choices such as memory coalescing, minimizing host-device transfers, and exploiting fused operations to reduce kernel launches—techniques discussed in literature from SC (Supercomputing Conference) and demonstrated in benchmarks alongside libraries like cuDNN and MKL (Math Kernel Library). For workloads sensitive to latency, developers may extract custom kernels via CUDA C++, HIP, or SYCL while retaining Thrust for high-level orchestration.
Official Thrust distributions target the CUDA Toolkit on NVIDIA GPUs and provide experimental or third-party backends for ROCm on AMD hardware, as well as CPU backends using OpenMP or standard C++ parallel facilities in libstdc++ and LLVM libc++. Community ports and adaptations enable integration with projects like PyCUDA, CuPy, and language bindings for platforms such as Windows, Linux, and macOS when supported by vendors. Continuous integration and packaging are managed through ecosystems including GitHub, Conda (package manager), and vendor SDKs.
Thrust is used in domains that require data-parallel computation, including scientific computing projects at institutions like Lawrence Berkeley National Laboratory and Argonne National Laboratory, machine learning frameworks such as PyTorch and TensorFlow for preprocessing kernels, and visualization stacks like ParaView and VisIt for heavy data transformations. It supports workloads in computational chemistry (with tools like GROMACS integrations), computational fluid dynamics referencing outputs from OpenFOAM, and signal processing pipelines that also rely on cuFFT. Thrust's high-level expressiveness makes it suitable for rapid prototyping of GPU algorithms before porting to specialized libraries such as cuBLAS or to vendor-specific intrinsics.
Category:Parallel computing libraries Category:CUDA