cancel
Showing results for 
Search instead for 
Did you mean: 

OpenCL

smatovic
Adept II

Host<->Device Memory Transfer during Kernel-Run?

Jump to solution

Heyho,

i try to transfer some data between Host and OpenCL Device during the Kernel Run,

by use of "cl_mem_use_persistent_mem_amd" i figured out that i can create an Pointer to an Buffer,

this works on my CPU but not on GPU (Programm crashes).

Is it even possible to transfer Data to the GPU during the Kernel-Run?

My System:

Ubuntu Linux 12.04 64 bit, AMD X4 CPU, AMD HD 7750, Catalyst 12.6

Thanks in advance,

Srdja

0 Kudos
Reply
1 Solution

Accepted Solutions
notzed
Challenger

Re: Host<->Device Memory Transfer during Kernel-Run?

Jump to solution

You can't modify the data during the kernel execution, if that's what you're trying to achieve.

The API wont even allow you do to it:

e.g. you can only write to a mapped buffer when it's mapped, and you can't pass a mapped buffer to enqueuendrangekernel.

Even with zero-copy buffers there are things like caches to flush and synchronise and so forth, mmu tables, etc.

Your example is invalid api use as you cannot access Pointer after calling unmap.  unmap should be considered the same way free() is: once you've called it that pointer cannot be re-used.

So, you can transfer memory whilst another kenel is in process, but you cannot modify the memory that the executing one is using.  And this is a good thing.

View solution in original post

0 Kudos
Reply
13 Replies
smatovic
Adept II

Re: Host<->Device Memory Transfer during Kernel-Run?

Jump to solution

Here my steps

1. Create an Buffer with clCreateBuffer with flag CL_MEM_READ_WRITE | CL_MEM_USE_PERSISTENT_MEM_AMD

2. Get Pointer to Buffer with clEnqueueMapBuffer

3. Set Value of Pointer to x

4. Unmap Buffer with clEnqueueUnmapMemObject

5. Set Kernel Args and run Kernel

6. do some stuff on Host

7. Set Value of Pointer to y

8. wait for Kernel run to finish

As i said,  step 7. works on CPU and not on GPU....

--

Srdja

0 Kudos
Reply
Wenju
Elite

Re: Host<->Device Memory Transfer during Kernel-Run?

Jump to solution

Hi Srdja,

    I think it's impossible to transfer data between cpu and gpu during the Kernel-Run at present.  And I think before step 7, the kernel has already finished.

nou
Exemplar

Re: Host<->Device Memory Transfer during Kernel-Run?

Jump to solution

there is special sample in SDK which cover this use case. but it needs zero copy support which is on Linux supported only for Northern Isladns aka 7xxx GPU.

0 Kudos
Reply
Wenju
Elite

Re: Host<->Device Memory Transfer during Kernel-Run?

Jump to solution

Hi nou,

which sample?

0 Kudos
Reply
nou
Exemplar

Re: Host<->Device Memory Transfer during Kernel-Run?

Jump to solution

Transfer Overlap

what I understand it should work like this.

1. you create buffers with CL_MEM_PERSISTENT_AMD

2. enqueue block map of first buffer

3. enqueue kernel with second buffer

4. clflush

5. write to first buffer

6. enqueu unmap

7. clfinish

0 Kudos
Reply
Wenju
Elite

Re: Host<->Device Memory Transfer during Kernel-Run?

Jump to solution

But it doesn't happen that data transfered during kernel-run.

0 Kudos
Reply
smatovic
Adept II

Re: Host<->Device Memory Transfer during Kernel-Run?

Jump to solution

as far as i understood the transfer overlap example, they use to run two kernels to exchange data...

map buffer 1

while(..)

{

memset to buffer 1, overlapping with kernel 2

unmap buffer 1

map buffer 2

launch kernel for buffer 1

memset to buffer 2, overlapping with kernel 1

unmap buffer 2

map buffer 1

launch kernel for buffer 2

}

Because the need of UnMapping an Memory Object to ensure it is written i guess it is impossible to transfer Data during the Kernel-Run....

--

Srdja

0 Kudos
Reply
nou
Exemplar

Re: Host<->Device Memory Transfer during Kernel-Run?

Jump to solution

map/unmap is with zero copy buffers return almost inmidietly. you write to mapped buffer with normal memcpy() memset()

0 Kudos
Reply
notzed
Challenger

Re: Host<->Device Memory Transfer during Kernel-Run?

Jump to solution

You can't modify the data during the kernel execution, if that's what you're trying to achieve.

The API wont even allow you do to it:

e.g. you can only write to a mapped buffer when it's mapped, and you can't pass a mapped buffer to enqueuendrangekernel.

Even with zero-copy buffers there are things like caches to flush and synchronise and so forth, mmu tables, etc.

Your example is invalid api use as you cannot access Pointer after calling unmap.  unmap should be considered the same way free() is: once you've called it that pointer cannot be re-used.

So, you can transfer memory whilst another kenel is in process, but you cannot modify the memory that the executing one is using.  And this is a good thing.

View solution in original post

0 Kudos
Reply