Skip to content

Commit d262c79

Browse files
committed
ops: add CEIL operator support for CPU and SYCL
1 parent a14bd35 commit d262c79

File tree

12 files changed

+124
-1
lines changed

12 files changed

+124
-1
lines changed

docs/ops.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Legend:
2222
| ARANGE ||||||||||
2323
| ARGMAX ||||||||||
2424
| ARGSORT ||||||||||
25+
| CEIL ||||||||||
2526
| CLAMP ||||| 🟡 | 🟡 || 🟡 ||
2627
| CONCAT |||| 🟡 || 🟡 | 🟡 |||
2728
| CONT || 🟡 |||| 🟡 | 🟡 | 🟡 ||

docs/ops/CPU.csv

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"backend_name","op_name","op_params","test_mode","supported","error_message","backend_reg_name"
22
"CPU","ABS","type=f16,ne_a=[128,2,2,2],v=0","support","1","yes","CPU"
33
"CPU","ABS","type=f16,ne_a=[5,7,11,13],v=0","support","1","yes","CPU"
4+
"CPU","CEIL","type=f16,ne_a=[128,2,2,2],v=0","support","1","yes","CPU"
5+
"CPU","CEIL","type=f16,ne_a=[5,7,11,13],v=0","support","1","yes","CPU"
46
"CPU","SGN","type=f16,ne_a=[128,2,2,2],v=0","support","1","yes","CPU"
57
"CPU","SGN","type=f16,ne_a=[5,7,11,13],v=0","support","1","yes","CPU"
68
"CPU","NEG","type=f16,ne_a=[128,2,2,2],v=0","support","1","yes","CPU"
@@ -61,6 +63,8 @@
6163
"CPU","GELU_ERF","type=f16,ne_a=[5,7,11,13],v=1","support","1","yes","CPU"
6264
"CPU","ABS","type=f32,ne_a=[128,2,2,2],v=0","support","1","yes","CPU"
6365
"CPU","ABS","type=f32,ne_a=[5,7,11,13],v=0","support","1","yes","CPU"
66+
"CPU","CEIL","type=f32,ne_a=[128,2,2,2],v=0","support","1","yes","CPU"
67+
"CPU","CEIL","type=f32,ne_a=[5,7,11,13],v=0","support","1","yes","CPU"
6468
"CPU","SGN","type=f32,ne_a=[128,2,2,2],v=0","support","1","yes","CPU"
6569
"CPU","SGN","type=f32,ne_a=[5,7,11,13],v=0","support","1","yes","CPU"
6670
"CPU","NEG","type=f32,ne_a=[128,2,2,2],v=0","support","1","yes","CPU"

docs/ops/SYCL.csv

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"backend_name","op_name","op_params","test_mode","supported","error_message","backend_reg_name"
22
"SYCL0","ABS","type=f16,ne_a=[128,2,2,2],v=0","support","1","yes","SYCL"
33
"SYCL0","ABS","type=f16,ne_a=[5,7,11,13],v=0","support","1","yes","SYCL"
4+
"SYCL0","CEIL","type=f16,ne_a=[128,2,2,2],v=0","support","1","yes","SYCL"
5+
"SYCL0","CEIL","type=f16,ne_a=[5,7,11,13],v=0","support","1","yes","SYCL"
46
"SYCL0","SGN","type=f16,ne_a=[128,2,2,2],v=0","support","1","yes","SYCL"
57
"SYCL0","SGN","type=f16,ne_a=[5,7,11,13],v=0","support","1","yes","SYCL"
68
"SYCL0","NEG","type=f16,ne_a=[128,2,2,2],v=0","support","1","yes","SYCL"
@@ -61,6 +63,8 @@
6163
"SYCL0","GELU_ERF","type=f16,ne_a=[5,7,11,13],v=1","support","0","no","SYCL"
6264
"SYCL0","ABS","type=f32,ne_a=[128,2,2,2],v=0","support","1","yes","SYCL"
6365
"SYCL0","ABS","type=f32,ne_a=[5,7,11,13],v=0","support","1","yes","SYCL"
66+
"SYCL0","CEIL","type=f32,ne_a=[128,2,2,2],v=0","support","1","yes","SYCL"
67+
"SYCL0","CEIL","type=f32,ne_a=[5,7,11,13],v=0","support","1","yes","SYCL"
6468
"SYCL0","SGN","type=f32,ne_a=[128,2,2,2],v=0","support","1","yes","SYCL"
6569
"SYCL0","SGN","type=f32,ne_a=[5,7,11,13],v=0","support","1","yes","SYCL"
6670
"SYCL0","NEG","type=f32,ne_a=[128,2,2,2],v=0","support","1","yes","SYCL"

ggml/include/ggml.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ extern "C" {
574574
GGML_UNARY_OP_HARDSIGMOID,
575575
GGML_UNARY_OP_EXP,
576576
GGML_UNARY_OP_GELU_ERF,
577+
GGML_UNARY_OP_CEIL,
577578

578579
GGML_UNARY_OP_COUNT,
579580
};
@@ -1147,6 +1148,14 @@ extern "C" {
11471148
GGML_API struct ggml_tensor * ggml_exp_inplace(
11481149
struct ggml_context * ctx,
11491150
struct ggml_tensor * a);
1151+
1152+
GGML_API struct ggml_tensor * ggml_ceil(
1153+
struct ggml_context * ctx,
1154+
struct ggml_tensor * a);
1155+
1156+
GGML_API struct ggml_tensor * ggml_ceil_inplace(
1157+
struct ggml_context * ctx,
1158+
struct ggml_tensor * a);
11501159

11511160
// gated linear unit ops
11521161
// A: n columns, r rows,

ggml/src/ggml-cpu/ops.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9767,6 +9767,10 @@ void ggml_compute_forward_unary(
97679767
{
97689768
ggml_compute_forward_exp(params, dst);
97699769
} break;
9770+
case GGML_UNARY_OP_CEIL:
9771+
{
9772+
ggml_compute_forward_ceil(params, dst);
9773+
} break;
97709774
default:
97719775
{
97729776
GGML_ABORT("fatal error");

ggml/src/ggml-cpu/unary-ops.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ static inline float op_log(float x) {
6464
return logf(x);
6565
}
6666

67+
static inline float op_ceil(float x) {
68+
return ceilf(x);
69+
}
70+
6771
template <float (*op)(float), typename src0_t, typename dst_t>
6872
static inline void vec_unary_op(int64_t n, dst_t * y, const src0_t * x) {
6973
constexpr auto src0_to_f32 = type_conversion_table<src0_t>::to_f32;
@@ -184,3 +188,8 @@ void ggml_compute_forward_cos(const ggml_compute_params * params, ggml_tensor *
184188
void ggml_compute_forward_log(const ggml_compute_params * params, ggml_tensor * dst) {
185189
unary_op<op_log>(params, dst);
186190
}
191+
192+
void ggml_compute_forward_ceil(const ggml_compute_params * params, ggml_tensor * dst) {
193+
unary_op<op_ceil>(params, dst);
194+
}
195+

ggml/src/ggml-cpu/unary-ops.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ void ggml_compute_forward_sqrt(const struct ggml_compute_params * params, struct
2222
void ggml_compute_forward_sin(const struct ggml_compute_params * params, struct ggml_tensor * dst);
2323
void ggml_compute_forward_cos(const struct ggml_compute_params * params, struct ggml_tensor * dst);
2424
void ggml_compute_forward_log(const struct ggml_compute_params * params, struct ggml_tensor * dst);
25+
void ggml_compute_forward_ceil(const struct ggml_compute_params * params, struct ggml_tensor * dst);
2526

2627
#ifdef __cplusplus
2728
}

ggml/src/ggml-sycl/element_wise.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ static void unary_op_sgn_kernel(const T * x, T * dst, const int k, const sycl::n
156156
dst[i] = op_sgn(x[i]);
157157
}
158158
}
159+
template<typename T>
160+
static __dpct_inline__ T op_ceil(T x) {
161+
return sycl::ceil(x);
162+
}
163+
159164

160165
template<typename T>
161166
static void unary_op_abs_kernel(const T * x, T * dst, const int k, const sycl::nd_item<1> &item_ct1) {
@@ -304,6 +309,13 @@ static void unary_op_clamp_kernel(const T * x, T * dst, const int k, const sycl:
304309
}
305310
}
306311

312+
template<typename T>
313+
static void unary_op_ceil_kernel(const T * x, T * dst, const int k, const sycl::nd_item<1> &item_ct1) {
314+
SYCL_GLOBAL_ID_LOOP(k, item_ct1) {
315+
dst[i] = op_ceil(x[i]);
316+
}
317+
}
318+
307319
template<typename T>
308320
static void upscale(const T *x, T *dst, const int nb00, const int nb01,
309321
const int nb02, const int nb03, const int ne10, const int ne11,
@@ -944,6 +956,19 @@ static inline void ggml_sycl_op_clamp(ggml_backend_sycl_context & ctx, ggml_tens
944956
}, min_val, max_val);
945957
}
946958

959+
static inline void ggml_sycl_op_ceil(ggml_backend_sycl_context & ctx, ggml_tensor * dst) {
960+
ggml_sycl_detail::dispatch_ggml_sycl_op_unary(ctx, dst,
961+
[](const auto* src, auto* dst_ptr, int k_elements, queue_ptr stream) {
962+
const int num_blocks = ceil_div(k_elements, 256);
963+
stream->parallel_for(
964+
sycl::nd_range<1>(sycl::range<1>(num_blocks) * sycl::range<1>(256),
965+
sycl::range<1>(256)),
966+
[=](sycl::nd_item<1> item_ct1) {
967+
unary_op_ceil_kernel(src, dst_ptr, k_elements, item_ct1);
968+
});
969+
});
970+
}
971+
947972
static inline void ggml_sycl_op_acc(ggml_backend_sycl_context & ctx, ggml_tensor *dst) {
948973
GGML_ASSERT(dst->src[0]->type == GGML_TYPE_F32);
949974
GGML_ASSERT(dst->src[1]->type == GGML_TYPE_F32);
@@ -1168,3 +1193,7 @@ void ggml_sycl_geglu_quick(ggml_backend_sycl_context & ctx, ggml_tensor * dst) {
11681193
scope_op_debug_print scope_dbg_print(__func__, dst, /*num_src=*/1);
11691194
ggml_sycl_op_geglu_quick(ctx, dst);
11701195
}
1196+
void ggml_sycl_ceil(ggml_backend_sycl_context & ctx, ggml_tensor * dst) {
1197+
scope_op_debug_print scope_dbg_print(__func__, dst, /*num_src=*/1);
1198+
ggml_sycl_op_ceil(ctx, dst);
1199+
}

ggml/src/ggml-sycl/element_wise.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ void ggml_sycl_sgn(ggml_backend_sycl_context & ctx, ggml_tensor * dst);
7575

7676
void ggml_sycl_abs(ggml_backend_sycl_context & ctx, ggml_tensor * dst);
7777

78+
void ggml_sycl_ceil(ggml_backend_sycl_context & ctx, ggml_tensor * dst);
79+
7880
void ggml_sycl_elu(ggml_backend_sycl_context & ctx, ggml_tensor * dst);
7981

8082
void ggml_sycl_geglu(ggml_backend_sycl_context & ctx, ggml_tensor * dst);

ggml/src/ggml-sycl/ggml-sycl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3636,6 +3636,9 @@ static bool ggml_sycl_compute_forward(ggml_backend_sycl_context & ctx, struct gg
36363636
case GGML_UNARY_OP_ELU:
36373637
ggml_sycl_elu(ctx, dst);
36383638
break;
3639+
case GGML_UNARY_OP_CEIL:
3640+
ggml_sycl_ceil(ctx, dst);
3641+
break;
36393642
default:
36403643
return false;
36413644
}
@@ -4190,6 +4193,7 @@ static bool ggml_backend_sycl_device_supports_op(ggml_backend_dev_t dev, const g
41904193
case GGML_UNARY_OP_SGN:
41914194
case GGML_UNARY_OP_ABS:
41924195
case GGML_UNARY_OP_ELU:
4196+
case GGML_UNARY_OP_CEIL:
41934197
#if defined (GGML_SYCL_F16)
41944198
return ggml_is_contiguous(op->src[0]) && (op->type == op->src[0]->type);
41954199
#else

0 commit comments

Comments
 (0)