Use array of float to GPU memory

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Use array of float to GPU memory

cheikhou
This post was updated on .
Hello.

I use OpenCL package developed by Ronie Salgado package to program on GPU.
When I initialize an array with ByteArray class and load data to GPU memory it works without any problem.

But the problem is it works only with ByteArray objects.
When I load array of floats to GPU , data are modify and I don't know how and why and results are wrong.

Please someone have any idea
First: how to load integer values upper than 255 (not possible with ByteArray)
Second: use float arrays correctly in GPU memory.

Thanks for your help.
Cheikhou
Reply | Threaded
Open this post in threaded view
|

Re: Use array of float to GPU memory

cheikhou

Finally I have found a useful method called "asCLFloatArray" that converts float arrays of CPU as CL float arrays of GPU. The reverse action is possible by using "asFloatArrayFromCL".(from GPU to CPU memory)

Thanks.
Cheikhou
Reply | Threaded
Open this post in threaded view
|

Re: Use array of float to GPU memory

Ben Coman
On Fri, Jun 12, 2015 at 10:38 PM, cheikhou <[hidden email]> wrote:
>
> Finally I have found a useful method called "asCLFloatArray" that converts
> float arrays of CPU as CL float arrays of GPU. The reverse action is
> possible by using "asFloatArrayFromCL".(from GPU to CPU memory)

sounds interesting, but what is the context of this?  Is this built
into Pharo, what version?  Or what library?
cheers -ben

Reply | Threaded
Open this post in threaded view
|

Re: Copy array of float to GPU memory

Ronie Salgado
In reply to this post by cheikhou
Hi Cheikhou,

Sorry for the late answering. I needed to check some stuffs.

But the problem is it works only with ByteArray objects.
When I load array of floats to GPU , data are modify and I don't know how
and why and results are wrong.

What kind of error are you getting? a NativeBoost error or incorrect results?

Since you were originally asking me about FloatArray or IntegerArray, I am assuming you are getting incorrect results or a segmentation fault.

The OpenCL package is just a binding with a bit of object orientation to the OpenCL C library that I wrote manually. Those binding don't try to do a lot of magic when receiving a Pharo object. The OpenCL C API when allocating a GPU side buffer is expecting a size in bytes. According to the class comment in IntegerArray and in FloatArray, they are composed of 32 bits elements. So, when passing their size to OpenCL, you have to multiply them by 4.

For an actual example, check the new tests that I just added to the OpenCL-Tests packages. I tried using IntegerArray and FloatArray, and it did work.

It seems that you found the asCLFloatArray and the asFloatArrayFromCL methods, that are used to convert from an Array into a ByteArray and backwards. For completeness, I just added the following new methods.

asCLInt16Array <-> asInt16ArrayFromCL
asCLInt32Array <-> asInt32ArrayFromCL
asCLInt64Array <-> asInt64ArrayFromCL
asCLUInt16Array <-> asUInt16ArrayFromCL
asCLUInt32Array <-> asUInt32ArrayFromCL
asCLUInt64Array <-> asUInt64ArrayFromCL
asCLDoubleArray <-> asDoubleArrayFromCL

Unlike passing an IntegerArray or a FloatArray, these are method are creating a new array, looping over all elements and doing marshalling/unmarshalling. These methods can be very inefficient. Be careful when using them.

Best regards,
Ronie Salgado

2015-06-12 8:09 GMT-03:00 cheikhou <[hidden email]>:
Hello.

I use OpenCL package developed by Ronie Salgado package to program on GPU.
When I initialize an array with ByteArray class and load data to GPU memory
it works without any problem.

But the problem is it works only with ByteArray objects.
When I load array of floats to GPU , data are modify and I don't know how
and why and results are wrong.

Please someone have any idea
First: how to load integer values upper than 255 (not possible with
ByteArray)
Second: use float arrays correctly in GPU memory.

Thanks for your help.



-----
Cheikhou
--
View this message in context: http://forum.world.st/Copy-array-of-float-to-GPU-memory-tp4831970.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|

Re: Use array of float to GPU memory

Ronie Salgado
In reply to this post by Ben Coman
sounds interesting, but what is the context of this?  Is this built
into Pharo, what version?  Or what library?
Those methods are not built into Pharo. They are present in the OpenCL bindings ( http://smalltalkhub.com/#!/~ronsaldo/OpenCL ), and I don't think they are very efficient in my opinion.

See my answer to the original question for more information.

Greetings,
Ronie

2015-06-12 22:22 GMT-03:00 Ben Coman <[hidden email]>:
On Fri, Jun 12, 2015 at 10:38 PM, cheikhou <[hidden email]> wrote:
>
> Finally I have found a useful method called "asCLFloatArray" that converts
> float arrays of CPU as CL float arrays of GPU. The reverse action is
> possible by using "asFloatArrayFromCL".(from GPU to CPU memory)

sounds interesting, but what is the context of this?  Is this built
into Pharo, what version?  Or what library?
cheers -ben


Reply | Threaded
Open this post in threaded view
|

Re: Copy array of float to GPU memory

cheikhou
In reply to this post by Ronie Salgado
Hello Ronie.

thanks for your response.
>Sorry for the late answering. I needed to check some stuffs.<quote author="Ronie Salgado">
no problem.

>What kind of error are you getting? a NativeBoost error or incorrect results?
Yes I were getting incorrect result. But when I use methods like asCLFloatArray and asFlotArrayFromCL it works.

> For completeness, I just added the following new methods.
Nice! I am sure that it makes OpenCL package more and more robust and enable friendly programming on GPU.  

>Unlike passing an IntegerArray or a FloatArray, these are method are creating a new array, looping over all >elements and doing marshalling/unmarshalling. These methods can be very inefficient. Be careful when >using them.

Yes thanks a lot Ronie I will be careful to this.

@Ben Cormas
Look at this link
http://forum.world.st/Using-VirtualGPU-td4826028.html
Cheikhou