P. 1
CUDA C Programming Guide

CUDA C Programming Guide

|Views: 241|Likes:
Published by Eugen Zaicanu

More info:

Published by: Eugen Zaicanu on Mar 02, 2012
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less





void* malloc(size_t size);
void free(void* ptr);

allocate and free memory dynamically from a fixed-size heap in global memory.
The CUDA in-kernel malloc() function allocates at least size bytes from the
device heap and returns a pointer to the allocated memory or NULL if insufficient
memory exists to fulfill the request. The returned pointer is guaranteed to be aligned
to a 16-byte boundary.
The CUDA in-kernel free() function deallocates the memory pointed to by ptr,
which must have been returned by a previous call to malloc(). If ptr is NULL,
the call to free() is ignored. Repeated calls to free() with the same ptr has
undefined behavior.
The memory allocated by a given CUDA thread via malloc() remains allocated
for the lifetime of the CUDA context, or until it is explicitly released by a call to
free(). It can be used by any other CUDA threads even from subsequent kernel
launches. Any CUDA thread may free memory allocated by another thread, but care
should be taken to ensure that the same pointer is not freed more than once.

Appendix B. C Language Extensions

CUDA C Programming Guide Version 3.2


You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->