MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / TEST_F

Function TEST_F

dnn/test/atlas/checksum.cpp:8–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6using namespace test;
7
8TEST_F(ATLAS, CHECKSUM_FORWARD) {
9 auto atlas_opr = handle_atlas()->create_operator<megdnn::Checksum>(),
10 naive_opr = handle_naive()->create_operator<megdnn::Checksum>();
11 std::mt19937 rng(std::random_device{}());
12 for (size_t size : {3, 8, 4 * 4 * 1024, 12345, 1024 * 1024, 1024 * 1024 * 10}) {
13 auto aligned_size = size + ((512 - size % 512) % 512);
14 auto run = [&](megdnn::Checksum* opr, void* ptr, bool log_size) {
15 TensorND tensor;
16 tensor.reset_ptr(ptr);
17 tensor.layout.init_contiguous_stride({size});
18 tensor.layout.dtype = dtype::Byte();
19 WorkspaceWrapper workspace(
20 handle_atlas(), opr->get_workspace_in_bytes(tensor.layout));
21 if (log_size) {
22 printf("checksum(%zu): workspace=%zu\n", size,
23 workspace.workspace().size);
24 }
25 return opr->exec(tensor, workspace.workspace());
26 };
27 std::vector<uint8_t> buf(aligned_size);
28 for (size_t i = 0; i < size; ++i)
29 buf[i] = 1;
30 auto run_offsset = [&](size_t offset) {
31 void* dev_ptr = megdnn_malloc(handle_atlas(), buf.size() + offset);
32 void* dev_buf = static_cast<char*>(dev_ptr) + offset;
33
34 Checksum::Result res_cambricon[2], res_naive[2];
35
36 for (int change_last = 0; change_last < 2; ++change_last) {
37 if (change_last)
38 ++buf[size - 1];
39
40 megdnn_memcpy_H2D(handle_atlas(), dev_buf, buf.data(), size);
41 res_cambricon[change_last] =
42 run(atlas_opr.get(), dev_buf, !change_last);
43 res_naive[change_last] = run(naive_opr.get(), buf.data(), false);
44 }
45
46 megdnn_free(handle_atlas(), dev_ptr);
47
48 ASSERT_EQ(res_naive[0], res_cambricon[0]) << "failed for size " << size;
49 ASSERT_EQ(res_naive[1], res_cambricon[1]);
50 ASSERT_NE(res_cambricon[0], res_cambricon[1]);
51 };
52
53 for (size_t i = 0; i < 8; ++i) {
54 run_offsset(i);
55 }
56 }
57}
58
59// vim: syntax=cpp.doxygen

Callers

nothing calls this directly

Calls 9

reset_ptrMethod · 0.80
runFunction · 0.50
workspaceMethod · 0.45
execMethod · 0.45
sizeMethod · 0.45
dataMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected