mandelbrot_def.jl 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. include("mandelbrot.jl")
  17. function mandelbrot_with_starpu(A ::Matrix{Int64}, params ::Vector{Float64}, nslicesx ::Int64, nslicesy ::Int64) #mettre params en matrice. (pour que starpu le traite en matrice et non vecteur)
  18. vert = StarpuDataFilter(STARPU_MATRIX_FILTER_VERTICAL_BLOCK, nslicesy)
  19. horiz = StarpuDataFilter(STARPU_MATRIX_FILTER_BLOCK, nslicesx)
  20. @starpu_block let
  21. hA = starpu_data_register(A)
  22. hP = starpu_data_register(params)
  23. starpu_data_map_filters(hA, vert, horiz)
  24. @starpu_sync_tasks for tasky in (1:nslicesy)
  25. for taskx in (1 : nslicesx)
  26. @starpu_block let
  27. v = Int64[tasky, taskx] #C'est le x qu'on augmente en fonction du nombre de slicey. Si il y a trois colonnes, x sera coupé en 3. Donc on inverse dans v.
  28. hV = starpu_data_register(v)
  29. @starpu_async_cl cl(hA[tasky, taskx], hP, hV)
  30. end
  31. end
  32. end
  33. end
  34. return nothing
  35. end
  36. function mandelbrot_with_starpu_cpu(A ::Matrix{Int64}, params ::Vector{Float64}, nslicesx ::Int64, nslicesy ::Int64) #mettre params en matrice. (pour que starpu le traite en matrice et non vecteur)
  37. vert = StarpuDataFilter(STARPU_MATRIX_FILTER_VERTICAL_BLOCK, nslicesy)
  38. horiz = StarpuDataFilter(STARPU_MATRIX_FILTER_BLOCK, nslicesx)
  39. @starpu_block let
  40. hA = starpu_data_register(A)
  41. hP = starpu_data_register(params)
  42. starpu_data_map_filters(hA, vert, horiz)
  43. @starpu_sync_tasks for tasky in (1:nslicesy)
  44. for taskx in (1 : nslicesx)
  45. v = Int64[tasky, taskx] #C'est le x qu'on augmente en fonction du nombre de slicey. Si il y a trois colonnes, x sera coupé en 3. Donc on inverse dans v.
  46. hV = starpu_data_register(v)
  47. @starpu_async_cl clcpu(hA[tasky, taskx], hP, hV)
  48. end
  49. end
  50. end
  51. return nothing
  52. end
  53. function mandelbrot_with_starpu_gpu(A ::Matrix{Int64}, params ::Vector{Float64}, nslicesx ::Int64, nslicesy ::Int64) #mettre params en matrice. (pour que starpu le traite en matrice et non vecteur)
  54. vert = StarpuDataFilter(STARPU_MATRIX_FILTER_VERTICAL_BLOCK, nslicesx)
  55. horiz = StarpuDataFilter(STARPU_MATRIX_FILTER_BLOCK, nslicesy)
  56. @starpu_block let
  57. hA = starpu_data_register(A)
  58. hP = starpu_data_register(params)
  59. starpu_data_map_filters(hA, vert, horiz)
  60. @starpu_sync_tasks for taskx in (1:nslicesx)
  61. for tasky in (1 : nslicesy)
  62. v = Int64[taskx, tasky] #C'est le x qu'on augmente en fonction du nombre de slicey. Si il y a trois colonnes, x sera coupé en 3. Donc on inverse dans v.
  63. hV = starpu_data_register(v)
  64. @starpu_async_cl clgpu(hA[taskx, tasky], hP, hV)
  65. end
  66. end
  67. end
  68. return nothing
  69. end
  70. function init_zero(Pixels ::Matrix{Int64}, width ::Int64, height ::Int64)
  71. for i in 1:height
  72. for j in 1:width
  73. Pixels[i,j] = 0
  74. end
  75. end
  76. end
  77. function graph_pixels(Pixels ::Matrix{Int64}, width ::Int64, height ::Int64, filename ::String)
  78. open(filename, "w") do f
  79. write(f, "P3\n$width $height\n255\n")
  80. for i = 1:height
  81. for j = 1:width
  82. write(f, "$(Pixels[i,j]) 0 0 ")
  83. end
  84. write(f, "\n")
  85. end
  86. end
  87. end
  88. function median_times(nbr_tests ::Int64, cr ::Float64, ci ::Float64, dim ::Int64, nslices ::Int64)
  89. exec_times_st ::Vector{Float64} = [0 for i = 1:nbr_tests]
  90. exec_times_cpu ::Vector{Float64} = [0 for i = 1:nbr_tests]
  91. exec_times_gpu ::Vector{Float64} = [0 for i = 1:nbr_tests]
  92. exec_times_jl ::Vector{Float64} = [0 for i = 1:nbr_tests]
  93. Pixels_st ::Matrix{Int64} = zeros(dim, dim)
  94. Pixels_cpu ::Matrix{Int64} = copy(Pixels_st)
  95. Pixels_gpu ::Matrix{Int64} = copy(Pixels_st)
  96. Pixels_jl ::Matrix{Int64} = copy(Pixels_st)
  97. max_iter ::Float64 = (dim/2) * 0.049715909 * log10(dim * 0.25296875)
  98. params = [cr, ci, dim, dim, max_iter]
  99. for i = 1:nbr_tests
  100. tic()
  101. mandelbrot_with_starpu(Pixels_st, params, nslices, nslices)
  102. t = toq()
  103. exec_times_st[i] = t
  104. # tic()
  105. # mandelbrot_with_starpu_cpu(Pixels_cpu, params, nslices, nslices)
  106. # t = toq()
  107. # exec_times_cpu[i] = t
  108. # tic()
  109. # mandelbrot_with_starpu_gpu(Pixels_gpu, params, nslices, nslices)
  110. # t = toq()
  111. # exec_times_gpu[i] = t
  112. # tic()
  113. # mandelbrotjl(Pixels_jl, cr, ci)
  114. # t = toq()
  115. # exec_times_jl[i] = t
  116. end
  117. # graph_pixels(Pixels_st, dim, dim, "../PPM/mandelbrotst$(dim).ppm")
  118. # graph_pixels(Pixels_cpu, dim, dim, "../PPM/mandelbrotcpu$(dim).ppm")
  119. # graph_pixels(Pixels_gpu, dim, dim, "../PPM/mandelbrotgpu$(dim).ppm")
  120. # graph_pixels(Pixels_jl, dim, dim, "../PPM/mandelbrotjl$(dim).ppm")
  121. sort!(exec_times_st)
  122. # sort!(exec_times_cpu)
  123. # sort!(exec_times_gpu)
  124. # sort!(exec_times_jl)
  125. results ::Vector{Float64} = [exec_times_st[1 + div(nbr_tests-1, 2)]]
  126. # results ::Vector{Float64} = [exec_times_st[1 + div(nbr_tests-1, 2)]]#, exec_times_cpu[1 + div(nbr_tests-1, 2)], exec_times_gpu[1 + div(nbr_tests-1, 2)]]#, exec_times_jl[1 + div(nbr_tests-1, 2)]]
  127. return results
  128. end
  129. function display_time(cr ::Float64, ci ::Float64, start_dim ::Int64, step_dim ::Int64, stop_dim ::Int64, nslices ::Int64, nbr_tests ::Int64)
  130. # mtc = map( (x->parse(Float64,x)), open("../DAT/mandelbrot_c.dat") do f
  131. # readlines(f)
  132. # end)
  133. # mtgen = map( (x->parse(Float64,x)), open("../DAT/mandelbrot_with_generated_times.dat") do f
  134. # readlines(f)
  135. # end)
  136. mtjl = map( (x->parse(Float64,x)), open("../DAT/mandelbrot_jl_times.dat") do f
  137. readlines(f)
  138. end)
  139. # mtjlcpu = map( (x->parse(Float64,x)), open("../DAT/mandelbrot_jl_cpu.dat") do f
  140. # readlines(f)
  141. # end)
  142. mtstruct = map( (x->parse(Float64,x)), open("../DAT/mandelbrot_c_struct_times.dat") do f
  143. readlines(f)
  144. end)
  145. mtarray = map( (x->parse(Float64,x)), open("../DAT/mandelbrot_c_array_times.dat") do f
  146. readlines(f)
  147. end)
  148. i = 1
  149. # open("../DAT/mandelbrot.dat", "w") do f
  150. # open("../DAT/mandelbrot_gen_times.dat", "w") do ft
  151. open("../DAT/mandelbrot_speedups.dat", "w") do f
  152. for dim in (start_dim : step_dim : stop_dim)
  153. println("Dimension: $dim")
  154. res ::Vector{Float64} = median_times(nbr_tests, cr, ci, dim, nslices)
  155. # println("C: $(mtc[i])")
  156. # println("C with generated: $(mtgen[i])")
  157. # println("Julia with starpu: $(res[1])")
  158. # println("cpu: $(res[2])")
  159. println("c_struct: $(mtstruct[i])")
  160. println("c_array: $(mtarray[i])")
  161. println("jl_st: $(res[1])")
  162. # println("cpu: $(res[1])")
  163. # write(ft, "$(dim) $(res[1]) $(mtgen[i])\n")
  164. # write(f, "$(dim) $(res[4]/res[1]) $(res[4]/res[2]) $(res[4]/res[3]) $(res[4]/mtc[i])\n")
  165. write(f, "$(dim) $(mtjl[i]/res[1]) $(mtjl[i]/mtstruct[i]) $(mtjl[i]/mtarray[i])\n")
  166. # write(f, "$(res[1])\n")
  167. i = i + 1
  168. end
  169. end
  170. end