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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:19:31+00:00 2026-06-02T15:19:31+00:00

I am trying to call a device function from global function. This function is

  • 0

I am trying to call a device function from global function. This function is only declaring an array to be used by all threads. But my problem when I printed the array its elements are not in the same order as declared. Is it because of all threads are creating the array again ? I confused about threads. If it is , Can I learn which thread is run first in global function and can I only allow it to declare the array for the others. Thanks.
Here my function to create array :

__device__ float myArray[20][20];

__device__ void calculation(int no){
filterWidth = 3+(2*no);
filterHeight = 3+(2*no);
int arraySize = filterWidth;
int middle = (arraySize - 1) / 2;
int startIndex = middle;
int stopIndex = middle;

// at first , all values of array are 0
for(int i=0; i<arraySize; i++)
    for (int j = 0; j < arraySize; j++)
    {
        myArray[i][j] = 0;
    }

//  until middle line of the array, required indexes are 1
for (int i = 0; i < middle; i++)
{
    for (int j = startIndex; j <= stopIndex; j++)
    { myArray[i][j] = 1; sum+=1; }
    startIndex -= 1;
    stopIndex += 1;
}

// for middle line
for (int i = 0; i < arraySize; i++)
{myArray[middle][i] = 1; sum+=1;}

// after middle line of the array, required indexes are 1
startIndex += 1;
stopIndex -= 1;
for (int i = (middle + 1); i < arraySize; i++)
{
    for (int j = startIndex; j <= stopIndex; j++)
    { myArray[i][j] = 1; sum+=1; }
    startIndex +=1 ;
    stopIndex -= 1;
}


filterFactor = 1.0f / sum;
  } 

And global function :

__global__ void FilterKernel(Format24bppRgb* imageData)
  {
int tidX = threadIdx.x + blockIdx.x * blockDim.x;
int tidY = threadIdx.y + blockIdx.y * blockDim.y;

Colour Cpixel = Colour (imageData[tidX + tidY*imageWidth] );
float depthPixel =  Colour(depthData[tidX + tidY*imageWidth]).Red;
float absoluteDistanceFromFocus = fabs (depthPixel - focusDepth);


if(depthPixel == 0)
    return;

Colour Cresult = Cpixel;
for (int i=0;i<8;i++)
{
    calculation(i);
     ...
     ...
    }
 }
  • 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-02T15:19:32+00:00Added an answer on June 2, 2026 at 3:19 pm

    If you really want to select and force one thread to call the function and the rest to wait for it to do so, use __shared__ memory for the array created by the device function so that all threads in a block see the same one, and you can call it with:

    for (int i=0;i<8;i++)
    {
        if (threadIdx.x == 0 && threadIdx.y == 0)
            calculation(i);
        __syncthreads();
        ...
    }
    

    Of course, this won’t work between blocks – in a globally defined function, you have no control over the order in which blocks are computed.

    Instead, if you can, you should do the initialization calculation (that only 1 thread needs to do) on the CPU and memcpy it to the GPU before launching your kernel. It looks like you’ll use 8x the memory for your myArray’s, but it’ll dramatically speed up your computation.

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

Sidebar

Related Questions

I am trying to call cleartool from an java application, but cleartool hangs even
I'm trying to call the HttpServerUtuility.URLDecode function in C# using Visual Studio 2005, but
I'm trying to call EWS from MonoTouch like in this snippet: byte[] bytes =
I'm trying to exploit shared memory in this kernel function, but the performance are
Trying to call a SAP SOAP Web Service from a generated sudzc app shows
I'm trying to call a stored procedure from my .NET code which has one
I am trying to call a web service from asp.net 3.5 application. I have
I'm trying to call the MyJavascriptFunction(arg1) from an asp button and it's doesn't work...
I'm trying to call the LumenWorks .csv file reading library from a C++/CLI application
I`am trying to download and install an apk from some link, but for some

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.