| 326 | } |
| 327 | } |
| 328 | void ExternCOprRunner::check_param() { |
| 329 | //! check extern dynamic param validity |
| 330 | //! nr_input=0 or nr_output=0 means do not provide input/output |
| 331 | //! ExternDeviceTensor for some case, ExternCOprParam may only config |
| 332 | //! device_id, extra_info, etc. so we need consider nr_input=0 or |
| 333 | //! nr_output=0 |
| 334 | if (!is_loader_support_dynamic_param) |
| 335 | return; |
| 336 | auto check = [](size_t nr_config_tensor, size_t var_node_size, |
| 337 | ExternDeviceTensor* e_tensor, const VarNodeArray& var_node_array, |
| 338 | const char* msg) { |
| 339 | mgb_assert(e_tensor, "%s ExternDeviceTensor should not be null!!", msg); |
| 340 | mgb_assert( |
| 341 | nr_config_tensor == var_node_size, |
| 342 | "param %s size provided by `config_extern_c_opr_dynamic_param` " |
| 343 | "mismatch with the number of %s, got %zu, expected %zu", |
| 344 | msg, msg, nr_config_tensor, var_node_size); |
| 345 | for (size_t i = 0; i < nr_config_tensor; i++) { |
| 346 | mgb_assert( |
| 347 | e_tensor[i].device_ptr, |
| 348 | "%s ExternDeviceTensor(index: %zu) device_ptr should " |
| 349 | "not be null!!", |
| 350 | msg, i); |
| 351 | auto param_shape = e_tensor[i].layout.shape; |
| 352 | auto shape = var_node_array.at(i)->shape(); |
| 353 | auto param_dtype = e_tensor[i].layout.dtype; |
| 354 | auto dtype = dtype_cpp2c(var_node_array.at(i)->dtype()); |
| 355 | mgb_assert( |
| 356 | param_dtype == dtype, |
| 357 | "%s dtype provided mismatch, expected: %u, got: %d", msg, |
| 358 | param_dtype, dtype); |
| 359 | mgb_assert( |
| 360 | shape.ndim == param_shape.ndim, |
| 361 | "%s ndim provided mismatch got: %u, expect: %zu of " |
| 362 | "index: %zu", |
| 363 | msg, param_shape.ndim, shape.ndim, i); |
| 364 | for (size_t j = 0; j < shape.ndim; j++) { |
| 365 | mgb_assert( |
| 366 | param_shape.shape[j] == shape.shape[j], |
| 367 | "config %s shape should same with c opr %s shape: " |
| 368 | "(got: %u expect: %zu) of index: %zu", |
| 369 | msg, msg, param_shape.shape[j], shape.shape[j], j); |
| 370 | } |
| 371 | } |
| 372 | }; |
| 373 | |
| 374 | if (m_param && m_param->nr_input > 0) { |
| 375 | check(m_param->nr_input, input().size(), m_param->input, input(), "input"); |
| 376 | } |
| 377 | |
| 378 | if (m_param && m_param->nr_output > 0) { |
| 379 | check(m_param->nr_output, output().size(), m_param->output, output(), "output"); |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | void ExternCOprRunner::scn_do_execute() { |
| 384 | SmallVector<MGBTensor> c_inp(input().size()), c_out(output().size()); |