-
Notifications
You must be signed in to change notification settings - Fork 3
feat(ascend): add Ascend framework layer — runtime, type mapping, bui… #46
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
19 commits
Select commit
Hold shift + click to select a range
1cc2e35
feat(ascend): add Ascend framework layer — runtime, type mapping, bui…
44d681a
style(ascend): apply `clang-format` to framework headers
d091275
fix(ascend): adapt `Memcpy`/`Memset` arity, assert workspace alloc, r…
11602fa
feat(ascend): add GEMM kernel, NPU test infra, and example integration
ff03814
fix(ascend): move `aclrtMalloc` out of `assert()` in `WorkspacePool`
1ccadc0
fix(nvidia): restore `CUDA::cublasLt` link dependency
2fa9e13
feat(test): add `--devices` option to pytest for platform-name filtering
cb46b57
fix(nvidia): add missing include and work around NVCC `std::forward` bug
4462b6e
fix(ci): upgrade NVIDIA CI image to 25.12 and restore `std::forward`
zhangyue207 40b5858
fix: add explicit narrowing casts in `RotaryEmbedding` initializer list
c1816eb
style: fix lint issues from PR review
1f5e0ef
style: fix lint issues in `feat/ascend-framework`
9a5a5f1
fix: address PR #46 review feedback
2cb185b
docs(base): add vLLM interface references to `FlashAttention`, `Resha…
41d67c0
fix(base): rename matmul.h to mat_mul.h to match MatMul class name
85ef359
fix(nvidia): revert std::forward workaround for NVCC 12.6 bug
7398f9f
Revert "fix(nvidia): revert std::forward workaround for NVCC 12.6 bug"
978f948
style: remove extra blank line in `conftest.py`
voltjia 2f5acb4
docs: add TODO for making `eps` optional in `AddRmsNorm`
voltjia 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
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,56 @@ | ||
| #ifndef INFINI_OPS_ASCEND_COMMON_H_ | ||
| #define INFINI_OPS_ASCEND_COMMON_H_ | ||
|
|
||
| #include <cstdint> | ||
| #include <vector> | ||
|
|
||
| #include "acl/acl.h" | ||
| #include "aclnn/acl_meta.h" | ||
| #include "ascend/data_type_.h" | ||
| #include "tensor.h" | ||
|
|
||
| namespace infini::ops::ascend { | ||
|
|
||
| // Build an `aclTensor` descriptor from an InfiniOps `Tensor`. | ||
| // | ||
| // When `transpose_last2` is true the last two dimensions are swapped in the | ||
| // descriptor (shape and strides) without copying data. This is used by `Gemm` | ||
| // and `MatMul` to express a transpose via the view. | ||
| inline aclTensor* buildAclTensor(const Tensor& t, | ||
| bool transpose_last2 = false) { | ||
| std::vector<int64_t> shape(t.shape().begin(), t.shape().end()); | ||
| std::vector<int64_t> strides(t.strides().begin(), t.strides().end()); | ||
|
|
||
| if (transpose_last2 && shape.size() >= 2) { | ||
| auto n = shape.size(); | ||
| std::swap(shape[n - 2], shape[n - 1]); | ||
| std::swap(strides[n - 2], strides[n - 1]); | ||
| } | ||
|
|
||
| // Compute the minimum physical storage needed for this strided view. | ||
| // For contiguous tensors this equals `numel()`; for non-contiguous (gapped) | ||
| // tensors it may be larger; for broadcast (stride-0) tensors it may be | ||
| // smaller. Passing the view shape as the storage shape causes | ||
| // "ViewShape overlap" errors in ACLNN for non-contiguous inputs. | ||
| int64_t storage_elems = 1; | ||
| for (size_t i = 0; i < shape.size(); ++i) { | ||
| if (shape[i] == 0) { | ||
| storage_elems = 0; | ||
| break; | ||
| } | ||
| if (strides[i] > 0 && shape[i] > 1) { | ||
| storage_elems += static_cast<int64_t>(shape[i] - 1) * strides[i]; | ||
| } | ||
| } | ||
| std::vector<int64_t> storage_shape = {storage_elems}; | ||
|
|
||
| return aclCreateTensor( | ||
| shape.data(), static_cast<int64_t>(shape.size()), ToAclDtype(t.dtype()), | ||
| strides.data(), | ||
| /*storageOffset=*/0, ACL_FORMAT_ND, storage_shape.data(), | ||
| static_cast<int64_t>(storage_shape.size()), const_cast<void*>(t.data())); | ||
| } | ||
|
|
||
| } // namespace infini::ops::ascend | ||
|
|
||
| #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,61 @@ | ||
| #ifndef INFINI_OPS_ASCEND_DATA_TYPE__H_ | ||
| #define INFINI_OPS_ASCEND_DATA_TYPE__H_ | ||
|
|
||
| #include <cassert> | ||
|
|
||
| #include "acl/acl.h" | ||
| #include "ascend/device_.h" | ||
| #include "data_type.h" | ||
|
|
||
| namespace infini::ops::ascend { | ||
|
|
||
| inline aclDataType ToAclDtype(DataType dt) { | ||
| switch (dt) { | ||
| case DataType::kInt8: | ||
| return ACL_INT8; | ||
| case DataType::kInt16: | ||
| return ACL_INT16; | ||
| case DataType::kInt32: | ||
| return ACL_INT32; | ||
| case DataType::kInt64: | ||
| return ACL_INT64; | ||
| case DataType::kUInt8: | ||
| return ACL_UINT8; | ||
| case DataType::kUInt16: | ||
| return ACL_UINT16; | ||
| case DataType::kUInt32: | ||
| return ACL_UINT32; | ||
| case DataType::kUInt64: | ||
| return ACL_UINT64; | ||
| case DataType::kFloat16: | ||
| return ACL_FLOAT16; | ||
| case DataType::kBFloat16: | ||
| return ACL_BF16; | ||
| case DataType::kFloat32: | ||
| return ACL_FLOAT; | ||
| default: | ||
| assert(false && "Unsupported dtype for Ascend backend."); | ||
| return ACL_DT_UNDEFINED; | ||
| } | ||
| } | ||
|
|
||
| // Returns true for integer (signed or unsigned) `DataType` values. | ||
| inline bool IsIntegerDtype(DataType dt) { | ||
| switch (dt) { | ||
| case DataType::kInt8: | ||
| case DataType::kInt16: | ||
| case DataType::kInt32: | ||
| case DataType::kInt64: | ||
| case DataType::kUInt8: | ||
| case DataType::kUInt16: | ||
| case DataType::kUInt32: | ||
| case DataType::kUInt64: | ||
| return true; | ||
| default: | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| } // namespace infini::ops::ascend | ||
|
|
||
| #endif |
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.
Uh oh!
There was an error while loading. Please reload this page.