memCUDA: Map Device Memory to Host Memory on GPGPU Platform

Hai Jin, Bo Li, Ran Zheng, Qin Zhang, Wenbing AoNPC 2010

Abstract

memCUDA is a high-level, directive-based programming framework designed to simplify GPGPU development by automating memory management. By using simple #pragma directives, it allows developers to map GPU device memory directly to host memory, shielding them from the tedious and error-prone "plumbing" of explicit data transfers. Experimental results demonstrate that memCUDA maintains performance comparable to hand-optimized CUDA code while significantly improving developer productivity through code reduction and automated asynchronous optimizations.

Introduction

In the traditional CUDA programming model, the CPU (host) and GPU (device) maintain separate address spaces. This creates a significant burden for developers, who must manually manage memory allocation (cudaMalloc), deallocation (cudaFree), and the movement of data between these spaces (cudaMemcpy). This manual management is not just tedious; it is a major source of bugs and makes code difficult to maintain. Furthermore, achieving peak performance—such as overlapping data transfers with kernel execution—requires complex, low-level code that many developers avoid. memCUDA addresses these challenges by providing a "memory mapping" abstraction that makes GPU programming feel more like standard sequential programming.

Methods and Implementation

The memCUDA framework consists of two main components: a source-to-source compiler and a runtime library.

memCUDA System Architecture

Directive-based Language

Developers use four primary #pragma memcuda directives to manage memory state:

  • map: Establishes a relationship between a host reference and device memory.
  • remap: Refreshes an existing mapping, useful for multi-kernel applications.
  • unmap: Dissolves the mapping and frees device memory.
  • update: Triggers the actual data transfer, with the direction determined automatically by the system.

Source-to-Source Translation

Built on the Cetus compiler framework, the memCUDA compiler parses these pragmas and translates the code into standard CUDA C. It automatically replaces host memory references inside GPU kernels with the appropriate device memory references, handling the underlying pointer arithmetic.

Runtime Mapping Table (mmTable)

A runtime library maintains the mmTable, which tracks the base addresses, sizes, and states of all mapped memory blocks. This allows the system to handle address translation and data movement behind the scenes.

Memory Mapping via mmTable

Asynchronous Optimization

To boost performance, the system adaptively uses page-locked (pinned) memory. This allows the runtime to overlap data transfers with kernel execution automatically if the compiler detects no data dependencies between consecutive kernels.

Results

The authors evaluated memCUDA using six standard benchmarks, primarily drawn from the Parboil benchmark suite and the NVIDIA CUDA SDK, including Matrix Multiplication (MM), Magnetic Resonance Imaging (MRI-Q/FHD), and Two Point Angular Correlation Function (TPACF).

Performance and Productivity

  • Performance Parity: Across all benchmarks, memCUDA programs achieved performance nearly identical to well-optimized, hand-written CUDA programs. The additional runtime overhead was consistently less than 5%.
  • Optimization Boost: In benchmarks that repeatedly invoke kernels (like CP and PNS), memCUDA’s automatic asynchronous optimization resulted in a ~30% performance boost over naive CUDA implementations.
  • Code Compactness: Qualitative analysis of the TPACF benchmark showed that memCUDA eliminates dozens of lines of boilerplate memory management code, allowing the developer to focus on the actual computation logic.

Conclusion

memCUDA successfully demonstrates that the overhead of automating memory management in GPGPU platforms is remarkably low. By handling the "bookkeeping" in a runtime table, the system provides a high-level abstraction that enhances productivity without sacrificing performance. Future work will focus on extending mapping support to texture and constant memory and implementing more sophisticated compiler optimizations like adaptive loop unrolling.

Summary updated

BibTeX
@inproceedings{jin2010memcuda,
  author = {Hai Jin and Bo Li and Ran Zheng and Qin Zhang and Wenbing Ao},
  title = {{memCUDA: Map Device Memory to Host Memory on GPGPU Platform}},
  booktitle = {NPC},
  year = {2010},
  doi = {10.1007/978-3-642-15672-4\_26},
}
Figure