0

I have a few scripts that after running for a while throw a Cuda out of memory exception. Inside of them I am using preallocated arrays, so I did not expect this to be a problem. Nevertheless, after I've turned the scripts into .fs files and compiled them, the profiler was not particularly useful for this task and the cuda-memcheck tool 6.5 (36) threw an CudaInterOp exception when I used it. cuda-memcheck 7.0 (40) actually forced me to reset the PC as the GPU went out.

I am a bit unsure of what to do at the moment. How would one go about fixing the leaks with Alea?

Marko Grdinić
  • 3,798
  • 3
  • 18
  • 21
  • Did you use worker.Mallco? that returns a DeviceMemory object, which implements .NET IDisposable interface. So normally in script, you have to dispose it your self. In normal .fs code, you can use F#'s `use` keyword to make sure it is freed. See https://msdn.microsoft.com/en-us/library/dd233240.aspx – Xiang Zhang Sep 07 '15 at 02:50

1 Answers1

1

A complete usage with resource management of device reduce would briefly looks like:

// 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
Xiang Zhang
  • 2,831
  • 20
  • 40
  • I found a line I'd missed in my code and now it works fine. One thing that complicates things is that I am using the DeviceMemory class inside a record, so not having the convenience of using 'use' I've been banking on the GC disposing the objects once they go out of scope. It worked to an extent... In the example above, is there any difference between using AllocateStreamBuffer and worker.Malloc? – Marko Grdinić Sep 07 '15 at 08:41
  • AllocateStreamBuffer has NO difference with worker.Malloc :) , just save your time to calculate the length and size and type. – Xiang Zhang Sep 07 '15 at 12:34
  • I know there are some comiplicates there, it uses lot of disposable stuff. we are in developing new release, trying to simplify these stuff. – Xiang Zhang Sep 07 '15 at 12:35