Skip to content

Commit b54aaa9

Browse files
committed
vulkan: implement CEIL
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
1 parent 637558c commit b54aaa9

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;
@@ -3840,6 +3841,7 @@ static void ggml_vk_load_shaders(vk_device& device) {
38403841
CREATE_UNARY(softplus)
38413842
CREATE_UNARY(step)
38423843
CREATE_UNARY(round)
3844+
CREATE_UNARY(ceil)
38433845
#undef CREATE_UNARY
38443846

38453847
#define CREATE_UNARY_RTE(name) \
@@ -8270,6 +8272,8 @@ static vk_pipeline ggml_vk_op_get_pipeline(ggml_backend_vk_context * ctx, const
82708272
return ctx->device->pipeline_step[dst->type == GGML_TYPE_F16];
82718273
case GGML_UNARY_OP_ROUND:
82728274
return ctx->device->pipeline_round[dst->type == GGML_TYPE_F16];
8275+
case GGML_UNARY_OP_CEIL:
8276+
return ctx->device->pipeline_ceil[dst->type == GGML_TYPE_F16];
82738277
default:
82748278
break;
82758279
}
@@ -11294,6 +11298,7 @@ static bool ggml_vk_build_graph(ggml_backend_vk_context * ctx, ggml_cgraph * cgr
1129411298
case GGML_UNARY_OP_SOFTPLUS:
1129511299
case GGML_UNARY_OP_STEP:
1129611300
case GGML_UNARY_OP_ROUND:
11301+
case GGML_UNARY_OP_CEIL:
1129711302
break;
1129811303
default:
1129911304
return false;
@@ -11649,6 +11654,7 @@ static bool ggml_vk_build_graph(ggml_backend_vk_context * ctx, ggml_cgraph * cgr
1164911654
case GGML_UNARY_OP_SOFTPLUS:
1165011655
case GGML_UNARY_OP_STEP:
1165111656
case GGML_UNARY_OP_ROUND:
11657+
case GGML_UNARY_OP_CEIL:
1165211658
ggml_vk_unary(ctx, compute_ctx, src0, node);
1165311659
break;
1165411660
default:
@@ -11928,6 +11934,7 @@ static bool ggml_vk_compute_forward(ggml_backend_vk_context * ctx, ggml_cgraph *
1192811934
case GGML_UNARY_OP_SOFTPLUS:
1192911935
case GGML_UNARY_OP_STEP:
1193011936
case GGML_UNARY_OP_ROUND:
11937+
case GGML_UNARY_OP_CEIL:
1193111938
buf = tensor->buffer;
1193211939
break;
1193311940
default:
@@ -13533,6 +13540,7 @@ static bool ggml_backend_vk_device_supports_op(ggml_backend_dev_t dev, const ggm
1353313540
case GGML_UNARY_OP_SOFTPLUS:
1353413541
case GGML_UNARY_OP_STEP:
1353513542
case GGML_UNARY_OP_ROUND:
13543+
case GGML_UNARY_OP_CEIL:
1353613544
return ggml_is_contiguous(op->src[0]) &&
1353713545
(op->src[0]->type == GGML_TYPE_F32 || op->src[0]->type == GGML_TYPE_F16) &&
1353813546
(op->type == GGML_TYPE_F32 || op->type == GGML_TYPE_F16) &&
@@ -14455,6 +14463,9 @@ static void ggml_vk_check_results_0(ggml_backend_vk_context * ctx, ggml_cgraph *
1445514463
case GGML_UNARY_OP_ROUND:
1445614464
tensor_clone = ggml_round(ggml_ctx, src_clone[0]);
1445714465
break;
14466+
case GGML_UNARY_OP_CEIL:
14467+
tensor_clone = ggml_ceil(ggml_ctx, src_clone[0]);
14468+
break;
1445814469
default:
1445914470
std::cerr << "Missing vk_check_results OP: " << ggml_op_name(tensor->op) << std::endl;
1446014471
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)