TODO: check length of indices and delete is_indices_defined The indexed axes are contiguous just like [..., indexed_axes, ...]
| 392 | // TODO: check length of indices and delete is_indices_defined |
| 393 | // The indexed axes are contiguous just like [..., indexed_axes, ...] |
| 394 | void IndexingMultiAxisVecImpl::exec( |
| 395 | _megdnn_tensor_in src, const IndexDesc& index, _megdnn_tensor_out dst, |
| 396 | _megdnn_workspace workspace) { |
| 397 | auto cambricon_handle = concrete_handle(handle()); |
| 398 | |
| 399 | WorkspaceBundle wk_bundle = get_workspace_bundle(src.layout, index, dst.layout); |
| 400 | size_t wk_size = wk_bundle.total_size_in_bytes(); |
| 401 | void* wk_ptr = cambricon_handle->alloc(wk_size); |
| 402 | wk_bundle.set(wk_ptr); |
| 403 | |
| 404 | auto src_indices_and_defined = prepare_src_and_index(src, index, wk_bundle); |
| 405 | auto prepared_src = std::get<0>(src_indices_and_defined); |
| 406 | auto prepared_indices = std::get<1>(src_indices_and_defined); |
| 407 | auto is_indices_defined = std::get<2>(src_indices_and_defined); |
| 408 | |
| 409 | CnnlTensorDescriptor cnnl_src_desc, cnnl_dst_desc, cnnl_output_dim_desc, |
| 410 | cnnl_expand_output_dims_desc; |
| 411 | cnnl_src_desc.set(&prepared_src); |
| 412 | if (dst.layout.is_contiguous()) { |
| 413 | cnnl_dst_desc.set(&dst); |
| 414 | } else { |
| 415 | TensorLayout dst_contig_layout(dst.layout); |
| 416 | dst_contig_layout.init_contiguous_stride(); |
| 417 | cnnl_dst_desc.set(dst_contig_layout); |
| 418 | } |
| 419 | |
| 420 | size_t len = 8; |
| 421 | CnnlTensorDescriptor cnnl_full_index_desc[len]; |
| 422 | for (size_t i = 0; i < len; ++i) { |
| 423 | if (!is_indices_defined[i]) { |
| 424 | } else { |
| 425 | cnnl_full_index_desc[i].set(prepared_indices[i].layout); |
| 426 | } |
| 427 | } |
| 428 | cnnlTensorDescriptor_t cnnl_full_index_desc_t[len]; |
| 429 | for (size_t i = 0; i < 8; ++i) { |
| 430 | cnnl_full_index_desc_t[i] = cnnl_full_index_desc[i].desc(); |
| 431 | } |
| 432 | void* indices_ptr[len]; |
| 433 | for (size_t i = 0; i < len; ++i) { |
| 434 | if (!is_indices_defined[i]) { |
| 435 | indices_ptr[i] = nullptr; |
| 436 | } else { |
| 437 | indices_ptr[i] = prepared_indices[i].raw_ptr(); |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | void* output_dim = wk_bundle.get(2); |
| 442 | void* output_dims = wk_bundle.get(3); |
| 443 | std::vector<size_t> output_dim_shape(1, 1); |
| 444 | cnnl_output_dim_desc.set(1, output_dim_shape, CNNL_DTYPE_INT32); |
| 445 | std::vector<size_t> expand_output_dims_shape(1, 8); |
| 446 | cnnl_expand_output_dims_desc.set(1, expand_output_dims_shape, CNNL_DTYPE_INT64); |
| 447 | |
| 448 | size_t advanced_index_wk_size = 0; |
| 449 | cnnl_check(cnnlGetAdvancedIndexWorkspaceSize( |
| 450 | cambricon_handle->cnnl_handle(), cnnl_src_desc.desc(), |
| 451 | cnnl_full_index_desc_t, &advanced_index_wk_size)); |
nothing calls this directly
no test coverage detected