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

1 Ansicht (letzte 30 Tage)
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

Akzeptierte Antwort

Joss Knight
Joss Knight am 12 Jul. 2018
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 Kommentar
D. Plotnick
D. Plotnick am 13 Jul. 2018
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu GPU Computing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by