profile#

cuml.accel.profile(quiet: bool = False) Iterator[ProfileResults][source]#

Profile a section of code.

This will collect stats on all accelerated (or potentially-accelerated) method and function calls within the context, and output a report summarizing what methods cuml.accel was able to accelerate, and what methods required a CPU fallback.

cuml.accel.profile provides programmatic access to this profiler. Alternatively, you may use the --profile flag when running under the CLI, or the %cuml.accel.profile IPython magic when running in IPython or a notebook environment.

Parameters:
quietbool, optional

Set to True to skip printing the report automatically upon exiting the context.

Returns:
resultsProfileResults

A record of the profile results within the context.

Examples

As part of cuml.accel, the profiler only works if the accelerator is installed. You may accomplish this programmatically with cuml.accel.install, or through an alternative method like the CLI (python -m cuml.accel) or the IPython magic (%load_ext cuml.accel).

>>> import cuml
>>> cuml.accel.install()

Once The accelerator is active, you’re free to start running some scikit-learn code. The profiler helps you understand when cuml.accel was able to accelerate your code, and when it needed to fallback to CPU.

>>> from sklearn.datasets import make_regression
>>> from sklearn.linear_model import Ridge

To profile only certain sections of your code, wrap them in a profile contextmanager.

>>> with cuml.accel.profile():
...     X, y = make_regression()
...     model = Ridge()
...     model.fit(X, y)
...     model.predict(X)
...
cuml.accel profile
┏━━━━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━┓
┃ Function      ┃ GPU calls ┃ GPU time ┃ CPU calls ┃ CPU time ┃
┡━━━━━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━┩
│ Ridge.fit     │         1 │    167ms │         0 │       0s │
│ Ridge.predict │         1 │    1.2ms │         0 │       0s │
├───────────────┼───────────┼──────────┼───────────┼──────────┤
│ Total         │         2 │  168.2ms │         0 │       0s │
└───────────────┴───────────┴──────────┴───────────┴──────────┘