-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathProgram.fs
More file actions
90 lines (74 loc) · 2.83 KB
/
Copy pathProgram.fs
File metadata and controls
90 lines (74 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// To run the benchmark execute the following command:
// dotnet run -c Release -- TensorBenchmark
namespace Tensor.Benchmark
open System
open System.Reflection
open System.IO
open System.Collections.Generic
open System.Runtime.InteropServices
open System.Diagnostics
open ManagedCuda
open ManagedCuda.BasicTypes
open Newtonsoft.Json
open BenchmarkDotNet.Jobs
open BenchmarkDotNet.Configs
open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Attributes.Jobs
open BenchmarkDotNet.Running
open BenchmarkDotNet.Order
open BenchmarkDotNet.Columns
open BenchmarkDotNet.Engines
open BenchmarkDotNet.Horology
open BenchmarkDotNet.Reports
open BenchmarkDotNet.Exporters
open BenchmarkDotNet.Exporters.Csv
open Tensor
open System.Text.RegularExpressions
module Main =
let getProcessOutput name args =
use p = new Process()
p.StartInfo.FileName <- name
p.StartInfo.Arguments <- args
p.StartInfo.RedirectStandardOutput <- true
p.Start() |> ignore
let out = p.StandardOutput.ReadToEnd()
p.WaitForExit()
out
let getCpu () =
if RuntimeInformation.IsOSPlatform (OSPlatform.Linux) then
File.ReadAllLines "/proc/cpuinfo"
|> Seq.pick (fun l ->
let m = Regex.Match(l, "model name\s*: (.+)")
if m.Success then Some m.Groups.[1].Value else None)
elif RuntimeInformation.IsOSPlatform (OSPlatform.Windows) then
(getProcessOutput "wmic" "cpu get name").Split("\n").[1].Trim()
else
raise (PlatformNotSupportedException ())
let getGpu () =
use context = new CudaContext(createNew=false)
"nVidia " + context.GetDeviceInfo().DeviceName
let getDotNetVersion () =
(getProcessOutput "dotnet" "--version").Trim()
let writeInfo () =
let resultsPath = Path.Combine("BenchmarkDotNet.Artifacts", "results") |> Path.GetFullPath
Directory.CreateDirectory resultsPath |> ignore
let infoPath = Path.Combine(resultsPath, "Info.json") |> Path.GetFullPath
let tv = typedefof<Tensor<_>>.Assembly.GetName().Version
let info = {
Name = Environment.MachineName
CPU = getCpu ()
GPU = getGpu ()
OS = RuntimeInformation.OSDescription.Trim()
Library = sprintf "F# Tensor %d.%d.%d" tv.Major tv.Minor tv.Build
Runtime = sprintf ".NET SDK %s" (getDotNetVersion())
Date = DateTime.UtcNow
}
File.WriteAllText (infoPath, JsonConvert.SerializeObject(info, Formatting.Indented))
[<EntryPoint>]
let main argv =
Tensor.Cuda.Cfg.FastKernelMath <- true
//Tensor.Cuda.Cfg.RestrictKernels <- true
writeInfo ()
let switcher = BenchmarkSwitcher (Assembly.GetExecutingAssembly())
switcher.Run (args=argv) |> ignore
0