thrust

how to free device_vector<int>

两盒软妹~` 提交于 2019-12-06 01:14:34
I allocated some space using thrust device vector as follows: thrust::device_vector<int> s(10000000000); How do i free this space explicitly and correctly ? device_vector deallocates the storage associated when it goes out of scope, just like any standard c++ container. If you'd like to deallocate any Thrust vector 's storage manually during its lifetime, you can do so using the following recipe: // empty the vector vec.clear(); // deallocate any capacity which may currently be associated with vec vec.shrink_to_fit(); The swap trick mentioned in Roger Dahl's answer should also work. Roger Dahl

Multi GPU usage with CUDA Thrust

空扰寡人 提交于 2019-12-05 22:41:59
I want to use my two graphic cards for calculation with CUDA Thrust. I have two graphic cards. Running on single cards works well for both cards, even when I store two device_vectors in the std::vector. If I use both cards at the same time, the first cycle in the loop works and causes no error. After the first run it causes an error, probably because the device pointer is not valid. I am not sure what the exact problem is, or how to use both cards for calculation. Minimal code sample: std::vector<thrust::device_vector<float> > TEST() { std::vector<thrust::device_vector<float> > vRes; unsigned

CUDA Thrust library: How can I create a host_vector of host_vectors of integers?

孤街浪徒 提交于 2019-12-05 19:31:19
In C++ in order to create a vector that has 10 vectors of integers I would do the following: std::vector< std::vector<int> > test(10); Since I thought Thrust was using the same logic with the STL I tried doing the same: thrust::host_vector< thrust::host_vector<int> > test(10); However I got too many confusing errors. I tried doing: thrust::host_vector< thrust::host_vector<int> > test; and it worked, however I can't add anything to this vector. Doing thrust::host_vector<int> temp(3); test.push_back(temp); would give me the same errors(too many to paste them here). Also generally speaking when

cuda/thrust: Trying to sort_by_key 2.8GB of data in 6GB of GPU RAM throws bad_alloc

纵然是瞬间 提交于 2019-12-05 18:53:18
I have just started using thrust and one of the biggest issues I have so far is that there seems to be no documentation as to how much memory operations require. So I am not sure why the code below is throwing bad_alloc when trying to sort (before the sorting I still have >50% of GPU memory available, and I have 70GB of RAM available on the CPU)--can anyone shed some light on this? #include <thrust/device_vector.h> #include <thrust/sort.h> #include <thrust/random.h> void initialize_data(thrust::device_vector<uint64_t>& data) { thrust::fill(data.begin(), data.end(), 10); } int main(void) { size

Multiple GPUs with Cuda Thrust?

蹲街弑〆低调 提交于 2019-12-05 16:27:21
How do I use Thrust with multiple GPUs? Is it simply a matter of using cudaSetDevice(deviceId) and then running the relevant Thrust code? With CUDA 4.0 or later, cudaSetDevice(deviceId) followed by your thrust code should work. Just keep in mind that you will need to create and operate on separate vectors on each device (unless you have devices that support peer-to-peer memory access and PCI-express bandwidth is sufficient for your task). 来源: https://stackoverflow.com/questions/8289860/multiple-gpus-with-cuda-thrust

How to sort two arrays/vectors in respect to values in one of the arrays, using CUDA/Thrust

ε祈祈猫儿з 提交于 2019-12-05 16:16:00
This is a conceptual question in regards programming. To summarize, I have two arrays/vectors and I need to sort one with the changes propagating in the other as well, so that if I sort arrayOne, for each swap in the sort - the same thing happens to arrayTwo. Now, I know that std::sort allows you to define a comparison function (for custom objects I assume) and I was thinking of defining one to swap arrayTwo at the same time. So what I want is - to sort the two vectors based on values in one of the vectors, using CUDA. This is where my uncertainty rises, essentially I want to use the Thrust

Fastest way to access device vector elements directly on host

北慕城南 提交于 2019-12-05 15:19:45
I refer you to following page http://code.google.com/p/thrust/wiki/QuickStartGuide#Vectors . Please see second paragraph where it says that Also note that individual elements of a device_vector can be accessed using the standard bracket notation. However, because each of these accesses requires a call to cudaMemcpy, they should be used sparingly. We'll look at some more efficient techniques later. I searched all over the document but I could not find the more efficient technique. Does anyone know the fastest way to do this? i.e how to access device vector/device pointer on host fastest? The

CUDA Thrust and sort_by_key

China☆狼群 提交于 2019-12-05 12:23:17
I’m looking for a sorting algorithm on CUDA that can sort an array A of elements (double) and returns an array of keys B for that array A. I know the sort_by_key function in the Thrust library but I want my array of elements A to remain unchanged. What can I do? My code is: void sortCUDA(double V[], int P[], int N) { real_t *Vcpy = (double*) malloc(N*sizeof(double)); memcpy(Vcpy,V,N*sizeof(double)); thrust::sort_by_key(V, V + N, P); free(Vcpy); } i'm comparing the thrust algorithm against others that i have on sequencial cpu N mergesort sortCUDA 113 0.000008 0.000010 226 0.000018 0.000016 452

CUDA thrust zip_iterator tuple transform_reduce

丶灬走出姿态 提交于 2019-12-05 10:49:28
I want to compute for vectors and , where denotes the magnitude of the vector . Since this involves taking the square root of the sum of the squares of the differences between each corresponding component of the two vectors, it should be a highly parallelizable task. I am using Cuda and Thrust, through Cygwin, on Windows 10. Both Cuda and Thrust are in general working. The below code compiles and runs (with nvcc), but only because I have commented out three lines toward the bottom of main , each of which I think should work but does not. func::operator()(tup t) thinks that the arguments I'm

Poor performance when calling cudaMalloc with 2 GPUs simultaneously

风格不统一 提交于 2019-12-05 07:57:42
I have an application where I split the processing load among the GPUs on a user's system. Basically, there is CPU thread per GPU that initiates a GPU processing interval when triggered periodically by the main application thread. Consider the following image (generated using NVIDIA's CUDA profiler tool) for an example of a GPU processing interval -- here the application is using a single GPU. As you can see a big portion of the GPU processing time is consumed by the two sorting operations and I am using the Thrust library for this (thrust::sort_by_key). Also, it looks like thrust::sort_by_key