Created
April 16, 2025 02:40
-
-
Save jamesdavidson/f71d3743b09f15e6eae1ad2b2419b347 to your computer and use it in GitHub Desktop.
tvm sum of rows reduction example https://tvm.apache.org/docs/v0.13.0/how_to/work_with_schedules/reduction.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# apache-tvm==0.14.dev273 | |
# numpy==1.26.4 | |
# pytest==8.3.5 | |
from __future__ import absolute_import, print_function | |
import tvm | |
import tvm.testing | |
from tvm import te | |
import numpy as np | |
n = te.var("n") | |
m = te.var("m") | |
A = te.placeholder((n, m), name="A") | |
k = te.reduce_axis((0, m), "k") | |
B = te.compute((n,), lambda i: te.sum(A[i, k], axis=k), name="B") | |
# Create schedule | |
s = te.create_schedule(B.op) | |
# Build and execute | |
mod = tvm.build(s, [A, B]) | |
ctx = tvm.cpu() | |
# set up input and output array | |
n, m = 10, 20 # Example dimensions | |
a = tvm.nd.array(np.arange(n*m, dtype=np.float32).reshape((n, m))) | |
b = tvm.nd.array(np.zeros((n,),dtype=np.float32)) | |
# Execute | |
mod(a, b) | |
print(b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment