cholesky_native.jl 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # StarPU --- Runtime system for heterogeneous multicore architectures.
  2. #
  3. # Copyright (C) 2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. #
  5. # StarPU is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU Lesser General Public License as published by
  7. # the Free Software Foundation; either version 2.1 of the License, or (at
  8. # your option) any later version.
  9. #
  10. # StarPU is distributed in the hope that it will be useful, but
  11. # WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. #
  14. # See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. #
  16. using LinearAlgebra
  17. function check(mat::Matrix{Float32})
  18. size_p = size(mat, 1)
  19. for i in 1:size_p
  20. for j in 1:size_p
  21. if j < i
  22. mat[i, j] = 0.0f0
  23. end
  24. end
  25. end
  26. test_mat ::Matrix{Float32} = zeros(Float32, size_p, size_p)
  27. BLAS.syrk!('L', 'T', 1.0f0, mat, 0.0f0, test_mat)
  28. for i in 1:size_p
  29. for j in 1:size_p
  30. if j <= i
  31. orig = (1.0f0/(1.0f0+(i-1)+(j-1))) + ((i == j) ? 1.0f0*size_p : 0.0f0)
  32. err = abs(test_mat[i,j] - orig) / orig
  33. if err > 0.0001
  34. got = test_mat[i,j]
  35. expected = orig
  36. error("[$i, $j] -> $got != $expected (err $err)")
  37. end
  38. end
  39. end
  40. end
  41. println(stderr, "Verification successful !")
  42. end
  43. function main(size_p :: Int; verify = false, verbose = false)
  44. mat = zeros(Float32, size_p, size_p)
  45. # create a simple definite positive symetric matrix
  46. # Hilbert matrix h(i,j) = 1/(i+j+1)
  47. for i in 1:size_p
  48. for j in 1:size_p
  49. mat[i, j] = 1.0f0 / (1.0f0+(i-1)+(j-1)) + ((i == j) ? 1.0f0*size_p : 0.0f0)
  50. end
  51. end
  52. if verbose
  53. display(mat)
  54. end
  55. t_start = time_ns()
  56. cholesky!(mat)
  57. t_end = time_ns()
  58. flop = (1.0*size_p*size_p*size_p)/3.0
  59. time_ms = (t_end-t_start) / 1e6
  60. gflops = flop/(time_ms*1000)/1000
  61. println("$size_p\t$time_ms\t$gflops")
  62. if verbose
  63. display(mat)
  64. end
  65. if verify
  66. check(mat)
  67. end
  68. end
  69. println("# size\tms\tGFlops")
  70. if length(ARGS) > 0 && ARGS[1] == "-quickcheck"
  71. main(1024, verify = true)
  72. else
  73. for size in 1024:1024:15360
  74. main(size)
  75. end
  76. end