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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:07:02+00:00 2026-06-08T17:07:02+00:00

i expected to see numbers from 0.0 to 999.0 but instead getting some very

  • 0

i expected to see numbers from 0.0 to 999.0 but instead getting some very weird and long number for some of the indices for the below code:

__global__ void kernel(double *res, int N)
{
  int i = (gridDim.y*blockIdx.y+
           blockIdx.x)*blockDim.x*blockDim.y+
           blockDim.y*threadIdx.y+threadIdx.x;
  if(i<N) res[i] = i;  
}

void callGPU(int N)
{
 dim3 dimBlock(8, 8);
 dim3 dimGrid(2, 8);
 ...
 kernel<<<dimGrid, dimBlock>>>(res, N);
 ...
} 

even if i change the dimGrid to (8,2) and (1,16), but if I change the gridDim to (16,1) then i am getting the indices right. plz can you show how to correctly compute the gridDim for this case? if possible to arbitrary N. many 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-06-08T17:07:03+00:00Added an answer on June 8, 2026 at 5:07 pm

    Your indexing pattern is wrong.
    Firstly, You should compute index by x and y dimensions.

    int i_x = blockIdx.x * blockDim.x + threadIdx.x;
    int i_y = blockIdx.y * blockDim.y + threadIdx.y;
    

    Then you should compute pitch as count of whole threads by x dimension

    int pitch = gridDim.x * blockDim.x;
    

    Finally, You can compute your 1D index from 2D grid.

    int i = i_y * pitch + i_x;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Very famous error message (see below), judging by the number of Google results. But
Getting Expected ',' or '{' but found '#44559' error. My code looks like this:
So I'm getting some interesting behaviour from some filters stacked within a for loop.
I'm using DataTables plugin from http://datatables.net . The plugin it self is very useful,but
For some reason I'm not getting the expected output on this curl function, IF
I have simple select tag, in which I would like to see numbers from
I have the following recursive code and it doesn't behave as expected (see details
I expected to see the word test appear in the output once and the
I recently ran git fsck --lost-found on my repository. I expected to see a
I expected this to print [b] but it prints [] : $x = abc;

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.