Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 24 additions & 20 deletions kernels/optimized/blas/BlasKernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <executorch/kernels/optimized/utils/math_utils.h>
#include <executorch/kernels/optimized/utils/unroll.h>

#include <executorch/extension/parallel/thread_parallel.h>
#include <executorch/runtime/core/portable_type/bfloat16.h>

#include <array>
Expand Down Expand Up @@ -177,34 +178,37 @@ inline void gemm_transa_<torch::executor::BFloat16, torch::executor::BFloat16>(
torch::executor::BFloat16 beta,
torch::executor::BFloat16 *c, int64_t ldc) {
// c = alpha * (a.T @ b) + beta * c
// parallel_for(0, m, 1, [&](int64_t begin, int64_t end) {
if (alpha == 1 && beta == 0) {
const auto *a_ = a;
for (int i = 0; i < m; ++i) {
executorch::extension::parallel_for(0, m, 1, [&](int64_t begin, int64_t end) {
const auto *a_ = a + begin * lda;
for (int i = begin; i < end; ++i) {
const auto *b_ = b;
for (int j = 0; j < n; ++j) {
const auto dot = internal::bf16_dot_with_fp32_arith(a_, b_, k);
b_ += ldb;
c[j*ldc+i] = dot;
}
a_ += lda;
}
});
return;
}
executorch::extension::parallel_for(0, m, 1, [&](int64_t begin, int64_t end) {
const auto *a_ = a + begin * lda;
for (int i = begin; i < end; ++i) {
const auto *b_ = b;
for (int j = 0; j < n; ++j) {
const auto dot = internal::bf16_dot_with_fp32_arith(a_, b_, k);
b_ += ldb;
c[j*ldc+i] = dot;
if (beta == 0) {
c[j*ldc+i] = alpha*dot;
} else {
c[j*ldc+i] = beta*c[j*ldc+i]+alpha*dot;
}
}
a_ += lda;
}
return;
}
const auto *a_ = a;
for (int i = 0; i < m; ++i) {
const auto *b_ = b;
for (int j = 0; j < n; ++j) {
const auto dot = internal::bf16_dot_with_fp32_arith(a_, b_, k);
b_ += ldb;
if (beta == 0) {
c[j*ldc+i] = alpha*dot;
} else {
c[j*ldc+i] = beta*c[j*ldc+i]+alpha*dot;
}
}
a_ += lda;
}
});
}
#endif

Expand Down
4 changes: 3 additions & 1 deletion kernels/optimized/lib_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ def define_libs():
deps = select({
":linux-x86_64": [mkl_dep] if not runtime.is_oss else [],
"DEFAULT": [],
}),
}) + [
"//executorch/extension/parallel:thread_parallel",
],
exported_deps = [
"//executorch/kernels/optimized:libutils",
"//executorch/runtime/core/exec_aten:lib",
Expand Down
Loading