Skip to content

Commit 1227757

Browse files
authored
Revert pthreadpool a56dcd7 update (backout D104906625 + dependent D108226589) (#20521)
Differential Revision: D109744957 Pull Request resolved: #20521
1 parent baa7525 commit 1227757

4 files changed

Lines changed: 2 additions & 45 deletions

File tree

extension/llm/custom_ops/op_sdpa_impl.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -805,9 +805,6 @@ void cpu_flash_attention(
805805
is_reduced_type ? reinterpret_cast<scalar_t*>(buf_reduced) : nullptr;
806806

807807
auto compute_lambda = [&](int64_t begin, int64_t end) {
808-
// Blocks are parallelized over the threadpool; keep each block's gemms
809-
// single-threaded so an OpenMP-threaded BLAS doesn't nest a second layer.
810-
::executorch::cpublas::SingleThreadedGemmGuard gemm_guard;
811808
int64_t i = 0, j = 0, k = 0;
812809
data_index_init(begin, i, batchSize, j, num_head, k, qSlice);
813810
int ompIdx = torch::executor::get_thread_num();

kernels/optimized/blas/CPUBlas.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,13 @@ extern "C" void zgemm_(char *transa, char *transb, int *m, int *n, int *k, void
2323
#endif // ET_BUILD_FOR_APPLE
2424
#endif // ET_BUILD_WITH_BLAS
2525

26-
#ifdef ET_CPUBLAS_MKL_OMP
27-
// MKL's thread-local thread-count setter. The C name aliases the Fortran
28-
// by-reference entry point in this MKL build, so the argument is int*. Only
29-
// referenced when linked against OpenMP MKL, so the strong ref always resolves.
30-
extern "C" int mkl_set_num_threads_local(int* nt);
31-
#endif // ET_CPUBLAS_MKL_OMP
32-
3326
namespace executorch {
3427
namespace cpublas {
3528

3629
using executorch::aten::BFloat16;
3730
using executorch::aten::complex;
3831
using executorch::aten::Half;
3932

40-
SingleThreadedGemmGuard::SingleThreadedGemmGuard() : prev_num_threads_(0) {
41-
#ifdef ET_CPUBLAS_MKL_OMP
42-
int one = 1;
43-
prev_num_threads_ = mkl_set_num_threads_local(&one);
44-
#endif // ET_CPUBLAS_MKL_OMP
45-
}
46-
47-
SingleThreadedGemmGuard::~SingleThreadedGemmGuard() {
48-
#ifdef ET_CPUBLAS_MKL_OMP
49-
mkl_set_num_threads_local(&prev_num_threads_);
50-
#endif // ET_CPUBLAS_MKL_OMP
51-
}
52-
5333
#ifdef ET_BUILD_WITH_BLAS
5434
#ifdef ET_BUILD_FOR_APPLE
5535
inline CBLAS_TRANSPOSE to_cblas_transpose(TransposeType trans) {

kernels/optimized/blas/CPUBlas.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,6 @@ enum class TransposeType {
2323
ConjTranspose,
2424
};
2525

26-
// Forces gemm() in its scope to run single-threaded when this library is built
27-
// against OpenMP-threaded MKL (-DET_CPUBLAS_MKL_OMP), so a gemm called from
28-
// inside a threadpool parallel region doesn't nest a second OpenMP team. No-op
29-
// for any other BLAS backend.
30-
class SingleThreadedGemmGuard {
31-
public:
32-
SingleThreadedGemmGuard();
33-
~SingleThreadedGemmGuard();
34-
SingleThreadedGemmGuard(const SingleThreadedGemmGuard&) = delete;
35-
SingleThreadedGemmGuard& operator=(const SingleThreadedGemmGuard&) = delete;
36-
SingleThreadedGemmGuard(SingleThreadedGemmGuard&&) = delete;
37-
SingleThreadedGemmGuard& operator=(SingleThreadedGemmGuard&&) = delete;
38-
39-
private:
40-
[[maybe_unused]] int prev_num_threads_;
41-
};
42-
4326
// clang-format off
4427
void normalize_last_dims(
4528
TransposeType transa, TransposeType transb,

kernels/optimized/lib_defs.bzl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def define_libs(is_fbcode=False):
175175
"//executorch/extension/threadpool:threadpool",
176176
]
177177

178-
for libblas_name, mkl_dep, mkl_omp_define in [("libblas", "fbsource//third-party/mkl:mkl_lp64_omp", ["-DET_CPUBLAS_MKL_OMP"]), ("libblas_mkl_noomp", "fbsource//third-party/mkl:mkl", [])]:
178+
for libblas_name, mkl_dep in [("libblas", "fbsource//third-party/mkl:mkl_lp64_omp"), ("libblas_mkl_noomp", "fbsource//third-party/mkl:mkl")]:
179179
# Merge platform-specific kwargs
180180
platform_kwargs = get_apple_framework_deps_kwargs(is_fbcode)
181181
if not is_fbcode:
@@ -217,10 +217,7 @@ def define_libs(is_fbcode=False):
217217
}),
218218
header_namespace = "executorch/kernels/optimized",
219219
visibility = ["PUBLIC"],
220-
preprocessor_flags = get_preprocessor_flags() + select({
221-
":linux-x86_64": mkl_omp_define,
222-
"DEFAULT": [],
223-
}),
220+
preprocessor_flags = get_preprocessor_flags(),
224221
fbobjc_exported_preprocessor_flags = [
225222
"-DET_BUILD_WITH_BLAS",
226223
"-DET_BUILD_FOR_APPLE",

0 commit comments

Comments
 (0)