-
Notifications
You must be signed in to change notification settings - Fork 6
feat(cambricon): add CausalSoftmaxOp in Cambricon #35
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
Draft
bitzyz
wants to merge
1
commit into
master
Choose a base branch
from
feat/dev-causal-softmax-cambricon
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
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,63 @@ | ||
| #ifndef INFINI_OPS_CAMBRICON_CAUSAL_SOFTMAX_H | ||
| #define INFINI_OPS_CAMBRICON_CAUSAL_SOFTMAX_H | ||
|
|
||
| #include "base/causal_softmax.h" | ||
| #include "native/cambricon/common.h" | ||
| #include "native/cambricon/data_type_.h" | ||
|
|
||
| namespace infini::ops { | ||
|
|
||
| // TODO: Remove forward declaration. | ||
| template <typename T> | ||
| void CausalSoftmaxUnion(void* workspace, int core_per_cluster, | ||
| int cluster_count, cnrtQueue_t queue, const void* x, | ||
| void* y, size_t batch_size_, size_t seq_len_, | ||
| size_t total_seq_len_, ptrdiff_t y_stride_b, | ||
| ptrdiff_t y_stride_i, ptrdiff_t y_stride_j, | ||
| ptrdiff_t x_stride_b, ptrdiff_t x_stride_i, | ||
| ptrdiff_t x_stride_j); | ||
|
|
||
| template <> | ||
| class Operator<CausalSoftmax, Device::Type::kCambricon> : public CausalSoftmax { | ||
| public: | ||
| Operator(const Tensor input, Tensor out) : CausalSoftmax{input, out} { | ||
| cnrt_utils::GetLaunchConfig(input.device(), &core_per_cluster, | ||
| &cluster_count); | ||
| } | ||
|
|
||
| void operator()(const Tensor input, Tensor out) const override { | ||
|
bitzyz marked this conversation as resolved.
|
||
| auto queue = static_cast<cnrtQueue_t>(stream_ ? stream_ : 0); | ||
| auto workspace{workspace_ ? workspace_ : default_workspace_}; | ||
| ptrdiff_t y_stride_b = ndim_ == 3 ? out_strides_[0] : 1; | ||
| ptrdiff_t y_stride_i = ndim_ == 3 ? out_strides_[1] : out_strides_[0]; | ||
| ptrdiff_t y_stride_j = ndim_ == 3 ? out_strides_[2] : out_strides_[1]; | ||
| ptrdiff_t x_stride_b = ndim_ == 3 ? input_strides_[0] : 1; | ||
| ptrdiff_t x_stride_i = ndim_ == 3 ? input_strides_[1] : input_strides_[0]; | ||
| ptrdiff_t x_stride_j = ndim_ == 3 ? input_strides_[2] : input_strides_[1]; | ||
|
|
||
| DispatchFunc< | ||
| List<DataType::kFloat16, DataType::kBFloat16, DataType::kFloat32>>( | ||
| {static_cast<int64_t>(input.dtype())}, | ||
| [&](auto input_tag) { | ||
| using InputT = infini::ops::TypeMapType<Device::Type::kCambricon, | ||
| ListGet<0>(input_tag)>; | ||
| CausalSoftmaxUnion<InputT>( | ||
| workspace, core_per_cluster, cluster_count, queue, input.data(), | ||
| out.data(), batch_size_, seq_len_, total_seq_len_, y_stride_b, | ||
| y_stride_i, y_stride_j, x_stride_b, x_stride_i, x_stride_j); | ||
| }, | ||
| "CambriconCausalSoftmax::operator() - output dispatch"); | ||
| } | ||
|
|
||
| std::size_t workspace_size_in_bytes() const override { return 0; } | ||
|
|
||
| ~Operator() {} | ||
|
|
||
| void* default_workspace_{nullptr}; | ||
| int core_per_cluster = 0; | ||
| int cluster_count = 0; | ||
| }; | ||
|
|
||
| } // namespace infini::ops | ||
|
|
||
| #endif | ||
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.
Uh oh!
There was an error while loading. Please reload this page.