# profile

### cuml.accel.profile(quiet: [bool](https://docs.python.org/3/builtins/functions.html#bool) = False) → [Iterator](https://docs.python.org/3/library/typing.html#typing.Iterator)[ProfileResults][[source]](https://github.com/NVIDIA/cuml/blob/93418baf5/python/cuml/cuml/accel/profilers.py#L163)

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:**
  **quiet**
  : Set to True to skip printing the report automatically upon exiting the context.
* **Returns:**
  **results**
  : 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`](../cuml.accel.install/index.html.md#cuml.accel.install),
or through an alternative method like the CLI (`python -m cuml.accel`) or the
IPython magic (`%load_ext cuml.accel`).

```pycon
>>> 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.

```pycon
>>> 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.

```pycon
>>> 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 │
└───────────────┴───────────┴──────────┴───────────┴──────────┘
```

<!-- !! processed by numpydoc !! -->
