Skip to content

Commit

Permalink
course3的修改
Browse files Browse the repository at this point in the history
  • Loading branch information
zjhellofss committed Jun 27, 2024
1 parent 3032489 commit a2df727
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
25 changes: 25 additions & 0 deletions test/test_add.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <glog/logging.h>
#include <gtest/gtest.h>
#include <tensor/tensor.h>
#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<float>(i) = 1;
t2.index<float>(i) = 2;
}

kernel::get_add_kernel(base::DeviceType::kDeviceCPU)(t1, t2, out);
for (int i = 0; i < size; ++i) {
ASSERT_EQ(out.index<float>(i), 3.f);
}
}

0 comments on commit a2df727

Please sign in to comment.