Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/layer/vulkan/shader/binaryop.comp
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,23 @@ void main()
#if NCNN_moltenvk
if (op_type == 10) res = afp(atan(float(v1), float(v2)));
if (op_type == 11) res = afp(atan(float(v2), float(v1)));
#else
#if ncnn_driverID == 13
// llvmpipe driver (VK_DRIVER_ID_MESA_LLVMPIPE = 13) workaround for atan(0, 0), match atan2f(0, 0) == 0
if (op_type == 10)
{
afp v2_safe = (v1 == afp(0.f) && v2 == afp(0.f)) ? afp(1.f) : v2;
res = atan(v1, v2_safe);
}
if (op_type == 11)
{
afp v1_safe = (v1 == afp(0.f) && v2 == afp(0.f)) ? afp(1.f) : v1;
res = atan(v2, v1_safe);
}
#else
if (op_type == 10) res = atan(v1, v2);
if (op_type == 11) res = atan(v2, v1);
#endif
#endif
if (op_type == 12) res = v1 - trunc(v1 / v2) * v2;
if (op_type == 13) res = v2 - trunc(v2 / v1) * v1;
Expand Down
14 changes: 14 additions & 0 deletions src/layer/vulkan/shader/binaryop_broadcast.comp
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,23 @@ void main()
#if NCNN_moltenvk
if (op_type == 10) res = afp(atan(float(v1), float(v2)));
if (op_type == 11) res = afp(atan(float(v2), float(v1)));
#else
#if ncnn_driverID == 13
// llvmpipe driver (VK_DRIVER_ID_MESA_LLVMPIPE = 13) workaround for atan(0, 0), match atan2f(0, 0) == 0
if (op_type == 10)
{
afp v2_safe = (v1 == afp(0.f) && v2 == afp(0.f)) ? afp(1.f) : v2;
res = atan(v1, v2_safe);
}
if (op_type == 11)
{
afp v1_safe = (v1 == afp(0.f) && v2 == afp(0.f)) ? afp(1.f) : v1;
res = atan(v2, v1_safe);
}
#else
if (op_type == 10) res = atan(v1, v2);
if (op_type == 11) res = atan(v2, v1);
#endif
#endif
if (op_type == 12) res = v1 - trunc(v1 / v2) * v2;
if (op_type == 13) res = v2 - trunc(v2 / v1) * v1;
Expand Down
16 changes: 16 additions & 0 deletions src/layer/vulkan/shader/binaryop_broadcast_pack1to4.comp
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,25 @@ void main()
#if NCNN_moltenvk
if (op_type == 10) res = afpvec4(atan(vec4(v1), vec4(v2)));
if (op_type == 11) res = afpvec4(atan(vec4(v2), vec4(v1)));
#else
#if ncnn_driverID == 13
// llvmpipe driver (VK_DRIVER_ID_MESA_LLVMPIPE = 13) workaround for atan(0, 0), match atan2f(0, 0) == 0
if (op_type == 10)
{
bvec4 zero_mask = bvec4(uvec4(equal(v1, afpvec4(0.f))) & uvec4(equal(v2, afpvec4(0.f))));
afpvec4 v2_safe = mix(v2, afpvec4(1.f), zero_mask);
res = atan(v1, v2_safe);
}
if (op_type == 11)
{
bvec4 zero_mask = bvec4(uvec4(equal(v1, afpvec4(0.f))) & uvec4(equal(v2, afpvec4(0.f))));
afpvec4 v1_safe = mix(v1, afpvec4(1.f), zero_mask);
res = atan(v2, v1_safe);
}
#else
if (op_type == 10) res = atan(v1, v2);
if (op_type == 11) res = atan(v2, v1);
#endif
#endif
if (op_type == 12) res = v1 - trunc(v1 / v2) * v2;
if (op_type == 13) res = v2 - trunc(v2 / v1) * v1;
Expand Down
16 changes: 16 additions & 0 deletions src/layer/vulkan/shader/binaryop_broadcast_pack4.comp
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,25 @@ void main()
#if NCNN_moltenvk
if (op_type == 10) res = afpvec4(atan(vec4(v1), vec4(v2)));
if (op_type == 11) res = afpvec4(atan(vec4(v2), vec4(v1)));
#else
#if ncnn_driverID == 13
// llvmpipe driver (VK_DRIVER_ID_MESA_LLVMPIPE = 13) workaround for atan(0, 0), match atan2f(0, 0) == 0
if (op_type == 10)
{
bvec4 zero_mask = bvec4(uvec4(equal(v1, afpvec4(0.f))) & uvec4(equal(v2, afpvec4(0.f))));
afpvec4 v2_safe = mix(v2, afpvec4(1.f), zero_mask);
res = atan(v1, v2_safe);
}
if (op_type == 11)
{
bvec4 zero_mask = bvec4(uvec4(equal(v1, afpvec4(0.f))) & uvec4(equal(v2, afpvec4(0.f))));
afpvec4 v1_safe = mix(v1, afpvec4(1.f), zero_mask);
res = atan(v2, v1_safe);
}
#else
if (op_type == 10) res = atan(v1, v2);
if (op_type == 11) res = atan(v2, v1);
#endif
#endif
if (op_type == 12) res = v1 - trunc(v1 / v2) * v2;
if (op_type == 13) res = v2 - trunc(v2 / v1) * v1;
Expand Down
16 changes: 16 additions & 0 deletions src/layer/vulkan/shader/binaryop_pack4.comp
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,25 @@ void main()
#if NCNN_moltenvk
if (op_type == 10) res = afpvec4(atan(vec4(v1), vec4(v2)));
if (op_type == 11) res = afpvec4(atan(vec4(v2), vec4(v1)));
#else
#if ncnn_driverID == 13
// llvmpipe driver (VK_DRIVER_ID_MESA_LLVMPIPE = 13) workaround for atan(0, 0), match atan2f(0, 0) == 0
if (op_type == 10)
{
bvec4 zero_mask = bvec4(uvec4(equal(v1, afpvec4(0.f))) & uvec4(equal(v2, afpvec4(0.f))));
afpvec4 v2_safe = mix(v2, afpvec4(1.f), zero_mask);
res = atan(v1, v2_safe);
}
if (op_type == 11)
{
bvec4 zero_mask = bvec4(uvec4(equal(v1, afpvec4(0.f))) & uvec4(equal(v2, afpvec4(0.f))));
afpvec4 v1_safe = mix(v1, afpvec4(1.f), zero_mask);
res = atan(v2, v1_safe);
}
#else
if (op_type == 10) res = atan(v1, v2);
if (op_type == 11) res = atan(v2, v1);
#endif
#endif
if (op_type == 12) res = v1 - trunc(v1 / v2) * v2;
if (op_type == 13) res = v2 - trunc(v2 / v1) * v1;
Expand Down
Loading