-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(kernel): 测试 MatMulInteger cpu kernel
Signed-off-by: YdrMaster <ydrml@hotmail.com>
- Loading branch information
Showing
7 changed files
with
110 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#include "../src/kernels/mat_mul/cpu_kernel.hh" | ||
#include <gtest/gtest.h> | ||
|
||
using namespace refactor; | ||
using namespace kernel; | ||
|
||
template<class T> | ||
static void check( | ||
Resources &&res, | ||
Routine &&routine, | ||
std::vector<T> ans, | ||
std::vector<T> const &a, | ||
std::vector<T> const &b, | ||
std::vector<T> const &c) { | ||
std::vector<T> result(ans.size()); | ||
// inference | ||
void const *inputs[]{a.data(), b.data(), c.data()}; | ||
void *outputs[]{result.data()}; | ||
routine(res, nullptr, inputs, outputs); | ||
// check | ||
EXPECT_EQ(result, ans); | ||
} | ||
|
||
TEST(kernel, MatMulCPU_WithBias) { | ||
// build routine | ||
auto A = Tensor::share(DataType::F32, Shape{1, 2, 2}); | ||
auto B = Tensor::share(DataType::F32, Shape{2, 2}); | ||
auto C = Tensor::share(DataType::F32, Shape{}); | ||
auto Y = Tensor::share(DataType::F32, Shape{2, 2}); | ||
auto kernel = MatMulCPU::build(MatMulInfo(*A, *B, *C, false, false, 1, 1)); | ||
ASSERT_TRUE(kernel); | ||
auto res = runtime::Resources(); | ||
check<float>(std::move(res), kernel->lower(res).routine, | ||
{2, 4, 1, 1.25}, | ||
{1.0, 2.0, 0.0, 0.5}, | ||
{1.0, 2.0, 0.0, 0.5}, | ||
{1.0}); | ||
} | ||
|
||
TEST(kernel, MatMulCPU_UINT16NoBias) { | ||
// build routine | ||
auto A = Tensor::share(DataType::U16, Shape{2, 2}); | ||
auto B = Tensor::share(DataType::U16, Shape{2, 2}); | ||
auto Y = Tensor::share(DataType::U16, Shape{2, 2}); | ||
auto kernel = MatMulCPU::build(MatMulInfo(*A, *B, std::nullopt, false, false, 1, 1)); | ||
ASSERT_TRUE(kernel); | ||
auto res = runtime::Resources(); | ||
check<uint16_t>(std::move(res), kernel->lower(res).routine, | ||
{7, 6, 2, 3}, | ||
{3, 2, 0, 1}, | ||
{1, 0, 2, 3}, | ||
{}); | ||
} | ||
|
||
TEST(kernel, MatMulCPU_Broadcast) { | ||
// build routine | ||
auto A = Tensor::share(DataType::F32, Shape{2, 1, 2, 2}); | ||
auto B = Tensor::share(DataType::F32, Shape{1, 2, 2, 2}); | ||
auto C = Tensor::share(DataType::F32, Shape{2, 1}); | ||
auto Y = Tensor::share(DataType::F32, Shape{2, 2, 2, 2}); | ||
auto kernel = MatMulCPU::build(MatMulInfo(*A, *B, *C, false, false, 1, 1)); | ||
ASSERT_TRUE(kernel); | ||
auto res = runtime::Resources(); | ||
check<float>(std::move(res), kernel->lower(res).routine, | ||
{2.0, 4.0, 0.0, 0.25, | ||
2.0, 3.0, 0.0, 0.5, | ||
2.0, 3.0, 0.0, 0.5, | ||
2.0, 1.0, 0.0, 1.0}, | ||
{1.0, 2.0, 0.0, 0.5, | ||
1.0, 0.0, 0.0, 1.0}, | ||
{1.0, 2.0, 0.0, 0.5, | ||
1.0, 0.0, 0.0, 1.0}, | ||
{1.0, 0.0}); | ||
} |
File renamed without changes.
31 changes: 31 additions & 0 deletions
31
src/04kernel/test/kernels/mat_mul_integer/test_cpu_kernel.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include "../src/kernels/mat_mul_integer/cpu_kernel.hh" | ||
#include <gtest/gtest.h> | ||
|
||
using namespace refactor; | ||
using namespace kernel; | ||
|
||
TEST(kernel, MatMulIntegerCpu) { | ||
// build routine | ||
auto A = Tensor::share(DataType::U8, Shape{2, 3}); | ||
auto B = Tensor::share(DataType::U8, Shape{3, 1}); | ||
auto Y = Tensor::share(DataType::I32, Shape{2, 1}); | ||
auto kernel = MatMulIntegerCpu::build(MatMulIntegerInfo(TensorRefs{*A, *B})); | ||
ASSERT_TRUE(kernel); | ||
auto res = runtime::Resources(); | ||
auto routine = kernel->lower(res).routine; | ||
// put input data | ||
std::vector<uint8_t> | ||
dataA{1, 2, 3, 4, 5, 6}, | ||
dataB{1, 2, 3}; | ||
std::vector<int32_t> | ||
result(Y->elementsSize()), | ||
ans{14, 32}; | ||
// inference | ||
{ | ||
void const *inputs[]{dataA.data(), dataB.data()}; | ||
void *outputs[]{result.data()}; | ||
routine(res, nullptr, inputs, outputs); | ||
} | ||
// check | ||
EXPECT_EQ(result, ans); | ||
} |
This file was deleted.
Oops, something went wrong.