Afficher la pageAnciennes révisionsHaut de page Cette page est en lecture seule. Vous pouvez afficher le texte source, mais ne pourrez pas le modifier. Contactez votre administrateur si vous pensez qu'il s'agit d'une erreur. ====== Thrust ====== **Thrust** is a CUDA library of parallel algorithms with an interface resembling the C++ Standard Template Library (STL). Thrust provides a flexible high-level interface for GPU programming that greatly enhances developer productivity. Develop high-performance applications rapidly with Thrust! ====== Version installée ====== * v1.4.0 ====== Utilisation ====== <note important> Pour utiliser Thrust il faut se connecter les machines tesla et de charger l'environnement CUDA</note> <code bash> $ qlogin -q tesla.q </code> <code bash> $ module load cuda </code> ===== Exemples ===== __** Génération des nombres aléatoires sur le CPU, les transférer sur GPU**__ <file C transfert.cu> #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; } </file> __ ** Calcul de la somme de 100 nombre sur le GPU**__ <file CPP somme.cu> #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; } </file> ===== Compilation ===== <note>Il suffit d'utiliser le compilateur Nvidia ''nvcc''</note> <code bash> $ nvcc Example.cpp -o Example </code> ===== Liens ===== http://code.google.com/p/thrust/ thrust.txt Dernière modification : 2014/10/20 15:06de admin