-
Notifications
You must be signed in to change notification settings - Fork 17
CUDA kernel registration supports #198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
fd9109c
add loadinline to support cuda kernel
jiannanWang 93e5d4c
update
jiannanWang e896275
Merge branch 'main' into jiannanwang/loadinline
jiannanWang 4a8d599
solve conflict
jiannanWang b5f441d
Merge branch 'main' into jiannanwang/loadinline
jiannanWang 222a7fd
ruff
jiannanWang d7f8074
fix
jiannanWang d1c8649
fix
jiannanWang 334a39e
add ninja to ci
jiannanWang 08b7054
set CUDA_HOME
jiannanWang 44a427b
add skip
jiannanWang 1cf7b4d
fix
jiannanWang 401473e
add no_implicit_headers
jiannanWang 39eb648
test
jiannanWang e417006
test cuda version
jiannanWang e65f8e9
update
jiannanWang 945353d
install cuda toolkit in ci
jiannanWang c35add9
install cuda toolkit in ci
jiannanWang e99eb6a
install cuda toolkit in ci
jiannanWang 05fe3b8
fix
jiannanWang 734c933
fix
jiannanWang 42fbe36
fix
jiannanWang f75fbaf
skip cuda testing in CI since no CUDA_HOME
jiannanWang c2f179d
merge
jiannanWang 27af6f5
find cuda path
jiannanWang 4f95593
install cuda toolkit
jiannanWang eb594ae
install cuda toolkit 12.8
jiannanWang 50e99c3
fix
jiannanWang ee2c8c0
generate cpp source from cu source
jiannanWang 6d74881
add comment
jiannanWang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| # Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| # All rights reserved. | ||
| # | ||
| # This source code is licensed under the BSD 3-Clause license found in the | ||
| # LICENSE file in the root directory of this source tree. | ||
|
|
||
| """ | ||
| Create simple kernel implementations for 5 common operations. | ||
| Each just calls the original PyTorch function. | ||
| """ | ||
|
|
||
| import argparse | ||
| import logging | ||
| import os | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def create_add(base_dir): | ||
| os.makedirs(f"{base_dir}/add__Tensor", exist_ok=True) | ||
| with open(f"{base_dir}/add__Tensor/add__Tensor_implementation_v1.cu", "w") as f: | ||
| f.write("""#include <torch/extension.h> | ||
| #include <ATen/cuda/CUDAContext.h> | ||
|
|
||
| __global__ void add__Tensor_kernel( | ||
| const float* __restrict__ x, | ||
| const float* __restrict__ y, | ||
| float* __restrict__ output, | ||
| const int size) { | ||
| const auto index = blockIdx.x * blockDim.x + threadIdx.x; | ||
| if (index < size) { | ||
| output[index] = x[index] + y[index]; | ||
| } | ||
| } | ||
|
|
||
| at::Tensor add__Tensor(const at::Tensor& a, const at::Tensor& b) { | ||
| auto out = at::empty_like(a); | ||
| int64_t numel = a.numel(); | ||
| const int threads = 256; | ||
| const int blocks = (numel + threads - 1) / threads; | ||
| add__Tensor_kernel<<<blocks, threads, 0, c10::cuda::getCurrentCUDAStream()>>>( | ||
| a.data_ptr<float>(), b.data_ptr<float>(), out.data_ptr<float>(), numel | ||
| ); | ||
| return out; | ||
| } | ||
| """) | ||
| logger.info("Created add implementation") | ||
|
|
||
|
|
||
| def main(): | ||
| """Create 1 simple test operations.""" | ||
| parser = argparse.ArgumentParser(description="Creating cuda kernel implementations for testing") | ||
| parser.add_argument( | ||
| "--base-dir", | ||
| default="generated_kernels", | ||
| help="Base directory containing operator subdirectories", | ||
| ) | ||
|
|
||
| args = parser.parse_args() | ||
|
|
||
| create_add(args.base_dir) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ dependencies = [ | |
| "pandas", | ||
| "datasets", | ||
| "tenacity", | ||
| "ninja", | ||
| "nvidia-cutlass-dsl", | ||
| ] | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if we can simplify this a a bit and only make the LLM spit out the .cu file - the cpp file should typically be quite simple for us to provide. see this as an example https://github.com/gpu-mode/reference-kernels/blob/main/problems/pmpp/vectoradd_py/solutions/correct/submission_cuda_inline.py#L48
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Solved! Added a new parameter load_cpp_source which by default set to false. It controls whether to load cpp source from the .cpp file (load_cpp_source=true) or to generate the cpp source content from the cuda source (oad_cpp_source=false)