Skip to content

Commit aa328f3

Browse files
committed
* Update readme
Signed-off-by: Jay Gu <jagu@nvidia.com>
1 parent d37ea80 commit aa328f3

3 files changed

Lines changed: 98 additions & 4 deletions

File tree

README.md

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,63 @@ cuTile Python is a programming language for NVIDIA GPUs. The official documentat
88
on [docs.nvidia.com](https://docs.nvidia.com/cuda/cutile-python),
99
or built from source located in the [docs](docs/) folder.
1010

11+
12+
Example
13+
-------
14+
```python
15+
# This examples uses CuPy which can be installed via `pip install cupy-cuda13x`
16+
# Make sure cuda toolkit 13.1+ is installed: https://developer.nvidia.com/cuda-downloads
17+
18+
import cuda.tile as ct
19+
import cupy
20+
21+
TILE_SIZE = 16
22+
23+
# cuTile kernel for adding two dense vectors. It runs in parallel on the GPU.
24+
@ct.kernel
25+
def vector_add_kernel(a, b, result):
26+
block_id = ct.bid(0)
27+
a_tile = ct.load(a, index=(block_id,), shape=(TILE_SIZE,))
28+
b_tile = ct.load(b, index=(block_id,), shape=(TILE_SIZE,))
29+
result_tile = a_tile + b_tile
30+
ct.store(result, index=(block_id,), tile=result_tile)
31+
32+
# Host-side function that launches the above kernel.
33+
def vector_add(a: cupy.ndarray, b: cupy.ndarray, result: cupy.ndarray):
34+
assert a.shape == b.shape == result.shape
35+
grid = (ct.cdiv(a.shape[0], TILE_SIZE), 1, 1)
36+
ct.launch(cupy.cuda.get_current_stream(), grid, vector_add_kernel, (a, b, result))
37+
38+
39+
import numpy as np
40+
41+
def test_vector_add():
42+
a = cupy.random.uniform(-5, 5, 128)
43+
b = cupy.random.uniform(-5, 5, 128)
44+
result = cupy.zeros_like(a)
45+
46+
vector_add(a, b, result)
47+
48+
a_np = cupy.asnumpy(a)
49+
b_np = cupy.asnumpy(b)
50+
result_np = cupy.asnumpy(result)
51+
52+
expected = a_np + b_np
53+
np.testing.assert_array_almost_equal(result_np, expected)
54+
55+
test_vector_add()
56+
```
57+
58+
System Requirements
59+
-------------------
60+
cuTile Python generates kernels based on [Tile IR](https://docs.nvidia.com/cuda/tile-ir/)
61+
which requries NVIDIA Driver r580 or later to run.
62+
Furthermore, the `tileiras` compiler only supports Blackwell GPU with 13.1 release, but the
63+
restriction will be removed in the coming versions.
64+
Checkout the [prerequisites](https://docs.nvidia.com/cuda/cutile-python/quickstart.html#prerequisites)
65+
for full list of requirements.
66+
67+
1168
Installing from PyPI
1269
--------------------
1370
cuTile Python is published on [PyPI](https://pypi.org/) under the
@@ -16,7 +73,10 @@ cuTile Python is published on [PyPI](https://pypi.org/) under the
1673
pip install cuda-tile
1774
```
1875
Currently, the [CUDA Toolkit 13.1+](https://developer.nvidia.com/cuda-downloads) is required
19-
and needs to be installed separately.
76+
and needs to be installed separately. On a Debian-based system, use `apt-get install
77+
cuda-tileiras-13.1 cuda-compiler-13.1` instead of `apt-get install cuda-toolkit-13.1`
78+
if you wish to avoid installing the full CUDA Toolkit.
79+
2080

2181
Building from Source
2282
--------------------
@@ -79,4 +139,4 @@ Copyright and License Information
79139
---------------------------------
80140
Copyright © 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
81141

82-
cuTile-Python is under Apache 2.0 license. See the [LICENSES](LICENSES/) folder for the full license text.
142+
cuTile-Python is licensed under the Apache 2.0 license. See the [LICENSES](LICENSES/) folder for the full license text.

test/test_frontpage_example.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
# flake8: noqa
66

7-
import torch # to load libnvrtc so that cupy works in the CI
8-
97
#example-begin
108
import cuda.tile as ct
119
import cupy

test/test_readme_example.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# SPDX-FileCopyrightText: Copyright (c) <2025> NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
# flake8: noqa
6+
7+
import atexit
8+
import os
9+
import subprocess
10+
import tempfile
11+
import sys
12+
13+
14+
file_path = os.path.realpath(__file__)
15+
16+
17+
def test_readme():
18+
readme_path = os.path.join(os.path.dirname(file_path), "..", "README.md")
19+
readme_txt = open(readme_path, 'r').read()
20+
header = "Example\n-------\n```python"
21+
example_begin = readme_txt.find(header)
22+
if example_begin < 0:
23+
raise RuntimeError("Unable to find Example header in readme")
24+
example_begin += len(header)
25+
example_end = readme_txt.find("```", example_begin)
26+
if example_end < 0:
27+
raise RuntimeError("Example is missing closing \"```\"")
28+
29+
example = readme_txt[example_begin : example_end]
30+
31+
with tempfile.NamedTemporaryFile(suffix=".py", mode='w', delete=False) as f:
32+
# On windows, we have to set delete=False with manual deletion
33+
# so the file can be read without permission denied.
34+
atexit.register(os.unlink, f.name)
35+
f.write(example)
36+
subprocess.check_call([sys.executable, f.name])

0 commit comments

Comments
 (0)