Skip to content

Commit 05bed00

Browse files
committed
vulkan: implement CEIL
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
1 parent d71c9c5 commit 05bed00

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

ggml/src/ggml-vulkan/ggml-vulkan.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,7 @@ struct vk_device_struct {
667667
vk_pipeline pipeline_softplus[2];
668668
vk_pipeline pipeline_step[2];
669669
vk_pipeline pipeline_round[2];
670+
vk_pipeline pipeline_ceil[2];
670671

671672
vk_pipeline pipeline_add1_f16_f16;
672673
vk_pipeline pipeline_add1_f16_f32;
@@ -3834,6 +3835,7 @@ static void ggml_vk_load_shaders(vk_device& device) {
38343835
CREATE_UNARY(softplus)
38353836
CREATE_UNARY(step)
38363837
CREATE_UNARY(round)
3838+
CREATE_UNARY(ceil)
38373839
#undef CREATE_UNARY
38383840

38393841
#define CREATE_UNARY_RTE(name) \
@@ -8264,6 +8266,8 @@ static vk_pipeline ggml_vk_op_get_pipeline(ggml_backend_vk_context * ctx, const
82648266
return ctx->device->pipeline_step[dst->type == GGML_TYPE_F16];
82658267
case GGML_UNARY_OP_ROUND:
82668268
return ctx->device->pipeline_round[dst->type == GGML_TYPE_F16];
8269+
case GGML_UNARY_OP_CEIL:
8270+
return ctx->device->pipeline_ceil[dst->type == GGML_TYPE_F16];
82678271
default:
82688272
break;
82698273
}
@@ -11288,6 +11292,7 @@ static bool ggml_vk_build_graph(ggml_backend_vk_context * ctx, ggml_cgraph * cgr
1128811292
case GGML_UNARY_OP_SOFTPLUS:
1128911293
case GGML_UNARY_OP_STEP:
1129011294
case GGML_UNARY_OP_ROUND:
11295+
case GGML_UNARY_OP_CEIL:
1129111296
break;
1129211297
default:
1129311298
return false;
@@ -11643,6 +11648,7 @@ static bool ggml_vk_build_graph(ggml_backend_vk_context * ctx, ggml_cgraph * cgr
1164311648
case GGML_UNARY_OP_SOFTPLUS:
1164411649
case GGML_UNARY_OP_STEP:
1164511650
case GGML_UNARY_OP_ROUND:
11651+
case GGML_UNARY_OP_CEIL:
1164611652
ggml_vk_unary(ctx, compute_ctx, src0, node);
1164711653
break;
1164811654
default:
@@ -11922,6 +11928,7 @@ static bool ggml_vk_compute_forward(ggml_backend_vk_context * ctx, ggml_cgraph *
1192211928
case GGML_UNARY_OP_SOFTPLUS:
1192311929
case GGML_UNARY_OP_STEP:
1192411930
case GGML_UNARY_OP_ROUND:
11931+
case GGML_UNARY_OP_CEIL:
1192511932
buf = tensor->buffer;
1192611933
break;
1192711934
default:
@@ -13527,6 +13534,7 @@ static bool ggml_backend_vk_device_supports_op(ggml_backend_dev_t dev, const ggm
1352713534
case GGML_UNARY_OP_SOFTPLUS:
1352813535
case GGML_UNARY_OP_STEP:
1352913536
case GGML_UNARY_OP_ROUND:
13537+
case GGML_UNARY_OP_CEIL:
1353013538
return ggml_is_contiguous(op->src[0]) &&
1353113539
(op->src[0]->type == GGML_TYPE_F32 || op->src[0]->type == GGML_TYPE_F16) &&
1353213540
(op->type == GGML_TYPE_F32 || op->type == GGML_TYPE_F16) &&
@@ -14448,6 +14456,9 @@ static void ggml_vk_check_results_0(ggml_backend_vk_context * ctx, ggml_cgraph *
1444814456
case GGML_UNARY_OP_ROUND:
1444914457
tensor_clone = ggml_round(ggml_ctx, src_clone[0]);
1445014458
break;
14459+
case GGML_UNARY_OP_CEIL:
14460+
tensor_clone = ggml_ceil(ggml_ctx, src_clone[0]);
14461+
break;
1445114462
default:
1445214463
std::cerr << "Missing vk_check_results OP: " << ggml_op_name(tensor->op) << std::endl;
1445314464
GGML_ABORT("fatal error");
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#version 450
2+
3+
#include "generic_head.glsl"
4+
#include "types.glsl"
5+
6+
#extension GL_EXT_control_flow_attributes : enable
7+
8+
layout(local_size_x = 512, local_size_y = 1, local_size_z = 1) in;
9+
10+
layout (binding = 0) readonly buffer X {A_TYPE data_a[];};
11+
layout (binding = 1) writeonly buffer D {D_TYPE data_d[];};
12+
13+
void main() {
14+
const uint i = gl_GlobalInvocationID.z * 262144 + gl_GlobalInvocationID.y * 512 + gl_GlobalInvocationID.x;
15+
16+
if (i >= p.KX) {
17+
return;
18+
}
19+
20+
const float x = float(data_a[i]);
21+
data_d[i] = D_TYPE(ceil(x));
22+
}

ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,8 @@ void process_shaders() {
855855
string_to_spv("step_f32", "step.comp", {{"A_TYPE", "float"}, {"D_TYPE", "float"}});
856856
string_to_spv("round_f16", "round.comp", {{"A_TYPE", "float16_t"}, {"D_TYPE", "float16_t"}});
857857
string_to_spv("round_f32", "round.comp", {{"A_TYPE", "float"}, {"D_TYPE", "float"}});
858+
string_to_spv("ceil_f16", "ceil.comp", {{"A_TYPE", "float16_t"}, {"D_TYPE", "float16_t"}});
859+
string_to_spv("ceil_f32", "ceil.comp", {{"A_TYPE", "float"}, {"D_TYPE", "float"}});
858860

859861
for (auto rte : {false, true}) {
860862
std::string suffix = rte ? "_rte" : "";

0 commit comments

Comments
 (0)