Commit 57ab687c authored by Lei Wang's avatar Lei Wang Committed by GitHub
Browse files

[Initialization] Migration of Codebase from Dev Branch into Main (#10)



* Add format.sh script for code formatting and linting

* docs update

* center align the title

* lint fix

* add ignore

* Add .gitignore for 3rdparty directory

* Add requirements-dev.txt, requirements-test.txt, and requirements.txt

* 3rdparty

* Add gemm.h, CMakeLists.txt, _ffi_api.py, __init__.py, runtime.h, reduce.h, loop_partition.h, utils.h, and loop_vectorize.h

* Refactor CMakeLists.txt and include statements

- Update CMakeLists.txt to use a newer version of CMake and add project name
- Remove unnecessary include directories

Fix include paths in layout.cc, codegen.cc, codegen.h, rt_mod.cc, frontend_legalize.cc, inject_pipeline.cc, layout_inference.cc, loop_vectorize.cc, and lower_tile_op.cc

- Update include paths to use relative paths instead of absolute paths

* Update submodule for 3rdparty/tvm

* update

* load dll first

* Refactor CMakeLists.txt and include statements

* Refactor CMakeLists.txt and include statements

* git keep update

* Refactor CMakeLists.txt and include statements

* Refactor CMakeLists.txt and include statements

* refactor code structure

* Update Readme

* CMakeLists Customized

* update readme

* update README

* update readme

* update usage

* with TVM_IMPORT_PYTHON_PATH to handle own tvm build python import

* annotate lower transform global func with `transform` prefix

* Migrate Simplify Pass from tilelang tvm branch

* enhance system environment handling with __init__ and CMake

* Initial commit

* CODE_OF_CONDUCT.md committed

* LICENSE committed

* README.md committed

* SECURITY.md committed

* SUPPORT.md committed

* CODE_OF_CONDUCT Commit

* LICENSE Commit

* SECURITY Commit

* SUPPORT Commit

* Modify Support

* Update README.md

* security ci update

* remove examples

* Update and implement clang-format

* add composable kernel components

* Migrate from latest update

* submodule update

* Test update

* Update License

* Spell check

* lint fix

* add clang-tidy to apply static analysis for c source

* update tilelang examples

* Update Install Docs

* Refactor filetree

* Enhance Install

* conflict resloved

* annotate_version

* Initial Update

* test fix

* install

* Implement setup.py

* lint fix

* Separate Init

* Separate test

* docker file commit

* add logo

* Update Readme and Examples

* update readme

* update logo

* Implement AMD Installation

* Add License

* Update AMD MI300x Benchmark

* update README

* update mi300 benchmark scripts

* update ignore

* enhance build scirpt

* update image

* enhance setup.py to remove duplicated libraries

* remove debug files

* update readme

* update image

* update gemm examples

* update flashattention README

* readme update

* add cmake into requirements

* libinfo fix

* auto update submodule

* lint fix

* Fix AMD Build and Test

* Update check for transpose attribute for CDNA Arch

* typo fix for amd

* Implement Matmul Benchmark

* Refactor Code

* [TypoFix] Fix GEMM Example

* [Docs] Init Linear Attention README

* [TYPO] Typo fix

* [Lint] Lint Fix

* enhance example with intrinsics

* [Enhancement] Improve Buffer Collection during IR Parser

* [Dev] Introduce Current classmethod to get current frame

* submodule update

* fake test pass update

* support thread_extent_api

* code optimize

* Add GEMM function implementation for matrix multiplication

* Update logging format to reflect TileLang in logger messages

* Refactor CMakeLists.txt for improved readability and set default build type to Release

* Support Gemm SS Primitives Implementation

* [README] Upload Tile Language Logo (#5)

* update logo

* Update README.md to enhance formatting and center the title

---------
Co-authored-by: default avatarmicrosoft-github-operations[bot] <55726097+microsoft-github-operations[bot]@users.noreply.github.com>
Co-authored-by: default avatarMicrosoft Open Source <microsoftopensource@users.noreply.github.com>
Co-authored-by: default avatarYu Cheng <yu.cheng@pku.edu.cn>
parent 64f17c2f
#!/usr/bin/env bash
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# Usage:
# # Do work and commit your work.
# # Format files that differ from origin/main.
# bash format.sh
# # Commit changed files with message 'Run yapf and ruff'
#
#
# YAPF + Clang formatter (if installed). This script formats all changed files from the last mergebase.
# You are encouraged to run this locally before pushing changes for review.
# Cause the script to exit if a single command fails
set -eo pipefail
# this stops git rev-parse from failing if we run this from the .git directory
builtin cd "$(dirname "${BASH_SOURCE:-$0}")"
ROOT="$(git rev-parse --show-toplevel)"
builtin cd "$ROOT" || exit 1
YAPF_VERSION=$(yapf --version | awk '{print $2}')
RUFF_VERSION=$(ruff --version | awk '{print $2}')
CODESPELL_VERSION=$(codespell --version)
# # params: tool name, tool version, required version
tool_version_check() {
if [[ $2 != $3 ]]; then
echo "Wrong $1 version installed: $3 is required, not $2."
exit 1
fi
}
tool_version_check "yapf" $YAPF_VERSION "$(grep yapf requirements-dev.txt | cut -d'=' -f3)"
tool_version_check "ruff" $RUFF_VERSION "$(grep "ruff==" requirements-dev.txt | cut -d'=' -f3)"
tool_version_check "codespell" "$CODESPELL_VERSION" "$(grep codespell requirements-dev.txt | cut -d'=' -f3)"
echo 'tile-lang yapf: Check Start'
YAPF_FLAGS=(
'--recursive'
'--parallel'
)
YAPF_EXCLUDES=(
'--exclude' 'build/**'
'--exclude' '3rdparty/**'
)
# Format specified files
format() {
yapf --in-place "${YAPF_FLAGS[@]}" "$@"
}
# Format files that differ from main branch. Ignores dirs that are not slated
# for autoformat yet.
format_changed() {
# The `if` guard ensures that the list of filenames is not empty, which
# could cause yapf to receive 0 positional arguments, making it hang
# waiting for STDIN.
#
# `diff-filter=ACM` and $MERGEBASE is to ensure we only format files that
# exist on both branches.
if git show-ref --verify --quiet refs/remotes/origin/main; then
BASE_BRANCH="origin/main"
else
BASE_BRANCH="main"
fi
MERGEBASE="$(git merge-base $BASE_BRANCH HEAD)"
if ! git diff --diff-filter=ACM --quiet --exit-code "$MERGEBASE" -- '*.py' '*.pyi' &>/dev/null; then
git diff --name-only --diff-filter=ACM "$MERGEBASE" -- '*.py' '*.pyi' | xargs -P 5 \
yapf --in-place "${YAPF_EXCLUDES[@]}" "${YAPF_FLAGS[@]}"
fi
}
# Format all files
format_all() {
yapf --in-place "${YAPF_FLAGS[@]}" "${YAPF_EXCLUDES[@]}" .
}
## This flag formats individual files. --files *must* be the first command line
## arg to use this option.
if [[ "$1" == '--files' ]]; then
format "${@:2}"
# If `--all` is passed, then any further arguments are ignored and the
# entire python directory is formatted.
elif [[ "$1" == '--all' ]]; then
format_all
else
# Format only the files that changed in last commit.
format_changed
fi
echo 'tile-lang yapf: Done'
echo 'tile-lang codespell: Check Start'
# check spelling of specified files
spell_check() {
codespell "$@"
}
spell_check_all(){
codespell --toml pyproject.toml
}
# Spelling check of files that differ from main branch.
spell_check_changed() {
# The `if` guard ensures that the list of filenames is not empty, which
# could cause ruff to receive 0 positional arguments, making it hang
# waiting for STDIN.
#
# `diff-filter=ACM` and $MERGEBASE is to ensure we only lint files that
# exist on both branches.
if git show-ref --verify --quiet refs/remotes/origin/main; then
BASE_BRANCH="origin/main"
else
BASE_BRANCH="main"
fi
MERGEBASE="$(git merge-base $BASE_BRANCH HEAD)"
if ! git diff --diff-filter=ACM --quiet --exit-code "$MERGEBASE" -- '*.py' '*.pyi' &>/dev/null; then
git diff --name-only --diff-filter=ACM "$MERGEBASE" -- '*.py' '*.pyi' | xargs \
codespell
fi
}
# Run Codespell
## This flag runs spell check of individual files. --files *must* be the first command line
## arg to use this option.
if [[ "$1" == '--files' ]]; then
spell_check "${@:2}"
# If `--all` is passed, then any further arguments are ignored and the
# entire python directory is linted.
elif [[ "$1" == '--all' ]]; then
spell_check_all
else
# Check spelling only of the files that changed in last commit.
spell_check_changed
fi
echo 'tile-lang codespell: Done'
echo 'tile-lang ruff: Check Start'
# Lint specified files
lint() {
ruff check "$@"
}
# Lint files that differ from main branch. Ignores dirs that are not slated
# for autolint yet.
lint_changed() {
# The `if` guard ensures that the list of filenames is not empty, which
# could cause ruff to receive 0 positional arguments, making it hang
# waiting for STDIN.
#
# `diff-filter=ACM` and $MERGEBASE is to ensure we only lint files that
# exist on both branches.
if git show-ref --verify --quiet refs/remotes/origin/main; then
BASE_BRANCH="origin/main"
else
BASE_BRANCH="main"
fi
MERGEBASE="$(git merge-base $BASE_BRANCH HEAD)"
if ! git diff --diff-filter=ACM --quiet --exit-code "$MERGEBASE" -- '*.py' '*.pyi' &>/dev/null; then
git diff --name-only --diff-filter=ACM "$MERGEBASE" -- '*.py' '*.pyi' | xargs \
ruff check
fi
}
# Run Ruff
### This flag lints individual files. --files *must* be the first command line
### arg to use this option.
if [[ "$1" == '--files' ]]; then
lint "${@:2}"
# If `--all` is passed, then any further arguments are ignored and the
# entire python directory is linted.
elif [[ "$1" == '--all' ]]; then
lint python testing
else
# Format only the files that changed in last commit.
lint_changed
fi
echo 'tile-lang ruff: Done'
echo 'tile-lang clang-format: Check Start'
# If clang-format is available, run it; otherwise, skip
if command -v clang-format &>/dev/null; then
CLANG_FORMAT_VERSION=$(clang-format --version | awk '{print $3}')
tool_version_check "clang-format" "$CLANG_FORMAT_VERSION" "$(grep clang-format requirements-dev.txt | cut -d'=' -f3)"
CLANG_FORMAT_FLAGS=("-i")
# Apply clang-format to specified files
clang_format() {
clang-format "${CLANG_FORMAT_FLAGS[@]}" "$@"
}
# Format all C/C++ files in the repo, excluding specified directories
clang_format_all() {
find . -type f \( -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.h' -o -name '*.hpp' \) \
-not -path "./3rdparty/*" \
-not -path "./build/*" \
-exec clang-format -i {} +
}
# Format changed C/C++ files relative to main
clang_format_changed() {
if git show-ref --verify --quiet refs/remotes/origin/main; then
BASE_BRANCH="origin/main"
else
BASE_BRANCH="main"
fi
MERGEBASE="$(git merge-base $BASE_BRANCH HEAD)"
if ! git diff --diff-filter=ACM --quiet --exit-code "$MERGEBASE" -- '*.c' '*.cc' '*.cpp' '*.h' '*.hpp' &>/dev/null; then
git diff --name-only --diff-filter=ACM "$MERGEBASE" -- '*.c' '*.cc' '*.cpp' '*.h' '*.hpp' | xargs clang-format -i
fi
}
if [[ "$1" == '--files' ]]; then
# If --files is given, format only the provided files
clang_format "${@:2}"
elif [[ "$1" == '--all' ]]; then
# If --all is given, format all eligible C/C++ files
clang_format_all
else
# Otherwise, format only changed C/C++ files
clang_format_changed
fi
else
echo "clang-format not found. Skipping C/C++ formatting."
fi
echo 'tile-lang clang-format: Done'
# Check if there are any uncommitted changes after all formatting steps.
# If there are, ask the user to review and stage them.
if ! git diff --quiet &>/dev/null; then
echo 'Reformatted files. Please review and stage the changes.'
echo 'Changes not staged for commit:'
echo
git --no-pager diff --name-only
exit 1
fi
# Check if clang-tidy is installed and get the version
if command -v clang-tidy &>/dev/null; then
CLANG_TIDY_VERSION=$(clang-tidy --version | head -n 1 | awk '{print $3}')
tool_version_check "clang-tidy" "$CLANG_TIDY_VERSION" "$(grep clang-tidy requirements-dev.txt | cut -d'=' -f3)"
else
echo "clang-tidy not found. Skipping C++ static analysis."
CLANG_TIDY_AVAILABLE=false
fi
# Function to run clang-tidy
clang_tidy() {
clang-tidy "$@" -- -std=c++17
}
# Run clang-tidy on all C/C++ files
clang_tidy_all() {
find . -type f \( -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.h' -o -name '*.hpp' \) \
-not -path "./3rdparty/*" -not -path "./build/*" \
| xargs -n 1 clang-tidy -- -std=c++17
}
# Run clang-tidy on changed C/C++ files relative to main
clang_tidy_changed() {
if git show-ref --verify --quiet refs/remotes/origin/main; then
BASE_BRANCH="origin/main"
else
BASE_BRANCH="main"
fi
MERGEBASE="$(git merge-base $BASE_BRANCH HEAD)"
if ! git diff --diff-filter=ACM --quiet --exit-code "$MERGEBASE" -- '*.c' '*.cc' '*.cpp' '*.h' '*.hpp' &>/dev/null; then
git diff --name-only --diff-filter=ACM "$MERGEBASE" -- '*.c' '*.cc' '*.cpp' '*.h' '*.hpp' | xargs -n 1 clang-tidy -- -std=c++17
fi
}
# Add clang-tidy support to the main script logic
echo 'tile-lang clang-tidy: Check Start'
if [[ "$CLANG_TIDY_AVAILABLE" != false ]]; then
if [[ "$1" == '--files' ]]; then
# If --files is given, analyze only the provided files
clang_tidy "${@:2}"
elif [[ "$1" == '--all' ]]; then
# If --all is given, analyze all eligible C/C++ files
clang_tidy_all
else
# Otherwise, analyze only changed C/C++ files
clang_tidy_changed
fi
else
echo "clang-tidy is not available. Skipping static analysis."
fi
echo 'tile-lang clang-tidy: Done'
if ! git diff --quiet &>/dev/null; then
echo 'Reformatted files. Please review and stage the changes.'
echo 'Changes not staged for commit:'
echo
git --no-pager diff --name-only
exit 1
fi
echo 'tile-lang: All checks passed'
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
#!/bin/bash
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
echo "Starting installation script..."
# Step 1: Install Python requirements
echo "Installing Python requirements from requirements.txt..."
pip install -r requirements.txt
if [ $? -ne 0 ]; then
echo "Error: Failed to install Python requirements."
exit 1
else
echo "Python requirements installed successfully."
fi
# Step 2: Define LLVM version and architecture
LLVM_VERSION="10.0.1"
IS_AARCH64=false
EXTRACT_PATH="3rdparty"
echo "LLVM version set to ${LLVM_VERSION}."
echo "Is AARCH64 architecture: $IS_AARCH64"
# Step 3: Determine the correct Ubuntu version based on LLVM version
UBUNTU_VERSION="16.04"
if [[ "$LLVM_VERSION" > "17.0.0" ]]; then
UBUNTU_VERSION="22.04"
elif [[ "$LLVM_VERSION" > "16.0.0" ]]; then
UBUNTU_VERSION="20.04"
elif [[ "$LLVM_VERSION" > "13.0.0" ]]; then
UBUNTU_VERSION="18.04"
fi
echo "Ubuntu version for LLVM set to ${UBUNTU_VERSION}."
# Step 4: Set download URL and file name for LLVM
BASE_URL="https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}"
if $IS_AARCH64; then
FILE_NAME="clang+llvm-${LLVM_VERSION}-aarch64-linux-gnu.tar.xz"
else
FILE_NAME="clang+llvm-${LLVM_VERSION}-x86_64-linux-gnu-ubuntu-${UBUNTU_VERSION}.tar.xz"
fi
DOWNLOAD_URL="${BASE_URL}/${FILE_NAME}"
echo "Download URL for LLVM: ${DOWNLOAD_URL}"
# Step 5: Create extraction directory
echo "Creating extraction directory at ${EXTRACT_PATH}..."
mkdir -p "$EXTRACT_PATH"
if [ $? -ne 0 ]; then
echo "Error: Failed to create extraction directory."
exit 1
else
echo "Extraction directory created successfully."
fi
# Step 6: Download LLVM
echo "Downloading $FILE_NAME from $DOWNLOAD_URL..."
curl -L -o "${EXTRACT_PATH}/${FILE_NAME}" "$DOWNLOAD_URL"
if [ $? -ne 0 ]; then
echo "Error: Download failed!"
exit 1
else
echo "Download completed successfully."
fi
# Step 7: Extract LLVM
echo "Extracting $FILE_NAME to $EXTRACT_PATH..."
tar -xJf "${EXTRACT_PATH}/${FILE_NAME}" -C "$EXTRACT_PATH"
if [ $? -ne 0 ]; then
echo "Error: Extraction failed!"
exit 1
else
echo "Extraction completed successfully."
fi
# Step 8: Determine LLVM config path
LLVM_CONFIG_PATH="$(realpath ${EXTRACT_PATH}/$(basename ${FILE_NAME} .tar.xz)/bin/llvm-config)"
echo "LLVM config path determined as: $LLVM_CONFIG_PATH"
# Step 9: Clone and build TVM
echo "Cloning TVM repository and initializing submodules..."
# clone and build tvm
git submodule update --init --recursive
if [ -d build ]; then
rm -rf build
fi
mkdir build
cp 3rdparty/tvm/cmake/config.cmake build
cd build
echo "Configuring TVM build with LLVM and CUDA paths..."
echo "set(USE_LLVM $LLVM_CONFIG_PATH)" >> config.cmake && echo "set(USE_CUDA /usr/local/cuda)" >> config.cmake
echo "Running CMake for TileLang..."
cmake ..
if [ $? -ne 0 ]; then
echo "Error: CMake configuration failed."
exit 1
fi
echo "Building TileLang with make..."
make -j
if [ $? -ne 0 ]; then
echo "Error: TileLang build failed."
exit 1
else
echo "TileLang build completed successfully."
fi
cd ../../..
# Step 11: Set environment variables
echo "Configuring environment variables for TVM..."
echo "export PYTHONPATH=$(pwd):\$PYTHONPATH" >> ~/.bashrc
echo "export CUDA_DEVICE_ORDER=PCI_BUS_ID" >> ~/.bashrc
# Step 12: Source .bashrc to apply changes
echo "Applying environment changes by sourcing .bashrc..."
source ~/.bashrc
if [ $? -ne 0 ]; then
echo "Error: Failed to source .bashrc."
exit 1
else
echo "Environment configured successfully."
fi
echo "Installation script completed successfully."
#!/bin/bash
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# install requirements
pip install -r requirements.txt
# determine if root
USER_IS_ROOT=false
if [ "$EUID" -eq 0 ]; then
USER_IS_ROOT=true
fi
if $USER_IS_ROOT; then
# Fetch the GPG key for the LLVM repository and add it to the trusted keys
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
# Check if the repository is already present in the sources.list
if ! grep -q "http://apt.llvm.org/focal/ llvm-toolchain-focal-16 main" /etc/apt/sources.list; then
# Add the LLVM repository to sources.list
echo "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-16 main" >> /etc/apt/sources.list
echo "deb-src http://apt.llvm.org/focal/ llvm-toolchain-focal-16 main" >> /etc/apt/sources.list
else
# Print a message if the repository is already added
echo "The repository is already added."
fi
# Update package lists and install llvm-16
apt-get update
apt-get install -y llvm-16
else
# Fetch the GPG key for the LLVM repository and add it to the trusted keys using sudo
wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc
# Check if the repository is already present in the sources.list
if ! grep -q "http://apt.llvm.org/focal/ llvm-toolchain-focal-16 main" /etc/apt/sources.list; then
# Add the LLVM repository to sources.list using sudo
echo "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-16 main" | sudo tee -a /etc/apt/sources.list
echo "deb-src http://apt.llvm.org/focal/ llvm-toolchain-focal-16 main" | sudo tee -a /etc/apt/sources.list
else
# Print a message if the repository is already added
echo "The repository is already added."
fi
# Update package lists and install llvm-16 using sudo
sudo apt-get update
sudo apt-get install -y llvm-16
fi
# Step 9: Clone and build TVM
echo "Cloning TVM repository and initializing submodules..."
# clone and build tvm
git submodule update --init --recursive
if [ -d build ]; then
rm -rf build
fi
mkdir build
cp 3rdparty/tvm/cmake/config.cmake build
cd build
echo "Configuring TVM build with LLVM and CUDA paths..."
echo "set(USE_LLVM $LLVM_CONFIG_PATH)" >> config.cmake && echo "set(USE_ROCM /opt/rocm)" >> config.cmake
echo "Running CMake for TileLang..."
cmake ..
if [ $? -ne 0 ]; then
echo "Error: CMake configuration failed."
exit 1
fi
echo "Building TileLang with make..."
make -j
if [ $? -ne 0 ]; then
echo "Error: TileLang build failed."
exit 1
else
echo "TileLang build completed successfully."
fi
cd ../../..
# Define the lines to be added
TVM_HOME_ENV="export TVM_HOME=$(pwd)/3rdparty/tvm"
TILELANG_PYPATH_ENV="export PYTHONPATH=\$TVM_HOME/python:$(pwd):\$PYTHONPATH"
CUDA_DEVICE_ORDER_ENV="export CUDA_DEVICE_ORDER=PCI_BUS_ID"
# Check and add the first line if not already present
if ! grep -qxF "$TVM_HOME_ENV" ~/.bashrc; then
echo "$TVM_HOME_ENV" >> ~/.bashrc
echo "Added TVM_HOME to ~/.bashrc"
else
echo "TVM_HOME is already set in ~/.bashrc"
fi
# Check and add the second line if not already present
if ! grep -qxF "$TILELANG_PYPATH_ENV" ~/.bashrc; then
echo "$TILELANG_PYPATH_ENV" >> ~/.bashrc
echo "Added PYTHONPATH to ~/.bashrc"
else
echo "PYTHONPATH is already set in ~/.bashrc"
fi
# Check and add the third line if not already present
if ! grep -qxF "$CUDA_DEVICE_ORDER_ENV" ~/.bashrc; then
echo "$CUDA_DEVICE_ORDER_ENV" >> ~/.bashrc
echo "Added CUDA_DEVICE_ORDER to ~/.bashrc"
else
echo "CUDA_DEVICE_ORDER is already set in ~/.bashrc"
fi
# Reload ~/.bashrc to apply the changes
source ~/.bashrc
echo "Installation script completed successfully."
#!/bin/bash
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
echo "Add MIT license boilerplate..."
PWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# TO source code root
pushd "${PWD}/../../" > /dev/null
EXITCODE=0
for SRC_FILE in $(find . -path './3rdparty' -prune -false -o -path './build' -prune -false -o -type f -not -name \
'*apply_mit_liscense.sh' -not -name '*check_mit_liscense.sh' -and \( -name '*.cpp' -or -name '*.h*' -or -name '*.cu' -or -name '*.in' \) ); do
sed -i '/\/\/\s*Microsoft\s*(c)/Id' ${SRC_FILE}
if !(grep -q "Copyright (c) Microsoft Corporation." "${SRC_FILE}"); then
cat maint/scripts/mit_liscense1.txt ${SRC_FILE} > ${SRC_FILE}.new
mv ${SRC_FILE}.new ${SRC_FILE}
fi
done
for SRC_FILE in $(find . -path './3rdparty' -prune -false -o -path './build' -prune -false -o -type f -not -name \
'*apply_mit_liscense.sh' -not -name '*check_mit_liscense.sh' -and \( -name 'CMakeLists.txt' -or -name '*.cmake' \
-or -name '*.py' -or -name '*.dockerfile' -or -name '*.yaml' \) ); do
sed -i '/\#\s*Microsoft\s*(c)/Id' ${SRC_FILE}
if !(grep -q "Copyright (c) Microsoft Corporation" "${SRC_FILE}"); then
cat maint/scripts/mit_liscense2.txt ${SRC_FILE} > ${SRC_FILE}.new
mv ${SRC_FILE}.new ${SRC_FILE}
fi
done
for SRC_FILE in $(find . -path './3rdparty' -prune -false -o -path './build' -prune -false -o -type f -not -name \
'*apply_mit_liscense.sh' -not -name '*check_mit_liscense.sh' -name '*.sh' ); do
sed -i '/\#\s*Microsoft\s*(c)/Id' ${SRC_FILE}
if !(grep -q "Copyright (c) Microsoft Corporation" "${SRC_FILE}"); then
line=$(head -n 1 ${SRC_FILE})
if [[ $line == "#!/bin/bash"* ]]; then
(echo ${line}; echo ''; cat maint/scripts/mit_liscense2.txt; echo "$(tail -n +2 "${SRC_FILE}")" ) > ${SRC_FILE}.new
else
cat maint/scripts/mit_liscense2.txt ${SRC_FILE} > ${SRC_FILE}.new
fi
mv ${SRC_FILE}.new ${SRC_FILE}
fi
done
echo "Done."
popd > /dev/null
exit $EXITCODE
#!/bin/bash
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
echo "Check MIT License boilerplate..."
PWD="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# To source code root
pushd "${PWD}/../../" > /dev/null
EXITCODE=0
for SRC_FILE in $(find . -path './3rdparty' -prune -false -o -path './build' -prune -false -o -type f -not -name '*apply_mit_license.sh' \
-not -name '*check_mit_license.sh' -and \( -name 'CMakeLists.txt' -or -name '*.cpp' -or -name '*.cu' -or -name '*.h' -or -name '*.hpp' \
-or -name '*.py' -or -name '*.sh' -or -name '*.dockerfile' -or -name '*.yaml' \) ); do
# Skip files that already contain the Apache License
if grep -q "Apache License" "${SRC_FILE}"; then
continue
fi
if !(grep -q "Copyright (c) Microsoft Corporation." "${SRC_FILE}") || !(grep -q "Licensed under the MIT License." "${SRC_FILE}") \
|| (grep -q -i -P "Microsoft( |)\(c\)" "${SRC_FILE}"); then
echo "[ERROR] Require: MIT License boilerplate" "${SRC_FILE}"
EXITCODE=1
fi
done
echo "Done."
popd > /dev/null
exit $EXITCODE
#!/bin/bash
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# if dist and build directories exist, remove them
if [ -d dist ]; then
rm -r dist
fi
python -m build --wheel -o dist
if [ $? -ne 0 ]; then
echo "Error: Failed to build the wheel."
exit 1
else
echo "Wheel built successfully."
fi
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
#!/bin/bash
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# if dist and build directories exist, remove them
if [ -d dist ]; then
rm -r dist
fi
if [ -d build ]; then
rm -r build
fi
PYPI_BUILD=TRUE python setup.py bdist_wheel --plat-name=manylinux1_x86_64
[build-system]
requires = [
"cmake>=3.26",
"packaging",
"setuptools>=61",
"setuptools-scm>=8.0",
"wheel",
]
build-backend = "setuptools.build_meta"
[tool.yapf]
based_on_style = "yapf"
column_limit = 100
indent_width = 4
[tool.codespell]
ignore-words-list = "nd, te, ist, LOD, offen"
skip = [
"build",
"3rdparty",
"dist",
".venv"
]
[tool.ruff.lint]
select = [
# pycodestyle
"E",
# Pyflakes
"F",
# pyupgrade
# "UP",
# flake8-bugbear
"B",
# flake8-simplify
"SIM",
# isort
# "I",
]
ignore = [
# Module level import not at top of file
"E402",
# star imports
"F405", "F403",
# ambiguous name
"E741",
# line too long
"E501",
# key in dict.keys()
"SIM118",
# memory leaks
"B019",
# No such file or directory
"E902",
]
# formatting
yapf==0.40.2
toml==0.10.2
tomli==2.0.1
ruff==0.6.5
codespell==2.3.0
clang-format==15.0.7
# build requirements
cmake>=3.26
# runtime requirements
cffi
cpplint
Cython
decorator
docutils
dtlib
numpy>=1.23.5
pytest>=6.2.4
pytest_xdist>=2.2.1
packaging>=21.0
PyYAML
tqdm>=4.62.3
typing_extensions>=4.10.0
requests
attrs
cloudpickle
ml_dtypes
psutil
scipy
tornado
torch
thefuzz
tabulate
wheel
setuptools
# formatting
yapf==0.40.2
toml==0.10.2
tomli==2.0.1
ruff==0.6.5
codespell==2.3.0
clang-format==15.0.7
# build requirements
cmake>=3.26
# runtime requirements
cffi
cpplint
Cython
decorator
docutils
dtlib
numpy>=1.23.5
pytest>=6.2.4
pytest_xdist>=2.2.1
packaging>=21.0
PyYAML
tqdm>=4.62.3
typing_extensions>=4.10.0
requests
attrs
cloudpickle
ml_dtypes
psutil
scipy
tornado
torch
thefuzz
tabulate
wheel
setuptools
This diff is collapsed.
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
/*!
* \file tl/ir.cc
* \brief Extension for the tvm script frontend.
*
*/
#include <tvm/script/ir_builder/tir/ir.h>
namespace tvm {
namespace tl {
using namespace script::ir_builder::tir;
ForFrame ParallelFor(Array<PrimExpr> extents,
Map<String, ObjectRef> annotations) {
using namespace tvm::tir;
ObjectPtr<ForFrameNode> n = make_object<ForFrameNode>();
n->vars.reserve(extents.size());
n->doms.reserve(extents.size());
for (const auto &extent : extents) {
DataType dtype = extent.dtype();
n->vars.push_back(Var("v", extent.dtype()));
n->doms.push_back(Range(make_const(dtype, 0), extent));
}
n->f_make_for_loop = [annotations](Array<Var> vars, Array<Range> doms,
Stmt body) -> Stmt {
ICHECK_EQ(vars.size(), doms.size());
int n = vars.size();
for (int i = n - 1; i >= 0; --i) {
Range dom = doms[i];
Var var = vars[i];
body =
For(var, dom->min, dom->extent, ForKind::kParallel, std::move(body),
/*thread_binding=*/NullOpt, /*annotations=*/annotations);
}
return body;
};
return ForFrame(n);
}
ForFrame PipelinedFor(PrimExpr start, PrimExpr stop, int num_stages,
Array<PrimExpr> order, Array<PrimExpr> stages,
Array<Array<PrimExpr>> sync,
Array<Array<PrimExpr>> groups) {
using namespace tvm::tir;
ObjectPtr<ForFrameNode> n = make_object<ForFrameNode>();
DataType dtype = stop.dtype();
n->vars.push_back(Var("v", dtype));
n->doms.push_back(Range(start, stop));
n->f_make_for_loop = [=](Array<Var> vars, Array<Range> doms,
Stmt body) -> Stmt {
ICHECK_EQ(vars.size(), doms.size());
int n = vars.size();
ICHECK(n == 1);
Map<String, ObjectRef> anno;
if (num_stages > 0)
anno.Set("num_stages", PrimExpr(num_stages));
if (order.size() > 0)
anno.Set("tl_pipeline_order", order);
if (stages.size() > 0)
anno.Set("tl_pipeline_stage", stages);
if (sync.size() > 0)
anno.Set("tl_pipeline_sync", sync);
if (groups.size() > 0)
anno.Set("tl_pipeline_group", groups);
body = For(vars[0], doms[0]->min, doms[0]->extent, ForKind::kSerial,
std::move(body),
/*thread_binding=*/NullOpt, /*annotations=*/anno);
return body;
};
return ForFrame(n);
}
/*!
* \brief A frame that represents a kernel launch.
*
* \sa KernelLaunchFrameNode
*/
class KernelLaunchFrameNode : public TIRFrameNode {
public:
Array<TIRFrame> frames;
void VisitAttrs(tvm::AttrVisitor *v) {
TIRFrameNode::VisitAttrs(v);
v->Visit("frames", &frames);
}
static constexpr const char *_type_key = "tl.KernelLaunchFrame";
TVM_DECLARE_FINAL_OBJECT_INFO(KernelLaunchFrameNode, TIRFrameNode);
public:
TVM_DLL void EnterWithScope() final {
for (auto frame = frames.begin(); frame != frames.end(); ++frame)
(*frame)->EnterWithScope();
}
/*!
* \brief The method called when exiting RAII scope.
* \sa tvm::support::With
*/
TVM_DLL void ExitWithScope() final {
for (auto frame = frames.rbegin(); frame != frames.rend(); ++frame)
(*frame)->ExitWithScope();
}
};
/*!
* \brief Managed reference to KernelLaunchFrameNode.
*
* \sa KernelLaunchFrameNode
*/
class KernelLaunchFrame : public TIRFrame {
public:
TVM_DEFINE_MUTABLE_NOTNULLABLE_OBJECT_REF_METHODS(KernelLaunchFrame, TIRFrame,
KernelLaunchFrameNode);
};
KernelLaunchFrame KernelLaunch(Array<PrimExpr> grid_size,
Array<PrimExpr> block_size,
Map<String, ObjectRef> attrs) {
ObjectPtr<KernelLaunchFrameNode> n = make_object<KernelLaunchFrameNode>();
ICHECK(grid_size.size() <= 3);
if (grid_size.size() > 0)
n->frames.push_back(LaunchThread("blockIdx.x", grid_size[0]));
if (grid_size.size() > 1)
n->frames.push_back(LaunchThread("blockIdx.y", grid_size[1]));
if (grid_size.size() > 2)
n->frames.push_back(LaunchThread("blockIdx.z", grid_size[2]));
if (block_size.defined()) {
ICHECK(block_size.size() <= 3);
if (block_size.size() > 0)
n->frames.push_back(LaunchThread("threadIdx.x", block_size[0]));
if (block_size.size() > 1)
n->frames.push_back(LaunchThread("threadIdx.y", block_size[1]));
if (block_size.size() > 2)
n->frames.push_back(LaunchThread("threadIdx.z", block_size[2]));
} else {
n->frames.push_back(Block(""));
}
if (attrs.defined()) {
auto empty_block = Block("");
empty_block->annotations = attrs;
n->frames.push_back(empty_block);
} else {
n->frames.push_back(Block(""));
}
return KernelLaunchFrame(n);
}
TVM_REGISTER_NODE_TYPE(KernelLaunchFrameNode);
TVM_REGISTER_GLOBAL("tl.Parallel").set_body_typed(ParallelFor);
TVM_REGISTER_GLOBAL("tl.Pipelined").set_body_typed(PipelinedFor);
TVM_REGISTER_GLOBAL("tl.KernelLaunch").set_body_typed(KernelLaunch);
} // namespace tl
} // namespace tvm
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment