Generalize parallel GEMM implementation in Core to work with ThreadPool in addition to OpenMP.

This commit is contained in:
Rasmus Munk Larsen
2023-11-10 17:42:30 +00:00
parent 4d54c43d6c
commit 76e8c04553
5 changed files with 228 additions and 91 deletions

33
test/product_threaded.cpp Normal file
View File

@@ -0,0 +1,33 @@
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2023 Rasmus Munk Larsen <rmlarsen@google.com>
//
// This Source Code Form is subject to the terms of the Mozilla
// Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
#define EIGEN_GEMM_THREADPOOL
#include "main.h"
void test_parallelize_gemm() {
constexpr int n = 1024;
constexpr int num_threads = 4;
MatrixXf a(n,n);
MatrixXf b(n,n);
MatrixXf c(n,n);
c.noalias() = a*b;
ThreadPool pool(num_threads);
MatrixXf c_threaded(n,n);
c_threaded.noalias() = a*b;
VERIFY_IS_APPROX(c, c_threaded);
}
EIGEN_DECLARE_TEST(product_threaded)
{
CALL_SUBTEST(test_parallelize_gemm());
}