OpTime gemm_direct_check <M, K, N>(IEnumerable <float> src, M m = default, K k = default, N n = default) where M : ITypeNat, new() where K : ITypeNat, new() where N : ITypeNat, new() { var A = BlockMatrix.Alloc <M, K, float>(); var B = BlockMatrix.Alloc <K, N, float>(); var X = BlockMatrix.Alloc <M, N, float>(); var E = BlockMatrix.Alloc <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); // Mul(A, B, ref E); // E.Unblocked.ClaimEqual(X.Unblocked,10); } var label = $"gemm<{nati<M>()},{nati<K>()},{nati<N>()}>"; OpTime timing = optime(CycleCount, runtime, label); if (collect) { Collect(timing, 30); } return(timing); }
OpTimePair vMulPerf(int samples, long cycles) { var lhs1 = RVec <double>(samples); var rhs1 = RVec <double>(samples); var dst1 = BlockVector.Alloc <double>(samples); var sw1 = stopwatch(); for (var i = 0; i < cycles; i++) { mathspan.mul(lhs1, rhs1, dst1.Unblocked); } var time1 = OpTime.Define(cycles, snapshot(sw1), "gmath"); var lhs2 = lhs1.Replicate(); var rhs2 = rhs1.Replicate(); var dst2 = dst1.Replicate(true); var sw2 = stopwatch(); for (var i = 0; i < cycles; i++) { mkl.mul(lhs2, rhs2, ref dst2); } var time2 = OpTime.Define(cycles, snapshot(sw2), "mkl"); return(time1, time2); }
void run_mean_bench() { var cycles = Pow2.T12; var samples = Pow2.T14; var src = Random.Array <long>(samples, closed(-2000L, 2000L)).Convert <double>(); var ds = Dataset.Load(src); var dst = 0.0; var last = 0.0; var sw1 = stopwatch(); for (var i = 0; i < cycles; i++) { last = ds.Mean(ref dst); } var t1 = OpTime.Define(cycles * samples, snapshot(sw1), "mkl-ssmean"); var sw2 = stopwatch(); for (var i = 0; i < cycles; i++) { last = src.Avg(); } var t2 = OpTime.Define(cycles * samples, snapshot(sw2), "direct"); Collect((t1, t2)); }
public static AppMsg TracePerf(OpTime timing, int?labelPad = null) { var msg = appMsg(timing.Format(labelPad), SeverityLevel.Benchmark); print(msg); return(msg); }
/// <summary> /// Measures the respective times required to execute a pair of functions, each of which /// iterate a computational block a specified number of times /// </summary> /// <param name="n">The number of computational block iterations</param> /// <param name="left">The first function</param> /// <param name="right">THe second function</param> public static OpTimePair measure(long n, string leftLabel, string rightLabel, Action <long> left, Action <long> right) { var lTimer = stopwatch(); left(n); var lTime = OpTime.Define(n, snapshot(lTimer), leftLabel); var rTimer = stopwatch(); right(n); var rTime = OpTime.Define(n, snapshot(rTimer), rightLabel); OpTimePair result = (lTime, rTime); return(result); }
OpTime 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 : ITypeNat, new() where K : ITypeNat, new() where N : ITypeNat, new() where T : struct { var A = BlockMatrix.Alloc <M, K, T>(); var B = BlockMatrix.Alloc <K, N, T>(); var X = BlockMatrix.Alloc <M, N, T>(); var E = BlockMatrix.Alloc <M, N, T>(); 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); MatMulRef.Mul(A, B, ref E); if (trace) { var padlen = Int32.MinValue.ToString().Length + 2; Trace($"X = {X.Format()}"); Trace($"E = {E.Format()}"); } E.Unblocked.ClaimEqual(X.Unblocked, epsilon); } var label = $"gemm<N{nati<M>()},N{nati<K>()},N{nati<N>()},{typeof(T).Name}>"; OpTime timing = optime(CycleCount, runtime, label); if (collect) { Collect(timing, 30); } return(timing); }
OpTime avg_bench(bool reference) { OpTime refbench() { var sw = stopwatch(false); for (var i = 0; i < SampleSize; i++) { var x = Random.Span256 <byte>(); var y = Random.Span256 <byte>(); sw.Start(); var b = math.avgi(x, y); sw.Stop(); } return(OpTime.Define <byte>(SampleSize, sw, $"vavg-ref")); } OpTime opbench() { var sw = stopwatch(false); for (var i = 0; i < SampleSize; i++) { var x = Random.CpuVec256 <byte>(); var y = Random.CpuVec256 <byte>(); sw.Start(); var a = dinx.avg(x, y); sw.Stop(); } return(OpTime.Define <byte>(SampleSize, sw, $"vavg")); } if (reference) { return(refbench()); } else { return(opbench()); } }
OpTime slli256u16Bench(int blocks, int cycles) { var blocklen = Vec256 <ushort> .Length; var opcount = blocks * cycles * blocklen; var shiftRange = closed <byte>(2, 14); var sw = stopwatch(false); var src = Random.Stream <ushort>(); var offsets = Random.Stream(shiftRange); for (var cycle = 0; cycle < cycles; cycle++) { for (var block = 0; block < blocks; block++) { var x = Vec256.Load(src.TakeSpan(blocklen)); var offset = offsets.First(); sw.Start(); Bits.sll(x, offset); sw.Stop(); } } return(OpTime.Define(opcount, snapshot(sw), "slli16u")); }
public void Execute(IJobExecutionContext context) { WebClient Client = null; int InsertCount = 0; string JsonResponse, Message; List <SqlDataRecord> CurrencyTable; EventLog Log = (EventLog)context.MergedJobDataMap["ServiceLog"]; string LogName = ConfigurationManager.AppSettings["ServiceLog"]; string SourceName = ConfigurationManager.AppSettings["CurrencyUpdateSource"]; string NextFire = context.NextFireTimeUtc.HasValue ? context.NextFireTimeUtc.Value.DateTime.ToString("F") : "Unavailable"; int RetryCount = 0; DateTime OpTime, CurrentTime; try { CLAYER_API_REQUEST: try { Client = new WebClient(); Client.QueryString = NameValue; JsonResponse = Client.DownloadString(BaseURL); } catch (Exception ex) { if (RetryCount < this.MaxRetryCount) { Thread.Sleep(1000); RetryCount += 1; Message = string.Format(ApiRequestFailFormat, Utility.DeepestExceptionMessage(ex), RetryCount, this.MaxRetryCount); Log.WriteEntry(Message, EventLogEntryType.Warning); goto CLAYER_API_REQUEST; } else { throw ex; } } CurrencyModel LiveCurrency = JsonConvert.DeserializeObject <CurrencyModel>(JsonResponse); OpTime = this.UnixTimeStampToUTC(LiveCurrency.timestamp); CurrentTime = DateTime.UtcNow; if (LiveCurrency.error == null) { CurrencyTable = this.BuildSqlRecordList(LiveCurrency); InsertCount = this.WriteDatabase(CurrencyTable); Message = string.Format(SuccessFormat, JsonResponse, InsertCount, OpTime.ToString("F"), CurrentTime.ToString("F"), NextFire); Log.WriteEntry(Message, EventLogEntryType.Information); } else { Message = string.Format(ApiErrorFormat, LiveCurrency.error.code, LiveCurrency.error.info, OpTime.ToString("F"), CurrentTime.ToString("F"), NextFire); Log.WriteEntry(Message, EventLogEntryType.Error); } } catch (Exception ex) { Message = string.Format(ErrorFormat, Utility.DeepestExceptionMessage(ex), DateTime.UtcNow.ToString("F"), NextFire); Log.WriteEntry(Message, EventLogEntryType.Error); } }
public static OpTime optime(long opcount, Duration time, [CallerMemberName] string label = null) => OpTime.Define(opcount, time, label);
public static OpTime optime(long opcount, Stopwatch sw, [CallerMemberName] string label = null) => OpTime.Define(opcount, snapshot(sw), label);
/// <summary> /// Prints an operation timing message to the console /// </summary> /// <param name="time">The operation timing</param> /// <param name="labelPad">Option label pad width</param> public static void print(OpTime time, int?labelPad = null) => print(AppMsg.Define(time.Format(labelPad), SeverityLevel.Benchmark));