Skip to content

Conversation

@FhqTreap
Copy link
Contributor

@FhqTreap FhqTreap commented Sep 3, 2023

add gelu vulkan operator

@codecov-commenter
Copy link

codecov-commenter commented Sep 3, 2023

Codecov Report

Merging #5001 (2afe627) into master (9ecf6a6) will increase coverage by 0.00%.
Report is 2 commits behind head on master.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #5001   +/-   ##
=======================================
  Coverage   94.71%   94.72%           
=======================================
  Files         767      768    +1     
  Lines      228515   228610   +95     
=======================================
+ Hits       216445   216540   +95     
  Misses      12070    12070           
Files Changed Coverage Δ
src/layer/vulkan/gelu_vulkan.cpp 100.00% <100.00%> (ø)

Copy link
Member

@nihui nihui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@nihui nihui merged commit cc54b88 into Tencent:master Sep 4, 2023
@nihui
Copy link
Member

nihui commented Sep 4, 2023

Thanks for your contribution !

@DickyQi
Copy link

DickyQi commented Sep 4, 2023

for MacOS with vulkan fp16 build failed.

@FhqTreap
Copy link
Contributor Author

FhqTreap commented Sep 5, 2023

for MacOS with vulkan fp16 build failed.

more details on this?😮

@nihui
Copy link
Member

nihui commented Sep 5, 2023

for MacOS with vulkan fp16 build failed.

more details on this?😮

tanh fp16 on moltenvk has precision issue, so it is banned on half values

workaround follows (ref tanh comp)

#if NCNN_moltenvk
    v = afpvec4(tanh(vec4(v)));
#else
    v = tanh(v);
#endif

@FhqTreap
Copy link
Contributor Author

FhqTreap commented Sep 5, 2023

for MacOS with vulkan fp16 build failed.

more details on this?😮

tanh fp16 on moltenvk has precision issue, so it is banned on half values

workaround follows (ref tanh comp)

#if NCNN_moltenvk
    v = afpvec4(tanh(vec4(v)));
#else
    v = tanh(v);
#endif

so it shuold look like this?

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

@nihui
Copy link
Member

nihui commented Sep 5, 2023

for MacOS with vulkan fp16 build failed.

more details on this?😮

tanh fp16 on moltenvk has precision issue, so it is banned on half values
workaround follows (ref tanh comp)

#if NCNN_moltenvk
    v = afpvec4(tanh(vec4(v)));
#else
    v = tanh(v);
#endif

so it shuold look like this?

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

yeah, exactly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants