Skip to content

Commit d61e1e4

Browse files
committed
Update README to include quickstart code; add headers for quick links
1 parent d532354 commit d61e1e4

File tree

1 file changed

+39
-8
lines changed

1 file changed

+39
-8
lines changed

tripy/README.md

+39-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
[**Installation**](#installation) | [**Quickstart**](#quickstart) | [**Documentation**](#documentation) | [**Examples**](#examples)
2+
13
# Tripy: A Python Programming Model For TensorRT
24

3-
Tripy is a Python programming model for TensorRT that aims to provide an excellent
5+
Tripy is a Python programming model for [TensorRT](https://developer.nvidia.com/tensorrt) that aims to provide an excellent
46
user experience without compromising performance. Some of the features of Tripy include:
57

68
- **Intuitive API**: Tripy doesn't reinvent the wheel: If you have used NumPy or
@@ -12,19 +14,48 @@ user experience without compromising performance. Some of the features of Tripy
1214
that caused it.
1315

1416

15-
<!-- Tripy: DOC: OMIT Start -->
16-
## Table Of Contents
17+
## Installation
1718

18-
[[_TOC_]]
19+
<!-- TODO (#release): Include `pip install` instructions here. Also, point to documentation for building mlir-tensorrt from source and using the built python packages. -->
1920

20-
<!-- Tripy: DOC: OMIT End -->
2121

22-
## Installation
22+
## Quickstart
2323

24-
<!-- TODO (#release): Include `pip install` instructions here -->
24+
In lazy mode evalulation, Tripy defers computation until it is actually needed:
2525

26+
```py
27+
import tripy as tp
28+
import os
29+
30+
def add(a, b):
31+
return a + b
32+
33+
print(add(tp.Tensor([1., 2.]), tp.Tensor([1.])))
34+
#tensor([2.0000, 3.0000], dtype=float32, loc=gpu:0, shape=(2,))
35+
```
36+
37+
Tripy can compile functions to generate efficient machine code for faster execution:
38+
39+
```py
40+
compiler = tp.Compiler(add)
41+
42+
# a is a 1D dynamic shape tensor of shape (d,), where `d` can range from 1 to 5.
43+
# `[1, 2, 5]` indicates a range from 1 to 5, with optimization for `d = 2`.
44+
a_info = tp.InputInfo(shape=([1, 2, 5],), dtype=tp.float32)
45+
46+
# `b` is a 1D tensor of shape (1,).
47+
b_info = tp.InputInfo((1,), dtype=tp.float32)
48+
49+
compiled_add = compiler.compile(a_info, b_info)
50+
51+
print(compiled_add(tp.Tensor([1., 2., 3.]), tp.Tensor([3.])))
52+
# tensor([4.0000, 5.0000, 6.0000], dtype=float32, loc=gpu:0, shape=(3,))
53+
54+
# Save the compile executable to disk.
55+
executable_file = os.path.join(os.getcwd(), "add_executable.json")
56+
compiled_add.save(executable_file)
57+
```
2658

27-
## Quickstart
2859

2960
<!-- TODO (#release): Link to intro to tripy guide -->
3061

0 commit comments

Comments
 (0)