我需要释放由推力返回的device_ptr吗?

Do I need to free device_ptr returned by thrust?

本文关键字:device ptr 返回 释放      更新时间:2023-10-16

我有一个函数来获取数组的最小值,它在循环中执行。

thrust::device_ptr<float> min_ptr = thrust::min_element(populationFitness, populationFitness + POPULATION);

我必须释放返回的device_ptr吗?我尝试使用thrust::device_free(min_ptr),但抛出异常。

thrust::min_element返回一个迭代器。你不应该直接释放它

我认为你不需要释放由thrust::min_element

返回的内存

查看http://docs.thrust.googlecode.com/hg/group__extrema.html

给出的示例代码
#include <thrust/extrema.h>
...
int data[6] = {1, 0, 2, 2, 1, 3};
int *result = thrust::max_element(data, data + 6);

似乎它返回一个指向数组元素的指针,你不需要删除它。