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

7 ビュー (過去 30 日間)
Matt J
Matt J 2016 年 9 月 23 日
編集済み: Walter Roberson 2016 年 9 月 23 日
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 件のコメント
Matt J
Matt J 2016 年 9 月 23 日
Hi Walter,
The OS is Windows 7 Enterprise SP1.
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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by