-
Notifications
You must be signed in to change notification settings - Fork 108
kernel-builder: ensure that HIP_ARCHITECTURES gets properly cleared
#684
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
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| --- | ||
| library_name: kernels | ||
| {% if license %}license: {{ license }} | ||
| {% endif %}--- | ||
|
|
||
| This is the repository card of {{ repo_id }} that has been pushed on the Hub. It was built to be used with the [`kernels` library](https://github.com/huggingface/kernels). This card was automatically generated. | ||
|
|
||
| ## How to use | ||
| {% if functions %} | ||
|
|
||
| ```python | ||
| # make sure `kernels` is installed: `pip install -U kernels` | ||
| from kernels import get_kernel | ||
|
|
||
| kernel_module = get_kernel("{{ repo_id }}", version={{ version }}) | ||
| {{ functions[0] }} = kernel_module.{{ functions[0] }} | ||
|
|
||
| {{ functions[0] }}(...) | ||
| ``` | ||
| {% else %} | ||
|
|
||
| Usage example not available. | ||
| {% endif %} | ||
|
|
||
| ## Available functions | ||
| {% if functions %} | ||
| {% for func in functions %} | ||
| - `{{ func }}` | ||
| {% endfor %} | ||
| {% else %} | ||
|
|
||
| Function list not available. | ||
| {% endif %} | ||
| {% if layers %} | ||
|
|
||
| ## Available layers | ||
| {% for layer in layers %} | ||
| - `{{ layer }}` | ||
| {% endfor %} | ||
| {% endif %} | ||
|
|
||
| ## Benchmarks | ||
| {% if has_benchmark %} | ||
|
|
||
| Benchmarking script is available for this kernel. Run `kernels benchmark {{ repo_id }} --version {{ version }}`. | ||
| {% else %} | ||
|
|
||
| No benchmark available yet. | ||
| {% endif %} | ||
| {% if upstream %} | ||
|
|
||
| ## Upstream | ||
|
|
||
| The original source code for this kernel comes from {{ upstream }}. | ||
| {% endif %} | ||
| {% if source %} | ||
|
|
||
| ## Source | ||
|
|
||
| The kernel-builder formatted source for this kernel is available at {{ source }}. | ||
| {% endif %} |
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,45 @@ | ||
| [general] | ||
| name = "relu-archs-subset" | ||
| version = 1 | ||
| license = "Apache-2.0" | ||
| backends = [ | ||
| "cuda", | ||
| "rocm", | ||
| ] | ||
|
|
||
| [general.hub] | ||
| repo-id = "kernels-test/relu-archs-subset" | ||
|
|
||
| [torch] | ||
| src = [ | ||
| "torch-ext/torch_binding.cpp", | ||
| "torch-ext/torch_binding.h", | ||
| ] | ||
|
|
||
| # The capability/architecture sets below intentionally contain entries that | ||
| # are not supported by the toolchain versions used in CI (e.g. CUDA 10.0/12.0 | ||
| # capabilities require CUDA >= 12.8, gfx940 is not in the supported arch set). | ||
| # CI checks that the built kernels contain exactly the intersection with the | ||
| # supported sets. | ||
|
|
||
| [kernel.relu_rocm] | ||
| backend = "rocm" | ||
| depends = ["torch"] | ||
| rocm-archs = [ | ||
| "gfx90a", | ||
| "gfx940", | ||
| "gfx942", | ||
| "gfx1100", | ||
| ] | ||
| src = ["relu_cuda/relu.cu"] | ||
|
|
||
| [kernel.relu] | ||
| backend = "cuda" | ||
| depends = ["torch"] | ||
| cuda-capabilities = [ | ||
| "5.0", | ||
| "7.5", | ||
| "8.0", | ||
| "9.0", | ||
| ] | ||
| src = ["relu_cuda/relu.cu"] | ||
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,17 @@ | ||
| { | ||
| description = "Flake for ReLU kernel with a subset of CUDA/ROCm archs"; | ||
|
|
||
| inputs = { | ||
| kernel-builder.url = "path:../../.."; | ||
| }; | ||
|
|
||
| outputs = | ||
| { | ||
| self, | ||
| kernel-builder, | ||
| }: | ||
| kernel-builder.lib.genKernelFlakeOutputs { | ||
| inherit self; | ||
| path = ./.; | ||
| }; | ||
| } |
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,47 @@ | ||
| #include <ATen/cuda/CUDAContext.h> | ||
| #include <c10/cuda/CUDAGuard.h> | ||
| #include <torch/all.h> | ||
|
|
||
| #include <cmath> | ||
|
|
||
| __global__ void relu_kernel(float *__restrict__ out, | ||
| float const *__restrict__ input, const int d) { | ||
| const int64_t token_idx = blockIdx.x; | ||
| for (int64_t idx = threadIdx.x; idx < d; idx += blockDim.x) { | ||
| auto x = input[token_idx * d + idx]; | ||
| out[token_idx * d + idx] = x > 0.0f ? x : 0.0f; | ||
| } | ||
| } | ||
|
|
||
| void relu(torch::Tensor &out, torch::Tensor const &input) { | ||
| TORCH_CHECK(input.device().is_cuda(), "input must be a CUDA tensor"); | ||
| TORCH_CHECK(input.is_contiguous(), "input must be contiguous"); | ||
| TORCH_CHECK(input.scalar_type() == at::ScalarType::Float && | ||
| input.scalar_type() == at::ScalarType::Float, | ||
| "relu_kernel only supports float32"); | ||
|
|
||
| TORCH_CHECK(input.sizes() == out.sizes(), | ||
| "Tensors must have the same shape. Got input shape: ", | ||
| input.sizes(), " and output shape: ", out.sizes()); | ||
|
|
||
| TORCH_CHECK(input.scalar_type() == out.scalar_type(), | ||
| "Tensors must have the same data type. Got input dtype: ", | ||
| input.scalar_type(), " and output dtype: ", out.scalar_type()); | ||
|
|
||
| TORCH_CHECK(input.device() == out.device(), | ||
| "Tensors must be on the same device. Got input device: ", | ||
| input.device(), " and output device: ", out.device()); | ||
|
|
||
| if (input.numel() == 0) { | ||
| return; | ||
| } | ||
|
|
||
| int d = input.size(-1); | ||
| int64_t num_tokens = input.numel() / d; | ||
| dim3 grid(num_tokens); | ||
| dim3 block(std::min(d, 1024)); | ||
| const at::cuda::OptionalCUDAGuard device_guard(device_of(input)); | ||
| const cudaStream_t stream = at::cuda::getCurrentCUDAStream(); | ||
| relu_kernel<<<grid, block, 0, stream>>>(out.data_ptr<float>(), | ||
| input.data_ptr<float>(), d); | ||
| } |
15 changes: 15 additions & 0 deletions
15
examples/kernels/relu-archs-subset/torch-ext/relu_archs_subset/__init__.py
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,15 @@ | ||
| from typing import Optional | ||
|
|
||
| import torch | ||
|
|
||
| from ._ops import ops | ||
|
|
||
|
|
||
| def relu(x: torch.Tensor, out: Optional[torch.Tensor] = None) -> torch.Tensor: | ||
| if out is None: | ||
| out = torch.empty_like(x) | ||
| ops.relu(out, x) | ||
| return out | ||
|
|
||
|
|
||
| __all__ = ["relu"] |
19 changes: 19 additions & 0 deletions
19
examples/kernels/relu-archs-subset/torch-ext/torch_binding.cpp
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,19 @@ | ||
| #include <torch/library.h> | ||
|
|
||
| #include "registration.h" | ||
| #include "torch_binding.h" | ||
|
|
||
| TORCH_LIBRARY_EXPAND(TORCH_EXTENSION_NAME, ops) { | ||
| ops.def("relu(Tensor! out, Tensor input) -> ()"); | ||
| #if defined(CPU_KERNEL) | ||
| ops.impl("relu", torch::kCPU, &relu); | ||
| #elif defined(CUDA_KERNEL) || defined(ROCM_KERNEL) | ||
| ops.impl("relu", torch::kCUDA, &relu); | ||
| #elif defined(METAL_KERNEL) | ||
| ops.impl("relu", torch::kMPS, relu); | ||
| #elif defined(XPU_KERNEL) | ||
| ops.impl("relu", torch::kXPU, &relu); | ||
| #endif | ||
| } | ||
|
|
||
| REGISTER_EXTENSION(TORCH_EXTENSION_NAME) |
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,5 @@ | ||
| #pragma once | ||
|
|
||
| #include <torch/torch.h> | ||
|
|
||
| void relu(torch::Tensor &out, torch::Tensor const &input); |
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
Oops, something went wrong.
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.
Do we reflect this in
build_kernel_rocm.yaml?I think we only test build?
kernels/.github/workflows/build_kernel_rocm.yaml
Lines 40 to 41 in b79face
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.
Builds all the test kernels and these tests fire on builds.