Matrix and vector multiplication of size using a CPU is very slow. Using GPU is much quicker but I need a way around the size limitation.
![40](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1463067/40.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1463072/image.png)
10 个评论
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1464112/image.png)
采纳的回答
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1464917/image.png)
37 个评论
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1464992/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1465682/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1465687/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1465692/image.png)
- load('debug.mat') this loads the debug file and AA; AB; rhs; U0 & U1
- surf(abs(AA),'EdgeColor','none') provides graph of tri diagonal matrix as before.
- surf(abs(AB),'EdgeColor','none') provides graph of matrix as before.
- plot(abs(U0)) provides graph of matrix as before.
- plot(abs(rhs)) provides graph of matrix as before.
- issparse(AA) logical 1 (yes), it does not say this in workspace, just gpuArray.
- issparse(AB) logical 1 (yes), it does not say this in workspace, just gpuArray.
- sol = AA\rhs; this failed in the program for U1.
- plot(abs(sol)) produces non NaN and shows a graph of a slightly moved soliton as required.
- isgpuarray(sol) logical 1 (yes),
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1466672/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1466677/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1466682/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1466687/image.jpeg)
Do make sure you move the result of backslash back to the GPU so that subsequent operations take place on the GPU. So use gpuArray(gather(AA)\gather(rhs)) rather than just gather(AA)\gather(rhs), to ensure U1 is still a gpuArray on output.
As a developer of the gpuArray datatype, I'm usually - not always, but usually! - pretty confident in my assertions about its behaviour. Whatever you're seeing in the task manager is heavily confused by the fact that MATLAB's GPU functionality pools memory and operates lazily and asynchronously. That means the GPU isn't always being used when a line of code is run, it doesn't always finish when the next line of code is run, and memory no longer assigned to a variable is not necessarily released back to the system to show up as free in the Task Manager. Hopefully we will soon have our own monitor apps so you can more easily see this behaviour in MATLAB.
Worth reminding you perhaps that gather(AA) does not move AA to the CPU, it creates a temporary variable on the CPU and copies AA there. So the GPU memory is not released.
I'm glad you've found some compromises about where to do CPU work and where GPU. It takes quite a lot of memory to move a sparse CPU array to the GPU because a conversion between two different storage formats is required (CSC to CSR, if you care). It's usually best to create the data on the GPU from the outset, for instance by passing gpuArray data to spdiags.
更多回答(0 个)
另请参阅
类别
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)