Repository navigation
Expand file tree
/
Copy pathlibblas_test.cpp
More file actions
76 lines (60 loc) · 1.76 KB
/
Copy pathlibblas_test.cpp
File metadata and controls
76 lines (60 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <gtest/gtest.h>
#include <executorch/kernels/optimized/blas/CPUBlas.h>
#include <vector>
#define TEST_FORALL_SUPPORTED_CTYPES(_, N) \
_<double, N>(); \
_<float, N>(); \
_<int64_t, N>(); \
_<uint8_t, N>(); \
_<int32_t, N>();
namespace {
// Fill a vector with a monotonic sequence of integer values
template <typename T>
void fill_ones(std::vector<T>& arr) {
for (size_t i = 0; i < arr.size(); ++i) {
arr[i] = static_cast<T>(1);
}
}
template <typename T>
bool check_all_equal_to(std::vector<T>& arr, const float value) {
for (size_t i = 0; i < arr.size(); ++i) {
if (arr[i] != static_cast<T>(value)) {
return false;
}
}
return true;
}
} // namespace
template <class CTYPE, int64_t N>
void test_matmul_ones() {
using executorch::cpublas::TransposeType;
std::vector<CTYPE> in_1(N * N);
fill_ones(in_1);
std::vector<CTYPE> in_2(N * N);
fill_ones(in_2);
std::vector<CTYPE> out(N * N);
const CTYPE* in_1_data = in_1.data();
const CTYPE* in_2_data = in_2.data();
CTYPE* out_data = out.data();
// clang-format off
executorch::cpublas::gemm(
TransposeType::NoTranspose, TransposeType::NoTranspose,
N, N, N,
static_cast<CTYPE>(1),
in_1_data, N,
in_2_data, N,
static_cast<CTYPE>(0),
out_data, N);
// clang-format on
EXPECT_TRUE(check_all_equal_to(out, static_cast<float>(N)));
}
TEST(BlasTest, MatmulOnes) {
TEST_FORALL_SUPPORTED_CTYPES(test_matmul_ones, 25);
}