diff --git a/csrc/helloworld/README.md b/csrc/helloworld/README.md index 1249fe50b..bd4655b27 100644 --- a/csrc/helloworld/README.md +++ b/csrc/helloworld/README.md @@ -1,5 +1,5 @@ ##### Description of Helloworld -This is an extreme simple example of writing an op on Ascend NPU. +This is an extremely simple example of writing an op on Ascend NPU. A typical op includes two major parts: * Device part which really running device, i.e. NPU diff --git a/docs/developer_guide/contribution_guide.md b/docs/developer_guide/contribution_guide.md index f99be1564..23355fe42 100644 --- a/docs/developer_guide/contribution_guide.md +++ b/docs/developer_guide/contribution_guide.md @@ -2,6 +2,8 @@ Welcome to **SGL-KERNEL-NPU**! We appreciate your interest in contributing. This guide provides a concise overview of how to set up your environment, run tests, build documentation, and open a Pull Request (PR). Whether you’re fixing a small bug or developing a major feature, we encourage following these steps for a smooth contribution process. +**SGL-KERNEL-NPU** is a kernel library for LLM inference engines, which provides optimized compute primitives (including Ascendc and Triton) especially for engines running on NPU. It has been used by [SGLang](https://github.com/sgl-project/sglang). + ## Install SGL-KERNEL-NPU from Source ### Fork and clone the repository @@ -16,42 +18,50 @@ git clone https://github.com//sgl-kernel-npu.git Refer to [Install SGL-KERNEL-NPU from Source](../../python/sgl_kernel_npu/README.md). -## Format code with pre-commit +## Ascend C Kernel Contribution -We use [pre-commit](https://pre-commit.com/) to maintain consistent code style checks. Before pushing your changes, please run: +### Steps to add a new Ascend C kernel: -```bash -pip3 install pre-commit -pre-commit install -pre-commit run --all-files -``` +1. Implement the kernel in [csrc](https://github.com/sgl-project/sgl-kernel-npu/tree/main/csrc). You can start by reading the [helloworld](https://github.com/sgl-project/sgl-kernel-npu/tree/main/csrc/helloworld) kernel, a simple example of adding two bf16 vectors. If you are new to this, the [Ascend C Kernel Development Guide](https://www.hiascend.com/document/detail/zh/CANNCommunityEdition/850alpha001/opdevg/Ascendcopdevg/atlas_ascendc_10_0001.html) could also be helpful. -- **`pre-commit run --all-files`** manually runs all configured checks, applying fixes if possible. If it fails the first time, re-run it to ensure lint errors are fully resolved. Make sure your code passes all checks **before** creating a Pull Request. -- **Do not commit** directly to the `main` branch. Always create a new branch (e.g., `feature/my-new-feature`), push your changes, and open a PR from that branch. +2. Expose the interface in [include/sgl_kernel_npu_ops.h](https://github.com/sgl-project/sgl-kernel-npu/blob/main/include/sgl_kenel_npu_ops.h) -## Run and add unit tests +3. Create torch extension in [pytorch_extensions.cpp](https://github.com/sgl-project/sgl-kernel-npu/blob/main/csrc/pytorch_extensions.cpp) -If you add a new feature or fix a bug, please add corresponding unit tests to ensure coverage and prevent regression. -SGL-KERNEL-NPU uses Python's built-in [unittest](https://docs.python.org/3/library/unittest.html) framework +4. Update [CMakeLists.txt](https://github.com/sgl-project/sgl-kernel-npu/blob/main/csrc/CMakeLists.txt) to include new kernel source -## Write documentations +## Triton Kernel Contribution +Triton kernels are located at [sgl_kernel_npu](https://github.com/sgl-project/sgl-kernel-npu/tree/main/python/sgl_kernel_npu/sgl_kernel_npu) -## Test the accuracy +## Development Tips +- How to write schema: [Schema reference](https://github.com/pytorch/pytorch/blob/main/aten/src/ATen/native/README.md#func) -## Benchmark the speed + ```cpp + // We need def with schema here for torch.compile + m.def("helloworld(Tensor x, Tensor y) -> Tensor"); + m.impl("helloworld", TORCH_FN(sglang::npu_kernel::helloworld)); + ``` +## Run and add unit tests -## Request a review +If you add a new feature or fix a bug, please add corresponding unit tests [test](https://github.com/sgl-project/sgl-kernel-npu/tree/main/tests/python/sgl_kernel_npu) to ensure coverage and prevent regression. +SGL-KERNEL-NPU uses Python's built-in [unittest](https://docs.python.org/3/library/unittest.html) framework. +## Format code with pre-commit -## General code style +We use [pre-commit](https://pre-commit.com/) to maintain consistent code style checks. Before pushing your changes, please run: +```bash +pip3 install pre-commit +pre-commit install +pre-commit run --all-files +``` -## How to update sgl-kernel +- **`pre-commit run --all-files`** manually runs all configured checks, applying fixes if possible. If it fails the first time, re-run it to ensure lint errors are fully resolved. Make sure your code passes all checks **before** creating a Pull Request. +- **Do not commit** directly to the `main` branch. Always create a new branch (e.g., `feature/my-new-feature`), push your changes, and open a PR from that branch. -## Tips for newcomers Thank you for your interest in SGL-KERNEL-NPU. Happy coding!