Skip to content

Commit

Permalink
Even fast version of BitwiseReLU.
Browse files Browse the repository at this point in the history
  • Loading branch information
colgreen committed Mar 31, 2023
1 parent ff4e4ea commit 3ec2787
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class ActivationFunctionsBenchmarks
static readonly IActivationFunction<double> __PolynomialApproximantSteep = new PolynomialApproximantSteep();
static readonly IActivationFunction<double> __QuadraticSigmoid = new QuadraticSigmoid();
static readonly IActivationFunction<double> __ReLU = new ReLU();
static readonly IActivationFunction<double> __BitwiseReLU = new BitwiseReLU();
static readonly IActivationFunction<double> __ScaledELU = new ScaledELU();
static readonly IActivationFunction<double> __SoftSignSteep = new SoftSignSteep();
static readonly IActivationFunction<double> __SReLU = new SReLU();
Expand Down Expand Up @@ -125,6 +126,12 @@ public void ReLU()
RunBenchmark(__ReLU);
}

[Benchmark]
public void BitwiseReLU()
{
RunBenchmark(__BitwiseReLU);
}

[Benchmark]
public void ScaledELU()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ public sealed class BitwiseReLU : IActivationFunction<double>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Fn(ref double x)
{
long xlong = BitConverter.DoubleToInt64Bits(x);
long xlong = Unsafe.As<double,long>(ref x);
x = BitConverter.Int64BitsToDouble(xlong & ~(xlong >> 63));
}

/// <inheritdoc/>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Fn(ref double x, ref double y)
{
long xlong = BitConverter.DoubleToInt64Bits(x);
long xlong = Unsafe.As<double,long>(ref x);
y = BitConverter.Int64BitsToDouble(xlong & ~(xlong >> 63));
}

Expand Down

0 comments on commit 3ec2787

Please sign in to comment.