我們如何使用AleaGpu釋放陣列的GPU內存? (在GPU卡上)我們如何使用AleaGpu釋放陣列的GPU內存? (在GPU卡上)
在函數/子裏面,如果我們想釋放數組dOutputs,dInputs的GPU內存,我們該怎麼做呢?
1 /志 「dOutputs 處置(); dInputs 處置();」。釋放GPU內存?
2 /是否存在用於GPU的「GC.Collect()」?有必要嗎 ?
3 /隨着AleaGpu,我們有一個命令來釋放GPUmemory?
private void button3_Click(object sender, EventArgs e)
{
textBox3.Text = "";
var worker = Worker.Default;
const int rows = 10;
const int cols = 5;
var rng = new Random();
var inputs = new double[rows, cols];
for (var row = 0; row < rows; ++row)
{
for (var col = 0; col < cols; ++col)
{
inputs[row, col] = rng.Next(1, 100);
}
}
var dInputs = worker.Malloc(inputs);
var dOutputs = worker.Malloc<double>(rows, cols);
var lp = new LaunchParam(1, 1);
worker.Launch(Kernel, lp, dOutputs.Ptr, dInputs.Ptr, rows, cols);
var outputs = new double[rows, cols];
dOutputs.Gather(outputs);
Assert.AreEqual(inputs, outputs);
dOutputs.Dispose();
dInputs.Dispose();"
}
3 /由於GPU卡的內存有限,我們需要使用Single/Int16/Int32而不是double。 我想:
var inputs = new Single[rows, cols];
var dOutputs = worker.Malloc<Single>(rows, cols);
var inputs2 = new Int16[rows, cols];
但
worker.Launch(Kernel, lp, dOutputs.Ptr, dInputs.Ptr, rows, cols);
不採取它。我得到錯誤「有一些無效的論點」。
我們如何讓worker.Launch(Kernel,lp,...)以Int16,Int32和single?
這很棒! – Emmanuel