Accessing gpuDevice WITHOUT resetting it, and without carrying around a gpuDevice handle, or declaring a global

2 次查看(过去 30 天)
Hello,
I have a question which sparked the issue I am having here: I want to access my gpuDevice properties, namely the AvailableMemory, without resetting the darned thing and losing all of my hard calculated variables.
The issue is that I typically reset the gpu at the top of the main file using g = gpuDevice(1). Now, many sub-functions down I want to check whether there is the AvailableMemory to perform a given calculation on the GPU (since the size of the matrices may be dynamic, or I may be using a smaller graphics card, etc. I cannot just assume it will work) and if not, do things another way.
This is easy using g.AvailableMemory...but I must have access to the gpuDevice handle in that sub function to avoid resetting the device; this means carrying that handle around at every level and function call, which just strikes me as bad practice. I suppose I could declare it as a global variable, but that again is bad practice.
So, is there any way to access gpuDevice.AvailableMemory without having selected the device in the local function using the carried around handle, or resetting the device (thus defeating the purpose of this excercise)?
Thanks,
-Dan

采纳的回答

Edric Ellis
Edric Ellis 2018-12-6
You can simply use gpuDevice() with no input arguments to access the currently selected GPU device without resetting it.
  1 个评论
D. Plotnick
D. Plotnick 2018-12-6
Ah, I misread the gpuDevice doc. The key line is:
D = gpuDevice or D = gpuDevice(), if no device is already selected, selects the default GPU device and returns a GPUDevice object representing that device. If a GPU device is already selected, this returns an object representing that device without clearing it.
Thanks.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Server Management 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by