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 9122929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:13:07+00:00 2026-06-17T06:13:07+00:00

I have a pointer int *h_a which references a large number N of data

  • 0

I have a pointer int *h_a which references a large number N of data points (on host) that I want to copy to device. So I do:

thrust::host_vector<int> ht_a(h_a, h_a + N);
thrust::device_vector<int> dt_a = ht_a;

However, creating ht_a seems to implictly copy h_a rather than reference it, which is inefficient as I don’t need another copy of h_a.

I just want to create ht_a such that &ht_a[0] points to h_a[0] – how to do this?

Many thanks.

Alternatively, as I’m not actually doing anything with ht_a other than copying to device memory, I’d be interested to know if we can go directly between int* and thrust::device_vector<int>.

  • 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-06-17T06:13:09+00:00Added an answer on June 17, 2026 at 6:13 am

    Edited code to also show how to copy back from device to host:

    #include <stdio.h>
    #include <thrust/device_vector.h>
    #include <thrust/copy.h>
    
    int main() {
    
     int N = 10;
     int *h_a;
     int *h_b;
     h_a = (int *)malloc(N*sizeof(int));
     h_b = (int *)malloc(N*sizeof(int));
     for (int i=0; i<N; i++) {
       h_a[i] = i;
       h_b[i] = 0;
       }
    
     thrust::device_vector<int> dt_a(h_a, h_a + N);
    
     thrust::copy(dt_a.begin(), dt_a.end(), h_b);
    
     for (int i=0; i<N; i++)
       printf("h_b[%d] = %d\n", i, h_b[i]);
     return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a pointer which points to a function. I would like to: if
As we know, we can use int (*p)[10] to define a pointer which points
I am having a new little problem; I have a little pointer called: int
I have a structure: struct mystruct { int* pointer; }; structure mystruct* struct_inst; Now
I have a pointer to a QScriptEngine that I'm passing through the overloaded class
I have a pointer to a map that I am trying to delete (this
I have a pointer of a structure type that I made. On program start
So I have this C .dll source code which I want to use in
I have a question regarding using intptr_t vs. long int . I've observed that
I have a little C program which takes a number of vectors and their

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.