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

Method extract_flow

src/opr/impl/nvof/denseflownvidia.cpp:122–181  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

120}
121
122void NVFlowExtractor::extract_flow(
123 unsigned char* frames, std::vector<size_t>& shape, int16_t* result_out_ptr) {
124 auto batch_size = shape[0];
125 auto temporal_size = shape[1];
126 auto height = shape[2];
127 auto width = shape[3];
128 auto channel = shape[4];
129 auto temporal_len = height * width * channel;
130 auto batch_len = temporal_size * height * width * channel;
131
132 init_nvof_engine();
133
134 auto src_mem_type = get_mem_type(reinterpret_cast<CUdeviceptr>(frames));
135 auto out_mem_type = get_mem_type(reinterpret_cast<CUdeviceptr>(result_out_ptr));
136
137 if ((height != m_height || width != m_width) ||
138 (m_temporal_size != temporal_size)) {
139 mgb_log_warn("We do not support dynamic shape at mgb side");
140 mgb_throw(MegBrainError, "NVOF: Nvof err shap!!!! err type: NV_OF_ERR_GENERIC");
141 }
142
143 for (size_t batch_idx = 0; batch_idx < batch_size; batch_idx++) {
144 auto input_buffer_batch_offsect = buffer_pool_size * batch_idx;
145 auto output_buffer_batch_offsect = (buffer_pool_size - 1) * batch_idx;
146 input_buffers[input_buffer_batch_offsect]->UploadData(
147 (unsigned char*)(frames + batch_idx * batch_len), src_mem_type);
148
149 for (size_t temporal_idx = 1; temporal_idx < temporal_size; temporal_idx++) {
150 input_buffers[input_buffer_batch_offsect + temporal_idx % buffer_pool_size]->UploadData(
151 (unsigned char*)(frames + batch_idx * batch_len + temporal_idx * temporal_len),
152 src_mem_type);
153
154 nv_optical_flow->Execute(
155 input_buffers
156 [input_buffer_batch_offsect +
157 (temporal_idx - 1) % buffer_pool_size]
158 .get(),
159 input_buffers
160 [input_buffer_batch_offsect +
161 temporal_idx % buffer_pool_size]
162 .get(),
163 output_buffers
164 [output_buffer_batch_offsect +
165 (temporal_idx - 1) % (buffer_pool_size - 1)]
166 .get(),
167 nullptr, nullptr);
168
169 output_buffers
170 [output_buffer_batch_offsect +
171 (temporal_idx - 1) % (buffer_pool_size - 1)]
172 ->DownloadData(
173 result_out_ptr +
174 batch_idx * (temporal_size - 1) * out_size +
175 (temporal_idx - 1) * out_size,
176 out_mem_type);
177 }
178 }
179

Callers 1

scn_do_executeMethod · 0.80

Calls 4

UploadDataMethod · 0.80
ExecuteMethod · 0.80
DownloadDataMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected