The Khronos Group - a non-profit industry consortium to develop, publish and promote open standard, royalty-free media authoring and acceleration standards for desktop and handheld devices, combined with conformance qualification programs for platform and device interoperability.

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

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?

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.

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?

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.

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.