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

  • Home
  • SEARCH
  • 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 8232925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:58:40+00:00 2026-06-07T17:58:40+00:00

I am developing a Windows 64-bit application that will manage concurrent execution of different

  • 0

I am developing a Windows 64-bit application that will manage concurrent execution of different CUDA-algorithms on several GPUs.

My design requires a way of passing pointers to device memory
around c++ code. (E.g. remember them as members in my c++ objects).
I know that it is impossible to declare class members with __device__ qualifiers.

However I couldn’t find a definite answer whether assigning __device__ pointer to a normal C pointer and then using the latter works. In other words: Is the following code valid?

__device__ float *ptr;
cudaMalloc(&ptr, size);
float *ptr2 = ptr
some_kernel<<<1,1>>>(ptr2);

For me it compiled and behaved correctly but I would like to know whether it is guaranteed to be correct.

  • 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-07T17:58:41+00:00Added an answer on June 7, 2026 at 5:58 pm

    No, that code isn’t strictly valid. While it might work on the host side (more or less by accident), if you tried to dereference ptr directly from device code, you would find it would have an invalid value.

    The correct way to do what your code implies would be like this:

    __device__ float *ptr;
    
    __global__ void some_kernel()
    {
        float val = ptr[threadIdx.x];
        ....
    }
    
    float *ptr2;
    cudaMalloc(&ptr2, size);
    cudaMemcpyToSymbol("ptr", ptr2, sizeof(float *));
    
    some_kernel<<<1,1>>>();
    

    for CUDA 4.x or newer, change the cudaMemcpyToSymbol to:

    cudaMemcpyToSymbol(ptr, ptr2, sizeof(float *));
    

    If the static device symbol ptr is really superfluous, you can just to something like this:

    float *ptr2;
    cudaMalloc(&ptr2, size);
    some_kernel<<<1,1>>>(ptr2);
    

    But I suspect that what you are probably looking for is something like the thrust library device_ptr class, which is a nice abstraction wrapping the naked device pointer and makes it absolutely clear in code what is in device memory and what is in host memory.

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

Sidebar

Related Questions

An in house application that I'm developing is behaving strange on a Windows 7
I am developing an ADO application (32 bit) on Windows 7 64 bit SP1
I am developing an application using visual studio on a 64 bit Windows 7
I'm developing a Windows Forms application using Visual Studio 2008 C# that uses an
I am developing an application and I will need to take measurements on different
I am developing a 32 bit application in .NET that for various reasons cannot
I'm developing on Windows 2008 R2 Server, 64 bit. I'm learning how to use
I am developing on a Windows 2008 R2 Server, 64 bit. I am developing
I am Developing Windows Form Application in .Net, I want to insert selected rows
I am developing Windows Phone 7 application in which I send encrypted data to

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.