Skip to content

Commit 7942c39

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

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
@@ -668,6 +668,7 @@ struct vk_device_struct {
668668
vk_pipeline pipeline_step[2];
669669
vk_pipeline pipeline_round[2];
670670
vk_pipeline pipeline_ceil[2];
671+
vk_pipeline pipeline_floor[2];
671672

672673
vk_pipeline pipeline_add1_f16_f16;
673674
vk_pipeline pipeline_add1_f16_f32;
@@ -3836,6 +3837,7 @@ static void ggml_vk_load_shaders(vk_device& device) {
38363837
CREATE_UNARY(step)
38373838
CREATE_UNARY(round)
38383839
CREATE_UNARY(ceil)
3840+
CREATE_UNARY(floor)
38393841
#undef CREATE_UNARY
38403842

38413843
#define CREATE_UNARY_RTE(name) \
@@ -8268,6 +8270,8 @@ static vk_pipeline ggml_vk_op_get_pipeline(ggml_backend_vk_context * ctx, const
82688270
return ctx->device->pipeline_round[dst->type == GGML_TYPE_F16];
82698271
case GGML_UNARY_OP_CEIL:
82708272
return ctx->device->pipeline_ceil[dst->type == GGML_TYPE_F16];
8273+
case GGML_UNARY_OP_FLOOR:
8274+
return ctx->device->pipeline_floor[dst->type == GGML_TYPE_F16];
82718275
default:
82728276
break;
82738277
}
@@ -11293,6 +11297,7 @@ static bool ggml_vk_build_graph(ggml_backend_vk_context * ctx, ggml_cgraph * cgr
1129311297
case GGML_UNARY_OP_STEP:
1129411298
case GGML_UNARY_OP_ROUND:
1129511299
case GGML_UNARY_OP_CEIL:
11300+
case GGML_UNARY_OP_FLOOR:
1129611301
break;
1129711302
default:
1129811303
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_STEP:
1165011655
case GGML_UNARY_OP_ROUND:
1165111656
case GGML_UNARY_OP_CEIL:
11657+
case GGML_UNARY_OP_FLOOR:
1165211658
ggml_vk_unary(ctx, compute_ctx, src0, node);
1165311659
break;
1165411660
default:
@@ -11929,6 +11935,7 @@ static bool ggml_vk_compute_forward(ggml_backend_vk_context * ctx, ggml_cgraph *
1192911935
case GGML_UNARY_OP_STEP:
1193011936
case GGML_UNARY_OP_ROUND:
1193111937
case GGML_UNARY_OP_CEIL:
11938+
case GGML_UNARY_OP_FLOOR:
1193211939
buf = tensor->buffer;
1193311940
break;
1193411941
default:
@@ -13535,6 +13542,7 @@ static bool ggml_backend_vk_device_supports_op(ggml_backend_dev_t dev, const ggm
1353513542
case GGML_UNARY_OP_STEP:
1353613543
case GGML_UNARY_OP_ROUND:
1353713544
case GGML_UNARY_OP_CEIL:
13545+
case GGML_UNARY_OP_FLOOR:
1353813546
return ggml_is_contiguous(op->src[0]) &&
1353913547
(op->src[0]->type == GGML_TYPE_F32 || op->src[0]->type == GGML_TYPE_F16) &&
1354013548
(op->type == GGML_TYPE_F32 || op->type == GGML_TYPE_F16) &&
@@ -14459,6 +14467,9 @@ static void ggml_vk_check_results_0(ggml_backend_vk_context * ctx, ggml_cgraph *
1445914467
case GGML_UNARY_OP_CEIL:
1446014468
tensor_clone = ggml_ceil(ggml_ctx, src_clone[0]);
1446114469
break;
14470+
case GGML_UNARY_OP_FLOOR:
14471+
tensor_clone = ggml_floor(ggml_ctx, src_clone[0]);
14472+
break;
1446214473
default:
1446314474
std::cerr << "Missing vk_check_results OP: " << ggml_op_name(tensor->op) << std::endl;
1446414475
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(floor(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
@@ -857,6 +857,8 @@ void process_shaders() {
857857
string_to_spv("round_f32", "round.comp", {{"A_TYPE", "float"}, {"D_TYPE", "float"}});
858858
string_to_spv("ceil_f16", "ceil.comp", {{"A_TYPE", "float16_t"}, {"D_TYPE", "float16_t"}});
859859
string_to_spv("ceil_f32", "ceil.comp", {{"A_TYPE", "float"}, {"D_TYPE", "float"}});
860+
string_to_spv("floor_f16", "floor.comp", {{"A_TYPE", "float16_t"}, {"D_TYPE", "float16_t"}});
861+
string_to_spv("floor_f32", "floor.comp", {{"A_TYPE", "float"}, {"D_TYPE", "float"}});
860862

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

0 commit comments

Comments
 (0)