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

Function test_param_pack_concat

dnn/test/rocm/param_pack.cpp:72–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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