【问题标题】:Finding memory leaks with Alea使用 Alea 查找内存泄漏
【发布时间】:2015-09-07 11:21:11
【问题描述】:

我有一些脚本在运行一段时间后会引发 Cuda 内存不足异常。在它们内部,我使用的是预先分配的数组,所以我没想到这是个问题。尽管如此,在我将脚本转换为 .fs 文件并对其进行编译后,分析器对于此任务并不是特别有用,并且 cuda-memcheck 工具 6.5 (36) 在我使用它时抛出了 CudaInterOp 异常。 cuda-memcheck 7.0 (40) 实际上迫使我在 GPU 熄灭时重置 PC。

我现在有点不确定该怎么做。如何使用 Alea 修复漏洞?

【问题讨论】:

  • 你用过worker.Mallco吗?它返回一个实现 .NET IDisposable 接口的 DeviceMemory 对象。所以通常在脚本中,你必须自己处理它。在普通的 .fs 代码中,您可以使用 F# 的 use 关键字来确保它被释放。见msdn.microsoft.com/en-us/library/dd233240.aspx

标签: aleagpu


【解决方案1】:

设备 reduce 资源管理的完整用法如下所示:

// first, create module, which has the compilation stuff
use reduceModule = new DeviceReduceModule<float>(Target, <@ (+) @>) 
// second, create a reduce object, which contains temp memory for that maxItems
use reduce = reduceModule.Create(maxItems)
// third, allocate your device memory for input
use numbers = reduce.AllocateStreamBuffer(xxx)
// now you can scatter data and do reduce
numbers.Scatter(your data)
reduce.Reduce(numbers)
// now because you are using "use" keyword, the dispose() will be called implicitly

【讨论】:

  • 我在我的代码中发现了我错过的一行,现在它可以正常工作了。使事情复杂化的一件事是,我在记录中使用了 DeviceMemory 类,因此无法方便地使用“使用”,我一直依赖 GC 来处理超出范围的对象。它在一定程度上起作用了...在上面的示例中,使用 AllocateStreamBuffer 和 worker.Malloc 有什么区别吗?
  • AllocateStreamBuffer 与 worker.Malloc 没有区别 :) ,只需节省您计算长度和大小和类型的时间。
  • 我知道那里有一些并发症,它使用了很多一次性的东西。我们正在开发新版本,试图简化这些东西。
猜你喜欢
  • 1970-01-01
  • 2017-11-29
  • 2013-11-06
  • 1970-01-01
  • 1970-01-01
  • 2015-09-19
  • 2012-02-27
  • 2011-07-05
  • 2017-12-30
相关资源
最近更新 更多