cuda - Thrust device_malloc and device_new -
what advantages using thrust device_malloc
instead of normal cudamalloc
, device_new
do?
for device_malloc
seems reason use it's bit cleaner.
the device_new
documentation says:
"device_new implements placement new operator types resident in device memory. device_new calls t's null constructor on array of objects in device memory. no memory allocated function."
which don't understand...
device_malloc
returns proper type of object if plan on using thrust other things. there no reason use cudamalloc
if using thrust. encapsulating cuda calls makes easier , cleaner. same thing goes c++ , stl containers versus c-style arrays , malloc
.
for device_new
, should read following line of documentation:
template<typename t> device_ptr<t> thrust::device_new (device_ptr< void > p, const size_t n = 1)
p: device_ptr region of device memory construct 1 or many ts.
basically, function can used if memory has been allocated. default constructor called, , return device_pointer
casted t's type.
on other hand, following method allocates memory , returns device_ptr<t>
:
template<typename t > device_ptr<t> thrust::device_new (const size_t n = 1)
Comments
Post a Comment