Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: problem passing struct kernel arguments (Apple)

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Location
    Seattle, WA
    Posts
    27

    problem passing struct kernel arguments (Apple)

    I've run into a problem where I would like to pass one or more simple structures to my OpenCL kernel. I am aware of potential issues of packing and endian-ness. I'm prepared to work with those carefully, but I don' think that's what's going on now.

    Bottom line: I can't pass a simple structure as a kernel argument into my kernel complied on Mac OS X 10.7.2, for NVIDIA GeForce 8600M GT. (OpenCL 1.0 supported)

    Struct passing works as expected when on the same machine, compiled for an Intel CPU. Also works fine on a linux machine compiled for a Fermi GPU (CUDA 4.1).

    I'm thinking this is a bug with Apple's implementation, but want to see what the community thinks before reporting it. Also, can anyone confirm this bug on a different Mac GPU device?

    Links are for two simple demo programs. The first demonstrates the struct problem (at least run on my setup. Desired output is:
    Input to kernel was: 2002, output back was 2002.
    The second demonstrates successful results when the native type is passed directly (not contained in the struct).

    The key point is that passing a kernel argument
    Code :
    struct { int intMember }
    does not work while the native-type argument
    Code :
    int nativeArg
    does.

    Struct Argument http://dl.dropbox.com/u/54478577/sup...roblemDemo.cpp

    Native Argument: http://dl.dropbox.com/u/54478577/sup...alarOKDemo.cpp

    Build commands are in the leading source file comments.

    Thanks.

  2. #2
    Junior Member
    Join Date
    May 2009
    Posts
    13

    Re: problem passing struct kernel arguments (Apple)

    It looks like passing structures by value to an OpenCL kernel doesn't work on Apple indeed.

  3. #3
    Junior Member
    Join Date
    Oct 2011
    Location
    Seattle, WA
    Posts
    27

    Re: problem passing struct kernel arguments (Apple)

    I reported this to Apple as a Bug Report back on April 3rd. Not that that has gone anywhere since, but maybe someday.

  4. #4
    Junior Member
    Join Date
    May 2009
    Posts
    13

    Re: problem passing struct kernel arguments (Apple)

    Although your own structs cannot be passed as arguments to OpenCL kernels,
    you can pass in built-in types such as int4, uint4 by value as a workaround. You can typedef the x,y,z,w fields to meaningful names:

    #define m_numElements x

    __kernel name(int4 args)
    {

    if (args.m_numElements)

    }

  5. #5
    Junior Member
    Join Date
    May 2012
    Posts
    13

    Re: problem passing struct kernel arguments (Apple)

    I can confirm that I came across this problem previously on a Mac (OS 10.6.. I never found a solution, so thanks for filing the bug report. I presume that you're getting the same error number as me (-51:CL_INVALID_ARG_SIZE). Actually I'm a little disappointed when I look at Apple's more recent efforts regarding OpenCL, I get the feeling from their website that they might not be so committed to it as they once were.

    Erwin: regarding your workaround, do you think that there would be any performance benefit to using an int4 buffer over 4 buffers of ints? I am currently using a random number generator with 4 state variable so this would be quite interesting to me.

    Thanks,
    Dave.

  6. #6
    Junior Member
    Join Date
    Oct 2011
    Location
    Seattle, WA
    Posts
    27

    Re: problem passing struct kernel arguments (Apple)

    Dave, I do not receive any error when setting the argument, just incorrect struct values within the kernel.


    Here's an update having tested a few different platforms and GPUs. The bug seems specific to Apple Mac OS X with NVIDIA GPU.

    FAILS:
    Mac OS X 10.7.4 - NVIDIA GeForce 8600M GT
    Mac OS X 10.8.2 - NVIDIA GeForce GT 650M
    Mac OS X 10.8.2 - NVIDIA Quadro 4000

    WORKS:
    Mac OS X 10.8.2 - ATI Radeon HD 5770
    Linux NVIDIA CUDA SDK - Tesla M2050
    Linux AMD APP SDK - Xenon CPU
    Linux AMD APP SDK - ATI Radeon HD 5770

  7. #7
    Junior Member
    Join Date
    Oct 2011
    Location
    Seattle, WA
    Posts
    27

    Re: problem passing struct kernel arguments (Apple)

    amending my previous update. In slightly more complicated struct cases, the Apple/AMD GPU case fails as well.

  8. #8

    Re: problem passing struct kernel arguments (Apple)

    I'm on OSX and, all day long, I pass in a structure containing dozens of variables with no problems. This struct contains bytes, ints, floats, and arrays of all three....

    no problems under 10.7.3, or 10.7.4. (I use ..4 on the laptop for coding, and ..3 on the production Mac Pro, since ..4 breaks OpenCL for the AMD GPU on that machine....)

  9. #9
    Junior Member
    Join Date
    Oct 2011
    Location
    Seattle, WA
    Posts
    27

    Re: problem passing struct kernel arguments (Apple)

    Photovore, does my "Struct Argument" program linked in my original post work for you when run for your GPU device? I'm saying that program works for me on my AMD GPU. It fails with NVIDIA GPU. (Both on 10.8.2)

  10. #10

    Re: problem passing struct kernel arguments (Apple)

    Noah,

    1) I didn't read carefully earlier; I pass my structure by address.

    2) My only nVidia device is in my laptop, where I run 10.7.4; indeed structProblemDemo fails:

    Available devices:

    device: 0
    ---------------
    CL_DEVICE_NAME: GeForce GT 330M
    CL_DRIVER_VERSION: CLH 1.0

    SELECTED DEVICE: 0.

    Build Log:

    End of Build Log.

    Setting kernel arguments...
    Enqueuing kernel...
    Kernel executed. retreiving results.
    Input to kernel was: 2002, output back was 1335342685.

    Struct size in host: 4, size in kernel: 0.



    The End

Page 1 of 2 12 LastLast

Similar Threads

  1. Passing struct to kernel
    By helloOpenCL in forum OpenCL
    Replies: 6
    Last Post: 08-29-2011, 02:56 PM
  2. Passing pointers in a struct
    By ibbles in forum OpenCL
    Replies: 3
    Last Post: 11-10-2009, 06:08 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
  •