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 620775a
Show file tree
Hide file tree
Showing 51 changed files with 67 additions and 44 deletions.
16 changes: 10 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
# macos-13 is x86
# macos-latest is arm64
# ubuntu-latest is x64
os: [ubuntu-latest]
os: [macos-latest]

runs-on: ${{ matrix.os }}

Expand All @@ -25,33 +25,37 @@ 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
working-directory: ./Lean
run: lake exe klr

# Run pytest
- uses: actions/setup-python@v5
with:
python-version: '3.x'
cache: 'pip'
- name: Install dependencies
working-directory: ./interop
working-directory: ./Python
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run pytest
working-directory: ./interop
working-directory: ./Python
run: |
pytest
- name: Make a wheel
# https://github.com/pypa/cibuildwheel
# Hit this: https://github.com/pypa/cibuildwheel/discussions/1926
env:
# https://github.com/leanprover/lean4/pull/6631/files
MACOSX_DEPLOYMENT_TARGET: 99.0
CIBW_BUILD_VERBOSITY: 1
# CIBW_BUILD: 'cp39-manylinux_x86_64 cp39-macosx_arm64'
run: |
pip install cibuildwheel
bin/make-wheel
- uses: actions/upload-artifact@v4
with:
name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
path: ./wheelhouse/*.whl
path: ./.wheel/wheelhouse/*.whl
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.
12 changes: 9 additions & 3 deletions interop/klr/parser.py → Python/klr/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import json
import numpy as np
import os
import pathlib
import subprocess
import tempfile
import types
Expand All @@ -16,15 +15,22 @@
from textwrap import dedent
from importlib.resources import files

def up(f, n):
d = os.path.dirname(f)
for _ in range(n):
d = os.path.dirname(d)
return d


def run_klr(infile, outfile):
# For development, pick up the klr binary from the project dir
project_root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
project_root = up(os.path.abspath(__file__), 2)
bin = project_root + '/bin/klr'
if not os.path.isfile(bin):
# For regular pip users, pick up the klr from the wheel. While the type of `bin` here is
# PosixPath rather than string, they both work as the first argument to subprocess.run
bin = files('klr').joinpath('bin/klr')
#bin = files('klr').joinpath('bin/klr')
raise Exception("no file: " + bin)
subprocess.run([bin, 'parse-json', infile.name], stdout=outfile, check=True)


Expand Down
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.
2 changes: 1 addition & 1 deletion bin/klr
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

ROOT=$(dirname $(dirname $(readlink -f $0)))

$ROOT/.lake/build/bin/klr $@
$ROOT/Lean/.lake/build/bin/klr $@
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 620775a

Please sign in to comment.