Results 1 to 3 of 3

Thread: Use of variables in kernel function using OpenCL

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    17

    Use of variables in kernel function using OpenCL

    Hello Everyone !
    My code is as follows.
    ******* host code******

    //some declarations
    cl_mem Curr_domain = NULL;
    cl_mem dMobj = NULL;

    //created check, AvgBlk of type structure domainBlock

    // now creating buffers for above datatypes
    dMobj = clCreateBuffer(context, CL_MEM_READ_ONLY|CL_MEM_USE_HOST_PTR, dCount * sizeof(struct domainBlock), AvgBlk, &ret);
    Curr_domain = clCreateBuffer(context, CL_MEM_READ_WRITE, dCount *sizeof(struct domainBlock), check, &ret);
    //passed these 2 objects to the kernel

    ******* kernel code******

    __kernel void calculateRms( __global struct domainBlock* dMobj, __global struct domainBlock* Curr_domain )
    {
    int l = get_global_id(0);
    int i=0;
    int iType=0;

    for(iType =0; iType<8;iType++)
    {
    if(iType==0)
    {
    Curr_domain = dMobj;
    }
    }
    }
    This gives me build failure error!
    But if I initialize Curr_domain = dMobj; before the loop it won't. But I want to do this for 6 more times.
    So how can I fix this issue?
    I'm using Intel(R) HD Graphics 4000 for executing this program.

  2. #2
    Junior Member
    Join Date
    Jun 2014
    Posts
    10
    Use code blocks next time to preserve indentation "(code=c) (/code)" with [ ] instead of ( ). Did you mean:
    Code c:
    *Curr_domain = *dMobj;
    instead of
    Code c:
    Curr_domain = dMobj;
    Because as it is right now, you're just setting the pointers equal to eachother. You also need to include the struct definition in the kernel file if you are going to be setting fields, the kernel won't know what to do otherwise. This compiles fine for me:
    Code c:
    struct domainBlock
    {
        int something;
        float an_array[7];
        double something_else;
    };
     
    __kernel void calculateRms(__global struct domainBlock* dMobj, __global struct domainBlock* Curr_domain )
    {
        for (int iType = 0; iType < 8; ++iType)
            if (iType==0)
                *Curr_domain = *dMobj;
    }

  3. #3
    Junior Member
    Join Date
    Apr 2014
    Posts
    17
    Thanks cartographer! But it is also not working in my code.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •