Skip to content

Commit ccee88e

Browse files
s8322ggerganov
authored andcommitted
sycl: implement GGML_UNARY_OP_SOFTPLUS (llama/19114)
* sycl: add softplus unary op implementation * sycl: add softplus unary op implementation * docs(ops): mark SYCL SOFTPLUS as supported * docs: update SYCL status for SOFTPLUS
1 parent af11f83 commit ccee88e

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

src/ggml-sycl/element_wise.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,15 @@ static __dpct_inline__ T op_log(T x) {
123123
return sycl::log(x);
124124
}
125125

126+
template<typename T>
127+
static __dpct_inline__ T op_softplus(T x) {
128+
const float xf = (float) x;
129+
const float ax = sycl::fabs(xf);
130+
const float m = sycl::fmax(xf, 0.0f);
131+
const float y = m + sycl::log1p(sycl::exp(-ax));
132+
return (T) y;
133+
}
134+
126135
template<typename T>
127136
static __dpct_inline__ T op_neg(T x) {
128137
return -x;
@@ -695,6 +704,12 @@ static inline void ggml_sycl_op_log(ggml_backend_sycl_context & ctx, ggml_tensor
695704
});
696705
}
697706

707+
static inline void ggml_sycl_op_softplus(ggml_backend_sycl_context & ctx, ggml_tensor * dst) {
708+
ggml_sycl_detail::ggml_sycl_op_unary(ctx, dst, [](auto x) {
709+
return op_softplus(x);
710+
});
711+
}
712+
698713
static inline void ggml_sycl_op_neg(ggml_backend_sycl_context & ctx, ggml_tensor * dst) {
699714
ggml_sycl_detail::ggml_sycl_op_unary(ctx, dst, [](auto x) {
700715
return op_neg(x);
@@ -1101,6 +1116,11 @@ void ggml_sycl_log(ggml_backend_sycl_context & ctx, ggml_tensor * dst) {
11011116
ggml_sycl_op_log(ctx, dst);
11021117
}
11031118

1119+
void ggml_sycl_softplus(ggml_backend_sycl_context & ctx, ggml_tensor * dst) {
1120+
scope_op_debug_print scope_dbg_print(__func__, dst, /*num_src=*/1);
1121+
ggml_sycl_op_softplus(ctx, dst);
1122+
}
1123+
11041124
void ggml_sycl_neg(ggml_backend_sycl_context & ctx, ggml_tensor * dst) {
11051125
scope_op_debug_print scope_dbg_print(__func__, dst, /*num_src=*/1);
11061126
ggml_sycl_op_neg(ctx, dst);

src/ggml-sycl/element_wise.hpp

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

6262
void ggml_sycl_log(ggml_backend_sycl_context & ctx, ggml_tensor * dst);
6363

64+
void ggml_sycl_softplus(ggml_backend_sycl_context & ctx, ggml_tensor * dst);
65+
6466
void ggml_sycl_neg(ggml_backend_sycl_context & ctx, ggml_tensor * dst);
6567

6668
void ggml_sycl_step(ggml_backend_sycl_context & ctx, ggml_tensor * dst);

src/ggml-sycl/ggml-sycl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3845,6 +3845,9 @@ static bool ggml_sycl_compute_forward(ggml_backend_sycl_context & ctx, struct gg
38453845
case GGML_UNARY_OP_EXP:
38463846
ggml_sycl_exp(ctx, dst);
38473847
break;
3848+
case GGML_UNARY_OP_SOFTPLUS:
3849+
ggml_sycl_softplus(ctx, dst);
3850+
break;
38483851
case GGML_UNARY_OP_SGN:
38493852
ggml_sycl_sgn(ctx, dst);
38503853
break;
@@ -4466,6 +4469,7 @@ static bool ggml_backend_sycl_device_supports_op(ggml_backend_dev_t dev, const g
44664469
case GGML_UNARY_OP_GELU_QUICK:
44674470
case GGML_UNARY_OP_GELU_ERF:
44684471
case GGML_UNARY_OP_EXP:
4472+
case GGML_UNARY_OP_SOFTPLUS:
44694473
case GGML_UNARY_OP_ELU:
44704474
return true;
44714475
case GGML_UNARY_OP_FLOOR:

0 commit comments

Comments
 (0)