我不能制作新的标签,但它应该在MANAGEDCUDA标签上,因为我使用该框架在C#中使用CUDA。在CUDA设备中的内存分配不是预期的
我分配2个INT阵列,该代码进行测试:
Console.WriteLine("Cells: "+sum+" Expected Total Memory (x4): "+sum*4);
int temp= 0;
temp = cntxt.GetFreeDeviceMemorySize();
Console.Write("\n Memory available before:" + cntxt.GetFreeDeviceMemorySize() + "\n");
CudaDeviceVariable<int> matrix = new CudaDeviceVariable<int>(sum);
CudaDeviceVariable<int> matrixDir = new CudaDeviceVariable<int>(sum);
Console.Write("\n Memory available after allocation:" + cntxt.GetFreeDeviceMemorySize() + "\n");
Console.WriteLine("Memory took: "+(temp - cntxt.GetFreeDeviceMemorySize()));
Console.WriteLine("Diference between the expected and allocated: " + ((temp - cntxt.GetFreeDeviceMemorySize())-sum*8));
运行后我在控制台得到这个:
习惯问一个问题。我想你想知道为什么分配了大约3MB的数据后,出现了大约40KB的差异?存在与分配相关的粒度/开销,而且该设备具有类似于运行在其上的操作系统的东西,这需要设备存储器用于它自己的内务处理任务。 – 2015-03-03 01:13:20
回答[tag:cuda]问题的用户池已经相对有限,进一步拆分标签只会使您的问题不太明显。 – 2015-03-03 01:21:45