Skip to content
Merged
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
2 changes: 1 addition & 1 deletion csrc/helloworld/README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
48 changes: 29 additions & 19 deletions docs/developer_guide/contribution_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,42 +18,50 @@ git clone https://github.com/<your_user_name>/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!