Skip to content

CUDA Unified Memory : C Example

One of the brand new features introduced by NVIDIA in CUDA 6.0 is Unified Memory. Helping the programmer to reduce the amount of code written, and simplify the code. The Unified Memory helps managing memory, and maximizing data access speed transparently between the CPU and GPU. This is a simple C example, on how to use unified memory, following a question I have seen on different forums.

The wrong code I have recently seen was the following :

 

This will not work, and the returned value will be

To be clear, you do not need to  allocate memory  twice !

The correct code is the following :

If you want to keep the function and allocate the memory in the main

and there you go.

 

 

 

Post a Comment

Your email is never published nor shared. Required fields are marked *