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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:33:08+00:00 2026-06-16T04:33:08+00:00

I know that each warp contains threads of consecutive, increasing thread IDs with the

  • 0

I know that “each warp contains threads of consecutive, increasing thread IDs with the first warp containing thread 0” so first 32 threads should be in the first warp. Also I know that all threads in one warp are executed simultaneously on any available Streaming Multiprocessor.

As I understood, because of that there is no need in thread syncing if only one warp is being executed. But code below produces wrong answer if I remove any of __syncthreads() in penultimate if block. I tried to find cause but have ended up with nothing. I really hope for your help, so you could tell me what is wrong with this code? Why I can’t leave only last __syncthreads() and get right answer?

#define BLOCK_SIZE 128

__global__ void reduce ( int * inData, int * outData )
{
 __shared__ int data [BLOCK_SIZE]; 
 int tid = threadIdx.x; 
 int i   = blockIdx.x * blockDim.x + threadIdx.x; 

 data [tid] = inData [i] + inData [i + blockDim.x / 2 ];
 __syncthreads ();

 for ( int s = blockDim.x / 4; s > 32; s >>= 1 ) 
 {
  if ( tid < s ) 
   data [tid] += data [tid + s]; 
  __syncthreads (); 
 } 

 if ( tid < 32 )
 { 
  data [tid] += data [tid + 32];
  __syncthreads (); 
  data [tid] += data [tid + 16];
  __syncthreads (); 
  data [tid] += data [tid + 8];
  __syncthreads (); 
  data [tid] += data [tid + 4];
  __syncthreads (); 
  data [tid] += data [tid + 2];
  __syncthreads (); 
  data [tid] += data [tid + 1];
  __syncthreads (); 
 }
 if ( tid == 0 )
  outData [blockIdx.x] = data [0];
}

void main()
{
...
 reduce<<<dim3(128), dim3(128)>>>(dev_data, dev_res);
...
}

P.S. I am using GT560Ti

  • 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-16T04:33:10+00:00Added an answer on June 16, 2026 at 4:33 am

    You should declare the shared memory variable as volatile:

    __shared__ volatile int data [BLOCK_SIZE]; 
    

    The problem you are seeing is an artifact of the Fermi architecture and compiler optimisation. The Fermi architecture lacks instructions to directly operate on shared memory (they were present in the G80/90/GT200 series). So everything is loaded to register, manipulated, and stored back to shared memory. But the compiler is free to deduce that code could be made faster if a series of operations were staged in register, without intermediate loads and stores from/to shared memory. This is perfectly fine except when you are relying on implicit synchronisation of threads within the same warp manipulating shared memory, as in this sort of reduction code.

    By declaring the shared memory buffer as volatile, you are forcing the compiler to enforce the shared memory write after each stage of the reduction, and the implicit data synchronisation between threads within the warp is restored.

    This issue is discussed in the programming notes for Fermi which ships (or perhaps shipped) with the CUDA toolkit.

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

Sidebar

Related Questions

I know that I should setup the trap service on each devices seperately but
I know that each class should to do its own job. So i always
I'm working on PostgreSQL 8.4 in read committed mode. I know that for each
I know that using the following codes will make each column have unique values,
I don't know how to convert the type for name so that each element
In jquery when I run: $('li').each(some-function(i){}); The IDE seems to know that some-function is
In my application, I have several components that have to know about each other,
I know that each file has metadata like title, subject, keywords and comments: But
we know that each executable file can be reverse engineered (disassembled, decompiled). No mater
Possible Duplicate: Style input type file? I know that each browser has its own

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.