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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:06:02+00:00 2026-05-22T12:06:02+00:00

Hey there, I have an array with the size SIZE*sizeof(double) on my host. I

  • 0

Hey there,
I have an array with the size SIZE*sizeof(double) on my host. I allocate a device pointer of the size of the host-array and copy the array to the device. Now I pass this device array dev_point to my kernel function. Each threads need to modify some values of the passed array and than calculates another _device__-function with the new array-values (different for each thread). Now I wonder how to do this? Before I had a complete CPU-version (serial code) of my program and I simply always created a new array like double new_array[ SIZE ] and than copied the data from the original array to it, modified it and than deleted it again. But how to do it in CUDA, since I can’t allocate memory from within a kernel-function. Is there any possibility to use ‘local’ memory of the thread to store a new array in? Or do I have to allocate a big array of the size SIZE * number_of_total_threads * sizeof(double) before calling my kernel function so that each thread can store the modified array in it?
Thanks a lot in advance!

EDIT: FULL DESCRIPTION!
Okay here’s a better problem description on my ‘current’ case: In my host program I have a array, let’s say with 300 values (dependent on the user input between 100 and 400, let’s call that variable numValues which is a size depending on the program parameters and not hardcoded into the program!) of doubles. Now I want each kernel-execution to take exactly this array (it is actually copied to GPU and passed to kernel function as a pointer), change the value to the n-th element (n = unique identifier which goes from 0 to numValues), whereas all other array elements stay the same. The modification is a simple addition of a certain constant value, which is also passed to the program by the user. And than call a function which is defined like that __device__ double thefunction(double *ary) passing the modified array.

So the first solution which I thought about was the one I asked here: Give each thread (each kernel execution) an own array-copy (I thought this could be done locally, but obviously can’t because numValues is runtime specific) and than let each thread modify value n and calculate thefunction with it.

Now I just came up with another idea while writing this here: Perhaps it would be better to have the array in constant or shared memory ONCE so that each thread passes the array as unmodified array to thefunction but specifies as additional parameters to thefunction an index int idx about which element to modify and another parameter double *add about the value to add to the idx-th element.
The only thing which I wonder about is than: How to add the value *add to the idx-th Element without modifying the array ary passed to the function because this is passed as a pointer and I don’t want to modify the original one!

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-22T12:06:03+00:00Added an answer on May 22, 2026 at 12:06 pm

    If you only need to modify some values, as you say, then at the level of the data required to compute a single result, it follows you should only need a local copy of some of the input data. That local copy should, ideally, be held in registers, which is the fastest place to store thread local data.

    If there is data dependency between the local modifications required for one result and the local modifications required for another, the usual solution is to group the computation of interdependent results into a single block and use shared memory to hold the modified data, which allows data exchange between threads within that block. If you algorithm is something like a recurrence relation where there is sequential dependence on data from a previous calculation, you need a new algorithm, because those types of calculations cannot be easily executed in parallel in any useful way.

    That is about as good a answer as you will get without specifics of the code and algorithms involved.

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

Sidebar

Related Questions

hey there, i have a div that expands when the page is loaded, now
Hey guys this is a followup to my previous question . I now have
Hey there, I have 20 divs floated left with different height. I use this
Hey there I have this function: void vdCleanTheArray(int (*Gen_Clean)[25]) { } I wanted to
Hey i have developed android application . Now at this stage i want to
Hey just a quick question for any experts out there. I have a site
Hey guys, one more quick question for any experts out there. I have a
Hey there, I am trying to get my signout button to work. This is
Hey, so basically I have this issue, where I'm trying to put an equation
Hey. I have this javascript file that I'm getting off the web and it

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.