Skip to content

Commit ea3cb4e

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

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;
@@ -3842,6 +3843,7 @@ static void ggml_vk_load_shaders(vk_device& device) {
38423843
CREATE_UNARY(step)
38433844
CREATE_UNARY(round)
38443845
CREATE_UNARY(ceil)
3846+
CREATE_UNARY(floor)
38453847
#undef CREATE_UNARY
38463848

38473849
#define CREATE_UNARY_RTE(name) \
@@ -8274,6 +8276,8 @@ static vk_pipeline ggml_vk_op_get_pipeline(ggml_backend_vk_context * ctx, const
82748276
return ctx->device->pipeline_round[dst->type == GGML_TYPE_F16];
82758277
case GGML_UNARY_OP_CEIL:
82768278
return ctx->device->pipeline_ceil[dst->type == GGML_TYPE_F16];
8279+
case GGML_UNARY_OP_FLOOR:
8280+
return ctx->device->pipeline_floor[dst->type == GGML_TYPE_F16];
82778281
default:
82788282
break;
82798283
}
@@ -11299,6 +11303,7 @@ static bool ggml_vk_build_graph(ggml_backend_vk_context * ctx, ggml_cgraph * cgr
1129911303
case GGML_UNARY_OP_STEP:
1130011304
case GGML_UNARY_OP_ROUND:
1130111305
case GGML_UNARY_OP_CEIL:
11306+
case GGML_UNARY_OP_FLOOR:
1130211307
break;
1130311308
default:
1130411309
return false;
@@ -11655,6 +11660,7 @@ static bool ggml_vk_build_graph(ggml_backend_vk_context * ctx, ggml_cgraph * cgr
1165511660
case GGML_UNARY_OP_STEP:
1165611661
case GGML_UNARY_OP_ROUND:
1165711662
case GGML_UNARY_OP_CEIL:
11663+
case GGML_UNARY_OP_FLOOR:
1165811664
ggml_vk_unary(ctx, compute_ctx, src0, node);
1165911665
break;
1166011666
default:
@@ -11935,6 +11941,7 @@ static bool ggml_vk_compute_forward(ggml_backend_vk_context * ctx, ggml_cgraph *
1193511941
case GGML_UNARY_OP_STEP:
1193611942
case GGML_UNARY_OP_ROUND:
1193711943
case GGML_UNARY_OP_CEIL:
11944+
case GGML_UNARY_OP_FLOOR:
1193811945
buf = tensor->buffer;
1193911946
break;
1194011947
default:
@@ -13541,6 +13548,7 @@ static bool ggml_backend_vk_device_supports_op(ggml_backend_dev_t dev, const ggm
1354113548
case GGML_UNARY_OP_STEP:
1354213549
case GGML_UNARY_OP_ROUND:
1354313550
case GGML_UNARY_OP_CEIL:
13551+
case GGML_UNARY_OP_FLOOR:
1354413552
return ggml_is_contiguous(op->src[0]) &&
1354513553
(op->src[0]->type == GGML_TYPE_F32 || op->src[0]->type == GGML_TYPE_F16) &&
1354613554
(op->type == GGML_TYPE_F32 || op->type == GGML_TYPE_F16) &&
@@ -14466,6 +14474,9 @@ static void ggml_vk_check_results_0(ggml_backend_vk_context * ctx, ggml_cgraph *
1446614474
case GGML_UNARY_OP_CEIL:
1446714475
tensor_clone = ggml_ceil(ggml_ctx, src_clone[0]);
1446814476
break;
14477+
case GGML_UNARY_OP_FLOOR:
14478+
tensor_clone = ggml_floor(ggml_ctx, src_clone[0]);
14479+
break;
1446914480
default:
1447014481
std::cerr << "Missing vk_check_results OP: " << ggml_op_name(tensor->op) << std::endl;
1447114482
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)