Skip to content

Commit

Permalink
refactor unary on wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
milhidaka committed Sep 16, 2021
1 parent 2778e0b commit 2d2ba5d
Showing 1 changed file with 10 additions and 34 deletions.
44 changes: 10 additions & 34 deletions src/shader/wasm/src/kernels/standard/unarys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,14 @@

extern "C"
{
void WEBDNN_KERNEL kernel_ceil(const float *src, float *dst, int length)
{
webdnn_unary(src, dst, length, [](float s) { return std::ceil(s); });
}

void WEBDNN_KERNEL kernel_exp(const float *src, float *dst, int length)
{
webdnn_unary(src, dst, length, [](float s) { return std::exp(s); });
}

void WEBDNN_KERNEL kernel_floor(const float *src, float *dst, int length)
{
webdnn_unary(src, dst, length, [](float s) { return std::floor(s); });
}

void WEBDNN_KERNEL kernel_relu(const float *src, float *dst, int length)
{
webdnn_unary(src, dst, length, [](float s) { return std::max(s, 0.0f); });
}

void WEBDNN_KERNEL kernel_sigmoid(const float *src, float *dst, int length)
{
webdnn_unary(src, dst, length, [](float s) { return (std::tanh(s * 0.5f) + 1.0f) * 0.5f; });
}

void WEBDNN_KERNEL kernel_sqrt(const float *src, float *dst, int length)
{
webdnn_unary(src, dst, length, [](float s) { return std::sqrt(s); });
}

void WEBDNN_KERNEL kernel_tanh(const float *src, float *dst, int length)
{
webdnn_unary(src, dst, length, [](float s) { return std::tanh(s); });
}

#define DEFINE_UNARY(name, func) \
void WEBDNN_KERNEL kernel_##name(const float *src, float *dst, int length) { webdnn_unary(src, dst, length, func); }
DEFINE_UNARY(ceil, [](float s) { return std::ceil(s); });
DEFINE_UNARY(exp, [](float s) { return std::exp(s); });
DEFINE_UNARY(floor, [](float s) { return std::floor(s); });
DEFINE_UNARY(relu, [](float s) { return std::max(s, 0.0f); });
DEFINE_UNARY(sigmoid, [](float s) { return (std::tanh(s * 0.5f) + 1.0f) * 0.5f; });
DEFINE_UNARY(sqrt, [](float s) { return std::sqrt(s); });
DEFINE_UNARY(tanh, [](float s) { return std::tanh(s); });
}

0 comments on commit 2d2ba5d

Please sign in to comment.