CUDA Memory Management¶
Overview¶
On GPUs the bottleneck is rarely arithmetic — it is getting the data there. A single transfer across PCIe can easily cost more time than the kernel that consumes it. CUDA offers several strategies for this — device, managed, pinned and constant memory — and picking the wrong one costs more performance than kernel tuning can win back afterwards. The underlying trade-offs (explicit copies versus automatic migration, page-locked transfers, keeping read-only data close to the compute units) are not vendor-specific and transfer to other accelerators.
NVIDIA GPUs and host CPUs have separate memory spaces, and choosing the right strategy for moving and placing data between them is one of the most important decisions in CUDA programming. This module walks through the main CUDA memory management strategies — device memory, unified memory, pinned host memory, and constant memory — and the synchronisation rules that go with them, so that learners can pick the right tool for their use case.
After completing the module, learners can allocate data in each of these memory types, move it between host and device explicitly or let the CUDA runtime migrate it, and place the synchronisation calls that make data written by an asynchronously running kernel safe to read on the host. The material consists of a software-setup episode, four lesson episodes — unified memory, explicit (manual) memory management, pinned and constant memory, and a synchronisation recap with a summary of all memory kinds — and a quiz. All code is shown in CUDA C/C++ and CUDA Fortran side by side, and the two longer episodes contain hands-on exercises that are compiled and run by the learners.
Prerequisites
The Introduction to CUDA module, or equivalent knowledge of CUDA kernels, execution configuration and error handling
Access to an NVIDIA GPU with CUDA Toolkit 12.x or newer installed (12.x if the GPU has compute capability 7.0, see the software-setup episode), either on your own machine or on a cluster, to compile and run the exercises
The ability to edit and compile a program on the machine that has the GPU — from a Linux shell (for example this tutorial) or from an IDE that can call
nvcc/nvfortran: the exercises are downloaded, edited and compiled by you
This module is aimed at researchers, engineers and students who can already write sequential programs in C, C++ or Fortran and want to start programming NVIDIA GPUs. It assumes the content of the Introduction to CUDA module.
Software setup
The lesson
Reference
Learning outcomes¶
After completing this module, learners will be able to:
Choose between device memory, managed memory, pinned memory and constant memory for a given workload
Allocate and free managed memory using
cudaMallocManagedin C/C++ (and themanagedattribute in CUDA Fortran), and explain how data migration worksAllocate device memory with
cudaMallocordevicein CUDA Fortran and copy data between host and deviceAllocate pinned host memory with
cudaMallocHost(orpinnedin CUDA Fortran) and explain when pinned memory is required (e.g. for asynchronous copies)Use constant memory for small read-only data accessed by many threads, and stay within its 64 KB limit
Insert
cudaDeviceSynchronize()correctly before reading GPU-modified data on the host, and recognise the race conditions that occur otherwise
Estimated commitment: about 2.5 hours (150 minutes of lecture and exercises; provisional estimate, to be re-measured at the first delivery).
EVITA skill tree: SD1.2.6 GPU Programming with CUDA — the module covers the refinement SD1.2.6.2 CUDA Memory Management (proposed).
Related topics not covered here:
Streams and asynchronous copies
Shared memory
Atomics
Profiling
The vendor-neutral view of heterogeneous memory management, covered by the EVITA PP.HS1 modules (e.g. PP.HS1-K1.5.4 Memory management in heterogeneous systems)
See also¶
Credit
This module is based on the CUDA course developed at HLRS, the High-Performance Computing Center Stuttgart (University of Stuttgart). Authors: Tobias Haas and Jasper Seehofer, HLRS.
If you want to reuse the material beyond the terms of the licence below, or if you find errors, please contact the authors through the module repository.
Related EVITA module: Introduction to CUDA
License
CC BY-SA for media and pedagogical material
Copyright © 2026, EVITA project, Tobias Haas, Jasper Seehofer. This material is released by EVITA project, Tobias Haas, Jasper Seehofer under the Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0).
Canonical URL: https://creativecommons.org/licenses/by-sa/4.0/
You are free to
Share — copy and redistribute the material in any medium or format for any purpose, even commercially.
Adapt — remix, transform, and build upon the material for any purpose, even commercially.
The licensor cannot revoke these freedoms as long as you follow the license terms.
Under the following terms
Attribution — You must give appropriate credit , provide a link to the license, and indicate if changes were made . You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.
No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.
Notices
You do not have to comply with the license for elements of the material in the public domain or where your use is permitted by an applicable exception or limitation .
No warranties are given. The license may not give you all of the permissions necessary for your intended use. For example, other rights such as publicity, privacy, or moral rights may limit how you use the material.
This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.
MIT for source code and code snippets
MIT License
Copyright (c) 2026, EVITA project, Tobias Haas, Jasper Seehofer
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.