Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Suboptimal swap performance on universal vectors #2948

Open
1 task done
gevtushenko opened this issue Nov 25, 2024 · 0 comments
Open
1 task done

[BUG]: Suboptimal swap performance on universal vectors #2948

gevtushenko opened this issue Nov 25, 2024 · 0 comments
Labels
bug Something isn't working right. good first issue Good for newcomers.

Comments

@gevtushenko
Copy link
Collaborator

Is this a duplicate?

Type of Bug

Performance

Component

Thrust

Describe the bug

Swap of universal vectors is unnecessary slow and occupies more memory than it should.
Device and host vectors have swap overloads in thrust:: namespace.
These overloads call efficient .swap member function:

template <typename T, typename Alloc>
void swap(device_vector<T, Alloc>& a, device_vector<T, Alloc>& b)
{
a.swap(b);
}

Universal and universal host pinned vectors are missing such an overload and the vector_base they alias to has swap overload in thrust::details, so it’s unreachable.

How to Reproduce

template <template <typename> class Vector>
void swap_time(const char* str) {
    Vector<char> a(1 << 30, 'a');
    Vector<char> b(1 << 30, 'b');

    auto begin = std::chrono::high_resolution_clock::now();
    thrust::swap(a, b);
    // a.swap(b);
    auto end = std::chrono::high_resolution_clock::now();
    std::cout << str << " swap time: " << std::chrono::duration<double>(end - begin).count() << " s" << std::endl;
    std::cout << "a: " << static_cast<char>(a[0]) << "; "
              << "b: " << static_cast<char>(b[0]) << std::endl;
}

int main() {
    swap_time<thrust::device_vector>("device");
    swap_time<thrust::host_vector>("host");
    swap_time<thrust::universal_vector>("universal");
    swap_time<thrust::universal_host_pinned_vector>("universal_host_pinned");
}

Expected behavior

  • Swap of universal host pinned vector is 30 million times faster
  • Swap of universal vector is 4 million times faster

Reproduction link

No response

Operating System

No response

nvidia-smi output

No response

NVCC version

No response

@gevtushenko gevtushenko added the bug Something isn't working right. label Nov 25, 2024
@github-project-automation github-project-automation bot moved this to Todo in CCCL Nov 25, 2024
@gevtushenko gevtushenko added the good first issue Good for newcomers. label Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working right. good first issue Good for newcomers.
Projects
Status: Todo
Development

No branches or pull requests

1 participant