Source-linked AI summary

A Performance Comparison of CUDA and OpenCL

Kamran Karimi, Neil G. Dickson, Firas Hamze

arXiv:1005.2581v3cs.PFcs.DCphysics.comp-ph

TL;DR

The paper asks whether OpenCL’s portability entails a performance cost relative to CUDA. It compares near-identical kernels and application runtimes in AQUA, finding faster CUDA execution and transfers, while portability across vendors remains constrained.

  • Problem

    The paper addresses limited systematic evidence comparing CUDA and OpenCL performance in a real-world scientific application.

  • Method

    The study compares CUDA and OpenCL versions of AQUA using near-identical kernels and measures data transfers, kernel execution, and end-to-end application times.

  • Results

    CUDA performed better for data transfers and kernel execution, with CUDA processing more variables per second and OpenCL running 13%–63% slower for kernels and 16%–67% slower end-to-end.

  • Takeaways & Limitations

    CUDA is the better choice when maximum performance is important; otherwise, familiarity and available target-hardware development tools can guide the choice.

  • Takeaways & Limitations

    The resulting executables were not runtime-compatible across ATI and NVIDIA hardware, despite source-level compatibility.

Abstract

from arXiv · show

CUDA and OpenCL are two different frameworks for GPU programming. OpenCL is an open standard that can be used to program CPUs, GPUs, and other devices from different vendors, while CUDA is specific to NVIDIA GPUs. Although OpenCL promises a portable language for GPU programming, its generality may entail a performance penalty. In this paper, we use complex, near-identical kernels from a Quantum Monte Carlo application to compare the performance of CUDA and OpenCL. We show that when using NVIDIA compiler tools, converting a CUDA kernel to an OpenCL kernel involves minimal modifications. Making such a kernel compile with ATI's build tools involves more modifications. Our performance tests measure and compare data transfer times to and from the GPU, kernel execution times, and end-to-end application execution times for both CUDA and OpenCL.

1. Introduction

The paper frames CUDA and OpenCL as similar GPU-computing interfaces with different portability and hardware-specific trade-offs. It compares their runtime performance using a real scientific application and near-identical kernels.

  • CUDA targets NVIDIA GPUs, whereas OpenCL is an open standard for CPUs, GPUs, DSPs, and other processors.
  • CUDA and OpenCL differ in kernel legality, context creation, data copying, and mapping kernels onto GPU processing elements.These differences may affect coding and debugging time, while this paper focuses mainly on runtime performance.
  • OpenCL offers portability and runtime compilation, while CUDA may better match NVIDIA hardware and expose more device-specific features.The paper presents these as competing considerations motivating a direct comparison.
  • The study measures GPU data-transfer times, kernel execution times, and end-to-end application running times.The CUDA and OpenCL kernels are very similar and the rest of the application is identical, isolating framework-related performance differences in this setting.
  • Prior formal systematic comparisons were limited, with one cited study finding similar CUDA and OpenCL performance.A performance study of ATI GPUs comparing OpenCL with ATI Stream is outside this paper’s scope.

2. The application

The application is AQUA, a Monte Carlo simulation of quantum spin systems represented as layered classical systems. Its CUDA kernel was ported to OpenCL, requiring minimal changes with NVIDIA tools but substantially more changes with ATI tools.

  • The application: AQUA is a C++ Monte Carlo simulation of quantum spin systems using a classical Ising approximation and Suzuki-Trotter decomposition.The simulated systems range from 8 to 128 qubits, with 128 layers used for every problem size.
  • The application: Each Monte Carlo sweep examines every variable in each layer and probabilistically flips and updates selected variables.
  • The application: The study simulates complete layered systems at multiple points during adiabatic quantum evolution, multiplying per-system variables by the number of points.Table 1 reports the corresponding quantum and classical system sizes.
  • The application: The CUDA kernel was optimized for memory access and ported to OpenCL; NVIDIA tools required minimal kernel changes, while GPU setup and transfer code had to be rewritten.
  • The application: Each GPU multiprocessor sweeps one layered system, producing one work group in OpenCL or one thread block in CUDA per simulation point.For an 8-qubit system with 27 simulation points, the implementation uses 27 work groups or thread blocks.
  • The application: OpenCL with NVIDIA tools required specific CUDA-kernel changes, including avoiding array-element addresses as array indices.No other changes were necessary for the compute kernel to compile and run under NVIDIA’s OpenCL tools.
  • The application: ATI OpenCL required many more kernel changes, primarily because ATI’s tools lacked global variable declarations.
  • The application: ATI’s OpenCL required dynamically preallocated memory and pointer-based access, while NVIDIA’s tools supported the original statically declared arrays.The alternative indexing code mapped one-dimensional allocations to the three-dimensional arrays required by Mersenne-Twister.

3. Performance tests

The experiments compare CUDA and OpenCL using GPU setup, transfer, kernel, and end-to-end timings across problem sizes. CUDA processes more variables per second and is faster overall in these tests.

  • Experimental procedure: The application measures GPU setup, input and output processing, data transfers, kernel execution, and end-to-end running time.GPU Operations Time sums data transfer and kernel execution; End-To-End time covers the complete application run.
  • Experimental procedure: Each problem was solved 10 times with both CUDA and OpenCL to obtain repeatable average times.
  • Data transfer: OpenCL’s data transfer overhead does not change significantly as problem size increases relative to CUDA.Figure 3 reports transfer time as OpenCL divided by CUDA for each problem size.
  • Kernel performance: CUDA processes more variables per second than OpenCL for every tested problem size.Figure 4 plots processed variables divided by kernel running time as a function of problem size.
  • Overall performance: 13%-63% slower OpenCL kernel execution and 16%-67% slower end-to-end time were observed across problem sizes.Both kernel and end-to-end times favored CUDA; their values converge for larger problems as kernel time contributes more to total runtime.

4. Concluding remarks

The paper compares CUDA with NVIDIA’s OpenCL implementation using a specific scientific application. CUDA performed better in data transfer and kernel execution, while the programming choice also depends on portability-related and practical development considerations.

  • Porting: Porting CUDA kernel code to NVIDIA’s OpenCL implementation requires minimal changes, but GPU setup and data-transfer code require new code.
  • Performance: CUDA transfers data faster and executes nearly identical kernels consistently faster than OpenCL in these tests.The comparison covers data transfers to and from the GPU and kernel execution.
  • Choice of framework: CUDA is presented as the better choice when maximizing performance matters; otherwise, familiarity and available target-GPU tools can guide the choice.
Loading 1005.2581v3…