1 /**
2 * Copyright (c) 2023, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 // Original source: /system/extras/cpu_loads/simd.cpp by Tim Murray
18
19 #include <arpa/inet.h>
20 #include <cutils/sockets.h>
21 #include <hardware/gralloc.h>
22
23 #include <fcntl.h>
24 #include <sys/stat.h>
25 #include <sys/wait.h>
26 #include <unistd.h>
27
28 #include <algorithm>
29 #include <fstream>
30 #include <iostream>
31 #include <numeric>
32 #include <string>
33 #include <tuple>
34 #include <vector>
35
36 #define EIGEN_RUNTIME_NO_MALLOC
37
38 #include <Eigen/Dense>
39
40 /*
41 * Multiplies matrix B and C and adds the result to matrix A for m iterations.
42 */
main(int,char **)43 int main(int, char**) {
44 int N = 4096;
45 Eigen::MatrixXd a(N, N);
46 Eigen::MatrixXd b(N, N);
47 Eigen::MatrixXd c(N, N);
48
49 for (int i = 0; i < N; i++) {
50 for (int j = 0; j < N; j++) {
51 a(i, j) = 1 + i * j;
52 b(i, j) = 2 + i * j;
53 c(i, j) = 3 + i * j;
54 }
55 }
56
57 int m = 5;
58 std::cout << "starting matrix multiplication (N: " << N << ", iters: " << m << ")" << std::endl;
59 for (int i = 0; i < m; ++i) {
60 a.noalias() += (b * c);
61 b(1, 5) += 5.0;
62 c(5, 1) -= 5.0;
63 }
64
65 return 0;
66 }
67