Skip to content

Commit

Permalink
update API to use the clearer 'annotate' command -- rather than 'mark'
Browse files Browse the repository at this point in the history
  • Loading branch information
JBlaschke committed Dec 23, 2020
1 parent 73ed4b9 commit f36b3f1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
16 changes: 8 additions & 8 deletions PyNVTX/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@


major_version = 0;
minor_version = 2;
release_version = 3;
minor_version = 3;
release_version = 0;

NVTX_IDENTIFIER = "NVTX"
REGISTRY = Registry()



def mark(label):
def _mark(func):
def annotate(label):
def _annotate(func):
@wraps(func)
def wrapped(*args, **kwargs):
RangePushA(label)
ret = func(*args, **kwargs)
RangePop()
return ret
return wrapped
return _mark
return _annotate



Expand All @@ -43,7 +43,7 @@ def dec_id_str(identifier):



def mark_all_methods(cls):
def annotate_all_methods(cls):
if is_decorated(cls, NVTX_IDENTIFIER):
return

Expand All @@ -52,12 +52,12 @@ def mark_all_methods(cls):
continue

if callable(cls.__dict__[attr]):
dec = mark(f"{cls}.{attr}")
dec = annotate(f"{cls}.{attr}")
type.__setattr__(cls, attr, dec(cls.__dict__[attr]))

type.__setattr__(cls, dec_id_str(NVTX_IDENTIFIER), True)

for base in cls.__bases__:
if base == object:
continue
mark_all_methods(base)
annotate_all_methods(base)
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
A thin python wrapper for the nvToolsExt (NVTX) library, using pybind11. This
wrapper is meant to be as thin as possible -- so only provides minimal support.
Currently supported features are:
1. NVTX markers: `nvtxRangePushA` and `nvtxRangePop`
2. Function decorator: `PyNVTX.mark`
3. Automatic decorator generation `PyNVTX.mark_all_methods(<class name>)`
1. NVTX annotations: `nvtxRangePushA` and `nvtxRangePop`
2. Function decorator: `PyNVTX.annotate`
3. Automatic decorator generation `PyNVTX.annotate_all_methods(<class name>)`



Expand Down Expand Up @@ -56,20 +56,20 @@ nvtx.RangePop()

### Function Decorator

The `PyNVTX.mark` will put `RangePushA` and `RangePop` the the beginning and of
The `PyNVTX.annotate` will put `RangePushA` and `RangePop` the the beginning and of
the function call:
```python
import PyNVTX as nvtx

@nvtx.mark("test_function")
@nvtx.annotate("test_function")
def test():
# You code goes here
```


### Automatic Instrumentation

The `PyNVTX.mark_all_methods` will automatically decorate all methods in a
The `PyNVTX.annotate_all_methods` will automatically decorate all methods in a
class, as well as all methods it inherits. A guard prevents accidentally
decorating any method twice. Eg.:
```python
Expand All @@ -90,16 +90,16 @@ class MyClassB(MyClassA):
pass


nvtx.mark_all_methods(MyClassB)
nvtx.annotate_all_methods(MyClassB)
```
Will instrument `MyClassB`'s `__init__`, as well as `f` and `g`, but _not_
`MyClassA`'s `__init__`.

Adding a class/method name to `PyNVTX.REGISTRY` will prevent it from being
instrumented by `PyNVTX.mark_all_methods`. For example:
instrumented by `PyNVTX.annotate_all_methods`. For example:
```python
nvtx.REGISTRY.add(MyClassB, "f") # note the method name is a string
nvtx.mark_all_methods(MyClassB)
nvtx.annotate_all_methods(MyClassB)
```
will not instrument `f`.

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def build_extensions(self):

setup(
name="PyNVTX",
version="0.2.3",
version="0.3.0",
author="Johannes Blaschke",
author_email="[email protected]",
description="A thin python wrapper for the nvToolsExt (NVTX) library, using pybind11 ... with some bells and whistles thrown in for good measure.",
Expand Down
4 changes: 2 additions & 2 deletions test/test-nvtx.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@



@nvtx.mark("Build CUDA code")
@nvtx.annotate("Build CUDA code")
def init():

#___________________________________________________________________________
Expand Down Expand Up @@ -113,7 +113,7 @@ def apply_fn(self, fn):

print(f"Running test for {size} elements")

nvtx.mark_all_methods(Test)
nvtx.annotate_all_methods(Test)

fn = init()
test = Test(size)
Expand Down

0 comments on commit f36b3f1

Please sign in to comment.