Skip to content
This repository has been archived by the owner on May 13, 2022. It is now read-only.

CUDA memory management

Jan Stephan edited this page Dec 9, 2016 · 2 revisions

GLADOS offers its own versions of std::unique_ptr for (pinned) host memory and (pitched where needed) device memory. In order to create one of these pointers use the make_unique_[type] functions:

#include <glados/cuda/memory.h>

// Device memory
auto dev_1D = make_unique_device<float>(n); // returns device_ptr<float>
auto dev_2D = make_unique_device<float>(x, y); // returns pitched_device_ptr<float>
auto dev_3D = make_unique_device<float>(x, y, z); // returns pitched_device_ptr<float>

// Standard host memory
auto host_1D = make_unique_host<float>(n); // returns host_ptr<float>
auto host_2D = make_unique_host<float>(x, y); // returns host_ptr<float>
auto host_3D = make_unique_host<float>(x, y, z); // returns host_ptr<float>

// Pinned host memory -- suitable for async operations
auto pinned_host_1D = make_unique_pinned_host<float>(n); // returns pinned_host_ptr<float>
auto pinned_host_2D = make_unique_pinned_host<float>(x, y); // returns pinned_host_ptr<float>
auto pinned_host_3D = make_unique_pinned_host<float>(x, y, z); // returns pinned_host_ptr<float>

There is no need to call cudaFree / cudaFreeHost manually as the memory will automatically be freed once the pointer goes out of scope.

Clone this wiki locally