interplane.Get Omega
Read in your language

ggml

[Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685)

Brought by drakestapleton

branch master Branches Tags History

ggml / src / ggml-cuda / unary.cuh

138 lines · 5154 bytes Raw Blame History
1#pragma once
2#include "common.cuh"
3
4#define CUDA_NEG_BLOCK_SIZE 256
5#define CUDA_STEP_BLOCK_SIZE 256
6#define CUDA_GELU_BLOCK_SIZE 256
7#define CUDA_SILU_BLOCK_SIZE 256
8#define CUDA_SILU_BACK_BLOCK_SIZE 256
9#define CUDA_TANH_BLOCK_SIZE 256
10#define CUDA_RELU_BLOCK_SIZE 256
11#define CUDA_SIGMOID_BLOCK_SIZE 256
12#define CUDA_HARDSIGMOID_BLOCK_SIZE 256
13#define CUDA_EXP_BLOCK_SIZE 256
14#define CUDA_HARDSWISH_BLOCK_SIZE 256
15#define CUDA_SQR_BLOCK_SIZE 256
16#define CUDA_SQRT_BLOCK_SIZE 256
17#define CUDA_SIN_BLOCK_SIZE 256
18#define CUDA_COS_BLOCK_SIZE 256
19#define CUDA_GLU_BLOCK_SIZE 256
20#define CUDA_XIELU_BLOCK_SIZE 256
21
22void ggml_cuda_op_abs(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
23
24void ggml_cuda_op_sgn(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
25
26void ggml_cuda_op_neg(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
27
28void ggml_cuda_op_step(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
29
30void ggml_cuda_op_gelu(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
31
32void ggml_cuda_op_silu(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
33
34void ggml_cuda_op_silu_back(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
35
36void ggml_cuda_op_gelu_erf(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
37
38void ggml_cuda_op_gelu_quick(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
39
40void ggml_cuda_op_tanh(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
41
42void ggml_cuda_op_relu(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
43
44void ggml_cuda_op_sigmoid(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
45
46void ggml_cuda_op_hardsigmoid(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
47
48void ggml_cuda_op_exp(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
49
50void ggml_cuda_op_hardswish(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
51
52void ggml_cuda_op_leaky_relu(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
53
54void ggml_cuda_op_sqr(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
55
56void ggml_cuda_op_sqrt(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
57
58void ggml_cuda_op_sin(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
59
60void ggml_cuda_op_cos(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
61
62void ggml_cuda_op_log(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
63
64void ggml_cuda_op_expm1(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
65
66void ggml_cuda_op_softplus(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
67
68void ggml_cuda_op_elu(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
69
70void ggml_cuda_op_floor(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
71
72void ggml_cuda_op_ceil(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
73
74void ggml_cuda_op_round(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
75
76void ggml_cuda_op_trunc(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
77
78void ggml_cuda_op_reglu(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
79
80void ggml_cuda_op_geglu(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
81
82void ggml_cuda_op_swiglu(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
83
84void ggml_cuda_op_swiglu_oai(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
85
86void ggml_cuda_op_swiglu_clamp(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
87
88void ggml_cuda_op_geglu_erf(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
89
90void ggml_cuda_op_geglu_quick(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
91
92void ggml_cuda_op_xielu(ggml_backend_cuda_context & ctx, ggml_tensor * dst);
93
94void ggml_cuda_op_unary_mul(ggml_backend_cuda_context & ctx, ggml_tensor * unary_node, ggml_tensor * mul_node);
95
96void ggml_cuda_op_relu_sqr(ggml_backend_cuda_context & ctx, ggml_tensor * relu_node, ggml_tensor * sqr_node);
97
98__device__ __forceinline__ float ggml_cuda_op_silu_single(float x) {
99 return x / (1.0f + expf(-x));
100}
101
102__device__ __forceinline__ float ggml_cuda_op_gelu_single(float x) {
103 const float GELU_COEF_A = 0.044715f;
104 const float SQRT_2_OVER_PI = 0.79788456080286535587989211986876f;
105
106 return 0.5f * x * (1.0f + tanhf(SQRT_2_OVER_PI * x * (1.0f + GELU_COEF_A * x * x)));
107}
108
109__device__ __forceinline__ float ggml_cuda_op_swiglu_oai_single(float x, float g, float alpha = 1.702f, float limit = 7.0f) {
110 x = fminf(x, limit);
111 g = fmaxf(fminf(g, limit), -limit);
112
113 float out_glu = x / (1.0f + expf(-x * alpha));
114 out_glu = out_glu * (1.0f + g);
115 return out_glu;
116}
117
118__device__ __forceinline__ float ggml_cuda_op_swiglu_clamp_single(float gate, float up, float limit) {
119 gate = fminf(gate, limit);
120 up = fmaxf(fminf(up, limit), -limit);
121
122 return ggml_cuda_op_silu_single(gate) * up;
123}
124
125__device__ __forceinline__ float ggml_cuda_op_glu_single(ggml_glu_op op, float gate, float up, float limit) {
126 switch (op) {
127 case GGML_GLU_OP_SWIGLU:
128 return up * ggml_cuda_op_silu_single(gate);
129 case GGML_GLU_OP_GEGLU:
130 return up * ggml_cuda_op_gelu_single(gate);
131 case GGML_GLU_OP_SWIGLU_OAI:
132 return ggml_cuda_op_swiglu_oai_single(gate, up);
133 case GGML_GLU_OP_SWIGLU_CLAMP:
134 return ggml_cuda_op_swiglu_clamp_single(gate, up, limit);
135 default:
136 return up * gate;
137 }
138}