Skip to content

Commit

Permalink
[Ascend] fuj / optimize bmm and triu (#726)
Browse files Browse the repository at this point in the history
* optimize impl to avoid redundant dispatch for performance: bmm, triu, triu_

* fix bmm impl

* fix tensor operation for bmm

* remove custom fallback option for bmm

* remove custom fallback for dipu bmm
  • Loading branch information
jingguo-st authored Mar 14, 2024
1 parent c2d2f6d commit afa03ae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions dipu/SupportedDiopiFunctions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ diopiTopk
diopiTranspose
diopiTril
diopiTriu
diopiTriuInp
diopiUniformInp
diopiUnique
diopiUpsampleLinear
Expand Down
16 changes: 16 additions & 0 deletions dipu/scripts/autogen_diopi_wrapper/diopi_functions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,14 @@
- schema: "cos_(Tensor(a!) self) -> Tensor(a!)"
interface: diopiCosInp(ctx, self)

- schema: "bmm(Tensor self, Tensor mat2) -> Tensor"
custom_code_at_the_beginning: |
TORCH_CHECK(self.dim() == 3, "Tensor self shoud be 3-D tensor.");
TORCH_CHECK(mat2.dim() == 3, "Tensor mat2 shoud be 3-D tensor.");
TORCH_CHECK(self.size(0) == mat2.size(0), "Tensor batch size of self and mat2 shoud be equal.");
auto out = nodispatch::empty({self.size(0), self.size(1), mat2.size(2)}, self.options());
interface: diopiBmm(ctx, out, self, mat2)

- schema: "bmm.out(Tensor self, Tensor mat2, *, Tensor(a!) out) -> Tensor(a!)"
custom_fallback: True
interface: diopiBmm(ctx, out, self, mat2)
Expand Down Expand Up @@ -2178,6 +2186,14 @@
- schema: "sgn.out(Tensor self, *, Tensor(a!) out) -> Tensor(a!)"
interface: diopiSgn(ctx, out,self)

- schema: "triu(Tensor self, int diagonal=0) -> Tensor"
custom_code_at_the_beginning: |
auto out = nodispatch::empty_like(self);
interface: diopiTriu(ctx, out, self, diagonal)

- schema: "triu_(Tensor(a!) self, int diagonal=0) -> Tensor(a!)"
interface: diopiTriuInp(ctx, self, diagonal)

- schema: "triu.out(Tensor self, int diagonal=0, *, Tensor(a!) out) -> Tensor(a!)"
interface: diopiTriu(ctx, out, self, diagonal)

Expand Down

0 comments on commit afa03ae

Please sign in to comment.