TopGit theo dõi NVIDIA/thrust trên GitHub trong nhóm Backend, đã đạt 5.0k sao. [ARCHIVED] The C++ parallel algorithms library. See https://github.com/NVIDIA/cccl
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
:warning: The Thrust repository has been archived and is now part of the unified nvidia/cccl repository. See the announcement here for more information. Please visit the new repository for the latest updates. :warning:
Thrust: The C++ Parallel Algorithms Library
Examples
Godbolt
Documentation
Thrust is the C++ parallel algorithms library which inspired the introduction
of parallel algorithms to the C++ Standard Library.
Thrust's high-level interface greatly enhances programmer productivity
while enabling performance portability between GPUs and multicore CPUs.
It builds on top of established parallel programming frameworks (such as CUDA,
TBB, and OpenMP).
It also provides a number of general-purpose facilities similar to those found
in the C++ Standard Library.
The NVIDIA C++ Standard Library is an open source project; it is available on
GitHub and included in the NVIDIA HPC SDK and CUDA Toolkit.
If you have one of those SDKs installed, no additional installation or compiler
flags are needed to use libcu++.
Examples
Thrust is best learned through examples.
The following example generates random numbers serially and then transfers them
to a parallel 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 <thrust/random.h>
int main() {
// Generate 32M random numbers serially.
thrust::default_random_engine rng(1337);
thrust::uniform_int_distribution<int> dist;
thrust::host_vector<int> h_vec(32 << 20);
thrust::generate(h_vec.begin(), h_vec.end(), [&] { return dist(rng); });
// Transfer data to the device.
thrust::device_vector<int> d_vec = h_vec;
// Sort data on the device.
thrust::sort(d_vec.begin(), d_vec.end());
// Transfer data back to host.
thrust::copy(d_vec.begin(), d_vec.end(), h_vec.begin());
}
See it on Godbolt
This example demonstrates computing the sum of some random numbers in parallel:
#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include <thrust/generate.h>
#include <thrust/reduce.h>
#include <thrust/functional.h>
#include <thrust/random.h>
int main() {
// Generate random data serially.
thrust::default_random_engine rng(1337);
thrust::uniform_real_distribution<double> dist(-50.0, 50.0);
thrust::host_vector<double> h_vec(32 << 20);
thrust::generate(h_vec.begin(), h_vec.end(), [&] { return dist(rng); });
// Transfer to device and compute the sum.
thrust::device_vector<double> d_vec = h_vec;
double x = thrust::reduce(d_vec.begin(), d_vec.end(), 0, thrust::plus<int>());
}
See it on Godbolt
This example show how to perform such a reduction asynchronously:
#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include <thrust/generate.h>
#include <thrust/async/copy.h>
#include <thrust/async/reduce.h>
#include <thrust/functional.h>
#include <thrust/random.h>
#include <numeric>
int main() {
// Generate 32M random numbers serially.
thrust::default_random_engine rng(123456);
thrust::uniform_real_distribution<double> dist(-50.0, 50.0);
thrust::host_vector<double> h_vec(32 << 20);
thrust::generate(h_vec.begin(), h_vec.end(), [&] { return dist(rng); });
// Asynchronously transfer to the device.
thrust::device_vector<double> d_vec(h_vec.size());
thrust::device_event e = thrust::async::copy(h_vec.begin(), h_vec.end(),
d_vec.begin());
// After the transfer completes, asynchronously compute the sum on the device.
thrust::device_future<double> f0 = thrust::async::reduce(thrust::device.after(e),
d_vec.begin(), d_vec.end(),
0.0, thrust::plus<double>());
// While the sum is being computed on the device, compute the sum serially on
// the host.
double f1 = std::accumulate(h_vec.begin(), h_vec.end(), 0.0, thrust::plus<double>());
}
See it on Godbolt
Getting The Thrust Source Code
Thrust is a header-only library; there is no need to build or install the project
unless you want to run the Thrust unit tests.
The CUDA Toolkit provides a recent release of the Thrust source code in
include/thrust. This will be suitable for most users.
Users that wish to contribute to Thrust or try out newer features should
recursively clone the Thrust Github repository:
For CMake-based projects, we provide a CMake package for use with
find_package. See the CMake README for more
information. Thrust can also be added via add_subdirectory or tools like
the CMake Package Manager.
For non-CMake projects, compile with:
The Thrust include path (-I<thrust repo root>)
The libcu++ include path (-I<thrust repo root>/dependencies/libcudacxx/)
The CUB include path, if using the CUDA device system (-I<thrust repo root>/dependencies/cub/)
By default, the CPP host system and CUDA device system are used.
These can be changed using compiler definitions:
-DTHRUST_HOST_SYSTEM=THRUST_HOST_SYSTEM_XXX,
where XXX is CPP (serial, default), OMP (OpenMP), or TBB (Intel TBB)
-DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_XXX, where XXX is
CPP, OMP, TBB, or CUDA (default).
Developing Thrust
Thrust uses the CMake build system to build unit tests, examples, and header
tests.
To build Thrust as a developer, it is recommended that you use our
containerized development system:
# Clone Thrust and CUB repos recursively:
git clone --recursive https://github.com/NVIDIA/thrust.git
cd thrust
# Build and run tests and examples:
ci/local/build.bash
That does the equivalent of the following, but in a clean containerized
environment which has all dependencies installed:
# Clone Thrust and CUB repos recursively:
git clone --recursive https://github.com/NVIDIA/thrust.git
cd thrust
# Create build directory:
mkdir build
cd build
# Configure -- use one of the following:
cmake .. # Command line interface.
ccmake .. # ncurses GUI (Linux only).
cmake-gui # Graphical UI, set source/build directories in the app.
# Build:
cmake --build . -j ${NUM_JOBS} # Invokes make (or ninja, etc).
# Run tests and examples:
ctest
By default, a serial CPP host system, CUDA accelerated device system, and
C++14 standard are used.
This can be changed in CMake and via flags to ci/local/build.bash
More information on configuring your Thrust build and creating a pull request
can be found in the contributing section.
Licensing
Thrust is an open source project developed on GitHub.
Thrust is distributed under the Apache License v2.0 with LLVM Exceptions;
some parts are distributed under the Apache License v2.0 and the
Boost License v1.0.
NVIDIA/thrust có 5.0k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/NVIDIA/thrust. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
Commit gần nhất trên NVIDIA/thrust là 2.5 năm trước (theo timestamp GitHub). Repo có 760 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
NVIDIA/thrust là gì?
NVIDIA/thrust (NVIDIA/thrust) là dự án C++ trên GitHub. Theo mô tả gốc: [ARCHIVED] The C++ parallel algorithms library. See https://github.com/NVIDIA/cccl
NVIDIA/thrust so với các dự án Backend khác thế nào?
NVIDIA/thrust được TopGit xếp vào nhóm Backend, với 5.0k sao GitHub và viết bằng C++. Xem trang chủ đề Backend trên TopGit để so sánh với các dự án tương tự theo số sao và mức độ hoạt động.
NVIDIA/thrust viết bằng ngôn ngữ gì?
NVIDIA/thrust chủ yếu viết bằng C++. Trường "language" của GitHub dựa trên phần lớn byte ở nhánh mặc định.
Vì sao NVIDIA/thrust được xếp vào nhóm Backend?
TopGit xếp NVIDIA/thrust vào nhóm Backend dựa trên GitHub topics và mô tả của repo (gắn thẻ: "algorithms", "cpp", "cpp11"). Việc phân loại dựa trên metadata thật của repo, không phải đoán theo cảm tính biên tập.
Đọc đầy đủ README ở tab phía trên.
Vẫn đang phân vân về thrust?
Một cú bấm sẽ gửi câu hỏi kèm trang này cho AI — xem AI nói gì về thrust.