| 78 | return engine::core::ensure_backend_addressable_layout(ctx, input); |
| 79 | } |
| 80 | |
| 81 | engine::core::TensorValue permute_tensor( |
| 82 | engine::core::ModuleBuildContext & ctx, |
| 83 | const engine::core::TensorValue & input, |
| 84 | std::array<int, engine::core::kMaxTensorRank> axes) { |
| 85 | std::array<int, engine::core::kMaxTensorRank> ggml_axes = {0, 1, 2, 3}; |
| 86 | engine::core::TensorShape output_shape = {}; |
| 87 | output_shape.rank = input.shape.rank; |
| 88 | for (size_t out_logical_axis = 0; out_logical_axis < input.shape.rank; ++out_logical_axis) { |
| 89 | const int in_logical_axis = axes[out_logical_axis]; |
| 90 | output_shape.dims[out_logical_axis] = input.shape.dims[in_logical_axis]; |
| 91 | const int out_ggml_axis = static_cast<int>(input.shape.rank) - 1 - static_cast<int>(out_logical_axis); |
| 92 | ggml_axes[out_ggml_axis] = engine::core::logical_axis_to_ggml_axis(input.shape.rank, in_logical_axis); |
| 93 | } |
| 94 | return engine::core::wrap_tensor( |
| 95 | ggml_permute(ctx.ggml, input.tensor, ggml_axes[0], ggml_axes[1], ggml_axes[2], ggml_axes[3]), |
| 96 | output_shape, |
| 97 | input.type); |
| 98 | } |
| 99 | |
| 100 | engine::core::TensorValue transpose_last_two( |
no test coverage detected