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

Function test_param_pack_concat

dnn/test/cuda/param_pack.cpp:70–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

68
69template <class T>
70void test_param_pack_concat(
71 Handle* handle, const TensorShapeArray& shapes, DType type) {
72 auto concat = handle->create_operator<ParamPackConcat>();
73 size_t nr_params = shapes.size();
74
75 std::vector<T*> param_ptrs;
76 std::vector<std::vector<T>> params = create_params<T>(nr_params, shapes);
77 for (size_t i = 0; i < nr_params; ++i) {
78 param_ptrs.push_back(create_device_data<T>(
79 handle, params[i].data(), shapes[i].total_nr_elems()));
80 }
81 std::vector<int32_t> offsets =
82 create_offsets<T>(shapes, handle->alignment_requirement());
83 size_t pack_size = offsets.back();
84 int32_t* offsets_gpu =
85 create_device_data<int32_t>(handle, offsets.data(), offsets.size());
86
87 std::vector<T> expected_pack = create_pack<T>(pack_size, offsets, params);
88 T* pack_gpu = create_device_data<T>(handle, nullptr, expected_pack.size());
89
90 TensorLayout dst_layout({pack_size}, type);
91 TensorND dst_tensor(pack_gpu, dst_layout);
92
93 TensorLayout offsets_layout({offsets.size()}, dtype::Int32());
94 TensorND offsets_tensor(offsets_gpu, offsets_layout);
95
96 test::WorkspaceWrapper workspace(
97 handle,
98 concat->get_workspace_in_bytes({nr_params}, offsets_layout, {pack_size}));
99 TensorND src_tensor(param_ptrs.data(), TensorLayout({nr_params}, dtype::Int32()));
100
101 concat->exec(src_tensor, offsets_tensor, dst_tensor, workspace.workspace());
102
103 // check
104 T* actual_pack = static_cast<T*>(malloc(pack_size * sizeof(T)));
105 test::megdnn_memcpy_D2H(handle, actual_pack, pack_gpu, sizeof(T) * pack_size);
106 for (size_t i = 0; i < pack_size; ++i) {
107 ASSERT_EQ(actual_pack[i], expected_pack[i]);
108 }
109 free(actual_pack);
110 test::megdnn_free(handle, pack_gpu);
111 test::megdnn_free(handle, offsets_gpu);
112 for (auto ptr : param_ptrs) {
113 test::megdnn_free(handle, ptr);
114 }
115}
116
117} // namespace
118

Callers

nothing calls this directly

Calls 11

TensorLayoutClass · 0.85
freeFunction · 0.85
backMethod · 0.80
sizeMethod · 0.45
push_backMethod · 0.45
dataMethod · 0.45
total_nr_elemsMethod · 0.45
alignment_requirementMethod · 0.45
execMethod · 0.45
workspaceMethod · 0.45

Tested by

no test coverage detected