Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7536761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:39:51+00:00 2026-05-30T06:39:51+00:00

Recently I have been using thrust a lot. I have noticed that in order

  • 0

Recently I have been using thrust a lot. I have noticed that in order to use thrust, one must always copy the data from the cpu memory to the gpu memory.
Let’s see the following example :

int foo(int *foo)
{
     host_vector<int> m(foo, foo+ 100000);
     device_vector<int> s = m;
}

I’m not quite sure how the host_vector constructor works, but it seems like I’m copying the initial data, coming from *foo, twice – once to the host_vector when it is initialized, and another time when device_vector is initialized. Is there a better way of copying from cpu to gpu without making an intermediate data copies? I know I can use device_ptras a wrapper, but that still doesn’t fix my problem.
thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T06:39:52+00:00Added an answer on May 30, 2026 at 6:39 am

    One of device_vector‘s constructors takes a range of elements specified by two iterators. It’s smart enough to understand the raw pointer in your example, so you can construct a device_vector directly and avoid the temporary host_vector:

    void my_function_taking_host_ptr(int *raw_ptr, size_t n)
    {
      // device_vector assumes raw_ptrs point to system memory
      thrust::device_vector<int> vec(raw_ptr, raw_ptr + n);
    
      ...
    }
    

    If your raw pointer points to CUDA memory, introduce a device_ptr:

    void my_function_taking_cuda_ptr(int *raw_ptr, size_t n)
    {
      // wrap raw_ptr before passing to device_vector
      thrust::device_ptr<int> d_ptr(raw_ptr);
    
      thrust::device_vector<int> vec(d_ptr, d_ptr + n);
    
      ...
    }
    

    Using a device_ptr doesn’t allocate any storage; it just encodes the location of the pointer in the type system.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been using Rstudio a great deal these days but recently noticed that
I've been using extension methods quite a bit recently and have found a lot
I've recently come to appreciate the copy-and-swap idiom, and have been using it to
I have recently been using Charles the debugging app. And noticed a very chatty
Recently I have been using anonymous method a lot, so I wonder if I
I have recently figured out that I haven't been using regex properly in my
I have been using Netbeans 6.5 recently - it complains (on startup, and if
I have been using NotePAD++ for editing Python scripts. I recently downloaded the PyDEV
I have recently been working with Python using Komodo Edit and other simpler editors
I've been looking at some server logs using tail -f recently, and have thought

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.