Results 1 to 2 of 2

Thread: initialize global variables

  1. #1

    initialize global variables

    Is there any way to initialize a global variable with a value that is passed on from the host?
    The reason is that otherwise you need to pass the variable as an argument to every function which uses it, meaning that functions will have a huge amount of arguments. Also, it seems intuitive that it would slow down the program if the host has to pass on the variable each time a kernel uses it.
    A simple example is:

    host code:

    device code:
    __constant int x=y;

    __kernel void func()
    int z;

  2. #2
    Senior Member
    Join Date
    May 2010
    Toronto, Canada

    Re: initialize global variables

    No, it's not possible. Variables at global scope must be initialized with literals. In order to have __constant variables whose value comes from the host you need to pass them as kernel arguments as you say.
    Disclaimer: Employee of Qualcomm Canada. Any opinions expressed here are personal and do not necessarily reflect the views of my employer. LinkedIn profile.

Similar Threads

  1. Global variables in OpenCL
    By Considerate in forum OpenCL
    Replies: 1
    Last Post: 05-03-2010, 03:12 PM
  2. Create and initialize a pbuffer.
    By muratmat in forum EGL
    Replies: 0
    Last Post: 09-16-2009, 06:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean