Skip to content

Comment on CUDA and OpenCL run time comparison using Vector Additionparent

Comments

In CUDA kernel to PTX compilation is performed when the project is build. In OpenCL it is performed at runtime. That is "initialization overhead" which cause result to be different. You could use cache to avoid it.

So the reason of the performance differences is caused by the OpenCL's design. In OpenCL it is unknown on which hardware the kernel will run, so the compilation is postpone to runtime. I could hardly see any reason why NVIDIA would want to make OpenCL slower.

There are two major differences between CUDA and OpenCL: -OpenCL is industry standard while CUDA is NVIDIA's platform -OpenCL is a regular C library, CUDA in addition to that is extension to C language

CUDA kernel code will be much nicer, it will takes less lines and looks much better. The cost is it requires a special compiler (nvcc).

Example CUDA code: (run a kernel) myCudaKernel<<< grid, block, sharedMemorySize >>> (... arguments);

Equivalent in OpenCL: clSetKernelArg (...); // for each kernel argument! ... clEnqueueNDRangeKernel (...); // run kernel

the last part above is not clear.

the code referred to as "kernel code" is actually code that runs on the client to invoke the kernel. opencl uses a library api, which cuda takes a dsl approach. so opencl is more verbose.

as far as i know, the actual kernel code (which describes what happens on the gpu) is pretty similar.

Agree, you are right.

s/kernel code/kernel related code/g.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.