Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ using `pip`:

For more information see the [Getting Started Guide](docs/getting_started.md)

## Development commands

```
# Build the project
lake build

# Re-generate files under interop/KLR
lake build Extract

# Run KLR executable
lake exe klr
```

**Note**: if you are building using Amazon Linux 2, you will probably want to use the [build container](build_container/README.md).

# Interop with Python

The KLR compiler starts with Python code (e.g. NKI kernels), and converts this
Expand Down
8 changes: 8 additions & 0 deletions build_container/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM ubuntu:latest

RUN apt-get update && apt-get install -y curl git && rm -rf /var/lib/apt/lists/*

RUN curl https://elan.lean-lang.org/elan-init.sh -sSf | sh -s -- -y --default-toolchain none
ENV PATH="/root/.elan/bin:${PATH}"

WORKDIR /workspace
31 changes: 31 additions & 0 deletions build_container/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# KLR build container

Amazon Linux 2 (AL2) currently uses an old GLIBC version that is not supported by our Lean toolchain.
We provide a Docker image that can be used for development on AL2 and other unsupported platforms.

## Usage

The project root contains a simple wrapper script, `lakew`. Use `lakew` in place of `lake`:

```
$ ./lakew build
<...>
Build completed successfully (575 jobs).
$ ./lakew exe klr
klr [0.0.12]
KLR is an IR for NKI and other tensor-like languages in Lean.

USAGE:
klr [SUBCOMMAND] [FLAGS]

FLAGS:
-h, --help Prints this message.
--version Prints the version.

SUBCOMMANDS:
compile Compile a NKI kernel
gather Gather Python sources into an AST file
info Display information about a KLR file
trace Trace Python to KLR
list List builtin functions and constants
```
19 changes: 19 additions & 0 deletions build_container/build_container_exec
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
# build_container_exec: run a command inside build container

cd "$(dirname "$0")/.." || exit 1

if ! docker image inspect klr-build &>/dev/null; then
echo "Error: klr-build image not found."
read -p "Build it now? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
docker build -t klr-build build_container/ || exit 1
else
exit 1
fi
fi

# Mount project directory at /workspace so generated sources end up in the right place.
# Override ELAN_HOME and mount it as a volume so we cache Lean toolchains in between invocations.
docker run -it --rm -v "$(pwd):/workspace" -v /tmp/klr-elan:/elan -e ELAN_HOME=/elan -w /workspace klr-build "$@"
8 changes: 8 additions & 0 deletions lakew
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put this in bin with the other tools?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, maybe combine the two scripts

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I left this in the project root so users can write ./lakew in place of lake. I stole this idea from Gradle, which often puts Gradle wrapper scripts at ./gradlew. But if you two agree it should be in bin, then I'll do that and then set up a shell alias on my end.
  2. I originally just had a single script in case there were other commands we would want to run (e.g., pypi publish commands?) so I am inclined to leave the original script there

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, makes sense.

# lakew: lake wrapper
# runs lake inside build container
# see build_container/README.md for additional details

cd "$(dirname "$0")" || exit 1

./build_container/build_container_exec lake "$@"
Loading