Now let's look at how OpenCL works. Note that OpenCL is independent of ROCm, but is also provided when the latter is installed.
OpenCL is a cross-platform language and relatively more complex than CUDA, but not difficult to learn. In order to understand OpenCL easily, let's compare its syntax with that of CUDA's through the following OpenCL program. It computes a similar operation as to the one we did on CUDA in the previous chapter.
The first thing to note is that an OpenCL kernel code is to be written inside a separate kernel file with a .cl extension. Contrary to a CUDA .cu file, an OpenCL .cl file contains only kernel code, which is equivalent to the global function we write on CUDA, along with the main ...