Debugging: finding all instances of gpuArray in large code base [or finding all instances of other function calls]

조회 수: 1 (최근 30일)
Hello all,
I am building a code set that I prefer to run on the GPU, but would also like to be capable of executing on a non-CUDA enabled machine (like many Macs). The issue is that during the prototyping phase, I have hidden lots of a = gpuArray(a); type commands in the code, like little landmines. I have a flag called 'useTheGPU' that nominally flips on/off GPU acceleration, and I can just put a little if statement around the gpuArray command. However, first I need to find the calls to gpuArray. There are a couple of ways to do this I can think of, but they all have issues, and I am hoping for something more efficient/ that works:
  • Brute force - go through every file and do a find. Lordy, I do NOT want to do that.
  • Overload the function locally - I put a dummy version of the command in the local folder with an enabled breakpoint. Every time I call gpuArray, it gets caught by the local breakpoint. The issue is that many Matlab commands, including gpuArray, do not permit overloading and will still default to the Matlab version
  • Put a breakpoint in the Matlab command - usually open functionName and then dropping the breakpoint there will work, but again not with gpuArray
  • Disable the GPU entirely, so gpuArray throws an error the way a Mac will - I tried to do this, but cannot figure out how. I once had my machine start in something called opengl mode, where I could not access my GPU, but I haven't reproduced that state.
  • Run it on a machine without a GPU and debug there - I don't have such a machine, and the point is to be able to do the coding locally.
  • Some wizardry that lets you find all calls to a function, or view the dependency tree - This would be the best shot, similar to the profiler...well, maybe I can Macgyver something out of the profiler. I will check that out next.
Any ideas heartily welcomed. -Dan

채택된 답변

Joss Knight
Joss Knight 2018년 7월 12일
On Linux? Use grep. On Windows? Just use Windows Explorer and type gpuArray into the search bar in the parent folder. Or write some MATLAB code to look for the string.
You can disable the GPU by starting MATLAB and typing
setenv CUDA_VISIBLE_DEVICES -1
  댓글 수: 1
D. Plotnick
D. Plotnick 2018년 7월 13일
Thanks, the
setenv CUDA_VISIBLE_DEVICES -1
Is what I needed. The problem with grep or other file-contents searches was still the speed + manual issue. I wanted to be able to quickly link to any spot where I had used gpuARRAY but NOT included a bracketing if statement. Since there are, at this point, hundreds of instances of gpuARRAY in the code set, I am just estimating it is faster to find the ones that throw errors when run without a gpu enabled. The code itself is fast enough that re-running it umpteen times is not a burden.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 GPU Computing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by