【发布时间】:2013-02-06 03:34:45
【问题描述】:
现在我需要使用 cuda 技术分配所有可用内存。 我用 Tesla C2050、Quadro 600 和 GeForce GTX 560 Ti 做到这一点: 首先,我在设备上分配了 0 字节的全局内存。第二步是通过 cudaMemGetInfo 函数定义设备的可用内存并分配该可用内存。它适用于上面列出的设备。 但这种机制不适用于 GeForce GTX 690。
有人可以帮我吗,我可以使用什么机制在 GeForce GTX 690 设备上分配内存或该操作的任何范例?
看起来像这样:
cudaSetDevice(deviceIndex);
int (*reservedMemory);
cudaMalloc(&reservedMemory, 0);
size_t freeMemory, totalMemory;
cudaMemGetInfo(&freeMemory, &totalMemory);
cudaMalloc(&reservedMemory, freeMemory);
在 GeForce GTX 690 上,现有的两个流式多处理器之一在 2147483648 字节的内存上运行,但我只能分配 1341915136 字节的空闲全局内存,即 2050109440 字节。 在 Quadro 600 上,一个现有的流式多处理器在 1073414144 字节内存上运行,我可以分配所有可用的 859803648 字节可用全局内存,即 859803648 字节。
以 Quadro 600 为例(显示编译、链接和执行过程):
D:\Gdmt> nvcc -arch=compute_20 -code=sm_21 -c ./Gdmt.cu -o ./Gdmt.obj
Gdmt.cu
tmpxft_00000bb4_00000000-3_Gdmt.cudafe1.gpu
tmpxft_00000bb4_00000000-8_Gdmt.cudafe2.gpu
Gdmt.cu
tmpxft_00000bb4_00000000-3_Gdmt.cudafe1.cpp
tmpxft_00000bb4_00000000-14_Gdmt.ii
D:\Gdmt> nvcc ./Gdmt.obj -o ./Gdmt.exe
D:\Gdmt> nvcc -arch=compute_20 -code=sm_21 -c ./Gdmt_additional.cu -o ./Gdmt_add
itional.obj
Gdmt_additional.cu
tmpxft_00000858_00000000-3_Gdmt_additional.cudafe1.gpu
tmpxft_00000858_00000000-8_Gdmt_additional.cudafe2.gpu
Gdmt_additional.cu
tmpxft_00000858_00000000-3_Gdmt_additional.cudafe1.cpp
tmpxft_00000858_00000000-14_Gdmt_additional.ii
D:\Gdmt> nvcc ./Gdmt_additional.obj -o ./Gdmt_additional.exe
D:\Gdmt> Gdmt.exe
Total amount of memory: 1073414144 Bytes;
Memory to reserve: 859803648 Bytes;
Memory reserved: 859803648 Bytes;
^C
D:\Gdmt> Gdmt_additional.exe
Allocation is succeeded on 890830848 bytes of reserved memory.
^C
D:\Gdmt>
以 GeForce GTX 690 为例(显示编译、链接和执行过程):
J:\Gdmt> nvcc -arch=compute_30 -code=sm_30 -c ./Gdmt.cu -o ./Gdmt.obj
Gdmt.cu
tmpxft_000011f0_00000000-5_Gdmt.cudafe1.gpu
tmpxft_000011f0_00000000-10_Gdmt.cudafe2.gpu
Gdmt.cu
tmpxft_000011f0_00000000-5_Gdmt.cudafe1.cpp
tmpxft_000011f0_00000000-15_Gdmt.ii
J:\Gdmt> nvcc ./Gdmt.obj -o ./Gdmt.exe
J:\Gdmt> nvcc -arch=compute_30 -code=sm_30 -c ./Gdmt_additional.cu -o ./Gdmt_add
itional.obj
Gdmt_additional.cu
tmpxft_00001164_00000000-5_Gdmt_additional.cudafe1.gpu
tmpxft_00001164_00000000-10_Gdmt_additional.cudafe2.gpu
Gdmt_additional.cu
tmpxft_00001164_00000000-5_Gdmt_additional.cudafe1.cpp
tmpxft_00001164_00000000-15_Gdmt_additional.ii
J:\Gdmt> nvcc ./Gdmt_additional.obj -o ./Gdmt_additional.exe
J:\Gdmt> Gdmt.exe
Total amount of memory: 2147483648 Bytes;
Memory to reserve: 2050109440 Bytes;
Warning, memory allocation process is not succeeded!
^C
J:\Gdmt> Gdmt_additional.exe
Allocation is succeeded on 1341915136 bytes of reserved memory.
^C
示例已存档并位于:
(z7 存档 - 78.5 KB ~ 80,434 字节) https://docs.google.com/file/d/0BzZ5q0v8n-qTTDctVDV5Mnh2ODA/edit (zip 存档 - 163 KB ~ 167,457 字节) https://docs.google.com/file/d/0BzZ5q0v8n-qTT2xoV3NXSzhQMDQ/edit
此主题是在“The GeForce Lounge”和“CUDA Programming and Performance”上发布的同名主题的克隆。
【问题讨论】:
-
您显然是在 Windows 主机上运行它。您提到的其他设备是否也在 Windows 主机上运行?此外,您还展示了用于编译为计算 2.0 目标的构建过程。如果为计算 3.0 目标编译,GTX690 的行为是否相同?
-
所以您可以在其中一个 GTX 690 子 gpu 上分配 2GB,而在另一个子 gpu 上分配大约 1.3GB?如果是,我的第一个猜测是使用这个 sub gpu 作为显卡,它会占用一些内存(虽然 700MB 会有点多)。
-
感谢 talonmies 和 GeorgT。 talonmies,首先 - 是的,我使用 Windows 作为此设备的操作系统平台,其次 - 在上面显示的构建过程中,计算编号 2.0 的目标适用于 Quadro 600 设备,计算编号 3.0 的目标适用于 GeForce GTX 690 设备。 GeorgT - 不,我可以在两个使用 GeForce GTX 690 设备的现有流式多处理器上分配 1.3 * 8^9.98(9.98 是 8 的度数)字节的全局内存。