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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:01:36+00:00 2026-05-31T11:01:36+00:00

About atomic access of __local variables: I know it’s slow to do global operations

  • 0

About atomic access of __local variables:

I know it’s slow to do global operations compared with local ones. In this sense I’d like to make atomic access of some variables.

I know I can do atomic operations in OpenCL:

// Program A:
#pragma OPENCL EXTENSION cl_khr_global_int32_base_atomics : enable
#pragma OPENCL EXTENSION cl_khr_local_int32_base_atomics : enable
__kernel void test(global int * num)
{
    atom_inc(&num[0]);
}

How do I share atomic data between work-itens within a given work-group?

for ex: I’d like to do something like that:

// Program B: (it doesn't work, just to show how I'd like it to be)
#pragma OPENCL EXTENSION cl_khr_global_int32_base_atomics : enable
#pragma OPENCL EXTENSION cl_khr_local_int32_base_atomics : enable
__kernel void test(global int * num, const int numOperations)
{
    __local int num;
    if (get_global_id(0) < numOperations) {
        atom_inc(&num);
    }
}

In the end the num value should return: numOperations – 1;

Isn’t this possible? If not how could I do it?

  • 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-31T11:01:39+00:00Added an answer on May 31, 2026 at 11:01 am

    Typically, you have one thread which intializes the shared (local) atomic followed by some barrier. I.e. your kernel starts like this:

    __local int sharedNum;
    if (get_local_id (0) == 0) {
        sharedNum = 0;
    }
    barrier (CLK_LOCAL_MEM_FENCE);
    
    // Now, you can use sharedNum
    while (is_work_left ()) {
        atomic_inc (&sharedNum);
    }
    

    There’s not much magic to it — all items in a work-group can see the same local variables, so you can just access it as usual.

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

Sidebar

Related Questions

I'm using atomic operations on counters, and I care about performance. I know that
About six years ago, a software engineer named Harri Porten wrote this article ,
Whenever I face a situation when atomic method should access private parts of different
the question is about when does a 64bit load/store operations are considered to be
We know from the C# specification that reference read/writes are atomic. In a statement
This maybe a related question: Java assignment issues - Is this atomic? I have
Microsoft offers the InterlockedCompareExchange function for performing atomic compare-and-swap operations. There is also an
Iam new to iPhone Programming,Now i want to know about what is the uses
I have a question about the volatile statement in Java. Please look at this
There's a name for this, but I don't know what it is so it's

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.