Why do I see "Conversion to logical from gpuArray is not possible"
7 views (last 30 days)
Show older comments
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 Comments
Walter Roberson
on 23 Sep 2016
Edited: Walter Roberson
on 23 Sep 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.]
Answers (1)
Edric Ellis
on 23 Sep 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 Comment
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!