Skip to content

Commit a2423f6

Browse files
committed
support OP EXPM1, support all UT cases of FLOOR, TRUNC, ROUND
1 parent d6d0ce8 commit a2423f6

3 files changed

Lines changed: 32 additions & 35 deletions

File tree

ggml/src/ggml-sycl/element_wise.cpp

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ static __dpct_inline__ T op_exp(T x) {
124124
return sycl::exp(x);
125125
}
126126

127+
template<typename T>
128+
static __dpct_inline__ T op_expm1(T x) {
129+
return sycl::expm1(x);
130+
}
131+
127132
template<typename T>
128133
static __dpct_inline__ T op_log(T x) {
129134
if (x <= static_cast<T>(0)) {
@@ -605,6 +610,12 @@ static inline void ggml_sycl_op_exp(ggml_backend_sycl_context & ctx, ggml_tensor
605610
});
606611
}
607612

613+
static inline void ggml_sycl_op_expm1(ggml_backend_sycl_context & ctx, ggml_tensor * dst) {
614+
ggml_sycl_detail::ggml_sycl_op_unary(ctx, dst, [](auto x) {
615+
return op_expm1(x);
616+
});
617+
}
618+
608619
static inline void ggml_sycl_op_log(ggml_backend_sycl_context & ctx, ggml_tensor * dst) {
609620
ggml_sycl_detail::dispatch_ggml_sycl_op_unary(ctx, dst,
610621
[](const auto* src, auto* dst_ptr, int k_elements, queue_ptr stream) {
@@ -728,16 +739,9 @@ static inline void ggml_sycl_op_clamp(ggml_backend_sycl_context & ctx, ggml_tens
728739
}
729740

730741
static inline void ggml_sycl_op_floor(ggml_backend_sycl_context & ctx, ggml_tensor * dst) {
731-
ggml_sycl_detail::dispatch_ggml_sycl_op_unary(ctx, dst,
732-
[](const auto* src, auto* dst_ptr, int k_elements, queue_ptr stream) {
733-
const int num_blocks = ceil_div(k_elements, 256);
734-
stream->parallel_for(
735-
sycl::nd_range<1>(sycl::range<1>(num_blocks) * sycl::range<1>(256),
736-
sycl::range<1>(256)),
737-
[=](sycl::nd_item<1> item_ct1) {
738-
unary_op_floor_kernel(src, dst_ptr, k_elements, item_ct1);
739-
});
740-
});
742+
ggml_sycl_detail::ggml_sycl_op_unary(ctx, dst, [](auto x) {
743+
return op_floor(x);
744+
});
741745
}
742746

743747
static inline void ggml_sycl_op_ceil(ggml_backend_sycl_context & ctx, ggml_tensor * dst) {
@@ -747,29 +751,15 @@ static inline void ggml_sycl_op_ceil(ggml_backend_sycl_context & ctx, ggml_tenso
747751
}
748752

749753
static inline void ggml_sycl_op_round(ggml_backend_sycl_context & ctx, ggml_tensor * dst) {
750-
ggml_sycl_detail::dispatch_ggml_sycl_op_unary(ctx, dst,
751-
[](const auto* src, auto* dst_ptr, int k_elements, queue_ptr stream) {
752-
const int num_blocks = ceil_div(k_elements, 256);
753-
stream->parallel_for(
754-
sycl::nd_range<1>(sycl::range<1>(num_blocks) * sycl::range<1>(256),
755-
sycl::range<1>(256)),
756-
[=](sycl::nd_item<1> item_ct1) {
757-
unary_op_round_kernel(src, dst_ptr, k_elements, item_ct1);
758-
});
759-
});
754+
ggml_sycl_detail::ggml_sycl_op_unary(ctx, dst, [](auto x) {
755+
return op_round(x);
756+
});
760757
}
761758

762759
static inline void ggml_sycl_op_trunc(ggml_backend_sycl_context & ctx, ggml_tensor * dst) {
763-
ggml_sycl_detail::dispatch_ggml_sycl_op_unary(ctx, dst,
764-
[](const auto* src, auto* dst_ptr, int k_elements, queue_ptr stream) {
765-
const int num_blocks = ceil_div(k_elements, 256);
766-
stream->parallel_for(
767-
sycl::nd_range<1>(sycl::range<1>(num_blocks) * sycl::range<1>(256),
768-
sycl::range<1>(256)),
769-
[=](sycl::nd_item<1> item_ct1) {
770-
unary_op_trunc_kernel(src, dst_ptr, k_elements, item_ct1);
771-
});
772-
});
760+
ggml_sycl_detail::ggml_sycl_op_unary(ctx, dst, [](auto x) {
761+
return op_trunc(x);
762+
});
773763
}
774764

775765
static inline void ggml_sycl_op_acc(ggml_backend_sycl_context & ctx, ggml_tensor *dst) {
@@ -1018,6 +1008,11 @@ void ggml_sycl_exp(ggml_backend_sycl_context & ctx, ggml_tensor * dst) {
10181008
ggml_sycl_op_exp(ctx, dst);
10191009
}
10201010

1011+
void ggml_sycl_expm1(ggml_backend_sycl_context & ctx, ggml_tensor * dst) {
1012+
scope_op_debug_print scope_dbg_print(__func__, dst, /*num_src=*/1);
1013+
ggml_sycl_op_expm1(ctx, dst);
1014+
}
1015+
10211016
void ggml_sycl_log(ggml_backend_sycl_context & ctx, ggml_tensor * dst) {
10221017
scope_op_debug_print scope_dbg_print(__func__, dst, /*num_src=*/1);
10231018
ggml_sycl_op_log(ctx, dst);

ggml/src/ggml-sycl/element_wise.hpp

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

6060
void ggml_sycl_exp(ggml_backend_sycl_context & ctx, ggml_tensor * dst);
6161

62+
void ggml_sycl_expm1(ggml_backend_sycl_context & ctx, ggml_tensor * dst);
63+
6264
void ggml_sycl_log(ggml_backend_sycl_context & ctx, ggml_tensor * dst);
6365

6466
void ggml_sycl_softplus(ggml_backend_sycl_context & ctx, ggml_tensor * dst);

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4592,6 +4592,9 @@ static bool ggml_sycl_compute_forward(ggml_backend_sycl_context & ctx, struct gg
45924592
case GGML_UNARY_OP_EXP:
45934593
ggml_sycl_exp(ctx, dst);
45944594
break;
4595+
case GGML_UNARY_OP_EXPM1:
4596+
ggml_sycl_expm1(ctx, dst);
4597+
break;
45954598
case GGML_UNARY_OP_SOFTPLUS:
45964599
ggml_sycl_softplus(ctx, dst);
45974600
break;
@@ -5238,18 +5241,15 @@ static bool ggml_backend_sycl_device_supports_op(ggml_backend_dev_t dev, const g
52385241
case GGML_UNARY_OP_GELU_QUICK:
52395242
case GGML_UNARY_OP_GELU_ERF:
52405243
case GGML_UNARY_OP_EXP:
5244+
case GGML_UNARY_OP_EXPM1:
52415245
case GGML_UNARY_OP_SOFTPLUS:
52425246
case GGML_UNARY_OP_ELU:
52435247
case GGML_UNARY_OP_CEIL:
52445248
return true;
52455249
case GGML_UNARY_OP_FLOOR:
52465250
case GGML_UNARY_OP_ROUND:
52475251
case GGML_UNARY_OP_TRUNC:
5248-
#if defined (GGML_SYCL_F16)
5249-
return ggml_is_contiguous(op->src[0]) && (op->type == op->src[0]->type);
5250-
#else
5251-
return ggml_is_contiguous(op->src[0]) && (op->src[0]->type == GGML_TYPE_F32 && op->type == GGML_TYPE_F32) && (op->type == op->src[0]->type);
5252-
#endif
5252+
return true;
52535253
default:
52545254
return false;
52555255
}

0 commit comments

Comments
 (0)