Results 1 to 8 of 8

Thread: Globally visible buffers or direct memory access?

  1. #1
    Junior Member
    Join Date
    Dec 2010
    Posts
    26

    Globally visible buffers or direct memory access?

    Hi, I try to create a host class that would generate kernel source code for its internal computations. At the time point of generating the source code I have buffers in gpu's global memory that are to be passed to the kernel as arguments. However its some extra programming effort to generate the arguments list and it will also impact the performance since the arguments list is pretty long.
    Looking for the workarounds I would like to ask following questions:

    1) is it possible to declare a global buffer so that it would be visible to the kernel without passing a pointer on it to the kernel as an argument?
    2) is possible to have something like this in the kernel's source: *(0x24fd452) or *((0x24fd452)[gid]) - a kind of direct access without a pointer variable?


    thank you in advance
    qwer

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

    Re: Globally visible buffers or direct memory access?

    1) is it possible to declare a global buffer so that it would be visible to the kernel without passing a pointer on it to the kernel as an argument?
    No, but that has not stopped people from trying to come up with clever workarounds. Be warned: the only method that will work in all implementations and is guaranteed to produce correct results is passing the buffers as kernel arguments. Don't even think of anything else if you care about the stability and correctness of your software.

    2) is possible to have something like this in the kernel's source: *(0x24fd452) or *((0x24fd452)[gid]) - a kind of direct access without a pointer variable?
    Doing that sort of thing will never be portable across systems.

    I'm sorry to be blunt. I'm simply trying to save you some headaches.
    Disclaimer: Employee of Qualcomm Canada. Any opinions expressed here are personal and do not necessarily reflect the views of my employer. LinkedIn profile.

  3. #3
    Junior Member
    Join Date
    Dec 2010
    Posts
    26

    Re: Globally visible buffers or direct memory access?

    [quote:2uirr0jt]1) is it possible to declare a global buffer so that it would be visible to the kernel without passing a pointer on it to the kernel as an argument?
    No, but that has not stopped people from trying to come up with clever workarounds. Be warned: the only method that will work in all implementations and is guaranteed to produce correct results is passing the buffers as kernel arguments. Don't even think of anything else if you care about the stability and correctness of your software.[/quote:2uirr0jt]

    I also had a couple ideas - but the problem with them that they impact performance - I would need one extra lookup to access my buffer (while doing it inderectly)... global variable would be better. Do you know any workaround without performance lost?

    [quote:2uirr0jt]2) is possible to have something like this in the kernel's source: *(0x24fd452) or *((0x24fd452)[gid]) - a kind of direct access without a pointer variable?
    Doing that sort of thing will never be portable across systems.[/quote:2uirr0jt]

    Why? remember I have a pointer on buffer, on each platform it will point to a different place, but all I will do is just convert its integer value into a string and paste into kernel's code... why is it not portable?

    But anyway - is it possible?

  4. #4
    Senior Member
    Join Date
    May 2010
    Location
    Toronto, Canada
    Posts
    845

    Re: Globally visible buffers or direct memory access?

    If you want to access a buffer object, pass it as a kernel argument. Don't attempt workarounds: they may work on some driver versions and on some machines, and they will fail everywhere else.


    why is it not portable?
    Because you are assuming that the address of a buffer doesn't change. It can change from one NDRange to the next.

    I'm not stopping you from doing anything. I'm just saying that the only portable way to access a buffer is passing it as a kernel arguments. Anything else is a hack and will give you headaches in the future.
    Disclaimer: Employee of Qualcomm Canada. Any opinions expressed here are personal and do not necessarily reflect the views of my employer. LinkedIn profile.

  5. #5
    Junior Member
    Join Date
    Dec 2010
    Posts
    26

    Re: Globally visible buffers or direct memory access?

    thank you very much! you saved me a lot of time and nerves.

  6. #6
    Junior Member
    Join Date
    Dec 2010
    Posts
    26

    Re: Globally visible buffers or direct memory access?

    should I request global kernel variables as a new feature or was it already discussed somewhere and rejected?

  7. #7
    Senior Member
    Join Date
    May 2010
    Location
    Toronto, Canada
    Posts
    845

    Re: Globally visible buffers or direct memory access?

    You can ask for it, sure. It was discussed and rejected IIRC, but if enough people want something like this I guess the group may talk about it again.

    Personally I don't think it is likely to be added; it would introduce a number of problems with thread safety, driver complexity, etc.
    Disclaimer: Employee of Qualcomm Canada. Any opinions expressed here are personal and do not necessarily reflect the views of my employer. LinkedIn profile.

  8. #8
    Member
    Join Date
    Oct 2010
    Location
    Vancouver, Canada
    Posts
    66

    Re: Globally visible buffers or direct memory access?

    I also had a couple ideas - but the problem with them that they impact performance - I would need one extra lookup to access my buffer (while doing it inderectly)... global variable would be better. Do you know any workaround without performance lost?
    I'm not sure exactly what you are doing here, but are you speculating or have you tried it and measured the performance? The performance cost of adding kernel arguments is going to be insignificant compared to the cost of executing your kernel. If it isn't then I would question whether you should be doing your computation in a kernel at all. And the cost of having a constant global pointer vs. having an argument is going to be zero or extremely negligible because you are almost certainly memory bound on the access to the actual data.

Similar Threads

  1. Memory Access
    By lcnepo in forum OpenCL
    Replies: 1
    Last Post: 12-09-2010, 04:22 PM
  2. Global memory access
    By Rui in forum OpenCL
    Replies: 1
    Last Post: 03-23-2010, 12:18 PM
  3. Information concerning memory access
    By benschaff in forum OpenCL
    Replies: 14
    Last Post: 03-04-2010, 01:25 PM

Posting Permissions

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