解决使用GPU处理图像时提示数据不能是gpuArray的问题

【时间】2018.10.11

【题目】解决使用GPU处理图像时提示数据不能是gpuArray的问题

 

【问题描述】今天我在MATLAB中,用GPU进行图像处理,最后想用imwrite保存下来,但出现了以下错误:错误使用 imwrite  需要的 DATA 应为以下类型之一:numeric, logical ,但其类型是 gpuArray。出错 test (line 1) imwrite(X,'01.png');

 

【出错原因】没有将GPU上的数据回传给CPU

 

 【解决办法】在imwrite语句之前,使用gather函数,即X= gather(X),这个语句的作用是将GPU上的数据回传给CPU,详细用法如下:

 

gather函数用法

>> help gather

     gather collect values into current workspace

     X = gather(A) when A is a codistributed array, X is a replicated array with

     all the data of the array on every lab.  This would typically be executed

     inside SPMD statements, or in parallel jobs.

 

     X = gather(A) when A is a distributed array, X is an array in the local

     workspace with the data transferred from the multiple labs.  This would

     typically be executed outside SPMD statements.

 

     X = gather(A) when A is a gpuArray, X is an array in the local workspace

     with the data transferred from the GPU device.

 

     If A is not one of the types mentioned above, then no operation is

     performed and X is the same as A.

 

Example:

     % create a distributed array

     d = distributed(magic(5));

     % gather values back to the client

     x = gather(d);

     % a second gather is a no-op

     isequal(x, gather(x)) % returns true

     

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值