PairedBench vMulPerf(int samples, long cycles) { var lhs1 = RVec <double>(samples); var rhs1 = RVec <double>(samples); var dst1 = RowVectors.blockalloc <double>(samples); var sw1 = Time.stopwatch(true); for (var i = 0; i < cycles; i++) { Calcs.mul(lhs1, rhs1, dst1.Unblocked); } var time1 = BenchmarkRecord.Define(cycles, Time.snapshot(sw1), "gmath"); var lhs2 = lhs1.Replicate(); var rhs2 = rhs1.Replicate(); var dst2 = dst1.Replicate(); var sw2 = Time.stopwatch(true); for (var i = 0; i < cycles; i++) { mkl.mul(lhs2, rhs2, ref dst2); } var time2 = BenchmarkRecord.Define(cycles, Time.snapshot(sw2), "mkl"); return(time1, time2); }
BenchmarkRecord gemm_direct_check <M, K, N>(IEnumerable <float> src, M m = default, K k = default, N n = default) where M : unmanaged, ITypeNat where K : unmanaged, ITypeNat where N : unmanaged, ITypeNat { var A = Matrix.blockalloc <M, K, float>(); var B = Matrix.blockalloc <K, N, float>(); var X = Matrix.blockalloc <M, N, float>(); var E = Matrix.blockalloc <M, N, float>(); var collect = false; var runtime = Duration.Zero; for (var i = 0; i < CycleCount; i++) { src.StreamTo(A.Unblocked); src.StreamTo(B.Unblocked); var sw = stopwatch(); mkl.gemm(A, B, ref X); runtime += snapshot(sw); } var label = $"gemm<{nat32i<M>()},{nat32i<K>()},{nat32i<N>()}>"; BenchmarkRecord timing = Benchmark(CycleCount, runtime, label); if (collect) { ReportBenchmark(label, CycleCount, TimeSpan.FromMilliseconds(runtime.Ms)); } return(timing); }
BenchmarkRecord gemm_check <M, K, N, T>(IEnumerable <T> src, T epsilon = default, M m = default, K k = default, N n = default, bool trace = false) where M : unmanaged, ITypeNat where K : unmanaged, ITypeNat where N : unmanaged, ITypeNat where T : unmanaged { var A = Matrix.blockalloc <M, K, T>(); var B = Matrix.blockalloc <K, N, T>(); var X = Matrix.blockalloc <M, N, T>(); var XU = X.Unblocked; var E = Matrix.blockalloc <M, N, T>(); var EU = E.Unblocked; var collect = false; var label = $"gemm<N{nat32i<M>()},N{nat32i<K>()},N{nat32i<N>()},{typeof(T).Name}>"; var runtime = Duration.Zero; for (var i = 0; i < CycleCount; i++) { src.StreamTo(A.Unblocked); src.StreamTo(B.Unblocked); var sw = stopwatch(); mkl.gemm(A, B, ref X); runtime += snapshot(sw); Matrix.mul(A, B, ref E); if (trace) { var padlen = Int32.MinValue.ToString().Length + 2; Notify($"X = {X.Format()}"); Notify($"E = {E.Format()}"); } Claim.close(E.Unblocked, X.Unblocked, epsilon); } BenchmarkRecord timing = Benchmark(CycleCount, runtime, label); if (collect) { ReportBenchmark(label, CycleCount, TimeSpan.FromMilliseconds(runtime.Ms)); } return(timing); }
void rng_bench <T>(IDataStream <T> stream, [CallerMemberName] string caller = null) where T : unmanaged { var segment = Pow2.T08; var total = Pow2.T17; var stats = StatCollector.Create(0.0); var sw = stopwatch(false); for (var i = 0; i < total; i += segment) { sw.Start(); var sample = stream.TakeArray(segment); sw.Stop(); for (var j = 0; j < segment; j++) { stats.Collect(Numeric.force <T, double>(sample[j])); } } var opname = $"{caller}<{typeof(T).DisplayName()}>"; Deposit(BenchmarkRecord.Define(total, sw.Elapsed, opname)); }