Why do I see "Conversion to logical from gpuArray is not possible"

9 次查看(过去 30 天)
I am receiving the error message below (R2015a), where X is a gpuArray,
Conversion to logical from gpuArray is not possible.
Error in PWLS_OSMOM3/recon (line 272)
if anynonfins(X), keyboard ;end
The contents of the function anynonfins.m is as follows,
function tf=anynonfins(V)
tf=any(~isfinite(V(:)));
Clearly the if statement above is complaining that anynonfins() is returning a gpuArray that cannot be converted to logical type. The only simple scenario that I've found to re-produce this error message is
>> if gpuArray(nan), 'hello', end
Conversion to logical from gpuArray is not possible.
However, I cannot see how my anynonfins function could ever analogously generate NaNs for gpuArray or any other input. The output of any() should always be logical.
Any ideas what the cause might be?
  3 个评论
Walter Roberson
Walter Roberson 2016-9-23
编辑:Walter Roberson 2016-9-23
Dang, I just discovered that my virtual machines cannot access my GPU; and that is apparently a limitation in most virtualization software. So that's why there is no configuration control over what GPU or graphics card to allow access to...
(I did find a project that allows GPUs to be virtualized, at least in some instances, but unfortunately the web site for that is timing out for me; also that project might require that one have booted to Linux)
[Also, I do not appear to have Windows 7 to test on, unless I have it backed up on a CD somewhere buried.]

请先登录,再进行评论。

回答(1 个)

Edric Ellis
Edric Ellis 2016-9-23
In the case
if gpuArray(nan), 'hello', end
the error message you're seeing is slightly misleading. The error you should see in this case is the same one you see if you run
if nan, 'hello', end
I think probably the condition you're hitting is something more like this:
if gpuArray(1:3), 'hello', end
in other words - the condition is non-scalar. In this case, MATLAB tries to convert the condition to logical, but for non-scalar gpuArray, the logical method of gpuArray returns another gpuArray with classUnderlying logical. Unfortunately, the if statement doesn't know how to deal with that, and throws the error.
The fix is simple: use gather on gpuArray conditions to if statements, i.e.
if gather(gpuArray(1:3)), 'hello', end
  1 个评论
Matt J
Matt J 2016-9-23
编辑:Matt J 2016-9-23
Thanks, Edric, but is there a reason you suspect the condition is non-scalar, as opposed to NaN, when the two produce the same error message? The line
tf=any(~isfinite(V(:)));
should produce non-NaN scalars always.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by