Skip to content

Commit

Permalink
afpvec4 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
FhqTreap committed Sep 18, 2023
1 parent b9a9d85 commit af70ca9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/layer/vulkan/shader/gelu_pack4.comp
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ void main()
// y = 0.5x * (1 + tanh(sqrt(2/Pi) * (x + 0.044715x^3)))

#if NCNN_moltenvk
v = afp(0.5f) * v * (afp(1.0f) + afpvec4(tanh(vec4(afp(0.79788452f) * (v + afp(0.044715f) * v * v * v)))));
v = afpvec4(0.5f) * v * (afpvec4(1.0f) + afpvec4(tanh(vec4(afpvec4(0.79788452f) * (v + afpvec4(0.044715f) * v * v * v)))));
#else
v = afp(0.5f) * v * (afp(1.0f) + tanh(afp(0.79788452f) * (v + afp(0.044715f) * v * v * v)));
v = afpvec4(0.5f) * v * (afpvec4(1.0f) + tanh(afpvec4(0.79788452f) * (v + afpvec4(0.044715f) * v * v * v)));
#endif

#if NCNN_image_shader
Expand Down
8 changes: 4 additions & 4 deletions src/layer/vulkan/shader/gelu_pack8.comp
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ void main()
// y = 0.5x * (1 + tanh(sqrt(2/Pi) * (x + 0.044715x^3)))

#if NCNN_moltenvk
v[0] = afp(0.5f) * v[0] * (afp(1.0f) + afpvec4(tanh(vec4(afp(0.79788452f) * (v[0] + afp(0.044715f) * v[0] * v[0] * v[0])))));
v[1] = afp(0.5f) * v[1] * (afp(1.0f) + afpvec4(tanh(vec4(afp(0.79788452f) * (v[1] + afp(0.044715f) * v[1] * v[1] * v[1])))));
v[0] = afpvec4(0.5f) * v[0] * (afpvec4(1.0f) + afpvec4(tanh(vec4(afpvec4(0.79788452f) * (v[0] + afpvec4(0.044715f) * v[0] * v[0] * v[0])))));
v[1] = afpvec4(0.5f) * v[1] * (afpvec4(1.0f) + afpvec4(tanh(vec4(afpvec4(0.79788452f) * (v[1] + afpvec4(0.044715f) * v[1] * v[1] * v[1])))));
#else
v[0] = afp(0.5f) * v[0] * (afp(1.0f) + tanh(afp(0.79788452f) * (v[0] + afp(0.044715f) * v[0] * v[0] * v[0])));
v[1] = afp(0.5f) * v[1] * (afp(1.0f) + tanh(afp(0.79788452f) * (v[1] + afp(0.044715f) * v[1] * v[1] * v[1])));
v[0] = afpvec4(0.5f) * v[0] * (afpvec4(1.0f) + tanh(afpvec4(0.79788452f) * (v[0] + afpvec4(0.044715f) * v[0] * v[0] * v[0])));
v[1] = afpvec4(0.5f) * v[1] * (afpvec4(1.0f) + tanh(afpvec4(0.79788452f) * (v[1] + afpvec4(0.044715f) * v[1] * v[1] * v[1])));
#endif

#if NCNN_image_shader
Expand Down

0 comments on commit af70ca9

Please sign in to comment.