Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 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
13 changes: 13 additions & 0 deletions build/cmake_deps.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ excludes = [
deps = [
"executorch_no_prim_ops",
"executorch",
"extension_parallel_thread_parallel",
]

[targets.optimized_native_cpu_ops_oss]
Expand Down Expand Up @@ -197,6 +198,18 @@ deps = [
"executorch",
"executorch_no_prim_ops",
]

[targets.extension_parallel_thread_parallel]
buck_targets = [
"//extension/parallel:thread_parallel",
]
filters = [
".cpp$",
]
deps = [
"executorch",
"pthreadpool",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete this line

]
# ---------------------------------- extension end ----------------------------------
# ---------------------------------- binary start ----------------------------------

Expand Down
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
1 change: 1 addition & 0 deletions kernels/optimized/lib_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def define_libs():
"DEFAULT": [],
}),
exported_deps = [
"//executorch/extension/parallel:thread_parallel",
"//executorch/kernels/optimized:libutils",
"//executorch/runtime/core/exec_aten:lib",
],
Expand Down
Loading