Skip to content

Commit

Permalink
y
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmcl committed Feb 7, 2025
1 parent d3828ca commit 7b1244a
Show file tree
Hide file tree
Showing 50 changed files with 49 additions and 35 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ jobs:
# Build (and test) Lean. Tests are all via #guard macros
# now so you can't really build without testing.
- uses: leanprover/lean-action@v1
with:
lake-package-directory: ./Lean
- name: Run tests
run: lake exe klr

# Run pytest
- uses: actions/setup-python@v5
with:
Expand Down
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.lake/**
\.lake/
__pycache__/
*.so
*.dSYM
/.vscode/
.wheel/
.vscode/
/.wheel/
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions Python/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# All files must be below the python project root
include bin/klr
9 changes: 9 additions & 0 deletions interop/README.md → Python/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

Python bindings for KLR

# Usage
Expand All @@ -19,3 +20,11 @@ We do this to remove a dependency on the `neuronxcc` Python package that does no
require it since it's large and unnecessary.

2. Automatically sync `nki` examples with the github examples

# Notes

I keep getting __pycache__ directories created in the source tree, even with

export PYTHONDONTWRITEBYTECODE=1

This is annoying.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions interop/noop.c → Python/noop.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// A dummy file to trick Python's `build` into makeing an arch-specific wheel.

#include <stdio.h>

int main() {
Expand Down
31 changes: 12 additions & 19 deletions interop/pyproject.toml → Python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
# NB: All this setuptools stuff took about 1000 hours to figure out so never delete this.
[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[project]
name = "klr"
version = "0.0.2"
description = "Intermediate langauge for tensor compilers"
version = "0.0.3"
authors = [
{name = "Paul Govereau", email = "[email protected]"},
{name = "Sean McLaughlin", email = "[email protected]"},
]
description = "Intermediate langauge for tensor compilers"
readme = "README.md"
requires-python = ">=3.8"
license = { file = "LICENSE" }
keywords = ["trainium", "tpu", "pallas", "triton", "gpu"]

Expand All @@ -21,31 +27,18 @@ dependencies = [
"numpy",
]

[project.urls]
Repository = "https://github.com/leanprover/KLR"

[tool.pytest.ini_options]
pythonpath = "." # Needed for tests to pass
testpaths = [
"test",
]

# NB: All this setuptools stuff took about 1000 hours to figure out so never delete this.
[tool.setuptools]
# This makes it ok for there to be both klr and wheelhouse (where we generates wheels on github actions) in the same directory
#packages = ["klr"]
# This tricks setuptools into knowing this is a binary wheel
# The output says this is experimental and likely to change in future releases, but
# we will keep our fingers crossed. Pretty sure we can make a setup.py file that does
# this and it won't be that different.
#ext-modules = [
# {name = "klr.noop", sources = ["noop.c"]}
#]
packages = ["bin", "klr", "nki", 'nki.isa', 'nki.language'] # Required to have 2 top level packages

[[tool.setuptools.ext-modules]]
name = "noop"
sources = ["noop.c"]

[tool.setuptools.package-data]
# This part is essential to get the binary bin/klr included in the wheel
klr = ["bin/klr"]

[project.urls]
Repository = "https://github.com/leanprover/KLR"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
30 changes: 19 additions & 11 deletions bin/make-wheel
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,36 @@ set -e -u -o pipefail
trap "kill 0" SIGINT SIGTERM

ROOT=$(dirname $(dirname $(readlink -f $0)))
WHEEL_DIR=$ROOT/.wheel/klr
WHEEL_DIR=$ROOT/.wheel/
LEAN_DIR=$ROOT/Lean
PYTHON_DIR=$ROOT/Python
rm -rf $WHEEL_DIR
mkdir -p $WHEEL_DIR/klr/bin
mkdir -p $WHEEL_DIR/{klr,bin}

# Build Lean code
pushd .
cd $LEAN_DIR
lake build
cp $ROOT/.lake/build/bin/klr $WHEEL_DIR/klr/bin/klr
cp -R $ROOT/interop/nki $WHEEL_DIR/klr/nki
cp -R $ROOT/interop/klr $WHEEL_DIR/klr/klr
popd

# Get klr binary
cp $LEAN_DIR/.lake/build/bin/klr $WHEEL_DIR/bin/klr

# Get Python packages
cp -R $PYTHON_DIR/* $WHEEL_DIR
cp $ROOT/LICENSE $WHEEL_DIR
cp $ROOT/interop/README.md $WHEEL_DIR
cp $ROOT/interop/noop.c $WHEEL_DIR
cp $ROOT/interop/pyproject.toml $WHEEL_DIR
cp $ROOT/interop/MANIFEST.in $WHEEL_DIR

cd $WHEEL_DIR

if [ -z "${GITHUB_RUN_ID+x}" ]; then
echo "Building wheel locally"
python -m build -w
python -m build
else
# https://github.com/pypa/cibuildwheel
# NB: I could never get this to run on my mac locally. I got it to
# work on linux with no trouble.
echo "Building wheel via GitHub Actions"
python -m cibuildwheel --output-dir $ROOT/wheelhouse
python -m cibuildwheel --output-dir ./wheelhouse
fi

# To upload the wheel, with the proper token in ~/.pypirc, run
Expand Down
1 change: 0 additions & 1 deletion interop/MANIFEST.in

This file was deleted.

0 comments on commit 7b1244a

Please sign in to comment.