thrust::host_vector allocation is slow compared to std::vector
- Dominant language
- C++
- Stars
- 2.5k
- Forks
- 486
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 295
Description
I was trying to debug a performance issue and it lead me to testing the memory allocation of `thrust::host_vector`. Here's a simple benchmark I was running:
```cpp
#include
#include
#include
#include
const int length = 64'000'000;
template
void benchmark(const int num_repeats) {
std::vector buffers;
auto start = std::chrono::high_resolution_clock::now();
for (int i = 0; i < num_repeats; i++) {
buffers.emplace_back(length);
}
auto finish = std::chrono::high_resolution_clock::now();
std::cout << "took " << std::chrono::duration_cast(finish - start).count() / (float)num_repeats << "ms\n";
}
int main () {
std::cout << "std::vector: ";
benchmark>(100);
std::cout << "thrust::host_vector: ";
benchmark>(100);
}
```
on my machine I get:
```
$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2020 NVIDIA Corporation
Built on Mon_Nov_30_19:08:53_PST_2020
Cuda compilation tools, release 11.2, V11.2.67
Build cuda_11.2.r11.2/compiler.29373293_0
$ nvcc -O2 -std=c++17 mem.cu && ./a.out
std::vector: took 15.27ms
thrust::host_vector: took 61ms
```
I was wondering if I am missing something trivial or perhaps this is a known issue? Thanks!
Contributor guide
Assessment
This issue has not been assessed yet.