diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 39a2340..97d65dc 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -2,7 +2,7 @@ find_package(GTest REQUIRED) find_package(glog REQUIRED) set(link_ext_lib glog::glog GTest::gtest) -add_executable(test_llm test_main.cpp test_buffer.cpp test_math.cpp) +add_executable(test_llm test_main.cpp test_buffer.cpp test_add.cpp test_math.cpp) target_link_libraries(test_llm ${link_ext_lib}) target_include_directories(test_llm PUBLIC ${glog_INCLUDE_DIR}) diff --git a/test/test_add.cpp b/test/test_add.cpp new file mode 100644 index 0000000..6630c27 --- /dev/null +++ b/test/test_add.cpp @@ -0,0 +1,25 @@ +#include +#include +#include +#include "base/buffer.h" +#include "../kuiper/source/op/kernels/add_kernel.h" + +TEST(test_op, add) { + using namespace base; + auto alloc_cu = base::CPUDeviceAllocatorFactory::get_instance(); + + int32_t size = 32 * 151; + + tensor::Tensor t1(base::DataType::kDataTypeFp32, size, true, alloc_cu); + tensor::Tensor t2(base::DataType::kDataTypeFp32, size, true, alloc_cu); + tensor::Tensor out(base::DataType::kDataTypeFp32, size, true, alloc_cu); + for (int i = 0; i < t1.size(); ++i) { + t1.index(i) = 1; + t2.index(i) = 2; + } + + kernel::get_add_kernel(base::DeviceType::kDeviceCPU)(t1, t2, out); + for (int i = 0; i < size; ++i) { + ASSERT_EQ(out.index(i), 3.f); + } +}