Skip to content

Commit 05de114

Browse files
author
“ph0375”
committed
Modify the BMM code according to the review comments
1 parent 0d634d8 commit 05de114

3 files changed

Lines changed: 8 additions & 8 deletions

File tree

include/flag_gems/operators.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ std::tuple<at::Tensor, at::Tensor> rotary_embedding(
3030
const std::optional<at::Tensor> &position_ids = std::nullopt,
3131
bool rotary_interleaved = false);
3232

33-
at::Tensor bmm(at::Tensor &A, at::Tensor &B);
33+
at::Tensor bmm(const at::Tensor &A, const at::Tensor &B);
3434
} // namespace flag_gems

lib/bmm.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace flag_gems {
99
using namespace triton_jit;
1010

11-
at::Tensor bmm(at::Tensor& A, at::Tensor& B) {
11+
at::Tensor bmm(const at::Tensor& A, const at::Tensor& B) {
1212
TORCH_CHECK(A.dim() == 3 && B.dim() == 3, "both the tensors must be 3-D");
1313
TORCH_CHECK(A.dtype() == B.dtype(),
1414
"expected a and b to have the same dtype, but got: ",
@@ -18,10 +18,10 @@ at::Tensor bmm(at::Tensor& A, at::Tensor& B) {
1818
at::IntArrayRef A_sizes = A.sizes();
1919
at::IntArrayRef B_sizes = B.sizes();
2020

21-
A = A.contiguous();
22-
B = B.contiguous();
21+
at::Tensor A_contig = A.contiguous();
22+
at::Tensor B_contig = B.contiguous();
2323

24-
at::Tensor out = at::empty({A_sizes[0], A_sizes[1], B_sizes[2]}, A.options());
24+
at::Tensor out = at::empty({A_sizes[0], A_sizes[1], B_sizes[2]}, A_contig.options());
2525

2626
const TritonJITFunction& f =
2727
TritonJITFunction::getInstance(std::string(utils::get_triton_src_path() / "bmm.py"), "bmm_kernel");
@@ -51,8 +51,8 @@ at::Tensor bmm(at::Tensor& A, at::Tensor& B) {
5151
/* grid_z = */ A_sizes[0],
5252
/* num_warps = */ 4,
5353
/* num_stages = */ 1,
54-
A,
55-
B,
54+
A_contig,
55+
B_contig,
5656
out,
5757
A_sizes[1],
5858
B_sizes[2],

src/flag_gems/csrc/cstub.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ TORCH_LIBRARY(flag_gems, m) {
2020
m.def(
2121
"rotary_embedding(Tensor q, Tensor k, Tensor cos, Tensor sin, Tensor? position_ids=None, "
2222
"bool rotary_interleaved=False) -> (Tensor, Tensor)"); // q and k may be view to other size
23-
m.def("bmm(Tensor A, Tensor B) -> Tensor");
23+
m.def("bmm(Tensor self, Tensor mat2) -> Tensor");
2424
}
2525

2626
TORCH_LIBRARY_IMPL(flag_gems, CUDA, m) {

0 commit comments

Comments
 (0)