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

7 visualizzazioni (ultimi 30 giorni)
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 Commenti
Walter Roberson
Walter Roberson il 23 Set 2016
Modificato: Walter Roberson il 23 Set 2016
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.]

Accedi per commentare.

Risposte (1)

Edric Ellis
Edric Ellis il 23 Set 2016
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 Commento
Matt J
Matt J il 23 Set 2016
Modificato: Matt J il 23 Set 2016
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.

Accedi per commentare.

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by