@@ -345,6 +345,9 @@ enum vk_conv_shapes {
345
345
CONV_SHAPE_COUNT,
346
346
};
347
347
348
+ static constexpr uint32_t num_argsort_pipelines = 11;
349
+ static constexpr uint32_t max_argsort_cols = 1 << (num_argsort_pipelines-1);
350
+
348
351
struct vk_device_struct {
349
352
std::recursive_mutex mutex;
350
353
@@ -505,7 +508,7 @@ struct vk_device_struct {
505
508
vk_pipeline pipeline_rope_neox_f32, pipeline_rope_neox_f16;
506
509
vk_pipeline pipeline_rope_multi_f32, pipeline_rope_multi_f16;
507
510
vk_pipeline pipeline_rope_vision_f32, pipeline_rope_vision_f16;
508
- vk_pipeline pipeline_argsort_f32;
511
+ vk_pipeline pipeline_argsort_f32[num_argsort_pipelines] ;
509
512
vk_pipeline pipeline_sum_rows_f32;
510
513
vk_pipeline pipeline_argmax_f32;
511
514
vk_pipeline pipeline_count_equal_i32;
@@ -870,7 +873,6 @@ struct vk_op_soft_max_push_constants {
870
873
871
874
struct vk_op_argsort_push_constants {
872
875
uint32_t ncols;
873
- uint32_t ncols_pad;
874
876
int32_t order;
875
877
};
876
878
@@ -3099,7 +3101,9 @@ static void ggml_vk_load_shaders(vk_device& device) {
3099
3101
ggml_vk_create_pipeline(device, device->pipeline_rope_vision_f16, "rope_vision_f16", rope_vision_f16_len, rope_vision_f16_data, "main", 4, sizeof(vk_op_rope_push_constants), {1, 512, 1}, {}, 1);
3100
3102
}
3101
3103
3102
- ggml_vk_create_pipeline(device, device->pipeline_argsort_f32, "argsort_f32", argsort_f32_len, argsort_f32_data, "main", 2, sizeof(vk_op_argsort_push_constants), {1024, 1, 1}, {}, 1);
3104
+ for (uint32_t i = 0; i < num_argsort_pipelines; ++i) {
3105
+ ggml_vk_create_pipeline(device, device->pipeline_argsort_f32[i], "argsort_f32_"+std::to_string(i), argsort_f32_len, argsort_f32_data, "main", 2, sizeof(vk_op_argsort_push_constants), {1u<<i, 1, 1}, {1u<<i, i}, 1, true);
3106
+ }
3103
3107
3104
3108
ggml_vk_create_pipeline(device, device->pipeline_argmax_f32, "argmax_f32", argmax_f32_len, argmax_f32_data, "main", 2, sizeof(vk_op_push_constants), {1, 1, 1}, { device->subgroup_size }, 1);
3105
3109
@@ -7160,7 +7164,8 @@ static vk_pipeline ggml_vk_op_get_pipeline(ggml_backend_vk_context * ctx, const
7160
7164
}
7161
7165
case GGML_OP_ARGSORT:
7162
7166
if (src0->type == GGML_TYPE_F32 && dst->type == GGML_TYPE_I32) {
7163
- return ctx->device->pipeline_argsort_f32;
7167
+ uint32_t idx = (uint32_t)ceilf(log2f(float(dst->ne[0])));
7168
+ return ctx->device->pipeline_argsort_f32[idx];
7164
7169
}
7165
7170
return nullptr;
7166
7171
case GGML_OP_SUM:
@@ -8485,16 +8490,8 @@ static void ggml_vk_argsort(ggml_backend_vk_context * ctx, vk_context& subctx, c
8485
8490
8486
8491
uint32_t ncols = src0->ne[0];
8487
8492
8488
- uint32_t ncols_pad = 1;
8489
- while (ncols_pad < ncols) {
8490
- ncols_pad *= 2;
8491
- }
8492
-
8493
- GGML_ASSERT(ncols_pad <= 1024);
8494
-
8495
8493
ggml_vk_op_f32<vk_op_argsort_push_constants>(ctx, subctx, src0, nullptr, nullptr, dst, GGML_OP_ARGSORT, {
8496
8494
ncols,
8497
- ncols_pad,
8498
8495
op_params[0],
8499
8496
}, dryrun);
8500
8497
}
@@ -11367,6 +11364,8 @@ static bool ggml_backend_vk_device_supports_op(ggml_backend_dev_t dev, const ggm
11367
11364
case GGML_OP_OPT_STEP_ADAMW:
11368
11365
case GGML_OP_OPT_STEP_SGD:
11369
11366
return op->src[0]->type == GGML_TYPE_F32;
11367
+ case GGML_OP_ARGSORT:
11368
+ return op->ne[0] <= max_argsort_cols;
11370
11369
case GGML_OP_UPSCALE:
11371
11370
case GGML_OP_ACC:
11372
11371
case GGML_OP_CONCAT:
@@ -11376,7 +11375,6 @@ static bool ggml_backend_vk_device_supports_op(ggml_backend_dev_t dev, const ggm
11376
11375
case GGML_OP_DIAG_MASK_INF:
11377
11376
case GGML_OP_SOFT_MAX:
11378
11377
case GGML_OP_SOFT_MAX_BACK:
11379
- case GGML_OP_ARGSORT:
11380
11378
case GGML_OP_SUM:
11381
11379
case GGML_OP_SUM_ROWS:
11382
11380
case GGML_OP_ARGMAX:
0 commit comments