Skip to content

Instantly share code, notes, and snippets.

@TakaoNarikawa
Created April 24, 2020 22:19
Show Gist options
  • Save TakaoNarikawa/b21f7a9e2e5c6a2b114515ee61ac85d2 to your computer and use it in GitHub Desktop.
Save TakaoNarikawa/b21f7a9e2e5c6a2b114515ee61ac85d2 to your computer and use it in GitHub Desktop.
#include <metal_stdlib>
using namespace metal;
kernel void mish(
texture2d_array<half, access::read> inTexture [[texture(0)]],
texture2d_array<half, access::write> outTexture [[texture(1)]],
ushort3 gid [[thread_position_in_grid]])
{
if (gid.x >= outTexture.get_width() || gid.y >= outTexture.get_height()) {
return;
}
const float4 x = float4(inTexture.read(gid.xy, gid.z));
const float4 y = x * tanh(log(1.0f + exp(x)));
outTexture.write(half4(y), gid.xy, gid.z);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment