我不能製作新的標籤,但它應該在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