remove inplace optimization

This commit is contained in:
Xuan Son Nguyen
2026-08-19 00:47:45 +02:00
parent 6d4aa04337
commit e3d49edbf4
3 changed files with 7 additions and 21 deletions
+4 -8
View File
@@ -1656,7 +1656,6 @@ struct vk_op_rope_push_constants {
uint32_t is_imrope;
uint32_t is_back;
uint32_t set_rows_stride;
uint32_t inplace;
uint32_t ne00;
uint32_t ne01;
uint32_t ne02;
@@ -13119,7 +13118,7 @@ static uint32_t ggml_vk_rms_partials_size(ggml_backend_vk_context * ctx, const g
return num_bytes;
}
static vk_op_rope_push_constants ggml_vk_make_rope_constants(const ggml_tensor *dst, const ggml_tensor *src0, const bool has_ff, bool backprop, const uint32_t set_rows_stride, const bool inplace) {
static vk_op_rope_push_constants ggml_vk_make_rope_constants(const ggml_tensor *dst, const ggml_tensor *src0, const bool has_ff, bool backprop, const uint32_t set_rows_stride) {
const int n_dims = ((const int32_t *) dst->op_params)[1];
const int mode = ((const int32_t *) dst->op_params)[2];
const int n_offs = ((const int32_t *) dst->op_params)[15];
@@ -13154,7 +13153,7 @@ static vk_op_rope_push_constants ggml_vk_make_rope_constants(const ggml_tensor *
vk_op_rope_push_constants rope {
(uint32_t)mode, (uint32_t)ggml_nrows(src0), (uint32_t)n_dims, (uint32_t)n_offs, freq_scale,
freq_base, ext_factor, attn_factor, {corr_dims[0], corr_dims[1]}, theta_scale, has_ff,
{ sections[0], sections[1], sections[2], sections[3] }, is_imrope, backprop, set_rows_stride, inplace,
{ sections[0], sections[1], sections[2], sections[3] }, is_imrope, backprop, set_rows_stride,
(uint32_t)src0->ne[0],
(uint32_t)src0->ne[1],
@@ -13223,7 +13222,7 @@ static void ggml_vk_rms_norm(ggml_backend_vk_context * ctx, vk_context& subctx,
vk_op_rms_norm_mul_rope_push_constants pc;
pc.bin = bin;
pc.rope = ggml_vk_make_rope_constants(rope, rope->src[0], tensors[4] != nullptr, false, set_rows_stride, false);
pc.rope = ggml_vk_make_rope_constants(rope, rope->src[0], tensors[4] != nullptr, false, set_rows_stride);
vk_pipeline pipeline = tensors[5]->type == GGML_TYPE_F16 ? ctx->device->pipeline_rms_norm_mul_rope_f32_f16 : ctx->device->pipeline_rms_norm_mul_rope_f32_f32;
@@ -13571,11 +13570,8 @@ static void ggml_vk_rope(ggml_backend_vk_context * ctx, vk_context& subctx, cons
dst = cgraph->nodes[node_idx + 2];
}
// when dst aliases src0, the channels outside the rotated window already hold the correct data
const bool inplace = dst->data == src0->data;
ggml_vk_op_f32<vk_op_rope_push_constants>(ctx, subctx, src0, src1, src2, src3, dst, GGML_OP_ROPE,
ggml_vk_make_rope_constants(cgraph->nodes[node_idx], src0, src2 != nullptr, backprop, set_rows_stride, inplace));
ggml_vk_make_rope_constants(cgraph->nodes[node_idx], src0, src2 != nullptr, backprop, set_rows_stride));
}
static void ggml_vk_argsort(ggml_backend_vk_context * ctx, vk_context& subctx, const ggml_tensor * src0, ggml_tensor * dst) {
@@ -51,16 +51,13 @@ void rope_norm(const uint i0, const uint i1, const uint i2, const uint i3, rope_
idst += p.d_offset;
if (i0 < p.n_offs || i0 >= p.n_offs + p.n_dims) {
if (p.inplace != 0) {
return;
}
rope_data_d[idst + 0] = ROPE_D_TYPE(rope_data_a[ix + 0]);
rope_data_d[idst + 1] = ROPE_D_TYPE(rope_data_a[ix + 1]);
return;
}
const uint iw = i0 - p.n_offs; // channel index relative to the rotated window
const uint iw = i0 - p.n_offs; // relative idx
const float theta_base = rope_data_pos[i2] * pow(p.theta_scale, iw/2.0f);
@@ -93,16 +90,13 @@ void rope_neox(const uint i0, const uint i1, const uint i2, const uint i3, rope_
idst += p.d_offset;
if (i0 < p.n_offs || i0 >= p.n_offs + p.n_dims) {
if (p.inplace != 0) {
return;
}
rope_data_d[idst + i0/2 + 0] = ROPE_D_TYPE(rope_data_a[ix + i0/2 + 0]);
rope_data_d[idst + i0/2 + 1] = ROPE_D_TYPE(rope_data_a[ix + i0/2 + 1]);
return;
}
const uint iw = i0 - p.n_offs; // channel index relative to the rotated window
const uint iw = i0 - p.n_offs; // relative idx
const float theta_base = rope_data_pos[i2] * pow(p.theta_scale, iw/2.0f);
@@ -137,16 +131,13 @@ void rope_multi(const uint i0, const uint i1, const uint i2, const uint i3, rope
idst += p.d_offset;
if (i0 < p.n_offs || i0 >= p.n_offs + p.n_dims) {
if (p.inplace != 0) {
return;
}
rope_data_d[idst + i0/2 + 0] = ROPE_D_TYPE(rope_data_a[ix + i0/2 + 0]);
rope_data_d[idst + i0/2 + 1] = ROPE_D_TYPE(rope_data_a[ix + i0/2 + 1]);
return;
}
const uint iw = i0 - p.n_offs; // channel index relative to the rotated window
const uint iw = i0 - p.n_offs; // relative idx
const int sect_dims = p.sections[0] + p.sections[1] + p.sections[2] + p.sections[3];
const int sec_w = p.sections[1] + p.sections[0];
@@ -17,7 +17,6 @@ struct rope_params {
uint is_imrope;
uint is_back;
uint set_rows_stride;
uint inplace;
uint ne00;
uint ne01;