| 372 | } |
| 373 | |
| 374 | void compute_index_node(GraphNode& node, const std::vector<std::unique_ptr<GraphNode>>& nodes, const std::unordered_map<size_t, size_t>& node_index_map) { |
| 375 | const auto& input_buffer = get_input(node, 0, nodes, node_index_map); |
| 376 | const auto& input_shape = input_buffer.shape; |
| 377 | |
| 378 | int dim = node.params.axis; |
| 379 | size_t index_value = node.params.index_value; |
| 380 | |
| 381 | const char* input_data = static_cast<const char*>(input_buffer.get_data()); |
| 382 | char* output_data = static_cast<char*>(node.output_buffer.get_data()); |
| 383 | |
| 384 | if (dim == 0) { |
| 385 | size_t slice_size = input_buffer.total_size / input_shape[0]; |
| 386 | size_t offset_bytes = PrecisionTraits::byte_offset_of(input_buffer.precision, index_value * slice_size); |
| 387 | node.output_buffer.set_external(const_cast<char*>(input_data) + offset_bytes); |
| 388 | return; |
| 389 | } |
| 390 | |
| 391 | std::vector<size_t> input_strides(input_shape.size()); |
| 392 | input_strides[input_shape.size() - 1] = 1; |
| 393 | for (int i = static_cast<int>(input_shape.size()) - 2; i >= 0; --i) { |
| 394 | input_strides[i] = input_strides[i + 1] * input_shape[i + 1]; |
| 395 | } |
| 396 | |
| 397 | size_t slice_size = input_strides[dim]; |
| 398 | size_t outer_size = input_buffer.total_size / input_strides[dim - 1]; |
| 399 | size_t dim_stride = input_strides[dim]; |
| 400 | size_t block_size = dim_stride * input_shape[dim]; |
| 401 | |
| 402 | size_t output_idx = 0; |
| 403 | for (size_t outer_idx = 0; outer_idx < outer_size; ++outer_idx) { |
| 404 | size_t input_base = outer_idx * block_size + index_value * dim_stride; |
| 405 | |
| 406 | char* output_offset_bytes = output_data + PrecisionTraits::byte_offset_of(input_buffer.precision, output_idx); |
| 407 | const char* input_offset_bytes = input_data + PrecisionTraits::byte_offset_of(input_buffer.precision, input_base); |
| 408 | size_t length = PrecisionTraits::byte_offset_of(input_buffer.precision, slice_size); |
| 409 | std::memcpy(output_offset_bytes, input_offset_bytes, length); |
| 410 | |
| 411 | output_idx += slice_size; |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | void compute_bilinear_interpolation_node(GraphNode& node, const std::vector<std::unique_ptr<GraphNode>>& nodes, const std::unordered_map<size_t, size_t>& node_index_map) { |
| 416 | const auto& pos_embeds_buffer = get_input(node, 0, nodes, node_index_map); |
nothing calls this directly
no test coverage detected