GPU memory usage for Hadamard product
조회 수: 6 (최근 30일)
이전 댓글 표시
I have a GPU with 48 Gb of RAM.
I have a large matrix A (complex single 45927x45927, gpuArray) taking 16 Gb of my GPU.
I get to the following Hadamard product with a vector B (complex single 45927x1, gpuArray) with approximately 28 Gb of free RAM on the GPU:
C = A .* (B.')
But this throws an "out of memory on the device" error, despite there being enough memory for C (also 16 Gb). Why is this happening? Does MATLAB implicitly convert B to a full matrix? Is there a way to get this multiplication to work on the GPU within the available memory? (maybe this has been fixed in later releases of MATLAB?)
답변 (4개)
Sivsankar
2024년 7월 12일
Hi,
I believe that you are probably limited by the size of RAM of your GPU. I can suggest some ideas that you can implement which may work.
- Upgrade to the latest version of MATLAB.
- Pre-allocate the memory for the resultant gpuArray matrix C.
- Clear any existing gpuArray that may take up the RAM.
- Reset GPU device to release memory.
You can leverage this MATLAB answer that highlights a similar issue.
You can also make use of this MathWorks documentation that explains on how to resolve such “out of memory” errors.
Hope this works for you. Thanks.
Matt J
2024년 7월 14일
This is just a guess, but possibly the GPU memory is fragmented. I.e., maybe your available 28GB is broken into blocks that are smaller than 16GB and therefore Matlab cannot find enough space to allocate C.
댓글 수: 0
Catalytic
2024년 7월 14일
편집: Catalytic
2024년 7월 14일
Does MATLAB implicitly convert B to a full matrix?
When you say this, are you implying that issparse(B)=true? If so, then it is possible that C could consume up to 32 GB.
댓글 수: 2
Matt J
2024년 7월 14일
I don't think that would be possible. If B were sparse, you would get a different error if you tried to multiply it with a single matrix.
Joss Knight
2024년 7월 18일
편집: Joss Knight
2024년 7월 18일
I can't reproduce this.
You say you have 48Gb of GPU memory available...have you checked this? Try running gpuDevice and looking at the output. Maybe you have other variables taking up space. Maybe you have another MATLAB running and using the GPU?
Also, did it work the first time you ran it but not the second? If C already exists then you would need space for A, C and the new C all at once, and you would run out of memory.
댓글 수: 3
Joss Knight
2024년 7월 18일
Your gpuDevice output seems to indicate you have quite an old version of MATLAB. What version are you on?
Joss Knight
2024년 7월 18일
Never mind. I can't reproduce this in any old version, on Linux or Windows.
Just to be sure, make sure your script is standalone and is the only thing you run after you've started MATLAB. It should contain no other computation than creating A and B and then computing C, so for instance:
n = 45927;
proto = gpuArray(single(1i));
A = randn(n,'like',proto);
B = randn(n,1,'like',proto);
C = A.*(B.');
gpuDevice
whos
참고 항목
카테고리
Help Center 및 File Exchange에서 GPU Computing in MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!