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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:26:40+00:00 2026-05-24T22:26:40+00:00

I have some general parameters declared as a global (__constant) struct, like so: typedef

  • 0

I have some general parameters declared as a global (__constant) struct, like so:

typedef struct
{
    int a;
    int b;
    float c;
    /// blah blah

} SomeParams;

__constant SomeParams Parameters;

in the kernel, I need to use it like so:

__kernel void Foo()
{
    int a = Parameters.a;
    /// do something useful...
}

I’m not sure how I can initialize the value of Parameters from the host before I execute the kernel.

I have no problem creating buffers, etc for kernel arguments, but since this isn’t a kernel argument, what do I need to do?

I’m using the Cloo C#/OpenCL bindings, but even a raw CL API would be helpful.

  • 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-24T22:26:42+00:00Added an answer on May 24, 2026 at 10:26 pm

    As far as I know (but I wouldn’t swear by this), you can’t initialize variables from the host code that are declared in that way (with one exception, see below). You could declare a variable and initialize it like this:

    __constant float pi = 3.14f;
    

    You could also do something like this:

    Kernel: __constant float width = WIDTH

    Host: Build the kernel with a -D build parameter defining the value of WIDTH.

    What I have done in the past is have the constant variable as a kernel parameter.

    __kernel void Foo(__constant SomeParams Parameters)
    {
        int a = Parameters.a;
        /// do something useful...
    }
    

    Then you can allocate and set the value just like any other kernel argument.

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

Sidebar

Related Questions

I have a general question. I would like to have a window containing some
I have written some general functions to convert between decimal and any other base-n
I have a simple class that contains some general information about the current web
I have some code that generates image of a pie chart. It's a general
I have 3 tables, - Section table that defines some general item sections. -
I understand that some countries have laws regarding website accessibility. In general, what are
I have to give a general note to some huge Java project for which
I've done some research into server push with javascript and have found the general
I have a general understanding of restrict but I'm hoping to clarify some fine
I'd just like some general advice. My tables are structured like so (or rather,

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.