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

Do I need to free device_ptr returned by thrust?

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

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

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

我认为您不需要释放 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);

它似乎是 returns 一个指向数组元素的指针,您不需要删除它。

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