|
| 1 | +from numojo import * |
| 2 | +import numojo |
| 3 | +import benchmark |
| 4 | +from benchmark.compiler import keep |
| 5 | +from numojo._math_funcs import Vectorized, Naive, Parallelized, VectorizedParallelized |
| 6 | +alias backend = VectorizedParallelized |
| 7 | +fn main(): |
| 8 | + var tens1:Tensor[DType.float32] = Tensor[DType.float32](100,100) |
| 9 | + var tens2:Tensor[DType.float32] = Tensor[DType.float32](100,100) |
| 10 | + var tens3:Tensor[DType.float32] = Tensor[DType.float32](100,100) |
| 11 | + for i in range(10_000): |
| 12 | + tens1[i]= SIMD[DType.float32,1](3.141592/4) |
| 13 | + tens2[i]= SIMD[DType.float32,1](3.141592) |
| 14 | + tens3[i] = SIMD[DType.float32,1](3.141592/2) |
| 15 | + var res:Tensor[DType.float32] |
| 16 | + fn test_fma()capturing: |
| 17 | + try: |
| 18 | + res = fma[DType.float32,backend=backend](tens1, tens2, tens3) |
| 19 | + keep(res.unsafe_ptr()) |
| 20 | + except: |
| 21 | + print('fma: Failed shape error') |
| 22 | + var report_fma = benchmark.run[test_fma]() |
| 23 | + print('fma f32 100x100') |
| 24 | + report_fma.print() |
| 25 | + fn test_mod()capturing: |
| 26 | + try: |
| 27 | + res = mod[DType.float32,backend=backend](tens1, tens2) |
| 28 | + keep(res.unsafe_ptr()) |
| 29 | + except: |
| 30 | + print('mod: Failed shape error') |
| 31 | + var report_mod = benchmark.run[test_mod]() |
| 32 | + print('mod f32 100x100') |
| 33 | + report_mod.print() |
| 34 | + fn test_mul()capturing: |
| 35 | + try: |
| 36 | + res = mul[DType.float32,backend=backend](tens1, tens2) |
| 37 | + keep(res.unsafe_ptr()) |
| 38 | + except: |
| 39 | + print('mul: Failed shape error') |
| 40 | + var report_mul = benchmark.run[test_mul]() |
| 41 | + print('mul f32 100x100') |
| 42 | + report_mul.print() |
| 43 | + fn test_sub()capturing: |
| 44 | + try: |
| 45 | + res = sub[DType.float32,backend=backend](tens1, tens2) |
| 46 | + keep(res.unsafe_ptr()) |
| 47 | + except: |
| 48 | + print('sub: Failed shape error') |
| 49 | + var report_sub = benchmark.run[test_sub]() |
| 50 | + print('sub f32 100x100') |
| 51 | + report_sub.print() |
| 52 | + fn test_add()capturing: |
| 53 | + try: |
| 54 | + res = add[DType.float32,backend=backend](tens1, tens2) |
| 55 | + keep(res.unsafe_ptr()) |
| 56 | + except: |
| 57 | + print('add: Failed shape error') |
| 58 | + var report_add = benchmark.run[test_add]() |
| 59 | + print('add f32 100x100') |
| 60 | + report_add.print() |
| 61 | + fn test_div()capturing: |
| 62 | + try: |
| 63 | + res = div[DType.float32,backend=backend](tens1, tens2) |
| 64 | + keep(res.unsafe_ptr()) |
| 65 | + except: |
| 66 | + print('div: Failed shape error') |
| 67 | + var report_div = benchmark.run[test_div]() |
| 68 | + print('div f32 100x100') |
| 69 | + report_div.print() |
| 70 | + fn test_copysign()capturing: |
| 71 | + try: |
| 72 | + res = copysign[DType.float32,backend=backend](tens1, tens2) |
| 73 | + keep(res.unsafe_ptr()) |
| 74 | + except: |
| 75 | + print('copysign: Failed shape error') |
| 76 | + var report_copysign = benchmark.run[test_copysign]() |
| 77 | + print('copysign f32 100x100') |
| 78 | + report_copysign.print() |
| 79 | + fn test_atan2()capturing: |
| 80 | + try: |
| 81 | + res = atan2[DType.float32,backend=backend](tens1, tens2) |
| 82 | + keep(res.unsafe_ptr()) |
| 83 | + except: |
| 84 | + print('atan2: Failed shape error') |
| 85 | + var report_atan2 = benchmark.run[test_atan2]() |
| 86 | + print('atan2 f32 100x100') |
| 87 | + report_atan2.print() |
| 88 | + fn test_hypot()capturing: |
| 89 | + try: |
| 90 | + res = hypot[DType.float32,backend=backend](tens1, tens2) |
| 91 | + keep(res.unsafe_ptr()) |
| 92 | + except: |
| 93 | + print('hypot: Failed shape error') |
| 94 | + var report_hypot = benchmark.run[test_hypot]() |
| 95 | + print('hypot f32 100x100') |
| 96 | + report_hypot.print() |
| 97 | + fn test_hypot_fma()capturing: |
| 98 | + try: |
| 99 | + res = hypot_fma[DType.float32,backend=backend](tens1, tens2) |
| 100 | + keep(res.unsafe_ptr()) |
| 101 | + except: |
| 102 | + print('hypot: Failed shape error') |
| 103 | + var report_hypot_fma = benchmark.run[test_hypot_fma]() |
| 104 | + print('hypot_fma f32 100x100') |
| 105 | + report_hypot_fma.print() |
| 106 | + fn test_nextafter()capturing: |
| 107 | + try: |
| 108 | + res = nextafter[DType.float32,backend=backend](tens1, tens2) |
| 109 | + keep(res.unsafe_ptr()) |
| 110 | + except: |
| 111 | + print('nextafter: Failed shape error') |
| 112 | + var report_nextafter = benchmark.run[test_nextafter]() |
| 113 | + print('nextafter f32 100x100') |
| 114 | + report_nextafter.print() |
| 115 | + fn test_scalb()capturing: |
| 116 | + try: |
| 117 | + res = scalb[DType.float32,backend=backend](tens1, tens2) |
| 118 | + keep(res.unsafe_ptr()) |
| 119 | + except: |
| 120 | + print('scalb: Failed shape error') |
| 121 | + var report_scalb = benchmark.run[test_scalb]() |
| 122 | + print('scalb f32 100x100') |
| 123 | + report_scalb.print() |
| 124 | + fn test_remainder()capturing: |
| 125 | + try: |
| 126 | + res = remainder[DType.float32,backend=backend](tens1, tens2) |
| 127 | + keep(res.unsafe_ptr()) |
| 128 | + except: |
| 129 | + print('remainder: Failed shape error') |
| 130 | + var report_remainder = benchmark.run[test_remainder]() |
| 131 | + print('remainder f32 100x100') |
| 132 | + report_remainder.print() |
| 133 | + var tens:Tensor[DType.float32] = Tensor[DType.float32](100,100) |
| 134 | + for i in range(10_000): |
| 135 | + tens[i]= SIMD[DType.float32,1](3.141592/4) |
| 136 | + fn test_abs()capturing: |
| 137 | + res = tabs[DType.float32,backend=backend](tens) |
| 138 | + keep(res.unsafe_ptr()) |
| 139 | + var report_abs = benchmark.run[test_abs]() |
| 140 | + print('abs f32 100x100') |
| 141 | + report_abs.print() |
| 142 | + fn test_floor()capturing: |
| 143 | + res = tfloor[DType.float32,backend=backend](tens) |
| 144 | + keep(res.unsafe_ptr()) |
| 145 | + var report_floor = benchmark.run[test_floor]() |
| 146 | + print('floor f32 100x100') |
| 147 | + report_floor.print() |
| 148 | + fn test_ceil()capturing: |
| 149 | + res = tceil[DType.float32,backend=backend](tens) |
| 150 | + keep(res.unsafe_ptr()) |
| 151 | + var report_ceil = benchmark.run[test_ceil]() |
| 152 | + print('ceil f32 100x100') |
| 153 | + report_ceil.print() |
| 154 | + fn test_trunc()capturing: |
| 155 | + res = ttrunc[DType.float32,backend=backend](tens) |
| 156 | + keep(res.unsafe_ptr()) |
| 157 | + var report_trunc = benchmark.run[test_trunc]() |
| 158 | + print('trunc f32 100x100') |
| 159 | + report_trunc.print() |
| 160 | + fn test_round()capturing: |
| 161 | + res = tround[DType.float32,backend=backend](tens) |
| 162 | + keep(res.unsafe_ptr()) |
| 163 | + var report_round = benchmark.run[test_round]() |
| 164 | + print('round f32 100x100') |
| 165 | + report_round.print() |
| 166 | + fn test_roundeven()capturing: |
| 167 | + res = roundeven[DType.float32,backend=backend](tens) |
| 168 | + keep(res.unsafe_ptr()) |
| 169 | + var report_roundeven = benchmark.run[test_roundeven]() |
| 170 | + print('roundeven f32 100x100') |
| 171 | + report_roundeven.print() |
| 172 | + # fn test_round_half_down()capturing: |
| 173 | + # res = round_half_down[DType.float32,backend=backend](tens) |
| 174 | + # keep(res.unsafe_ptr()) |
| 175 | + # var report_round_half_down = benchmark.run[test_round_half_down]() |
| 176 | + # print('round_half_down f32 100x100') |
| 177 | + # report_round_half_down.print() |
| 178 | + # fn test_round_half_up()capturing: |
| 179 | + # res = round_half_up[DType.float32,backend=backend](tens) |
| 180 | + # keep(res.unsafe_ptr()) |
| 181 | + # var report_round_half_up = benchmark.run[test_round_half_up]() |
| 182 | + # print('round_half_up f32 100x100') |
| 183 | + # report_round_half_up.print() |
| 184 | + fn test_rsqrt()capturing: |
| 185 | + res = rsqrt[DType.float32,backend=backend](tens) |
| 186 | + keep(res.unsafe_ptr()) |
| 187 | + var report_rsqrt = benchmark.run[test_rsqrt]() |
| 188 | + print('rsqrt f32 100x100') |
| 189 | + report_rsqrt.print() |
| 190 | + fn test_sqrt()capturing: |
| 191 | + res = sqrt[DType.float32,backend=backend](tens) |
| 192 | + keep(res.unsafe_ptr()) |
| 193 | + var report_sqrt = benchmark.run[test_sqrt]() |
| 194 | + print('sqrt f32 100x100') |
| 195 | + report_sqrt.print() |
| 196 | + fn test_exp2()capturing: |
| 197 | + res = exp2[DType.float32,backend=backend](tens) |
| 198 | + keep(res.unsafe_ptr()) |
| 199 | + var report_exp2 = benchmark.run[test_exp2]() |
| 200 | + print('exp2 f32 100x100') |
| 201 | + report_exp2.print() |
| 202 | + fn test_exp()capturing: |
| 203 | + res = exp[DType.float32,backend=backend](tens) |
| 204 | + keep(res.unsafe_ptr()) |
| 205 | + var report_exp = benchmark.run[test_exp]() |
| 206 | + print('exp f32 100x100') |
| 207 | + report_exp.print() |
| 208 | + fn test_log()capturing: |
| 209 | + res = log[DType.float32,backend=backend](tens) |
| 210 | + keep(res.unsafe_ptr()) |
| 211 | + var report_log = benchmark.run[test_log]() |
| 212 | + print('log f32 100x100') |
| 213 | + report_log.print() |
| 214 | + fn test_log2()capturing: |
| 215 | + res = log2[DType.float32,backend=backend](tens) |
| 216 | + keep(res.unsafe_ptr()) |
| 217 | + var report_log2 = benchmark.run[test_log2]() |
| 218 | + print('log2 f32 100x100') |
| 219 | + report_log2.print() |
| 220 | + # fn test_erf()capturing: |
| 221 | + # res = erf[DType.float32,backend=backend](tens) |
| 222 | + # keep(res.unsafe_ptr()) |
| 223 | + # var report_erf = benchmark.run[test_erf]() |
| 224 | + # print('erf f32 100x100') |
| 225 | + # report_erf.print() |
| 226 | + fn test_tanh()capturing: |
| 227 | + res = tanh[DType.float32,backend=backend](tens) |
| 228 | + keep(res.unsafe_ptr()) |
| 229 | + var report_tanh = benchmark.run[test_tanh]() |
| 230 | + print('tanh f32 100x100') |
| 231 | + report_tanh.print() |
| 232 | + # fn test_reciprocal()capturing: |
| 233 | + # res = reciprocal[DType.float32,backend=backend](tens) |
| 234 | + # keep(res.unsafe_ptr()) |
| 235 | + # var report_reciprocal = benchmark.run[test_reciprocal]() |
| 236 | + # print('reciprocal f32 100x100') |
| 237 | + # report_reciprocal.print() |
| 238 | + # fn test_identity()capturing: |
| 239 | + # res = identity[DType.float32,backend=backend](tens) |
| 240 | + # keep(res.unsafe_ptr()) |
| 241 | + # var report_identity = benchmark.run[test_identity]() |
| 242 | + # print('identity f32 100x100') |
| 243 | + # report_identity.print() |
| 244 | + fn test_acos()capturing: |
| 245 | + res = acos[DType.float32,backend=backend](tens) |
| 246 | + keep(res.unsafe_ptr()) |
| 247 | + var report_acos = benchmark.run[test_acos]() |
| 248 | + print('acos f32 100x100') |
| 249 | + report_acos.print() |
| 250 | + fn test_asin()capturing: |
| 251 | + res = asin[DType.float32,backend=backend](tens) |
| 252 | + keep(res.unsafe_ptr()) |
| 253 | + var report_asin = benchmark.run[test_asin]() |
| 254 | + print('asin f32 100x100') |
| 255 | + report_asin.print() |
| 256 | + fn test_atan()capturing: |
| 257 | + res = atan[DType.float32,backend=backend](tens) |
| 258 | + keep(res.unsafe_ptr()) |
| 259 | + var report_atan = benchmark.run[test_atan]() |
| 260 | + print('atan f32 100x100') |
| 261 | + report_atan.print() |
| 262 | + fn test_cos()capturing: |
| 263 | + res = cos[DType.float32,backend=backend](tens) |
| 264 | + keep(res.unsafe_ptr()) |
| 265 | + var report_cos = benchmark.run[test_cos]() |
| 266 | + print('cos f32 100x100') |
| 267 | + report_cos.print() |
| 268 | + fn test_sin()capturing: |
| 269 | + res = sin[DType.float32,backend=backend](tens) |
| 270 | + keep(res.unsafe_ptr()) |
| 271 | + var report_sin = benchmark.run[test_sin]() |
| 272 | + print('sin f32 100x100') |
| 273 | + report_sin.print() |
| 274 | + fn test_tan()capturing: |
| 275 | + res = tan[DType.float32,backend=backend](tens) |
| 276 | + keep(res.unsafe_ptr()) |
| 277 | + var report_tan = benchmark.run[test_tan]() |
| 278 | + print('tan f32 100x100') |
| 279 | + report_tan.print() |
| 280 | + fn test_acosh()capturing: |
| 281 | + res = acosh[DType.float32,backend=backend](tens) |
| 282 | + keep(res.unsafe_ptr()) |
| 283 | + var report_acosh = benchmark.run[test_acosh]() |
| 284 | + print('acosh f32 100x100') |
| 285 | + report_acosh.print() |
| 286 | + fn test_asinh()capturing: |
| 287 | + res = asinh[DType.float32,backend=backend](tens) |
| 288 | + keep(res.unsafe_ptr()) |
| 289 | + var report_asinh = benchmark.run[test_asinh]() |
| 290 | + print('asinh f32 100x100') |
| 291 | + report_asinh.print() |
| 292 | + fn test_atanh()capturing: |
| 293 | + res = atanh[DType.float32,backend=backend](tens) |
| 294 | + keep(res.unsafe_ptr()) |
| 295 | + var report_atanh = benchmark.run[test_atanh]() |
| 296 | + print('atanh f32 100x100') |
| 297 | + report_atanh.print() |
| 298 | + fn test_cosh()capturing: |
| 299 | + res = cosh[DType.float32,backend=backend](tens) |
| 300 | + keep(res.unsafe_ptr()) |
| 301 | + var report_cosh = benchmark.run[test_cosh]() |
| 302 | + print('cosh f32 100x100') |
| 303 | + report_cosh.print() |
| 304 | + fn test_sinh()capturing: |
| 305 | + res = sinh[DType.float32,backend=backend](tens) |
| 306 | + keep(res.unsafe_ptr()) |
| 307 | + var report_sinh = benchmark.run[test_sinh]() |
| 308 | + print('sinh f32 100x100') |
| 309 | + report_sinh.print() |
| 310 | + fn test_expm1()capturing: |
| 311 | + res = expm1[DType.float32,backend=backend](tens) |
| 312 | + keep(res.unsafe_ptr()) |
| 313 | + var report_expm1 = benchmark.run[test_expm1]() |
| 314 | + print('expm1 f32 100x100') |
| 315 | + report_expm1.print() |
| 316 | + fn test_log10()capturing: |
| 317 | + res = log10[DType.float32,backend=backend](tens) |
| 318 | + keep(res.unsafe_ptr()) |
| 319 | + var report_log10 = benchmark.run[test_log10]() |
| 320 | + print('log10 f32 100x100') |
| 321 | + report_log10.print() |
| 322 | + fn test_log1p()capturing: |
| 323 | + res = log1p[DType.float32,backend=backend](tens) |
| 324 | + keep(res.unsafe_ptr()) |
| 325 | + var report_log1p = benchmark.run[test_log1p]() |
| 326 | + print('log1p f32 100x100') |
| 327 | + report_log1p.print() |
| 328 | + fn test_cbrt()capturing: |
| 329 | + res = cbrt[DType.float32,backend=backend](tens) |
| 330 | + keep(res.unsafe_ptr()) |
| 331 | + var report_cbrt = benchmark.run[test_cbrt]() |
| 332 | + print('cbrt f32 100x100') |
| 333 | + report_cbrt.print() |
| 334 | + # fn test_erfc()capturing: |
| 335 | + # res = erfc[DType.float32,backend=backend](tens) |
| 336 | + # keep(res.unsafe_ptr()) |
| 337 | + # var report_erfc = benchmark.run[test_erfc]() |
| 338 | + # print('erfc f32 100x100') |
| 339 | + # report_erfc.print() |
| 340 | + # fn test_lgamma()capturing: |
| 341 | + # res = lgamma[DType.float32,backend=backend](tens) |
| 342 | + # keep(res.unsafe_ptr()) |
| 343 | + # var report_lgamma = benchmark.run[test_lgamma]() |
| 344 | + # print('lgamma f32 100x100') |
| 345 | + # report_lgamma.print() |
| 346 | + # fn test_tgamma()capturing: |
| 347 | + # res = tgamma[DType.float32,backend=backend](tens) |
| 348 | + # keep(res.unsafe_ptr()) |
| 349 | + # var report_tgamma = benchmark.run[test_tgamma]() |
| 350 | + # print('tgamma f32 100x100') |
| 351 | + # report_tgamma.print() |
| 352 | + # fn test_nearbyint()capturing: |
| 353 | + # res = nearbyint[DType.float32,backend=backend](tens) |
| 354 | + # keep(res.unsafe_ptr()) |
| 355 | + # var report_nearbyint = benchmark.run[test_nearbyint]() |
| 356 | + # print('nearbyint f32 100x100') |
| 357 | + # report_nearbyint.print() |
| 358 | + # fn test_rint()capturing: |
| 359 | + # res = rint[DType.float32,backend=backend](tens) |
| 360 | + # keep(res.unsafe_ptr()) |
| 361 | + # var report_rint = benchmark.run[test_rint]() |
| 362 | + # print('rint f32 100x100') |
| 363 | + # report_rint.print() |
| 364 | + # fn test_j0()capturing: |
| 365 | + # res = j0[DType.float32,backend=backend](tens) |
| 366 | + # keep(res.unsafe_ptr()) |
| 367 | + # var report_j0 = benchmark.run[test_j0]() |
| 368 | + # print('j0 f32 100x100') |
| 369 | + # report_j0.print() |
| 370 | + # fn test_j1()capturing: |
| 371 | + # res = j1[DType.float32,backend=backend](tens) |
| 372 | + # keep(res.unsafe_ptr()) |
| 373 | + # var report_j1 = benchmark.run[test_j1]() |
| 374 | + # print('j1 f32 100x100') |
| 375 | + # report_j1.print() |
| 376 | + # fn test_y0()capturing: |
| 377 | + # res = y0[DType.float32,backend=backend](tens) |
| 378 | + # keep(res.unsafe_ptr()) |
| 379 | + # var report_y0 = benchmark.run[test_y0]() |
| 380 | + # print('y0 f32 100x100') |
| 381 | + # report_y0.print() |
| 382 | + # fn test_y1()capturing: |
| 383 | + # res = y1[DType.float32,backend=backend](tens) |
| 384 | + # keep(res.unsafe_ptr()) |
| 385 | + # var report_y1 = benchmark.run[test_y1]() |
| 386 | + # print('y1 f32 100x100') |
| 387 | + # report_y1.print() |
| 388 | + # fn test_ulp()capturing: |
| 389 | + # res = ulp[DType.float32,backend=backend](tens) |
| 390 | + # keep(res.unsafe_ptr()) |
| 391 | + # var report_ulp = benchmark.run[test_ulp]() |
| 392 | + # print('ulp f32 100x100') |
| 393 | + # report_ulp.print() |
| 394 | + |
0 commit comments