You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
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 Comments
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1464112/image.png)
Accepted Answer
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1464917/image.png)
37 Comments
![](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.
More Answers (0)
See Also
Categories
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)