PDA

View Full Version : how to create thread using openGL?



SagoO
11-13-2010, 03:41 AM
Hi all,

I want to create a function of task.
Eg. Pass value into array, compare the value inside the array
How I make it become a thread so that I can create multi-thread to run the function concurrently?

What function and array can I use here? I am new to openGL. Please advise... :D

V-man
11-13-2010, 11:07 AM
GL is only for rendering 3D scenes.
For threads, http://www.skycomputers.com/Software/threads/example03.html

SagoO
11-13-2010, 07:18 PM
Ya...But I try to utilize the benefits of openGL to do other simple calculation.

I just want to store bytes into array of openGL. Then, compare the value insides. I think this possible to be done in openGL right?

Alfonse Reinheart
11-13-2010, 09:05 PM
I just want to store bytes into array of openGL. Then, compare the value insides. I think this possible to be done in openGL right?

Yes, but why would you want to? OpenCL is designed for doing this kind of stuff; OpenGL is not.

SagoO
11-13-2010, 09:52 PM
Because I was restricted to the hardware support. OpenCL is not supported for my graphic card.
By the way, I search for a long time for the guidelines but still cant find the reference that I want. Can recommend some here? :p

V-man
11-14-2010, 07:01 AM
You want to write values into an OpenGL array?
I guess what you can do is write to the frame buffer or a render target (FBO).
I don't know any tutorials that show how to use GL to use the GPU as a CPU.
I can suggest that you study GL and then you'll know how to use it.

SagoO
11-14-2010, 08:42 AM
Ya...Definitely I need to study. But I just using a bit of openGL to do my tasks. So, I am not going to spend time to study completely. I just want to know which function can I use so that I can study on that. Tasks I am going to do are:

1. Pass bytes into array
2. Compare bytes in the array
For part 2, can the array in openGL compare like this for example:
if(byte[0]==byte[4]){
//
} ?
3. Then, pass bytes back to CPU

So, what kind of array I can use here?

Aleksandar
11-14-2010, 10:48 AM
Considering everything what you have said the solution could be something like this:
1. send your data as a texture to GPU
2. use shaders to calculate what you want
3. write results into the texture
4. read from the texture

But the question is: why would you do that? Do you think it would be faster on GPU than on CPU? If your GPU don't support CUDA/OpenCL, than it is very unlikely (because it is probably very old).

If you can store a large amount of data into a single buffer, and the calculation can be parallelized into hundreds of threads, than GPU can be more efficient. But if you have a lot of tiny buffers or there are dependencies that prevent efficient parallelization, than CPU can easily outperform even some of the mightiest GPUs.

In any case, the best way to find out what is the best is to try it yourself. I wish you luck! ;)

SagoO
11-14-2010, 06:48 PM
1. send your data as a texture to GPU
2. use shaders to calculate what you want
3. write results into the texture
4. read from the texture

Em...Can specify which function for each part? How to send data as texture? How to use shader? Just simply give some example so that I can understand. As I am not familiar with openGL functions.



If you can store a large amount of data into a single buffer, and the calculation can be parallelized into hundreds of threads, than GPU can be more efficient. But if you have a lot of tiny buffers or there are dependencies that prevent efficient parallelization, than CPU can easily outperform even some of the mightiest GPUs.

In any case, the best way to find out what is the best is to try it yourself. I wish you luck! ;)

Ya...The data is considered large. I have to try it. Lol...

Alfonse Reinheart
11-14-2010, 06:53 PM
Em...Can specify which function for each part? How to send data as texture? How to use shader? Just simply give some example so that I can understand. As I am not familiar with openGL functions.

You're going to have to become familiar with OpenGL as a graphics library before you can use it as an arbitrary computation library. This means you need to learn how to use OpenGL to draw stuff before you learn how to use it to do arbitrary computations.

SagoO
11-14-2010, 07:56 PM
You're going to have to become familiar with OpenGL as a graphics library before you can use it as an arbitrary computation library. This means you need to learn how to use OpenGL to draw stuff before you learn how to use it to do arbitrary computations.

I know I have to familiar with it. But there are lots of openGL functions. I am afraid I may go to the wrong direction since I will not use all the functions. So, may you specify which functions that I should use so that I can study on those functions?

I already know how to compile and run openGL applications. Only simply graphics applications.

aqnuep
11-15-2010, 04:13 AM
Telling you what functions you should use would not help you too much. You have to understand the design of OpenGL. Besides you should learn GLSL so you can write your shader to do the job. Without that background knowledge the function names won't help you in any way.

alder
11-15-2010, 10:13 AM
The GPGPU.org site still has tutorials on how to use graphics APIs for gpgpu: http://gpgpu.org/developer/legacy-gpgpu-graphics-apis