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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:20:52+00:00 2026-05-26T17:20:52+00:00

In OpenCL what will be the consequences and differences between the following struct declarations.

  • 0

In OpenCL what will be the consequences and differences between the following struct declarations. And if they are illegal, why?

struct gr_array
{
    int ndims;
    __global m_integer* dim_size;
    __global m_real* data;
};
typedef struct gr_array g_real_array;

struct lr_array
{
    int ndims;
    __local m_integer* dim_size;
    __local m_real* data;
};
typedef struct lr_array l_real_array;

__ kernel temp(...){

        __local g_real_array A;
        g_real_array B;

        __local l_real_array C;
        l_real_array D;

}

My question is where will the structures be allocated (and the members)? who can access them? And is this a good practice or not?

EDIT

how about this

struct r_array
    {
       __local int ndims;
    };

typedef struct r_array real_array;

__ kernel temp(...){

        __local real_array A;
        real_array B;

}

if a work-item modifies ndims in struct B, is the change visible to other work-items in the work-group?

  • 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-26T17:20:52+00:00Added an answer on May 26, 2026 at 5:20 pm

    I’ve rewritten your code as valid CL, or at least CL that will compile. Here:

    typedef struct gr_array {
        int ndims;
        global int* dim_size;
        global float* data;
    } g_float_array;
    
    typedef struct lr_array {
        int ndims;
        local int* dim_size;
        local float* data;
    } l_float_array;
    
    kernel void temp() {
        local g_float_array A;
        g_float_array B;
    
        local l_float_array C;
        l_float_array D;
    }
    

    One by one, here’s how this breaks down:

    • A is in local space. It’s a struct that is composed of one int and two pointers. These pointers point to data in global space, but are themselves allocated in local space.

    • B is in private space; it’s an automatic variable. It is composed of an int and two pointers that point to stuff in global memory.

    • C is in local space. It contains an int and two pointers to stuff in local space.

    • D, you can probably guess at this point. It’s in private space, and contains an int and two pointers that point to stuff in local space.

    I cannot say if either is preferable for your problem, since you haven’t described what your are trying to accomplish.

    EDIT: I realized I didn’t address the second part of your question — who can access the structure fields.

    Well, you can access the fields anywhere the variable is in scope. I’m guessing that you were thinking that the fields you had marked as global in g_float_array were in global space (an local space for l_float_array). But they’re just pointing to stuff in global (or local) space.

    So, you’d use them like this:

    kernel void temp(
                global float* data, global int* global_size,
                local float* data_local, local int* local_size,
                int num) 
    {
        local g_float_array A;
        g_float_array B;
    
        local l_float_array C;
        l_float_array D;
    
        A.ndims = B.ndims = C.ndims = D.ndims = num;
    
        A.data = B.data = data;
        A.dim_size = B.dim_size = global_size;
    
        C.data = D.data = data_local;
        C.dim_size = D.dim_size = local_size;
    }
    

    By the way — if you’re hacking CL on a Mac running Lion, you can compile .cl files using the “offline” CL compiler, which makes experimenting with this kind of stuff a bit easier. It’s located here:

    /System/Library/Frameworks/OpenCL.framework/Libraries/openclc
    

    There is some sample code here.

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

Sidebar

Related Questions

I compiled the following code: // Triangle.cpp // Our first OpenGL program that will
I am experimenting with OpenCL to increase the speed of our software. We work
I am working on OpenCL. Does anyone know of a good debugger for OpenCL
I've been playing with the ATI OpenCL implementation in their Stream 2.0 beta. The
I'm just starting out learning OpenCL. I'm trying to get a feel for what
I've been playing with OpenCL recently, and I'm able to write simple kernels that
I recently started to learn how to use openCL to speed up some part
Is it possible to use custom types in OpenCL kernel like gmp types (mpz_t,
The definition of a platform in Khronos' OpenCL 1.0 and 1.1 specification : Platform:
In my relatively short time learning OpenCL I frequently see my application cause the

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.