Ahmed Fasih
Ahmed Fasih

Reputation: 6937

How to profile PyCUDA code with NVIDIA Nsight in Linux?

This question is almost the same as How to profile PyCuda code with the Visual Profiler? except about the new NVIDIA Nsight IDE with CUDA 5 for Linux.

I have a PyCUDA Python script that I'd like to profile using fancy Nsight.

I set up a Build External Tools Configuration, pointing to the example script (with executable permissions, included below). I can then run this, and see the printouts in the Console. Then I go to Profile mode and click Run -> Profile---I see the printouts in the Console but no profiler information visible. How do I get the timing plots and occupancy calculators and NVIDIA's suggestions for my code that appear when I run a C/CUDA program in Nsight?

Total IDE noob here (mostly command-line), sorry if my question doesn't include key information. Ubuntu 11.10, PyCUDA 2012.1.

Nsight screenshot

example.py:

#!/usr/bin/env python
import pycuda.autoinit
import pycuda.driver as drv
import numpy

from pycuda.compiler import SourceModule

mod = SourceModule("""
__global__ void multiply_them(float *dest, float *a, float *b)
{
  const int i = threadIdx.x;
  dest[i] = a[i] * b[i];
}
""")

multiply_them = mod.get_function("multiply_them")

a = numpy.random.randn(400).astype(numpy.float32)
b = numpy.random.randn(400).astype(numpy.float32)

dest = numpy.zeros_like(a)
multiply_them(
        drv.Out(dest), drv.In(a), drv.In(b),
        block=(400,1,1), grid=(1,1))

print "error:", numpy.sum(numpy.abs(dest - a*b).ravel())
print "Done"
#pycuda.autoinit.context.detach() # seems to break PyCUDA 2012.1

Upvotes: 2

Views: 4321

Answers (3)

Alexey Yurasov
Alexey Yurasov

Reputation: 109

Nvidia Visual Profiler

  • Go to your script path
# If you using conda:
conda activate env_name
# Run the Nvidia Visual Profiler:
nsight-sys
  • Command line with parameters: python3 script_name.py
  • Working directory: Script path
  • Press: Start

Nvidia Nsight Compute

  • Go to your script path
# If you using conda:
conda activate env_name

# To get the current python path:
which python3

# Run the Nvidia Nsight Compute:
nv-nsight-cu
  • Application executable: Set the current python path
  • Working directory: Script path
  • Command line arguments: Script file name
  • Press: Launch

Upvotes: 0

Ahmed Fasih
Ahmed Fasih

Reputation: 6937

I used nvvp to get the timeline and the program analysis. Just chmod 755 the script and add a #!/usr/bin/env python at the top and give it to nvvp.

Upvotes: 1

Eugene
Eugene

Reputation: 9474

Nsight Eclipse Edition currently do not support debugging PyCUDA applications.

One thing you could try though (I have not tried it myself):

  1. On the main menu, select Run->Profile Configurations...
  2. Enter your Python interpreter (e.g. '/usr/bin/python') as "C/C++ Application"
  3. Specify any existing project in the "Project" list.
  4. On the "Arguments" tab specify path to your script file.
  5. Press "Profile" in the bottom-right corner.

I don't have pycuda installed so profiling your script failed as expected...

Upvotes: 1

Related Questions