Skip to content

Instantly share code, notes, and snippets.

@unnonouno
Last active October 7, 2022 02:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unnonouno/877f314870d1e3a2f3f45d84de78d56c to your computer and use it in GitHub Desktop.
Save unnonouno/877f314870d1e3a2f3f45d84de78d56c to your computer and use it in GitHub Desktop.
cupy.fuse example
import cupy
import cupy.prof
def f(x):
return x + x + x + x + x
# This decorator fuses the kernels into one.
@cupy.fuse()
def g(x):
return x + x + x + x + x
x = cupy.arange(40000000)
with cupy.prof.time_range('without fuse', color_id=0):
f(x)
with cupy.prof.time_range('with fuse', color_id=1):
g(x)
# You can pass numpy arrays transparently to the fused function as well.
# In this case, no JIT compilation is applied and it just falls back to plain NumPy API calls.
g(numpy.arange(40000000))

Run the sample with nvprof command. Specify profile file with -o option. -f means force and it override an existed file.

$ nvprof -f -o fuse.nvvp python fuse_sample.py

And then run nvvp command, and open file fuse.nvvp.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment