-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathProgram.fs
More file actions
196 lines (154 loc) · 5.44 KB
/
Copy pathProgram.fs
File metadata and controls
196 lines (154 loc) · 5.44 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
open Tensor
open System.Diagnostics
let testCuda () =
let shape = [5L; 5L]
let a = HostTensor.ones<single> shape
printfn "a=\n%A" a
printfn "copy to cuda..."
let ca = a |> CudaTensor.transfer
printfn "ca=\n%A" ca.Full
printfn "copy to host..."
let ha = ca |> HostTensor.transfer
printfn "ha=\n%A" ha
printfn "copy cuda to cuda..."
let cb = Tensor.copy ca
printfn "cb=\n%A" cb
printfn "fill cuda..."
cb.FillConst(-5.5f)
printfn "cb=\n%A" cb
printfn "cuda abs..."
let cb = abs cb
printfn "cb=\n%A" cb
printfn "cuda ca + cb..."
let cc = ca + cb
printfn "cc=\n%A" cc
printfn "cuda sumAxis cc..."
let ci = Tensor.sumAxis 0 cc
printfn "ci=\n%A" ci
printfn "cuda maxAxis cc..."
let cg = Tensor.maxAxis 0 cc
printfn "cg=\n%A" cg
printfn "cuda ca <<== cb..."
let cd = ca <<== cb
printfn "cd=\n%A" cd
printfn "not cd..."
let ce = ~~~~cd
printfn "ce=\n%A" ce
printfn "cd or ce..."
let cf = cd |||| ce
printfn "cf=\n%A" cf
printfn "all cf..."
let ch = Tensor.allAxis 0 cf
printfn "ch=\n%A" ch
[<EntryPoint>]
let main argv =
//Tensor.Utils.Util.disableCrashDialog ()
//testCuda()
//exit 0
let shape = [10000L; 1000L]
printfn "Shape: %A" shape
let a : Tensor<single> = HostTensor.zeros shape
let b : Tensor<single> = HostTensor.ones shape
let mutable c : Tensor<single> = HostTensor.zeros shape
let mutable d : Tensor<bool> = HostTensor.falses shape
a.[[0L; 0L]] <- -1.0f
a.[[0L; 1L]] <- 3.0f
b.[[0L; 0L]] <- 2.0f
let iters = 30
let startTime = Stopwatch.StartNew()
for i in 1 .. iters do
c <- a + b
let duration = startTime.ElapsedMilliseconds
let timePerIter = float duration / float iters
printfn "Plus time per iteration: %.3f ms" timePerIter
let startTime = Stopwatch.StartNew()
for i in 1 .. iters do
c <- abs a
let duration = startTime.ElapsedMilliseconds
let timePerIter = float duration / float iters
printfn "Abs time per iteration: %.3f ms" timePerIter
let startTime = Stopwatch.StartNew()
for i in 1 .. iters do
c <- a.T .* b
let duration = startTime.ElapsedMilliseconds
let timePerIter = float duration / float iters
printfn "Dot time per iteration: %.3f ms" timePerIter
let startTime = Stopwatch.StartNew()
for i in 1 .. iters do
c <- sin a
let duration = startTime.ElapsedMilliseconds
let timePerIter = float duration / float iters
printfn "Sin time per iteration: %.3f ms" timePerIter
let startTime = Stopwatch.StartNew()
for i in 1 .. iters do
c <- exp a
let duration = startTime.ElapsedMilliseconds
let timePerIter = float duration / float iters
printfn "Exp time per iteration: %.3f ms" timePerIter
let startTime = Stopwatch.StartNew()
for i in 1 .. iters do
c <- sqrt a
let duration = startTime.ElapsedMilliseconds
let timePerIter = float duration / float iters
printfn "Sqrt time per iteration: %.3f ms" timePerIter
let startTime = Stopwatch.StartNew()
for i in 1 .. iters do
c <- sgn a
let duration = startTime.ElapsedMilliseconds
let timePerIter = float duration / float iters
printfn "Sgn time per iteration: %.3f ms" timePerIter
let startTime = Stopwatch.StartNew()
for i in 1 .. iters do
c <- a / b
let duration = startTime.ElapsedMilliseconds
let timePerIter = float duration / float iters
printfn "Divide time per iteration: %.3f ms" timePerIter
let startTime = Stopwatch.StartNew()
for i in 1 .. iters do
c <- a % b
let duration = startTime.ElapsedMilliseconds
let timePerIter = float duration / float iters
printfn "Modulo time per iteration: %.3f ms" timePerIter
let startTime = Stopwatch.StartNew()
for i in 1 .. iters do
c <- a ** b
let duration = startTime.ElapsedMilliseconds
let timePerIter = float duration / float iters
printfn "Power time per iteration: %.3f ms" timePerIter
let startTime = Stopwatch.StartNew()
for i in 1 .. iters do
d <- a <<<< b
let duration = startTime.ElapsedMilliseconds
let timePerIter = float duration / float iters
printfn "Less time per iteration: %.3f ms" timePerIter
printfn "a:\n%A" a
printfn "b:\n%A" b
printfn "c:\n%A" c
printfn "d:\n%A" d
printfn "sgn -1.0f: %f sgn 0.0f: %f" (sgn -1.0f) (sgn 0.0f)
printfn "ndims a: %d" (Tensor.nDims a)
let m : Tensor<bool> = HostTensor.falses shape
let n : Tensor<bool> = HostTensor.trues shape
let mutable k : Tensor<bool> = HostTensor.falses shape
let startTime = Stopwatch.StartNew()
for i in 1 .. iters do
k <- ~~~~m
let duration = startTime.ElapsedMilliseconds
let timePerIter = float duration / float iters
printfn "Not time per iteration: %.3f ms" timePerIter
let startTime = Stopwatch.StartNew()
for i in 1 .. iters do
k <- m &&&& n
let duration = startTime.ElapsedMilliseconds
let timePerIter = float duration / float iters
printfn "And time per iteration: %.3f ms" timePerIter
let startTime = Stopwatch.StartNew()
for i in 1 .. iters do
k <- m |||| n
let duration = startTime.ElapsedMilliseconds
let timePerIter = float duration / float iters
printfn "Or time per iteration: %.3f ms" timePerIter
printfn "m:\n%A" m
printfn "n:\n%A" n
printfn "k:\n%A" k
0