From Encyclopedia Dramatica
Jump to: navigation, search

So you've written your software in C but it's still too slow. Your next optimization step is to include SIMD instructions but you are to lazy to learn to do it yourself, or you are looking for an excuse to blow several grands on a graphic card and you hate Nvidia? OpenCL might be right for you !

How it works[edit]

1337 haxors can use it to crack passwords

While Nvidia's CUDA is made to be used by computer illiterate scientists, OpenCL forces you to tell it exactly what you want, so you'll need this. Both CUDA and OpenCL are lower-level than C, so you better know what kind of hardware you expect it to run on or check it at runtime and write the code for the different hardware.

  1. Environment variables are initiated. - This is were the program learn what device will execute the code, like which of your numerous GPU it will use if you are overcompensating for your lack of dick, etc...
  2. Memory initialization. - If you want to use the GPU, this is where you reserve memory on it. Special allocations also exists for CPU. Can also be done later.
  3. Reading and building the program. - The code have to be built at runtime to allow prior code to determine where the kernels will execute.
  4. Extracting the kernels. - Getting the different kernels functions from the compiled program.
  5. Write data to GPU memory, if program for GPU.
  6. Use them! aka enqueue a kernel in a command queue - You didn't do all that for nothing, didn't you.
  7. Read data from GPU memory if program for GPU, or unmap for CPU.
  8. Release Kernels, memory, and environment variables.

Best Practices[edit]

  • Limit data transfers. They take important computer time.
  • 256 work-item per GPU work-group will give good results most of the time.
  • Error-check continuously, or you'll only get them when freeing memory.
  • Make sure to create a fuckloads of threads. It is normal to sometime have more than one thread per data.

See also[edit]

External Links[edit]

Softwarez series.jpg

OpenCL is part of a series on


Visit the Softwarez Portal for complete coverage.


OpenCL is part of a series on Programming.

[2 L337 4 MEEnter the Matrix]