gpuDevice: Available memory greater than Total Memory -- What might be the cause?

3 views (last 30 days)
Hello, I'm using mexcuda compiler to compile a mex function(ending in .cu) which uses cufft toolkits to accelerate fft.
Both the input and output are 3D single gpuArrays, I'm using matlab2021a, compiler is 'mexcuda -R2018a' and my graphic card is 'NVIDIA GeForce RTX 3090'.
I'm running into this problem: The result of the function turns out correct, but all following matlab functions can't be performed as long as they involve computing on gpu. So I'm supposing that there's someting wrong with my gpuDevice.
A simple gpuDevice check after performing my function gives:
CUDADevice with properties:
Name: 'NVIDIA GeForce RTX 3090'
Index: 1
ComputeCapability: '8.6'
SupportsDouble: 1
DriverVersion: 11.4000
ToolkitVersion: 11
MaxThreadsPerBlock: 1024
MaxShmemPerBlock: 49152
MaxThreadBlockSize: [1024 1024 64]
MaxGridSize: [2.1475e+09 65535 65535]
SIMDWidth: 32
TotalMemory: 2.5770e+10
AvailableMemory: 4.9904e+10
MultiprocessorCount: 82
ClockRateKHz: 1695000
ComputeMode: 'Default'
GPUOverlapsTransfers: 1
KernelExecutionTimeout: 1
CanMapHostMemory: 1
DeviceSupported: 1
DeviceAvailable: 1
DeviceSelected: 1
I found that the AvailbleMemory is greater than TotalMemory after function execution, and I think here is the problem.
Any attempt to run other functions would arise CUDA_ERROR_ILLEGAL_ADDRESS error.
Memory manipulation (or maybe memory related) in my .cu file are listed as follows:
mxGPUCreateFromMxArray
mxGPUCreateMxArrayOnGPU
cudaMalloc
cudaMemcpy
cudaFree (in pair with cudaMalloc)
mxGPUDestroyGPUArray (in pair with mxGPUCreateFromMxArray)
mxGPUDestroyGPUArray (in pair with mxGPUCreateMxArrayOnGPU)
I'm wondering what might be the cause of problem. Any help would be appreciated!
  5 Comments
Joss Knight
Joss Knight on 6 Oct 2021
So are you saying that you are calling cudaSetDevice in your code and not switching back to the currently selected device at the end? So MATLAB's pooled memory on Device 1 is being added to the FreeMemory of Device 2.
This is a flag to me; I feel that we should look into checking that the right device is still selected after calling a MEX function. Thanks for the heads-up.

Sign in to comment.

Accepted Answer

Yuxin Yang
Yuxin Yang on 6 Oct 2021
Turns out that I'm using two different graphic cards in my .cu file and matlab terminal, which has memory of 25 GiB and 50GiB respectively. At first,I was using the 25GiB one. When I call the function, I'm switching gpu to the 50 GiB one, that's why the memory changed to a larger one.
Note: Index of GPU starts from 1 in matlab, but 0 in cuda programming. Hope it will helpful to anyone!

More Answers (0)

Categories

Find more on Get Started with GPU Coder in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!